Add rtc reset function.
PATCH v2 1/1 Add rtc reset function.
On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zero
hw/mc146818rtc.c +23 -0
@@ -57,6 +57,11 @@#define REG_B_SQWE 0x08#define REG_B_DM 0x04 +#define REG_C_UF 0x10 +#define REG_C_IRQF 0x80 +#define REG_C_PF 0x40 +#define REG_C_AF 0x20 +struct RTCState {uint8_t cmos_data[128 ];uint8_t cmos_index;
@@ -568,6 +573,21 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) }#endif +static void rtc_reset (void *opaque) +{ +RTCState *s = opaque; + + s->cmos_data[RTC_REG_B ] &= ~(REG_B_PIE |REG_B_AIE |REG_B_SQWE ); + s->cmos_data[RTC_REG_C ] &= ~(REG_C_UF |REG_C_IRQF |REG_C_PF |REG_C_AF ); + +qemu_irq_lower (s->irq); + +#ifdef TARGET_I386 +if (rtc_td_hack) + s->irq_coalesced =0 ; +#endif +} +RTCState *rtc_init_sqw (int base,qemu_irq irq,qemu_irq sqw_irq,int base_year) {RTCState *s;
@@ -606,6 +626,8 @@ RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)if (rtc_td_hack)register_savevm ("mc146818rtc-td" , base,1 , rtc_save_td, rtc_load_td, s);#endif +qemu_register_reset (rtc_reset,0 , s); +return s; }
@@ -721,5 +743,6 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,if (rtc_td_hack)register_savevm ("mc146818rtc-td" , base,1 , rtc_save_td, rtc_load_td, s);#endif +qemu_register_reset (rtc_reset,0 , s);return s; }
--
Gleb.
Quoted 32 lines · Gleb Natapov
On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zeroSigned-off-by Gleb Natapov <[email protected]>hw/mc146818rtc.c +7
-0@@ -57,6 +57,11 @@#define REG_B_SQWE 0x08#define REG_B_DM 0x04 +#define REG_C_UF 0x10 +#define REG_C_IRQF 0x80 +#define REG_C_PF 0x40 +#define REG_C_AF 0x20 +struct RTCState {uint8_t cmos_data[128 ];uint8_t cmos_index;@@ -568,6 +573,21 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) }#endif +static void rtc_reset (void *opaque) +{
hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 587
Quoted 10 lines
hw/mc146818rtc.c +10
-0+RTCState *s = opaque; + + s->cmos_data[RTC_REG_B ] &= ~(REG_B_PIE |REG_B_AIE |REG_B_SQWE ); + s->cmos_data[RTC_REG_C ] &= ~(REG_C_UF |REG_C_IRQF |REG_C_PF |REG_C_AF ); + +qemu_irq_lower (s->irq); + +#ifdef TARGET_I386 +if (rtc_td_hack) + s->irq_coalesced =0 ;
Sorry, missed that on first run: Isn't it safer, clearer, more beautiful to reset this unconditionally?
Jan
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
hw/mc146818rtc.c +7
-0+static void rtc_reset (void *opaque) +{ +RTCState *s = opaque; + + s->cmos_data[RTC_REG_B ] &= ~(REG_B_PIE |REG_B_AIE |REG_B_SQWE ); + s->cmos_data[RTC_REG_C ] &= ~(REG_C_UF |REG_C_IRQF |REG_C_PF |REG_C_AF ); +
Quoted 9 lines
hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 587
Quoted 5 lines
hw/mc146818rtc.c +5
-0+qemu_irq_lower (s->irq); + +#ifdef TARGET_I386 +if (rtc_td_hack) + s->irq_coalesced =0 ;Sorry, missed that on first run: Isn't it safer, clearer, more beautiful to reset this unconditionally?
It doesn't really matter. From safety point of view the code is safe.
--
Gleb.
Quoted 19 lines · Gleb Natapov
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
hw/mc146818rtc.c +7
-0+static void rtc_reset (void *opaque) +{ +RTCState *s = opaque; + + s->cmos_data[RTC_REG_B ] &= ~(REG_B_PIE |REG_B_AIE |REG_B_SQWE ); + s->cmos_data[RTC_REG_C ] &= ~(REG_C_UF |REG_C_IRQF |REG_C_PF |REG_C_AF ); +Quoted 10 lines
hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 587
Quoted 6 lines
hw/mc146818rtc.c +5
-0+qemu_irq_lower (s->irq); + +#ifdef TARGET_I386 +if (rtc_td_hack) + s->irq_coalesced =0 ;Sorry, missed that on first run: Isn't it safer, clearer, more beautiful to reset this unconditionally?
Quoted 3 lines
It doesn't really matter. From safety point of view the code is safe.
Actually we should drop this rtc-td-hack flag entirely.
The time drift fix is now only compiled for x86 so it will be harmless for other arch. Users are affected by not calling it although it is a must for every OS that uses rtc clock source and cannot deal with drifts (aka all windows, and some of the Linux guests).
Anthony, will you accept such a patch to remove rtc-td-hack or at least change it's default?
Quoted 5 lines
--
Gleb.
Quoted 34 lines · Gleb Natapov
On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zeroSigned-off-by Gleb Natapov <[email protected]>hw/mc146818rtc.c +9
-0@@ -57,6 +57,11 @@#define REG_B_SQWE 0x08#define REG_B_DM 0x04 +#define REG_C_UF 0x10 +#define REG_C_IRQF 0x80 +#define REG_C_PF 0x40 +#define REG_C_AF 0x20 +struct RTCState {uint8_t cmos_data[128 ];uint8_t cmos_index;@@ -568,6 +573,21 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) }#endif +static void rtc_reset (void *opaque) +{ +RTCState *s = opaque; +
hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 589
Quoted 10 lines
hw/mc146818rtc.c +10
-0+ s->cmos_data[RTC_REG_B ] &= ~(REG_B_PIE |REG_B_AIE |REG_B_SQWE ); + s->cmos_data[RTC_REG_C ] &= ~(REG_C_UF |REG_C_IRQF |REG_C_PF |REG_C_AF ); + +qemu_irq_lower (s->irq); + +#ifdef TARGET_I386 +if (rtc_td_hack) + s->irq_coalesced =0 ; +#endif +}
Don't you need to cancel the timer before clearing cmos_data[]?
Quoted 31 lines · Marcelo Tosatti
Quoted 30 lines · Gleb Natapov
On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zeroSigned-off-by Gleb Natapov <[email protected]>hw/mc146818rtc.c +5
-0@@ -57,6 +57,11 @@#define REG_B_SQWE 0x08#define REG_B_DM 0x04 +#define REG_C_UF 0x10 +#define REG_C_IRQF 0x80 +#define REG_C_PF 0x40 +#define REG_C_AF 0x20 +struct RTCState {uint8_t cmos_data[128 ];uint8_t cmos_index;@@ -568,6 +573,21 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) }#endif
Quoted 16 lines
Quoted 4 lines
hw/mc146818rtc.c +4
-0+static void rtc_reset (void *opaque) +{ +RTCState *s = opaque; +hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 589
Quoted 10 lines
hw/mc146818rtc.c +10
-0+ s->cmos_data[RTC_REG_B ] &= ~(REG_B_PIE |REG_B_AIE |REG_B_SQWE ); + s->cmos_data[RTC_REG_C ] &= ~(REG_C_UF |REG_C_IRQF |REG_C_PF |REG_C_AF ); + +qemu_irq_lower (s->irq); + +#ifdef TARGET_I386 +if (rtc_td_hack) + s->irq_coalesced =0 ; +#endif +}Don't you need to cancel the timer before clearing cmos_data[]?
I believe when this callback runs guest is already stopped, so there is not difference.
--
Gleb.