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(RTCState, MC146818_RTC) 20 21 struct RTCState { 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 int32_t base_year; 30 uint64_t base_rtc; 31 uint64_t last_update; 32 int64_t offset; 33 qemu_irq irq; 34 int it_shift; 35 /* periodic timer */ 36 QEMUTimer *periodic_timer; 37 int64_t next_periodic_time; 38 /* update-ended timer */ 39 QEMUTimer *update_timer; 40 uint64_t next_alarm_time; 41 uint16_t irq_reinject_on_ack_count; 42 uint32_t irq_coalesced; 43 uint32_t period; 44 QEMUTimer *coalesced_timer; 45 Notifier clock_reset_notifier; 46 LostTickPolicy lost_tick_policy; 47 Notifier suspend_notifier; 48 QLIST_ENTRY(RTCState) link; 49 }; 50 51 #define RTC_ISA_IRQ 8 52 #define RTC_ISA_BASE 0x70 53 54 ISADevice *mc146818_rtc_init(ISABus *bus, int base_year, 55 qemu_irq intercept_irq); 56 void rtc_set_memory(ISADevice *dev, int addr, int val); 57 int rtc_get_memory(ISADevice *dev, int addr); 58 59 #endif /* MC146818RTC_H */ 60