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-misc.h" 13 #include "qemu/queue.h" 14 #include "qemu/timer.h" 15 #include "hw/isa/isa.h" 16 17 #define TYPE_MC146818_RTC "mc146818rtc" 18 #define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC) 19 20 typedef struct RTCState { 21 ISADevice parent_obj; 22 23 MemoryRegion io; 24 MemoryRegion coalesced_io; 25 uint8_t cmos_data[128]; 26 uint8_t cmos_index; 27 int32_t base_year; 28 uint64_t base_rtc; 29 uint64_t last_update; 30 int64_t offset; 31 qemu_irq irq; 32 int it_shift; 33 /* periodic timer */ 34 QEMUTimer *periodic_timer; 35 int64_t next_periodic_time; 36 /* update-ended timer */ 37 QEMUTimer *update_timer; 38 uint64_t next_alarm_time; 39 uint16_t irq_reinject_on_ack_count; 40 uint32_t irq_coalesced; 41 uint32_t period; 42 QEMUTimer *coalesced_timer; 43 Notifier clock_reset_notifier; 44 LostTickPolicy lost_tick_policy; 45 Notifier suspend_notifier; 46 QLIST_ENTRY(RTCState) link; 47 } RTCState; 48 49 #define RTC_ISA_IRQ 8 50 51 ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, 52 qemu_irq intercept_irq); 53 void rtc_set_memory(ISADevice *dev, int addr, int val); 54 int rtc_get_memory(ISADevice *dev, int addr); 55 56 #endif /* MC146818RTC_H */ 57