Patchwork [03/10] RTC: Update interrupt state when interrupts are masked/unmasked

login
register
mail settings
Submitter Paolo Bonzini
Date Aug. 1, 2012, 4:41 p.m.
Message ID <1343839312-24030-4-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/174547/
State New
Headers show

Comments

Paolo Bonzini - Aug. 1, 2012, 4:41 p.m.
From: Yang Zhang <yang.z.zhang@intel.com>

If an interrupt flag is already set when the interrupt becomes enabled,
raise an interrupt immediately, and vice versa if interrupts become
disabled.

Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/mc146818rtc.c      |    9 +++++++++
 hw/mc146818rtc_regs.h |    1 +
 2 files changed, 10 insertions(+)

Patch

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index b99f4d3..293f174 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -220,6 +220,15 @@  static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
                     rtc_set_time(s);
                 }
             }
+            /* if an interrupt flag is already set when the interrupt
+             * becomes enabled, raise an interrupt immediately.  */
+            if (data & s->cmos_data[RTC_REG_C] & REG_C_MASK) {
+                s->cmos_data[RTC_REG_C] |= REG_C_IRQF;
+                qemu_irq_raise(s->irq);
+            } else {
+                s->cmos_data[RTC_REG_C] &= ~REG_C_IRQF;
+                qemu_irq_lower(s->irq);
+            }
             s->cmos_data[RTC_REG_B] = data;
             periodic_timer_update(s, qemu_get_clock_ns(rtc_clock));
             break;
diff --git a/hw/mc146818rtc_regs.h b/hw/mc146818rtc_regs.h
index 3ab3770..fc10076 100644
--- a/hw/mc146818rtc_regs.h
+++ b/hw/mc146818rtc_regs.h
@@ -58,5 +58,6 @@ 
 #define REG_C_IRQF 0x80
 #define REG_C_PF   0x40
 #define REG_C_AF   0x20
+#define REG_C_MASK 0x70
 
 #endif