Skip to contentSkip to conversation

ich9: clean up handling of output interrupt pins

PATCH In review Paolo Bonzini 2 participants 7 messages Jun 20, 2016 – Jun 22, 2016

lore
Share & tools
lore
#0 lore raw

cover ich9: clean up handling of output interrupt pins

Currently the southbridge in the q35 machine types gets 40 different qemu_irqs. The 16 lower GSIs (connected to both 8259 and IOAPIC) and the 24 input pins of the IOAPIC (the higher 8 of which correspond to the 8 higher GSIs). However, there's no reason to use the 16 first input pins of the IOAPIC except through the 16 lower GSIs.

This series cleans this up by passing just the 24 GSIs to lpc_ich9.c. The first patch is a bug fix.

Paolo

Paolo Bonzini (3):
ich9: call ich9_lpc_update_pic for disabled pirqs
ich9: clean up ich9_lpc_update_pic/ich9_lpc_update_apic and callers
ich9: unify pic and ioapic IRQ vectors

 hw/i386/pc_q35.c       |  3 +--
 hw/isa/lpc_ich9.c      | 44 +++++++++++++++++---------------------------
 include/hw/i386/ich9.h |  3 +--
 3 files changed, 19 insertions(+), 31 deletions(-)
Signature · 1 line
2.5.5
#1 lore raw

PATCH 1/3 ich9: call ich9_lpc_update_pic for disabled pirqs

An asserted pirq can be disabled and the corresponding GSIs should then go down to 0. However, because of the conditional in ich9_lpc_update_by_pirq, the legacy 8259 pin could remain stuck to 1.

---
 hw/isa/lpc_ich9.c | 3 ---
 1 file changed, 3 deletions(-)
hw/isa/lpc_ich9.c +0 -3
index 213741b..b116e1b 100644
@@ -234,9 +234,6 @@ static void ich9_lpc_update_by_pirq(ICH9LPCState *lpc, int pirq)
 
     ich9_lpc_pic_irq(lpc, pirq, &pic_irq, &pic_dis);
     assert(pic_irq < ICH9_LPC_PIC_NUM_PINS);
-    if (pic_dis) {
-        return;
-    }
 
     ich9_lpc_update_pic(lpc, pic_irq);
 }
Signature · 1 line
2.5.5
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] ich9: call ich9_lpc_update_pic for disabled pirqs

Quoted 15 lines · Paolo Bonzini

An asserted pirq can be disabled and the corresponding GSIs should then go down to 0. However, because of the conditional in ich9_lpc_update_by_pirq, the legacy 8259 pin could remain stuck to 1.

---
  hw/isa/lpc_ich9.c | 3 ---
  1 file changed, 3 deletions(-)
hw/isa/lpc_ich9.c +0 -0
index 213741b..b116e1b 100644

hw/isa/lpc_ich9.c static void ich9_lpc_update_by_pirq(ICH9LPCState *lpc, int pirq) · line 239

Quoted 9 lines
hw/isa/lpc_ich9.c +0 -3
@@ -234,9 +234,6 @@ static void ich9_lpc_update_by_pirq(ICH9LPCState *lpc, int pirq)
 
      ich9_lpc_pic_irq(lpc, pirq, &pic_irq, &pic_dis);
      assert(pic_irq < ICH9_LPC_PIC_NUM_PINS);
-    if (pic_dis) {
-        return;
-    }
 
      ich9_lpc_update_pic(lpc, pic_irq);
  }
#3 lore raw

PATCH 2/3 ich9: clean up ich9_lpc_update_pic/ich9_lpc_update_apic and callers

In reply to Paolo Bonzini

Make ich9_lpc_update_pic take care only of GSIs 0-15, and ich9_lpc_update_apic take care only of GSIs 16-23. Assert that they are called with the correct GSI indices.

---
 hw/isa/lpc_ich9.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)
hw/isa/lpc_ich9.c +16 -23
index b116e1b..446797b 100644
@@ -204,38 +204,28 @@ static void ich9_lpc_pic_irq(ICH9LPCState *lpc, int pirq_num,
     abort();
 }
 
