2 * QEMU MC146818 RTC emulation
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu-timer.h"
27 #include "mc146818rtc.h"
34 //#define DEBUG_COALESCED
37 # define CMOS_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
39 # define CMOS_DPRINTF(format, ...) do { } while (0)
42 #ifdef DEBUG_COALESCED
43 # define DPRINTF_C(format, ...) printf(format, ## __VA_ARGS__)
45 # define DPRINTF_C(format, ...) do { } while (0)
48 #define RTC_REINJECT_ON_ACK_COUNT 20
49 #define RTC_CLOCK_RATE 32768
51 typedef struct RTCState
{
54 uint8_t cmos_data
[128];
62 QEMUTimer
*periodic_timer
;
63 int64_t next_periodic_time
;
65 int64_t next_second_time
;
66 uint16_t irq_reinject_on_ack_count
;
67 uint32_t irq_coalesced
;
69 QEMUTimer
*coalesced_timer
;
70 QEMUTimer
*second_timer
;
71 QEMUTimer
*second_timer2
;
72 Notifier clock_reset_notifier
;
73 LostTickPolicy lost_tick_policy
;
74 Notifier suspend_notifier
;
77 static void rtc_set_time(RTCState
*s
);
78 static void rtc_copy_date(RTCState
*s
);
81 static void rtc_coalesced_timer_update(RTCState
*s
)
83 if (s
->irq_coalesced
== 0) {
84 qemu_del_timer(s
->coalesced_timer
);
86 /* divide each RTC interval to 2 - 8 smaller intervals */
87 int c
= MIN(s
->irq_coalesced
, 7) + 1;
88 int64_t next_clock
= qemu_get_clock_ns(rtc_clock
) +
89 muldiv64(s
->period
/ c
, get_ticks_per_sec(), RTC_CLOCK_RATE
);
90 qemu_mod_timer(s
->coalesced_timer
, next_clock
);
94 static void rtc_coalesced_timer(void *opaque
)
98 if (s
->irq_coalesced
!= 0) {
99 apic_reset_irq_delivered();
100 s
->cmos_data
[RTC_REG_C
] |= 0xc0;
101 DPRINTF_C("cmos: injecting from timer\n");
102 qemu_irq_raise(s
->irq
);
103 if (apic_get_irq_delivered()) {
105 DPRINTF_C("cmos: coalesced irqs decreased to %d\n",
110 rtc_coalesced_timer_update(s
);
114 static void periodic_timer_update(RTCState
*s
, int64_t current_time
)
116 int period_code
, period
;
117 int64_t cur_clock
, next_irq_clock
;
119 period_code
= s
->cmos_data
[RTC_REG_A
] & 0x0f;
121 && ((s
->cmos_data
[RTC_REG_B
] & REG_B_PIE
)
122 || ((s
->cmos_data
[RTC_REG_B
] & REG_B_SQWE
) && s
->sqw_irq
))) {
123 if (period_code
<= 2)
125 /* period in 32 Khz cycles */
126 period
= 1 << (period_code
- 1);
128 if (period
!= s
->period
) {
129 s
->irq_coalesced
= (s
->irq_coalesced
* s
->period
) / period
;
130 DPRINTF_C("cmos: coalesced irqs scaled to %d\n", s
->irq_coalesced
);
134 /* compute 32 khz clock */
135 cur_clock
= muldiv64(current_time
, RTC_CLOCK_RATE
, get_ticks_per_sec());
136 next_irq_clock
= (cur_clock
& ~(period
- 1)) + period
;
137 s
->next_periodic_time
=
138 muldiv64(next_irq_clock
, get_ticks_per_sec(), RTC_CLOCK_RATE
) + 1;
139 qemu_mod_timer(s
->periodic_timer
, s
->next_periodic_time
);
142 s
->irq_coalesced
= 0;
144 qemu_del_timer(s
->periodic_timer
);
148 static void rtc_periodic_timer(void *opaque
)
150 RTCState
*s
= opaque
;
152 periodic_timer_update(s
, s
->next_periodic_time
);
153 s
->cmos_data
[RTC_REG_C
] |= REG_C_PF
;
154 if (s
->cmos_data
[RTC_REG_B
] & REG_B_PIE
) {
155 s
->cmos_data
[RTC_REG_C
] |= REG_C_IRQF
;
157 if (s
->lost_tick_policy
== LOST_TICK_SLEW
) {
158 if (s
->irq_reinject_on_ack_count
>= RTC_REINJECT_ON_ACK_COUNT
)
159 s
->irq_reinject_on_ack_count
= 0;
160 apic_reset_irq_delivered();
161 qemu_irq_raise(s
->irq
);
162 if (!apic_get_irq_delivered()) {
164 rtc_coalesced_timer_update(s
);
165 DPRINTF_C("cmos: coalesced irqs increased to %d\n",
170 qemu_irq_raise(s
->irq
);
172 if (s
->cmos_data
[RTC_REG_B
] & REG_B_SQWE
) {
173 /* Not square wave at all but we don't want 2048Hz interrupts!
174 Must be seen as a pulse. */
175 qemu_irq_raise(s
->sqw_irq
);
179 static void cmos_ioport_write(void *opaque
, uint32_t addr
, uint32_t data
)
181 RTCState
*s
= opaque
;
183 if ((addr
& 1) == 0) {
184 s
->cmos_index
= data
& 0x7f;
186 CMOS_DPRINTF("cmos: write index=0x%02x val=0x%02x\n",
187 s
->cmos_index
, data
);
188 switch(s
->cmos_index
) {
189 case RTC_SECONDS_ALARM
:
190 case RTC_MINUTES_ALARM
:
191 case RTC_HOURS_ALARM
:
192 s
->cmos_data
[s
->cmos_index
] = data
;
197 case RTC_DAY_OF_WEEK
:
198 case RTC_DAY_OF_MONTH
:
201 s
->cmos_data
[s
->cmos_index
] = data
;
202 /* if in set mode, do not update the time */
203 if (!(s
->cmos_data
[RTC_REG_B
] & REG_B_SET
)) {
208 /* UIP bit is read only */
209 s
->cmos_data
[RTC_REG_A
] = (data
& ~REG_A_UIP
) |
210 (s
->cmos_data
[RTC_REG_A
] & REG_A_UIP
);
211 periodic_timer_update(s
, qemu_get_clock_ns(rtc_clock
));
214 if (data
& REG_B_SET
) {
215 /* set mode: reset UIP mode */
216 s
->cmos_data
[RTC_REG_A
] &= ~REG_A_UIP
;
219 /* if disabling set mode, update the time */
220 if (s
->cmos_data
[RTC_REG_B
] & REG_B_SET
) {
224 s
->cmos_data
[RTC_REG_B
] = data
;
225 periodic_timer_update(s
, qemu_get_clock_ns(rtc_clock
));
229 /* cannot write to them */
232 s
->cmos_data
[s
->cmos_index
] = data
;
238 static inline int rtc_to_bcd(RTCState
*s
, int a
)
240 if (s
->cmos_data
[RTC_REG_B
] & REG_B_DM
) {
243 return ((a
/ 10) << 4) | (a
% 10);
247 static inline int rtc_from_bcd(RTCState
*s
, int a
)
249 if (s
->cmos_data
[RTC_REG_B
] & REG_B_DM
) {
252 return ((a
>> 4) * 10) + (a
& 0x0f);
256 static void rtc_set_time(RTCState
*s
)
258 struct tm
*tm
= &s
->current_tm
;
260 tm
->tm_sec
= rtc_from_bcd(s
, s
->cmos_data
[RTC_SECONDS
]);
261 tm
->tm_min
= rtc_from_bcd(s
, s
->cmos_data
[RTC_MINUTES
]);
262 tm
->tm_hour
= rtc_from_bcd(s
, s
->cmos_data
[RTC_HOURS
] & 0x7f);
263 if (!(s
->cmos_data
[RTC_REG_B
] & REG_B_24H
)) {
265 if (s
->cmos_data
[RTC_HOURS
] & 0x80) {
269 tm
->tm_wday
= rtc_from_bcd(s
, s
->cmos_data
[RTC_DAY_OF_WEEK
]) - 1;
270 tm
->tm_mday
= rtc_from_bcd(s
, s
->cmos_data
[RTC_DAY_OF_MONTH
]);
271 tm
->tm_mon
= rtc_from_bcd(s
, s
->cmos_data
[RTC_MONTH
]) - 1;
272 tm
->tm_year
= rtc_from_bcd(s
, s
->cmos_data
[RTC_YEAR
]) + s
->base_year
- 1900;
274 rtc_change_mon_event(tm
);
277 static void rtc_copy_date(RTCState
*s
)
279 const struct tm
*tm
= &s
->current_tm
;
282 s
->cmos_data
[RTC_SECONDS
] = rtc_to_bcd(s
, tm
->tm_sec
);
283 s
->cmos_data
[RTC_MINUTES
] = rtc_to_bcd(s
, tm
->tm_min
);
284 if (s
->cmos_data
[RTC_REG_B
] & REG_B_24H
) {
286 s
->cmos_data
[RTC_HOURS
] = rtc_to_bcd(s
, tm
->tm_hour
);
289 int h
= (tm
->tm_hour
% 12) ? tm
->tm_hour
% 12 : 12;
290 s
->cmos_data
[RTC_HOURS
] = rtc_to_bcd(s
, h
);
291 if (tm
->tm_hour
>= 12)
292 s
->cmos_data
[RTC_HOURS
] |= 0x80;
294 s
->cmos_data
[RTC_DAY_OF_WEEK
] = rtc_to_bcd(s
, tm
->tm_wday
+ 1);
295 s
->cmos_data
[RTC_DAY_OF_MONTH
] = rtc_to_bcd(s
, tm
->tm_mday
);
296 s
->cmos_data
[RTC_MONTH
] = rtc_to_bcd(s
, tm
->tm_mon
+ 1);
297 year
= (tm
->tm_year
- s
->base_year
) % 100;
300 s
->cmos_data
[RTC_YEAR
] = rtc_to_bcd(s
, year
);
303 /* month is between 0 and 11. */
304 static int get_days_in_month(int month
, int year
)
306 static const int days_tab
[12] = {
307 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
310 if ((unsigned )month
>= 12)
314 if ((year
% 4) == 0 && ((year
% 100) != 0 || (year
% 400) == 0))
320 /* update 'tm' to the next second */
321 static void rtc_next_second(struct tm
*tm
)
326 if ((unsigned)tm
->tm_sec
>= 60) {
329 if ((unsigned)tm
->tm_min
>= 60) {
332 if ((unsigned)tm
->tm_hour
>= 24) {
336 if ((unsigned)tm
->tm_wday
>= 7)
338 days_in_month
= get_days_in_month(tm
->tm_mon
,
341 if (tm
->tm_mday
< 1) {
343 } else if (tm
->tm_mday
> days_in_month
) {
346 if (tm
->tm_mon
>= 12) {
357 static void rtc_update_second(void *opaque
)
359 RTCState
*s
= opaque
;
362 /* if the oscillator is not in normal operation, we do not update */
363 if ((s
->cmos_data
[RTC_REG_A
] & 0x70) != 0x20) {
364 s
->next_second_time
+= get_ticks_per_sec();
365 qemu_mod_timer(s
->second_timer
, s
->next_second_time
);
367 rtc_next_second(&s
->current_tm
);
369 if (!(s
->cmos_data
[RTC_REG_B
] & REG_B_SET
)) {
370 /* update in progress bit */
371 s
->cmos_data
[RTC_REG_A
] |= REG_A_UIP
;
373 /* should be 244 us = 8 / RTC_CLOCK_RATE seconds, but currently the
374 timers do not have the necessary resolution. */
375 delay
= (get_ticks_per_sec() * 1) / 100;
378 qemu_mod_timer(s
->second_timer2
,
379 s
->next_second_time
+ delay
);
383 static void rtc_update_second2(void *opaque
)
385 RTCState
*s
= opaque
;
387 if (!(s
->cmos_data
[RTC_REG_B
] & REG_B_SET
)) {
392 if (((s
->cmos_data
[RTC_SECONDS_ALARM
] & 0xc0) == 0xc0 ||
393 rtc_from_bcd(s
, s
->cmos_data
[RTC_SECONDS_ALARM
]) == s
->current_tm
.tm_sec
) &&
394 ((s
->cmos_data
[RTC_MINUTES_ALARM
] & 0xc0) == 0xc0 ||
395 rtc_from_bcd(s
, s
->cmos_data
[RTC_MINUTES_ALARM
]) == s
->current_tm
.tm_min
) &&
396 ((s
->cmos_data
[RTC_HOURS_ALARM
] & 0xc0) == 0xc0 ||
397 rtc_from_bcd(s
, s
->cmos_data
[RTC_HOURS_ALARM
]) == s
->current_tm
.tm_hour
)) {
399 s
->cmos_data
[RTC_REG_C
] |= REG_C_AF
;
400 if (s
->cmos_data
[RTC_REG_B
] & REG_B_AIE
) {
401 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_RTC
);
402 qemu_irq_raise(s
->irq
);
403 s
->cmos_data
[RTC_REG_C
] |= REG_C_IRQF
;
407 /* update ended interrupt */
408 s
->cmos_data
[RTC_REG_C
] |= REG_C_UF
;
409 if (s
->cmos_data
[RTC_REG_B
] & REG_B_UIE
) {
410 s
->cmos_data
[RTC_REG_C
] |= REG_C_IRQF
;
411 qemu_irq_raise(s
->irq
);
414 /* clear update in progress bit */
415 s
->cmos_data
[RTC_REG_A
] &= ~REG_A_UIP
;
417 s
->next_second_time
+= get_ticks_per_sec();
418 qemu_mod_timer(s
->second_timer
, s
->next_second_time
);
421 static uint32_t cmos_ioport_read(void *opaque
, uint32_t addr
)
423 RTCState
*s
= opaque
;
425 if ((addr
& 1) == 0) {
428 switch(s
->cmos_index
) {
432 case RTC_DAY_OF_WEEK
:
433 case RTC_DAY_OF_MONTH
:
436 ret
= s
->cmos_data
[s
->cmos_index
];
439 ret
= s
->cmos_data
[s
->cmos_index
];
442 ret
= s
->cmos_data
[s
->cmos_index
];
443 qemu_irq_lower(s
->irq
);
444 s
->cmos_data
[RTC_REG_C
] = 0x00;
446 if(s
->irq_coalesced
&&
447 (s
->cmos_data
[RTC_REG_B
] & REG_B_PIE
) &&
448 s
->irq_reinject_on_ack_count
< RTC_REINJECT_ON_ACK_COUNT
) {
449 s
->irq_reinject_on_ack_count
++;
450 s
->cmos_data
[RTC_REG_C
] |= REG_C_IRQF
| REG_C_PF
;
451 apic_reset_irq_delivered();
452 DPRINTF_C("cmos: injecting on ack\n");
453 qemu_irq_raise(s
->irq
);
454 if (apic_get_irq_delivered()) {
456 DPRINTF_C("cmos: coalesced irqs decreased to %d\n",
463 ret
= s
->cmos_data
[s
->cmos_index
];
466 CMOS_DPRINTF("cmos: read index=0x%02x val=0x%02x\n",
472 void rtc_set_memory(ISADevice
*dev
, int addr
, int val
)
474 RTCState
*s
= DO_UPCAST(RTCState
, dev
, dev
);
475 if (addr
>= 0 && addr
<= 127)
476 s
->cmos_data
[addr
] = val
;
479 void rtc_set_date(ISADevice
*dev
, const struct tm
*tm
)
481 RTCState
*s
= DO_UPCAST(RTCState
, dev
, dev
);
486 /* PC cmos mappings */
487 #define REG_IBM_CENTURY_BYTE 0x32
488 #define REG_IBM_PS2_CENTURY_BYTE 0x37
490 static void rtc_set_date_from_host(ISADevice
*dev
)
492 RTCState
*s
= DO_UPCAST(RTCState
, dev
, dev
);
496 /* set the CMOS date */
497 qemu_get_timedate(&tm
, 0);
498 rtc_set_date(dev
, &tm
);
500 val
= rtc_to_bcd(s
, (tm
.tm_year
/ 100) + 19);
501 rtc_set_memory(dev
, REG_IBM_CENTURY_BYTE
, val
);
502 rtc_set_memory(dev
, REG_IBM_PS2_CENTURY_BYTE
, val
);
505 static int rtc_post_load(void *opaque
, int version_id
)
508 RTCState
*s
= opaque
;
510 if (version_id
>= 2) {
511 if (s
->lost_tick_policy
== LOST_TICK_SLEW
) {
512 rtc_coalesced_timer_update(s
);
519 static const VMStateDescription vmstate_rtc
= {
520 .name
= "mc146818rtc",
522 .minimum_version_id
= 1,
523 .minimum_version_id_old
= 1,
524 .post_load
= rtc_post_load
,
525 .fields
= (VMStateField
[]) {
526 VMSTATE_BUFFER(cmos_data
, RTCState
),
527 VMSTATE_UINT8(cmos_index
, RTCState
),
528 VMSTATE_INT32(current_tm
.tm_sec
, RTCState
),
529 VMSTATE_INT32(current_tm
.tm_min
, RTCState
),
530 VMSTATE_INT32(current_tm
.tm_hour
, RTCState
),
531 VMSTATE_INT32(current_tm
.tm_wday
, RTCState
),
532 VMSTATE_INT32(current_tm
.tm_mday
, RTCState
),
533 VMSTATE_INT32(current_tm
.tm_mon
, RTCState
),
534 VMSTATE_INT32(current_tm
.tm_year
, RTCState
),
535 VMSTATE_TIMER(periodic_timer
, RTCState
),
536 VMSTATE_INT64(next_periodic_time
, RTCState
),
537 VMSTATE_INT64(next_second_time
, RTCState
),
538 VMSTATE_TIMER(second_timer
, RTCState
),
539 VMSTATE_TIMER(second_timer2
, RTCState
),
540 VMSTATE_UINT32_V(irq_coalesced
, RTCState
, 2),
541 VMSTATE_UINT32_V(period
, RTCState
, 2),
542 VMSTATE_END_OF_LIST()
546 static void rtc_notify_clock_reset(Notifier
*notifier
, void *data
)
548 RTCState
*s
= container_of(notifier
, RTCState
, clock_reset_notifier
);
549 int64_t now
= *(int64_t *)data
;
551 rtc_set_date_from_host(&s
->dev
);
552 s
->next_second_time
= now
+ (get_ticks_per_sec() * 99) / 100;
553 qemu_mod_timer(s
->second_timer2
, s
->next_second_time
);
554 periodic_timer_update(s
, now
);
556 if (s
->lost_tick_policy
== LOST_TICK_SLEW
) {
557 rtc_coalesced_timer_update(s
);
562 /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
563 BIOS will read it and start S3 resume at POST Entry */
564 static void rtc_notify_suspend(Notifier
*notifier
, void *data
)
566 RTCState
*s
= container_of(notifier
, RTCState
, suspend_notifier
);
567 rtc_set_memory(&s
->dev
, 0xF, 0xFE);
570 static void rtc_reset(void *opaque
)
572 RTCState
*s
= opaque
;
574 s
->cmos_data
[RTC_REG_B
] &= ~(REG_B_PIE
| REG_B_AIE
| REG_B_SQWE
);
575 s
->cmos_data
[RTC_REG_C
] &= ~(REG_C_UF
| REG_C_IRQF
| REG_C_PF
| REG_C_AF
);
577 qemu_irq_lower(s
->irq
);
580 if (s
->lost_tick_policy
== LOST_TICK_SLEW
) {
581 s
->irq_coalesced
= 0;
586 static const MemoryRegionPortio cmos_portio
[] = {
587 {0, 2, 1, .read
= cmos_ioport_read
, .write
= cmos_ioport_write
},
588 PORTIO_END_OF_LIST(),
591 static const MemoryRegionOps cmos_ops
= {
592 .old_portio
= cmos_portio
595 static void rtc_get_date(Object
*obj
, Visitor
*v
, void *opaque
,
596 const char *name
, Error
**errp
)
598 ISADevice
*isa
= ISA_DEVICE(obj
);
599 RTCState
*s
= DO_UPCAST(RTCState
, dev
, isa
);
601 visit_start_struct(v
, NULL
, "struct tm", name
, 0, errp
);
602 visit_type_int32(v
, &s
->current_tm
.tm_year
, "tm_year", errp
);
603 visit_type_int32(v
, &s
->current_tm
.tm_mon
, "tm_mon", errp
);
604 visit_type_int32(v
, &s
->current_tm
.tm_mday
, "tm_mday", errp
);
605 visit_type_int32(v
, &s
->current_tm
.tm_hour
, "tm_hour", errp
);
606 visit_type_int32(v
, &s
->current_tm
.tm_min
, "tm_min", errp
);
607 visit_type_int32(v
, &s
->current_tm
.tm_sec
, "tm_sec", errp
);
608 visit_end_struct(v
, errp
);
611 static int rtc_initfn(ISADevice
*dev
)
613 RTCState
*s
= DO_UPCAST(RTCState
, dev
, dev
);
616 s
->cmos_data
[RTC_REG_A
] = 0x26;
617 s
->cmos_data
[RTC_REG_B
] = 0x02;
618 s
->cmos_data
[RTC_REG_C
] = 0x00;
619 s
->cmos_data
[RTC_REG_D
] = 0x80;
621 rtc_set_date_from_host(dev
);
624 switch (s
->lost_tick_policy
) {
627 qemu_new_timer_ns(rtc_clock
, rtc_coalesced_timer
, s
);
629 case LOST_TICK_DISCARD
:
636 s
->periodic_timer
= qemu_new_timer_ns(rtc_clock
, rtc_periodic_timer
, s
);
637 s
->second_timer
= qemu_new_timer_ns(rtc_clock
, rtc_update_second
, s
);
638 s
->second_timer2
= qemu_new_timer_ns(rtc_clock
, rtc_update_second2
, s
);
640 s
->clock_reset_notifier
.notify
= rtc_notify_clock_reset
;
641 qemu_register_clock_reset_notifier(rtc_clock
, &s
->clock_reset_notifier
);
643 s
->suspend_notifier
.notify
= rtc_notify_suspend
;
644 qemu_register_suspend_notifier(&s
->suspend_notifier
);
646 s
->next_second_time
=
647 qemu_get_clock_ns(rtc_clock
) + (get_ticks_per_sec() * 99) / 100;
648 qemu_mod_timer(s
->second_timer2
, s
->next_second_time
);
650 memory_region_init_io(&s
->io
, &cmos_ops
, s
, "rtc", 2);
651 isa_register_ioport(dev
, &s
->io
, base
);
653 qdev_set_legacy_instance_id(&dev
->qdev
, base
, 2);
654 qemu_register_reset(rtc_reset
, s
);
656 object_property_add(OBJECT(s
), "date", "struct tm",
657 rtc_get_date
, NULL
, NULL
, s
, NULL
);
662 ISADevice
*rtc_init(ISABus
*bus
, int base_year
, qemu_irq intercept_irq
)
667 dev
= isa_create(bus
, "mc146818rtc");
668 s
= DO_UPCAST(RTCState
, dev
, dev
);
669 qdev_prop_set_int32(&dev
->qdev
, "base_year", base_year
);
670 qdev_init_nofail(&dev
->qdev
);
672 s
->irq
= intercept_irq
;
674 isa_init_irq(dev
, &s
->irq
, RTC_ISA_IRQ
);
679 static Property mc146818rtc_properties
[] = {
680 DEFINE_PROP_INT32("base_year", RTCState
, base_year
, 1980),
681 DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", RTCState
,
682 lost_tick_policy
, LOST_TICK_DISCARD
),
683 DEFINE_PROP_END_OF_LIST(),
686 static void rtc_class_initfn(ObjectClass
*klass
, void *data
)
688 DeviceClass
*dc
= DEVICE_CLASS(klass
);
689 ISADeviceClass
*ic
= ISA_DEVICE_CLASS(klass
);
690 ic
->init
= rtc_initfn
;
692 dc
->vmsd
= &vmstate_rtc
;
693 dc
->props
= mc146818rtc_properties
;
696 static TypeInfo mc146818rtc_info
= {
697 .name
= "mc146818rtc",
698 .parent
= TYPE_ISA_DEVICE
,
699 .instance_size
= sizeof(RTCState
),
700 .class_init
= rtc_class_initfn
,
703 static void mc146818rtc_register_types(void)
705 type_register_static(&mc146818rtc_info
);
708 type_init(mc146818rtc_register_types
)