Patchwork Re: [PATCH 0/6] Make hpet a compile time option

login
register
mail settings
Submitter Paolo Bonzini
Date May 25, 2010, 8:38 a.m.
Message ID <4BFB8C8E.4070602@redhat.com>
Download mbox | patch
Permalink /patch/53497/
State New
Headers show

Comments

Paolo Bonzini - May 25, 2010, 8:38 a.m.
On 05/24/2010 07:54 PM, Juan Quintela wrote:
> But for the other call, what do you propose?
>
> My best try was to hide the availability of hpet inside hpet_emul.h
> with:
>
> #ifdef CONFIG_HPET
> uint32_t hpet_in_legacy_mode(void);
> else
> uint32_t hpet_in_legacy_mode(void) { return 0;}
> #endif

Change this to a global variable rtc_disable_interrupts in 
hw/mc146818rtc.c?  (You didn't say it would need to be particularly 
pretty...).

Not tested beyond compilation.

Paolo
Jan Kiszka - May 25, 2010, 9:05 a.m.
Paolo Bonzini wrote:
> On 05/24/2010 07:54 PM, Juan Quintela wrote:
>> But for the other call, what do you propose?
>>
>> My best try was to hide the availability of hpet inside hpet_emul.h
>> with:
>>
>> #ifdef CONFIG_HPET
>> uint32_t hpet_in_legacy_mode(void);
>> else
>> uint32_t hpet_in_legacy_mode(void) { return 0;}
>> #endif
> 
> Change this to a global variable rtc_disable_interrupts in
> hw/mc146818rtc.c?  (You didn't say it would need to be particularly
> pretty...).
> 
> Not tested beyond compilation.
> 
> Paolo
> 

Please don't waste your time:

http://permalink.gmane.org/gmane.comp.emulators.qemu/71377

Jan
Paolo Bonzini - May 25, 2010, 9:56 a.m.
On 05/25/2010 11:05 AM, Jan Kiszka wrote:
> Please don't waste your time:
>
> http://permalink.gmane.org/gmane.comp.emulators.qemu/71377

I wasn't going to. :-)  I had seen the series---very nice work!

Paolo

Patch

diff --git a/hw/hpet.c b/hw/hpet.c
index 8729fb2..c2615c1 100644
--- a/hw/hpet.c
+++ b/hw/hpet.c
@@ -29,6 +29,7 @@ 
 #include "console.h"
 #include "qemu-timer.h"
 #include "hpet_emul.h"
+#include "mc146818rtc.h"
 
 //#define HPET_DEBUG
 #ifdef HPET_DEBUG
@@ -39,14 +40,6 @@ 
 
 static HPETState *hpet_statep;
 
-uint32_t hpet_in_legacy_mode(void)
-{
-    if (hpet_statep)
-        return hpet_statep->config & HPET_CFG_LEGACY;
-    else
-        return 0;
-}
-
 static uint32_t timer_int_route(struct HPETTimer *timer)
 {
     uint32_t route;
@@ -139,7 +132,7 @@  static void update_irq(struct HPETTimer *timer)
     qemu_irq irq;
     int route;
 
-    if (timer->tn <= 1 && hpet_in_legacy_mode()) {
+    if (timer->tn <= 1 && (timer->state->config & HPET_CFG_LEGACY)) {
         /* if LegacyReplacementRoute bit is set, HPET specification requires
          * timer0 be routed to IRQ0 in NON-APIC or IRQ2 in the I/O APIC,
          * timer1 be routed to IRQ8 in NON-APIC or IRQ8 in the I/O APIC.
@@ -474,8 +467,10 @@  static void hpet_ram_writel(void *opaque, target_phys_addr_t addr,
                 /* i8254 and RTC are disabled when HPET is in legacy mode */
                 if (activating_bit(old_val, new_val, HPET_CFG_LEGACY)) {
                     hpet_pit_disable();
+		    rtc_disable_interrupts = 1;
                 } else if (deactivating_bit(old_val, new_val, HPET_CFG_LEGACY)) {
                     hpet_pit_enable();
+		    rtc_disable_interrupts = 0;
                 }
                 break;
             case HPET_CFG + 4:
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 571c593..61d5980 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -94,6 +94,9 @@  typedef struct RTCState {
     QEMUTimer *second_timer2;
 } RTCState;
 
+
+int rtc_disable_interrupts = 0;
+
 static void rtc_irq_raise(qemu_irq irq)
 {
     /* When HPET is operating in legacy mode, RTC interrupts are disabled
@@ -101,9 +104,7 @@  static void rtc_irq_raise(qemu_irq irq)
      * mode is established while interrupt is raised. We want it to
      * be lowered in any case
      */
-#if defined TARGET_I386
-    if (!hpet_in_legacy_mode())
-#endif
+    if (!rtc_disable_interrupts)
         qemu_irq_raise(irq);
 }
 
@@ -148,14 +149,10 @@  static void rtc_timer_update(RTCState *s, int64_t current_time)
     int enable_pie;
 
     period_code = s->cmos_data[RTC_REG_A] & 0x0f;
-#if defined TARGET_I386
     /* disable periodic timer if hpet is in legacy mode, since interrupts are
      * disabled anyway.
      */
-    enable_pie = !hpet_in_legacy_mode();
-#else
-    enable_pie = 1;
-#endif
+    enable_pie = !rtc_disable_interrupts;
     if (period_code != 0
         && (((s->cmos_data[RTC_REG_B] & REG_B_PIE) && enable_pie)
             || ((s->cmos_data[RTC_REG_B] & REG_B_SQWE) && s->sqw_irq))) {
diff --git a/hw/mc146818rtc.h b/hw/mc146818rtc.h
index 6f46a68..ff4bcda 100644
--- a/hw/mc146818rtc.h
+++ b/hw/mc146818rtc.h
@@ -3,6 +3,7 @@ 
 
 #include "isa.h"
 
+extern int rtc_disable_interrupts;
 ISADevice *rtc_init(int base_year);
 void rtc_set_memory(ISADevice *dev, int addr, int val);
 void rtc_set_date(ISADevice *dev, const struct tm *tm);