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 #include "qom/object.h" 17 18 #define TYPE_MC146818_RTC "mc146818rtc" 19 typedef struct RTCState RTCState; 20 DECLARE_INSTANCE_CHECKER(RTCState, MC146818_RTC, 21 TYPE_MC146818_RTC) 22 23 struct RTCState { 24 ISADevice parent_obj; 25 26 MemoryRegion io; 27 MemoryRegion coalesced_io; 28 uint8_t cmos_data[128]; 29 uint8_t cmos_index; 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(RTCState) link; 50 }; 51 52 #define RTC_ISA_IRQ 8 53 #define RTC_ISA_BASE 0x70 54 55 ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, 56 qemu_irq intercept_irq); 57 void rtc_set_memory(ISADevice *dev, int addr, int val); 58 int rtc_get_memory(ISADevice *dev, int addr); 59 60 #endif /* MC146818RTC_H */ 61