Skip to contentSkip to conversation

hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

PATCH In review BALATON Zoltan 3 participants 11 messages Oct 25, 2021 – Nov 2, 2021

v2 of 4 In review Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Regards,

BALATON Zoltan (4):
usb/uhci: Misc clean up
usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

 hw/usb/hcd-uhci.c          | 14 ++++++++------
 hw/usb/hcd-uhci.h          |  3 ++-
 hw/usb/vt82c686-uhci-pci.c | 15 +++++++++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)
Signature · 1 line
2.21.4
#1 lore raw

PATCH v2 1/4 usb/uhci: Misc clean up

Fix a comment for coding style so subsequent patch will not get checkpatch error and simplify and shorten uhci_update_irq().

---
 hw/usb/hcd-uhci.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
hw/usb/hcd-uhci.c +2 -5
index 0cb02a6432..c557566ec2 100644
@@ -290,7 +290,7 @@ static UHCIAsync *uhci_async_find_td(UHCIState *s, uint32_t td_addr)
 
 static void uhci_update_irq(UHCIState *s)
 {
-    int level;
+    int level = 0;
     if (((s->status2 & 1) && (s->intr & (1 << 2))) ||
         ((s->status2 & 2) && (s->intr & (1 << 3))) ||
         ((s->status & UHCI_STS_USBERR) && (s->intr & (1 << 0))) ||
@@ -298,8 +298,6 @@ static void uhci_update_irq(UHCIState *s)
         (s->status & UHCI_STS_HSERR) ||
         (s->status & UHCI_STS_HCPERR)) {
         level = 1;
-    } else {
-        level = 0;
     }
     pci_set_irq(&s->dev, level);
 }
@@ -1170,8 +1168,7 @@ void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
 
     pci_conf[PCI_CLASS_PROG] = 0x00;
     /* TODO: reset value should be 0. */
-    pci_conf[USB_SBRN] = USB_RELEASE_1; // release number
-
+    pci_conf[USB_SBRN] = USB_RELEASE_1; /* release number */
     pci_config_set_interrupt_pin(pci_conf, u->info.irq_pin + 1);
 
     if (s->masterbus) {
Signature · 1 line
2.21.4
#2 lore raw

PATCH v2 2/4 usb/uhci: Disallow user creating a vt82c686-uhci-pci device

In reply to BALATON Zoltan

Because this device only works as part of VIA superio chips set user creatable to false. Since the class init method is common for UHCI variants introduce a flag in UHCIInfo for this.

---
 hw/usb/hcd-uhci.c          | 3 +++
 hw/usb/hcd-uhci.h          | 1 +
 hw/usb/vt82c686-uhci-pci.c | 2 ++
 3 files changed, 6 insertions(+)
hw/usb/hcd-uhci.c +3 -0
index c557566ec2..7d26e35194 100644
@@ -1282,6 +1282,9 @@ void uhci_data_class_init(ObjectClass *klass, void *data)
     } else {
         device_class_set_props(dc, uhci_properties_standalone);
     }
+    if (info->notuser) {
+        dc->user_creatable = false;
+    }
     u->info = *info;
 }
 
hw/usb/hcd-uhci.h +1 -0
index e61d8fcb19..316693f80b 100644
@@ -85,6 +85,7 @@ typedef struct UHCIInfo {
     uint8_t    irq_pin;
     void       (*realize)(PCIDevice *dev, Error **errp);
     bool       unplug;
+    bool       notuser; /* disallow user_creatable */
 } UHCIInfo;
 
 void uhci_data_class_init(ObjectClass *klass, void *data);
hw/usb/vt82c686-uhci-pci.c +2 -0
index b109c21603..ea262e6d70 100644
@@ -25,6 +25,8 @@ static UHCIInfo uhci_info[] = {
         .irq_pin   = 3,
         .realize   = usb_uhci_vt82c686b_realize,
         .unplug    = true,
+        /* Reason: only works as USB function of VT82xx superio chips */
+        .notuser   = true,
     }
 };
 
Signature · 1 line
2.21.4
#3 lore raw

PATCH v2 3/4 usb/uhci: Replace pci_set_irq with qemu_set_irq

In reply to BALATON Zoltan

Instead of using pci_set_irq, store the irq in the device state and use it explicitly so variants having different interrupt handling can use their own.

---
 hw/usb/hcd-uhci.c | 4 +++-
 hw/usb/hcd-uhci.h | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/usb/hcd-uhci.c +3 -1
index 7d26e35194..d1b5657d72 100644
@@ -31,6 +31,7 @@
 #include "hw/usb/uhci-regs.h"
 #include "migration/vmstate.h"
 #include "hw/pci/pci.h"
+#include "hw/irq.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
 #include "qemu/timer.h"
@@ -299,7 +300,7 @@ static void uhci_update_irq(UHCIState *s)
         (s->status & UHCI_STS_HCPERR)) {
         level = 1;
     }
-    pci_set_irq(&s->dev, level);
+    qemu_set_irq(s->irq, level);
 }
 
 static void uhci_reset(DeviceState *dev)
@@ -1170,6 +1171,7 @@ void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
     /* TODO: reset value should be 0. */
     pci_conf[USB_SBRN] = USB_RELEASE_1; /* release number */
     pci_config_set_interrupt_pin(pci_conf, u->info.irq_pin + 1);