-/* pic_irq: i8254 irq 0-15 */
-static void ich9_lpc_update_pic(ICH9LPCState *lpc, int pic_irq)
+/* gsi: i8259 irq 0-15, otherwise ignored */
+static void ich9_lpc_update_pic(ICH9LPCState *lpc, int gsi)
 {
     int i, pic_level;
 
+    assert(gsi < ICH9_LPC_PIC_NUM_PINS);
+
     /* The pic level is the logical OR of all the PCI irqs mapped to it */
     pic_level = 0;
     for (i = 0; i < ICH9_LPC_NB_PIRQS; i++) {
         int tmp_irq;
         int tmp_dis;
         ich9_lpc_pic_irq(lpc, i, &tmp_irq, &tmp_dis);
-        if (!tmp_dis && pic_irq == tmp_irq) {
+        if (!tmp_dis && tmp_irq == gsi) {
             pic_level |= pci_bus_get_irq_level(lpc->d.bus, i);
         }
     }
-    if (pic_irq == ich9_lpc_sci_irq(lpc)) {
+    if (gsi == ich9_lpc_sci_irq(lpc)) {
         pic_level |= lpc->sci_level;
     }
 
-    qemu_set_irq(lpc->pic[pic_irq], pic_level);
-}
-
-/* pirq: pirq[A-H] 0-7*/
-static void ich9_lpc_update_by_pirq(ICH9LPCState *lpc, int pirq)
-{
-    int pic_irq;
-    int pic_dis;
-
-    ich9_lpc_pic_irq(lpc, pirq, &pic_irq, &pic_dis);
-    assert(pic_irq < ICH9_LPC_PIC_NUM_PINS);
-
-    ich9_lpc_update_pic(lpc, pic_irq);
+    qemu_set_irq(lpc->pic[gsi], pic_level);
 }
 
 /* APIC mode: GSIx: PIRQ[A-H] -> GSI 16, ... no pirq shares same APIC pins. */
@@ -253,9 +243,9 @@ static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi)
 {
     int level = 0;
 
-    if (gsi >= ICH9_LPC_PIC_NUM_PINS) {
-        level |= pci_bus_get_irq_level(lpc->d.bus, ich9_gsi_to_pirq(gsi));
-    }
+    assert(gsi >= ICH9_LPC_PIC_NUM_PINS);
+
+    level |= pci_bus_get_irq_level(lpc->d.bus, ich9_gsi_to_pirq(gsi));
     if (gsi == ich9_lpc_sci_irq(lpc)) {
         level |= lpc->sci_level;
     }
@@ -266,12 +256,14 @@ static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi)
 void ich9_lpc_set_irq(void *opaque, int pirq, int level)
 {
     ICH9LPCState *lpc = opaque;
+    int pic_irq, pic_dis;
 
     assert(0 <= pirq);
     assert(pirq < ICH9_LPC_NB_PIRQS);
 
     ich9_lpc_update_apic(lpc, ich9_pirq_to_gsi(pirq));
-    ich9_lpc_update_by_pirq(lpc, pirq);
+    ich9_lpc_pic_irq(lpc, pirq, &pic_irq, &pic_dis);
+    ich9_lpc_update_pic(lpc, pic_irq);
 }
 
 /* return the pirq number (PIRQ[A-H]:0-7) corresponding to
@@ -362,8 +354,9 @@ static void ich9_set_sci(void *opaque, int irq_num, int level)
         return;
     }
 
-    ich9_lpc_update_apic(lpc, irq);
-    if (irq < ICH9_LPC_PIC_NUM_PINS) {
+    if (irq >= ICH9_LPC_PIC_NUM_PINS) {
+        ich9_lpc_update_apic(lpc, irq);
+    } else {
         ich9_lpc_update_pic(lpc, irq);
     }
 }
Signature · 1 line
2.5.5
Reviewed-by on v1 2/3
#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] ich9: clean up ich9_lpc_update_pic/ich9_lpc_update_apic and callers

Quoted 91 lines · Paolo Bonzini

Make ich9_lpc_update_pic take care only of GSIs 0-15, and ich9_lpc_update_apic take care only of GSIs 16-23. Assert that they are called with the correct GSI indices.

---
  hw/isa/lpc_ich9.c | 39 ++++++++++++++++-----------------------
  1 file changed, 16 insertions(+), 23 deletions(-)
hw/isa/lpc_ich9.c +13 -21
index b116e1b..446797b 100644
@@ -204,38 +204,28 @@ static void ich9_lpc_pic_irq(ICH9LPCState *lpc, int pirq_num,
      abort();
  }
 
-/* pic_irq: i8254 irq 0-15 */
-static void ich9_lpc_update_pic(ICH9LPCState *lpc, int pic_irq)
+/* gsi: i8259 irq 0-15, otherwise ignored */
+static void ich9_lpc_update_pic(ICH9LPCState *lpc, int gsi)
  {
      int i, pic_level;
 
+    assert(gsi < ICH9_LPC_PIC_NUM_PINS);
+
      /* The pic level is the logical OR of all the PCI irqs mapped to it */
      pic_level = 0;
      for (i = 0; i < ICH9_LPC_NB_PIRQS; i++) {
          int tmp_irq;
          int tmp_dis;
          ich9_lpc_pic_irq(lpc, i, &tmp_irq, &tmp_dis);
-        if (!tmp_dis && pic_irq == tmp_irq) {
+        if (!tmp_dis && tmp_irq == gsi) {
              pic_level |= pci_bus_get_irq_level(lpc->d.bus, i);
          }
      }
-    if (pic_irq == ich9_lpc_sci_irq(lpc)) {
+    if (gsi == ich9_lpc_sci_irq(lpc)) {
          pic_level |= lpc->sci_level;
      }
 
-    qemu_set_irq(lpc->pic[pic_irq], pic_level);
-}
-
-/* pirq: pirq[A-H] 0-7*/
-static void ich9_lpc_update_by_pirq(ICH9LPCState *lpc, int pirq)
-{
-    int pic_irq;
-    int pic_dis;
-
-    ich9_lpc_pic_irq(lpc, pirq, &pic_irq, &pic_dis);
-    assert(pic_irq < ICH9_LPC_PIC_NUM_PINS);
-
-    ich9_lpc_update_pic(lpc, pic_irq);
+    qemu_set_irq(lpc->pic[gsi], pic_level);
  }
 
  /* APIC mode: GSIx: PIRQ[A-H] -> GSI 16, ... no pirq shares same APIC pins. */
@@ -253,9 +243,9 @@ static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi)
  {
      int level = 0;
 
-    if (gsi >= ICH9_LPC_PIC_NUM_PINS) {
-        level |= pci_bus_get_irq_level(lpc->d.bus, ich9_gsi_to_pirq(gsi));
-    }
+    assert(gsi >= ICH9_LPC_PIC_NUM_PINS);
+
+    level |= pci_bus_get_irq_level(lpc->d.bus, ich9_gsi_to_pirq(gsi));
      if (gsi == ich9_lpc_sci_irq(lpc)) {
          level |= lpc->sci_level;
      }
@@ -266,12 +256,14 @@ static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi)
  void ich9_lpc_set_irq(void *opaque, int pirq, int level)
  {
      ICH9LPCState *lpc = opaque;
+    int pic_irq, pic_dis;
 
      assert(0 <= pirq);
      assert(pirq < ICH9_LPC_NB_PIRQS);
 
      ich9_lpc_update_apic(lpc, ich9_pirq_to_gsi(pirq));
-    ich9_lpc_update_by_pirq(lpc, pirq);
+    ich9_lpc_pic_irq(lpc, pirq, &pic_irq, &pic_dis);
+    ich9_lpc_update_pic(lpc, pic_irq);
  }
 
  /* return the pirq number (PIRQ[A-H]:0-7) corresponding to
@@ -362,8 +354,9 @@ static void ich9_set_sci(void *opaque, int irq_num, int level)
          return;

hw/isa/lpc_ich9.c static void ich9_set_sci(void *opaque, int irq_num, int level) · line 362

Quoted 10 lines
hw/isa/lpc_ich9.c +3 -2
      }
 
-    ich9_lpc_update_apic(lpc, irq);
-    if (irq < ICH9_LPC_PIC_NUM_PINS) {
+    if (irq >= ICH9_LPC_PIC_NUM_PINS) {
+        ich9_lpc_update_apic(lpc, irq);
+    } else {
          ich9_lpc_update_pic(lpc, irq);
      }
  }
#5 lore raw

PATCH 3/3 ich9: unify pic and ioapic IRQ vectors

In reply to Paolo Bonzini

ich9->pic and ich9->ioapic differ for the first 16 GSIs (because ich9->pic is wired to 8259+IOAPIC but ich9->ioapic is wired to IOAPIC only). However, ich9->ioapic is never used for the first 16 GSIs, so the two vectors can be merged.

---
 hw/i386/pc_q35.c       | 3 +--
 hw/isa/lpc_ich9.c      | 4 ++--
 include/hw/i386/ich9.h | 3 +--
 3 files changed, 4 insertions(+), 6 deletions(-)
hw/i386/pc_q35.c +1 -2
index e4b541f..78afd4f 100644
@@ -184,8 +184,7 @@ static void pc_q35_init(MachineState *machine)
                              PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
 
     ich9_lpc = ICH9_LPC_DEVICE(lpc);
-    ich9_lpc->pic = gsi;
-    ich9_lpc->ioapic = gsi_state->ioapic_irq;
+    ich9_lpc->gsi = gsi;
     pci_bus_irqs(host_bus, ich9_lpc_set_irq, ich9_lpc_map_irq, ich9_lpc,
                  ICH9_LPC_NB_PIRQS);
     pci_bus_set_route_irq_fn(host_bus, ich9_route_intx_pin_to_irq);
hw/isa/lpc_ich9.c +2 -2
index 446797b..7703357 100644
@@ -225,7 +225,7 @@ static void ich9_lpc_update_pic(ICH9LPCState *lpc, int gsi)
         pic_level |= lpc->sci_level;
     }
 
-    qemu_set_irq(lpc->pic[gsi], pic_level);
+    qemu_set_irq(lpc->gsi[gsi], pic_level);
 }
 
 /* APIC mode: GSIx: PIRQ[A-H] -> GSI 16, ... no pirq shares same APIC pins. */
@@ -250,7 +250,7 @@ static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi)
         level |= lpc->sci_level;
     }
 
