Skip to contentSkip to conversation

VT82xx PCI IRQ routing fixes

PATCH Superseded Bernhard Beschow 2 participants 5 messages Feb 25, 2023 – Feb 26, 2023

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover VT82xx PCI IRQ routing fixes

This series makes PCI interrupt routing in the VIA south bridges more compliant to the PCI specification. It aims to help bringing audio output support to the ppc/pegasos2 machine [1].

v2:
* Remove audio patches which were included for proof of concept

Testing done with via-ac97 audio patches on top:
* make check
* qemu-system-ppc -M pegasos2 -rtc base=localtime -device ati-vga,guest_hwcursor=true,romfile="" -cdrom morphos-3.17.iso -kernel morphos-3.17/boot.img
-> There is a nice sound when the Desktop becomes visible.
* qemu-system-ppc -M pegasos2 -bios pegasos2.rom -rtc base=localtime -device ati-vga,guest_hwcursor=true,romfile="" -cdrom morphos-3.17.iso -> There is a nice sound when the Desktop becomes visible.
* qemu-system-ppc -M pegasos2 -bios pegasos2.rom -rtc base=localtime -device ati-vga,guest_hwcursor=true,romfile="" -cdrom morphos-3.17.iso -device usb-mouse -device usb-kbd
-> The machine hangs when audio is supposed to play while the mouse is moved.
This behavior can also be reproduced in v1.

[1] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (3):
hw/ppc/pegasos2: Initialize VT8231 PCI IRQ router hw/isa/vt82c686: Implement PCI IRQ routing hw/usb/vt82c686-uhci-pci: Use PCI IRQ routing

 hw/isa/vt82c686.c          | 44 ++++++++++++++++++++++++++++++++++++++
 hw/ppc/pegasos2.c          |  6 ++++++
 hw/usb/vt82c686-uhci-pci.c | 12 -----------
 3 files changed, 50 insertions(+), 12 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/3 hw/ppc/pegasos2: Initialize VT8231 PCI IRQ router

The firmware of the real PegasosII board routes all PIRQx to IRQ9, so do the same in QEMU. The PCI_INTERRUPT_LINE registers of the respective internal PCI functions are already initialized with IRQ9 which are currently used for routing.

Note that the PCI interrupt router isn't implemented yet in the VIA south bridges. This change has therefore no effect until this happens.

Inspired-by:
<c046d77c20875c8cd8bfdc79b4619a98ffd0bf33.1677004415.git.balaton@eik.bme.hu> ("hw/ppc/pegasos2: Fix PCI interrupt routing")

---
 hw/ppc/pegasos2.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/ppc/pegasos2.c +6 -0
index a9563f4fb2..41688699eb 100644
@@ -268,6 +268,12 @@ static void pegasos2_machine_reset(MachineState *machine, ShutdownCause reason)
                               PCI_INTERRUPT_LINE, 2, 0x9);
     pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) |
                               0x50, 1, 0x2);
+    pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) |
+                              0x55, 1, 0x90);
+    pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) |
+                              0x56, 1, 0x99);
+    pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) |
+                              0x57, 1, 0x90);
 
     pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) |
                               PCI_INTERRUPT_LINE, 2, 0x109);
Signature · 1 line
2.39.2
#2 lore raw

PATCH v2 2/3 hw/isa/vt82c686: Implement PCI IRQ routing

In reply to Bernhard Beschow

The real VIA south bridges implement a PCI IRQ router which is configured by the BIOS or the OS. In order to respect these configurations, QEMU needs to implement it as well.

Note: The implementation was taken from piix4_set_irq() in hw/isa/piix4.

---
 hw/isa/vt82c686.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
hw/isa/vt82c686.c +44 -0
index 3f9bd0c04d..f24e387d63 100644
@@ -604,6 +604,48 @@ static void via_isa_request_i8259_irq(void *opaque, int irq, int level)
     qemu_set_irq(s->cpu_intr, level);
 }
 
+static int via_isa_get_pci_irq(const ViaISAState *s, int irq_num)
+{
+    switch (irq_num) {
+    case 0:
+        return s->dev.config[0x55] >> 4;
+
+    case 1:
+        return s->dev.config[0x56] & 0xf;
+
+    case 2:
+        return s->dev.config[0x56] >> 4;
+
+    case 3:
+        return s->dev.config[0x57] >> 4;
+    }
+
+    return 0;
+}
+
+static void via_isa_set_pci_irq(void *opaque, int irq_num, int level)
+{
+    ViaISAState *s = opaque;
+    PCIBus *bus = pci_get_bus(&s->dev);
+    int pic_irq;
+
+    /* now we change the pic irq level according to the via irq mappings */
+    /* XXX: optimize */
+    pic_irq = via_isa_get_pci_irq(s, irq_num);
+    if (pic_irq < ISA_NUM_IRQS) {
+        int i, pic_level;
+
+        /* The pic level is the logical OR of all the PCI irqs mapped to it. */
+        pic_level = 0;
+        for (i = 0; i < PCI_NUM_PINS; i++) {
+            if (pic_irq == via_isa_get_pci_irq(s, i)) {
+                pic_level |= pci_bus_get_irq_level(bus, i);
+            }
+        }
+        qemu_set_irq(s->isa_irqs[pic_irq], pic_level);
+    }
+}
+
 static void via_isa_realize(PCIDevice *d, Error **errp)
 {
     ViaISAState *s = VIA_ISA(d);
@@ -676,6 +718,8 @@ static void via_isa_realize(PCIDevice *d, Error **errp)
     if (!qdev_realize(DEVICE(&s->mc97), BUS(pci_bus), errp)) {
         return;
     }
+
+    pci_bus_irqs(pci_bus, via_isa_set_pci_irq, s, PCI_NUM_PINS);
 }
 
 /* TYPE_VT82C686B_ISA */