+    s->irq = pci_allocate_irq(dev);
 
     if (s->masterbus) {
         USBPort *ports[NB_PORTS];
hw/usb/hcd-uhci.h +1 -1
index 316693f80b..c85ab7868e 100644
@@ -60,7 +60,7 @@ typedef struct UHCIState {
     uint32_t frame_bandwidth;
     bool completions_only;
     UHCIPort ports[NB_PORTS];
-
+    qemu_irq irq;
     /* Interrupts that should be raised at the end of the current frame.  */
     uint32_t pending_int_mask;
 
Signature · 1 line
2.21.4
#4 lore raw

PATCH v2 4/4 hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

In reply to BALATON Zoltan

This device is part of a superio/ISA bridge chip and IRQs from it are routed to an ISA interrupt set by the Interrupt Line PCI config register. Implement this in a vt82c686-uhci-pci specific irq handler Using via_isa_set_irq().

---
 hw/usb/vt82c686-uhci-pci.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/usb/vt82c686-uhci-pci.c +13 -0
index ea262e6d70..0bf2b72ff0 100644
@@ -1,6 +1,17 @@
 #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);
@@ -14,6 +25,8 @@ 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.21.4
#5 lore raw
In reply to BALATON Zoltan
Quoted 7 lines · BALATON Zoltan

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Quoted 7 lines

Regards,

BALATON Zoltan (4):
usb/uhci: Misc clean up
usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

Thanks, series applied to mips-next tree.

#6 lore raw

Hello,

Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · BALATON Zoltan

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Regards,

Quoted 7 lines
Quoted 5 lines

BALATON Zoltan (4):
usb/uhci: Misc clean up
usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

Thanks, series applied to mips-next tree.

According to https://wiki.qemu.org/Planning/6.2 freeze starts today and I haven't yet seen a pull request with this series. Is it still to come? (As it is fixing a bug with USB IRQ it may be OK before hard freeze but to be safe I'm asking now to avoid missing a release and having to wait months to get it merged).

Thank you,
BALATON Zoltan

#7 lore raw
Quoted 19 lines · BALATON Zoltan

Hello,

Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 14 lines · BALATON Zoltan

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Regards,

BALATON Zoltan (4):
  usb/uhci: Misc clean up
  usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

Quoted 7 lines
Quoted 1 line

Thanks, series applied to mips-next tree.

According to https://wiki.qemu.org/Planning/6.2 freeze starts today and I haven't yet seen a pull request with this series. Is it still to come? (As it is fixing a bug with USB IRQ it may be OK before hard freeze but to be safe I'm asking now to avoid missing a release and having to wait months to get it merged).

According to my time zone it is only 1pm here, the day is not yet finished :)

#8 lore raw
In reply to BALATON Zoltan
Quoted 19 lines · BALATON Zoltan

Hello,

Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 14 lines · BALATON Zoltan

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Regards,

BALATON Zoltan (4):
usb/uhci: Misc clean up
usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

Quoted 4 lines
Quoted 1 line

Thanks, series applied to mips-next tree.

According to https://wiki.qemu.org/Planning/6.2 freeze starts today and I haven't yet seen a pull request with this series. Is it still to come?

Oh, damn, was busy with edk2 stuff and didn't notice the freeze is *that* close already. Going over pending bits now and prepare a pull req ...

take care,
Gerd

#9 lore raw
Quoted 20 lines · Gerd Hoffmann
Quoted 19 lines · BALATON Zoltan

Hello,

Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 14 lines · BALATON Zoltan

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Regards,

BALATON Zoltan (4):
usb/uhci: Misc clean up
usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Thanks, series applied to mips-next tree.

According to https://wiki.qemu.org/Planning/6.2 freeze starts today and I haven't yet seen a pull request with this series. Is it still to come?

Oh, damn, was busy with edk2 stuff and didn't notice the freeze is *that* close already. Going over pending bits now and prepare a pull req ...

I think this series is taken care of by Philippe already so if you have other bits to go over that's fine, maybe you don't have to worry about this one. Was just asking to make sure this won't miss the release.

Regards,
BALATON Zoltan

#10 lore raw
Quoted 27 lines · BALATON Zoltan
Quoted 26 lines · Gerd Hoffmann
Quoted 24 lines · BALATON Zoltan

Hello,

Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · BALATON Zoltan

This is the same as posted before just omitting the two patches that are optimisations by caching the func0 and avoiding QOM casts which could not be measured to have an effect but these reamaining patches are still needed to fix USB interrupts on pegasos2

Gerd, could you please take them?

Regards,

Quoted 7 lines
Quoted 5 lines

BALATON Zoltan (4):
  usb/uhci: Misc clean up
  usb/uhci: Disallow user creating a vt82c686-uhci-pci device usb/uhci: Replace pci_set_irq with qemu_set_irq hw/usb/vt82c686-uhci-pci: Use ISA instead of PCI interrupts

Thanks, series applied to mips-next tree.

According to https://wiki.qemu.org/Planning/6.2 freeze starts today and I
haven't yet seen a pull request with this series. Is it still to come?

Quoted 7 lines
Quoted 3 lines

Oh, damn, was busy with edk2 stuff and didn't notice the freeze is *that* close already.  Going over pending bits now and prepare a pull req ...

I think this series is taken care of by Philippe already so if you have other bits to go over that's fine, maybe you don't have to worry about this one. Was just asking to make sure this won't miss the release.

Yes, I just flushed the MIPS patch queue.