-    qemu_set_irq(lpc->ioapic[gsi], level);
+    qemu_set_irq(lpc->gsi[gsi], level);
 }
 
 void ich9_lpc_set_irq(void *opaque, int pirq, int level)
include/hw/i386/ich9.h +1 -2
index 88233c3..11243e5 100644
@@ -68,8 +68,7 @@ typedef struct ICH9LPCState {
     MemoryRegion rcrb_mem; /* root complex register block */
     Notifier machine_ready;
 
-    qemu_irq *pic;
-    qemu_irq *ioapic;
+    qemu_irq *gsi;
 } ICH9LPCState;
 
 Object *ich9_lpc_find(void);
Signature · 1 line
2.5.5
Reviewed-by on v1 3/3
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] ich9: unify pic and ioapic IRQ vectors

Quoted 54 lines · Paolo Bonzini

ich9->pic and ich9->ioapic differ for the first 16 GSIs (because ich9->pic is wired to 8259+IOAPIC but ich9->ioapic is wired to IOAPIC only). However, ich9->ioapic is never used for the first 16 GSIs, so the two vectors can be merged.

---
  hw/i386/pc_q35.c       | 3 +--
  hw/isa/lpc_ich9.c      | 4 ++--
  include/hw/i386/ich9.h | 3 +--
  3 files changed, 4 insertions(+), 6 deletions(-)
