1 /* 2 * QEMU MC146818 RTC emulation 3 * 4 * Copyright (c) 2003-2004 Fabrice Bellard 5 * 6 * SPDX-License-Identifier: MIT 7 */ 8 9 #ifndef HW_RTC_MC146818RTC_H 10 #define HW_RTC_MC146818RTC_H 11 12 #include "qapi/qapi-types-machine.h" 13 #include "qemu/queue.h" 14 #include "qemu/timer.h" 15 #include "hw/isa/isa.h" 16 #include "qom/object.h" 17 18 #define TYPE_MC146818_RTC "mc146818rtc" 19 OBJECT_DECLARE_SIMPLE_TYPE(MC146818RtcState, MC146818_RTC) 20 21 struct MC146818RtcState { 22 ISADevice parent_obj; 23 24 MemoryRegion io; 25 MemoryRegion coalesced_io; 26 uint8_t cmos_data[128]; 27 uint8_t cmos_index; 28 uint8_t isairq; 29 uint16_t io_base; 30 int32_t base_year; 31 uint64_t base_rtc; 32 uint64_t last_update; 33 int64_t offset; 34 qemu_irq irq; 35 int it_shift; 36 /* periodic timer */ 37 QEMUTimer *periodic_timer; 38 int64_t next_periodic_time; 39 /* update-ended timer */ 40 QEMUTimer *update_timer; 41 uint64_t next_alarm_time; 42 uint16_t irq_reinject_on_ack_count; 43 uint32_t irq_coalesced; 44 uint32_t period; 45 QEMUTimer *coalesced_timer; 46 Notifier clock_reset_notifier; 47 LostTickPolicy lost_tick_policy; 48 Notifier suspend_notifier; 49 QLIST_ENTRY(MC146818RtcState) link; 50 }; 51 52 #define RTC_ISA_IRQ 8 53 54 MC146818RtcState *mc146818_rtc_init(ISABus *bus, int base_year, 55 qemu_irq intercept_irq); 56 void mc146818rtc_set_cmos_data(MC146818RtcState *s, int addr, int val); 57 int mc146818rtc_get_cmos_data(MC146818RtcState *s, int addr); 58 void rtc_reset_reinjection(MC146818RtcState *rtc); 59 60 #endif /* HW_RTC_MC146818RTC_H */ 61