xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Tim Deegan <tim@xen.org>
To: xen-devel@lists.xen.org
Cc: suravee.suthikulpanit@amd.com, JBeulich@suse.com
Subject: [PATCH 4/4] x86/hvm: Centralize and simplify the RTC IRQ logic.
Date: Thu, 28 Mar 2013 16:09:30 +0000	[thread overview]
Message-ID: <1364486970-14990-5-git-send-email-tim@xen.org> (raw)
In-Reply-To: <1364486970-14990-1-git-send-email-tim@xen.org>

This keeps the behaviour of strobing the IRQ line every time any RTC
interrupt source is raised.  I rather suspect (based on the behaviour
of the MC146818A RTC) that we ought to be suppressing all subsequent
interrupts whenever RTC_IRQF is set, but this way avoids making
guest-visible changes.

Signed-off-by: Tim Deegan <tim@xen.org>
---
 xen/arch/x86/hvm/rtc.c |   40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/xen/arch/x86/hvm/rtc.c b/xen/arch/x86/hvm/rtc.c
index 88cacd1..26ab12c 100644
--- a/xen/arch/x86/hvm/rtc.c
+++ b/xen/arch/x86/hvm/rtc.c
@@ -50,14 +50,25 @@ static void rtc_set_time(RTCState *s);
 static inline int from_bcd(RTCState *s, int a);
 static inline int convert_hour(RTCState *s, int hour);
 
-static void rtc_toggle_irq(RTCState *s)
+static void rtc_update_irq(RTCState *s)
 {
     struct domain *d = vrtc_domain(s);
+    uint8_t irqf;
 
     ASSERT(spin_is_locked(&s->lock));
-    s->hw.cmos_data[RTC_REG_C] |= RTC_IRQF;
+
+    /* IRQ is raised if any source is both raised & enabled */
+    irqf = (s->hw.cmos_data[RTC_REG_B]
+            & s->hw.cmos_data[RTC_REG_C]
+            & (RTC_PF|RTC_AF|RTC_UF))
+        ? RTC_IRQF : 0;
+
+    s->hw.cmos_data[RTC_REG_C] &= ~RTC_IRQF;
+    s->hw.cmos_data[RTC_REG_C] |= irqf;
+
     hvm_isa_irq_deassert(d, RTC_IRQ);
-    hvm_isa_irq_assert(d, RTC_IRQ);
+    if ( irqf )
+        hvm_isa_irq_assert(d, RTC_IRQ);
 }
 
 void rtc_periodic_interrupt(void *opaque)
@@ -68,8 +79,7 @@ void rtc_periodic_interrupt(void *opaque)
     if ( !(s->hw.cmos_data[RTC_REG_C] & RTC_PF) )
     {
         s->hw.cmos_data[RTC_REG_C] |= RTC_PF;
-        if ( s->hw.cmos_data[RTC_REG_B] & RTC_PIE )
-            rtc_toggle_irq(s);
+        rtc_update_irq(s);
     }
     else if ( ++(s->pt_dead_ticks) >= 10 )
     {
@@ -187,8 +197,7 @@ static void rtc_update_timer2(void *opaque)
     {
         s->hw.cmos_data[RTC_REG_C] |= RTC_UF;
         s->hw.cmos_data[RTC_REG_A] &= ~RTC_UIP;
-        if ((s->hw.cmos_data[RTC_REG_B] & RTC_UIE))
-            rtc_toggle_irq(s);
+        rtc_update_irq(s);
         check_update_timer(s);
     }
     spin_unlock(&s->lock);
@@ -378,9 +387,7 @@ static void rtc_alarm_cb(void *opaque)
     if (!(s->hw.cmos_data[RTC_REG_B] & RTC_SET))
     {
         s->hw.cmos_data[RTC_REG_C] |= RTC_AF;
-        /* alarm interrupt */
-        if (s->hw.cmos_data[RTC_REG_B] & RTC_AIE)
-            rtc_toggle_irq(s);
+        rtc_update_irq(s);
         alarm_timer_update(s);
     }
     spin_unlock(&s->lock);
@@ -390,7 +397,7 @@ static int rtc_ioport_write(void *opaque, uint32_t addr, uint32_t data)
 {
     RTCState *s = opaque;
     struct domain *d = vrtc_domain(s);
-    uint32_t orig, mask;
+    uint32_t orig;
 
     spin_lock(&s->lock);
 
@@ -464,15 +471,8 @@ static int rtc_ioport_write(void *opaque, uint32_t addr, uint32_t data)
         /*
          * If the interrupt is already set when the interrupt becomes
          * enabled, raise an interrupt immediately.
-         * NB: RTC_{A,P,U}IE == RTC_{A,P,U}F respectively.
          */
-        for ( mask = RTC_UIE; mask <= RTC_PIE; mask <<= 1 )
-            if ( (data & mask) && !(orig & mask) &&
-                 (s->hw.cmos_data[RTC_REG_C] & mask) )
-            {
-                rtc_toggle_irq(s);
-                break;
-            }
+        rtc_update_irq(s);
         s->hw.cmos_data[RTC_REG_B] = data;
         if ( (data ^ orig) & RTC_SET )
             check_update_timer(s);
@@ -628,8 +628,8 @@ static uint32_t rtc_ioport_read(RTCState *s, uint32_t addr)
         break;
     case RTC_REG_C:
         ret = s->hw.cmos_data[s->hw.cmos_index];
-        hvm_isa_irq_deassert(vrtc_domain(s), RTC_IRQ);
         s->hw.cmos_data[RTC_REG_C] = 0x00;
+        rtc_update_irq(s);
         check_update_timer(s);
         alarm_timer_update(s);
         rtc_timer_update(s);
-- 
1.7.10.4

  parent reply	other threads:[~2013-03-28 16:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 16:09 [PATCH 0/4 v2] x86/hvm: RTC periodic timer adjustments Tim Deegan
2013-03-28 16:09 ` [PATCH 1/4] x86/hvm: Run the RTC periodic timer on a consistent time series Tim Deegan
2013-03-28 16:09 ` [PATCH 2/4] x86/hvm: Avoid needlessly resetting the periodic timer Tim Deegan
2013-03-28 16:09 ` [PATCH 3/4] x86/hvm: Let the guest miss a few ticks before resetting the timer Tim Deegan
2013-03-28 16:09 ` Tim Deegan [this message]
2013-03-28 16:18 ` [PATCH 0/4 v2] x86/hvm: RTC periodic timer adjustments Jan Beulich
2013-03-28 21:36   ` Suravee Suthikulanit
2013-03-28 19:57 ` Keir Fraser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364486970-14990-5-git-send-email-tim@xen.org \
    --to=tim@xen.org \
    --cc=JBeulich@suse.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).