hw/i386/pc_q35.c +1 -2
index e4b541f..78afd4f 100644
@@ -184,8 +184,7 @@ static void pc_q35_init(MachineState *machine)
                               PC_MACHINE_ACPI_DEVICE_PROP, &error_abort);
 
      ich9_lpc = ICH9_LPC_DEVICE(lpc);
-    ich9_lpc->pic = gsi;
-    ich9_lpc->ioapic = gsi_state->ioapic_irq;
+    ich9_lpc->gsi = gsi;
      pci_bus_irqs(host_bus, ich9_lpc_set_irq, ich9_lpc_map_irq, ich9_lpc,
                   ICH9_LPC_NB_PIRQS);
      pci_bus_set_route_irq_fn(host_bus, ich9_route_intx_pin_to_irq);
hw/isa/lpc_ich9.c +2 -2
index 446797b..7703357 100644
@@ -225,7 +225,7 @@ static void ich9_lpc_update_pic(ICH9LPCState *lpc, int gsi)
          pic_level |= lpc->sci_level;
      }
 
-    qemu_set_irq(lpc->pic[gsi], pic_level);
+    qemu_set_irq(lpc->gsi[gsi], pic_level);
  }
 
  /* APIC mode: GSIx: PIRQ[A-H] -> GSI 16, ... no pirq shares same APIC pins. */
@@ -250,7 +250,7 @@ static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi)
          level |= lpc->sci_level;
      }
 
-    qemu_set_irq(lpc->ioapic[gsi], level);
+    qemu_set_irq(lpc->gsi[gsi], level);
  }
 
  void ich9_lpc_set_irq(void *opaque, int pirq, int level)
include/hw/i386/ich9.h +0 -0
index 88233c3..11243e5 100644

include/hw/i386/ich9.h typedef struct ICH9LPCState { · line 74

Quoted 9 lines
include/hw/i386/ich9.h +1 -2
@@ -68,8 +68,7 @@ typedef struct ICH9LPCState {
      MemoryRegion rcrb_mem; /* root complex register block */
      Notifier machine_ready;
 
-    qemu_irq *pic;
-    qemu_irq *ioapic;
+    qemu_irq *gsi;
  } ICH9LPCState;
 
  Object *ich9_lpc_find(void);