Signature · 1 line
2.39.2
#3 lore raw

PATCH v2 3/3 hw/usb/vt82c686-uhci-pci: Use PCI IRQ routing

In reply to Bernhard Beschow

According to the PCI specification, PCI_INTERRUPT_LINE shall have no effect on hardware operations. Now that the VIA south bridges implement the internal PCI interrupt router let's be more conformant to the PCI specification.

---
 hw/usb/vt82c686-uhci-pci.c | 12 ------------
 1 file changed, 12 deletions(-)
hw/usb/vt82c686-uhci-pci.c +0 -12
index 46a901f56f..b4884c9011 100644
@@ -1,17 +1,7 @@
 #include "qemu/osdep.h"
-#include "hw/irq.h"
 #include "hw/isa/vt82c686.h"
 #include "hcd-uhci.h"
 
-static void uhci_isa_set_irq(void *opaque, int irq_num, int level)
-{
-    UHCIState *s = opaque;
-    uint8_t irq = pci_get_byte(s->dev.config + PCI_INTERRUPT_LINE);
-    if (irq > 0 && irq < 15) {
-        via_isa_set_irq(pci_get_function_0(&s->dev), irq, level);
-    }
-}
-
 static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
 {
     UHCIState *s = UHCI(dev);
@@ -25,8 +15,6 @@ static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
     pci_set_long(pci_conf + 0xc0, 0x00002000);
 
     usb_uhci_common_realize(dev, errp);
-    object_unref(s->irq);
-    s->irq = qemu_allocate_irq(uhci_isa_set_irq, s, 0);
 }
 
 static UHCIInfo uhci_info[] = {
Signature · 1 line
2.39.2
#4 lore raw
In reply to Bernhard Beschow
Quoted 6 lines · Bernhard Beschow

This series makes PCI interrupt routing in the VIA south bridges more compliant to the PCI specification. It aims to help bringing audio output support to the ppc/pegasos2 machine [1].

v2:
* Remove audio patches which were included for proof of concept

I've merged this with my other patches and made a series with all patches needed for AmigaOS on pegasos2 and MorphOS sound support here on branch pegasos2-alt:

https://osdn.net/projects/qmiga/scm/git/qemu/tree/pegasos2-alt/

I hope to get it tested before Monday so we can finalise it early next week.

Quoted 6 lines

Testing done with via-ac97 audio patches on top:
* make check
* qemu-system-ppc -M pegasos2 -rtc base=localtime -device ati-vga,guest_hwcursor=true,romfile="" -cdrom morphos-3.17.iso -kernel morphos-3.17/boot.img
-> There is a nice sound when the Desktop becomes visible.

Quoted 8 lines

* qemu-system-ppc -M pegasos2 -bios pegasos2.rom -rtc base=localtime -device ati-vga,guest_hwcursor=true,romfile="" -cdrom morphos-3.17.iso -> There is a nice sound when the Desktop becomes visible.
* qemu-system-ppc -M pegasos2 -bios pegasos2.rom -rtc base=localtime -device ati-vga,guest_hwcursor=true,romfile="" -cdrom morphos-3.17.iso -device usb-mouse -device usb-kbd
-> The machine hangs when audio is supposed to play while the mouse is moved.
This behavior can also be reproduced in v1.

Please come up with a similar workaround for this issue that I've done in my series on which this works now without hanging. My series is on pegasos2 branch:

https://osdn.net/projects/qmiga/scm/git/qemu/tree/pegasos2/

but I don't understand your irq mapping function and don't know how could I add similar workaround to that.

Regards,
BALATON Zoltan

Quoted 17 lines

[1] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (3):
hw/ppc/pegasos2: Initialize VT8231 PCI IRQ router hw/isa/vt82c686: Implement PCI IRQ routing hw/usb/vt82c686-uhci-pci: Use PCI IRQ routing

hw/isa/vt82c686.c          | 44 ++++++++++++++++++++++++++++++++++++++
hw/ppc/pegasos2.c          |  6 ++++++
hw/usb/vt82c686-uhci-pci.c | 12 -----------
3 files changed, 50 insertions(+), 12 deletions(-)

--
2.39.2