Skip to contentSkip to conversation

hw/i386/pc_piix: Make piix_intx_routing_notifier_xen() more device independent

PATCH In review Bernhard Beschow 4 participants 7 messages Jan 7, 2024 – Jan 24, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/i386/pc_piix: Make piix_intx_routing_notifier_xen() more device independent

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

---
 hw/i386/pc_piix.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/i386/pc_piix.c +3 -6
index 042c13cdbc..abfcfe4d2b 100644
@@ -92,13 +92,10 @@ static void piix_intx_routing_notifier_xen(PCIDevice *dev)
 {
     int i;
 
-    /* Scan for updates to PCI link routes (0x60-0x63). */
+    /* Scan for updates to PCI link routes. */
     for (i = 0; i < PIIX_NUM_PIRQS; i++) {
-        uint8_t v = dev->config_read(dev, PIIX_PIRQCA + i, 1);
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
+        const PCIINTxRoute route = pci_device_route_intx_to_irq(dev, i);
+        const uint8_t v = route.mode == PCI_INTX_ENABLED ? route.irq : 0;
         xen_set_pci_link_route(i, v);
     }
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Bernhard Beschow

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

---
  hw/i386/pc_piix.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
hw/i386/pc_piix.c +0 -0
index 042c13cdbc..abfcfe4d2b 100644
@@ -92,13 +92,10 @@ static void piix_intx_routing_notifier_xen(PCIDevice *dev)
  {
      int i;

hw/i386/pc_piix.c static void piix_intx_routing_notifier_xen(PCIDevice *dev) · line 97

Quoted 10 lines
hw/i386/pc_piix.c +2 -6
 
-    /* Scan for updates to PCI link routes (0x60-0x63). */
+    /* Scan for updates to PCI link routes. */
      for (i = 0; i < PIIX_NUM_PIRQS; i++) {
-        uint8_t v = dev->config_read(dev, PIIX_PIRQCA + i, 1);
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
+        const PCIINTxRoute route = pci_device_route_intx_to_irq(dev, i);

This indeed dispatch to piix_route_intx_pin_to_irq().

Quoted 4 lines
hw/i386/pc_piix.c +1 -0
+        const uint8_t v = route.mode == PCI_INTX_ENABLED ? route.irq : 0;
          xen_set_pci_link_route(i, v);
      }
  }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Bernhard Beschow
Quoted 7 lines · Bernhard Beschow

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

Quoted 6 lines

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

I'm still moderately unhappy that all this code is written with the apparent assumption that there is only *one* IRQ# which is the target for a given INTx, when in fact it gets routed to that pin# on the legacy PIC and a potentially *different* pin# on the I/O APIC.

But you aren't making that worse, so

#3 lore raw

Am 9. Januar 2024 08:51:37 UTC schrieb David Woodhouse <[email protected]>:

Quoted 13 lines · Bernhard Beschow
Quoted 12 lines

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

Quoted 6 lines
Quoted 1 line

I'm still moderately unhappy that all this code is written with the apparent assumption that there is only *one* IRQ# which is the target for a given INTx, when in fact it gets routed to that pin# on the legacy PIC and a potentially *different* pin# on the I/O APIC.

Would TYPE_SPLIT_IRQ help in any way?

Quoted 4 lines

But you aren't making that worse, so

Thanks!

#4 lore raw
In reply to Bernhard Beschow

Am 7. Januar 2024 23:16:23 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 7 lines

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

Quoted 6 lines

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

Hi Michael,

could you tag this, too? Or do we need another R-b?

Best regards,
Bernhard

Quoted 25 lines

---
hw/i386/pc_piix.c | 9 +++------

1 file changed, 3 insertions(+), 6 deletions(-)
hw/i386/pc_piix.c +3 -6
index 042c13cdbc..abfcfe4d2b 100644
@@ -92,13 +92,10 @@ static void piix_intx_routing_notifier_xen(PCIDevice *dev)
 {
    int i;
 
-    /* Scan for updates to PCI link routes (0x60-0x63). */
+    /* Scan for updates to PCI link routes. */
    for (i = 0; i < PIIX_NUM_PIRQS; i++) {
-        uint8_t v = dev->config_read(dev, PIIX_PIRQCA + i, 1);
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
+        const PCIINTxRoute route = pci_device_route_intx_to_irq(dev, i);
+        const uint8_t v = route.mode == PCI_INTX_ENABLED ? route.irq : 0;
        xen_set_pci_link_route(i, v);
    }
 }
#5 lore raw
Quoted 15 lines · Bernhard Beschow

Am 7. Januar 2024 23:16:23 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 12 lines

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

Quoted 8 lines
Quoted 1 line

Hi Michael,

could you tag this, too? Or do we need another R-b?

Best regards,
Bernhard

tagged, too.

Quoted 25 lines
Quoted 25 lines

---
hw/i386/pc_piix.c | 9 +++------

1 file changed, 3 insertions(+), 6 deletions(-)
hw/i386/pc_piix.c +3 -6
index 042c13cdbc..abfcfe4d2b 100644
@@ -92,13 +92,10 @@ static void piix_intx_routing_notifier_xen(PCIDevice *dev)
 {
    int i;
 
-    /* Scan for updates to PCI link routes (0x60-0x63). */
+    /* Scan for updates to PCI link routes. */
    for (i = 0; i < PIIX_NUM_PIRQS; i++) {
-        uint8_t v = dev->config_read(dev, PIIX_PIRQCA + i, 1);
-        if (v & 0x80) {
-            v = 0;
-        }
-        v &= 0xf;
+        const PCIINTxRoute route = pci_device_route_intx_to_irq(dev, i);
+        const uint8_t v = route.mode == PCI_INTX_ENABLED ? route.irq : 0;
        xen_set_pci_link_route(i, v);
    }
 }
#6 lore raw
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Bernhard Beschow

Am 7. Januar 2024 23:16:23 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 13 lines

This is a follow-up on commit 89965db43cce "hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()" which introduced piix_intx_routing_notifier_xen(). This function is implemented in board code but accesses the PCI configuration space of the PIIX ISA function to determine the PCI interrupt routes. Avoid this by reusing pci_device_route_intx_to_irq() which makes piix_intx_routing_notifier_xen() more device-agnostic.

One remaining improvement would be making piix_intx_routing_notifier_xen() agnostic towards the number of PCI interrupt routes and move it to xen-hvm. This might be useful for possible Q35 Xen efforts but remains a future exercise for now.

Quoted 8 lines
Quoted 6 lines

Hi Michael,

could you tag this, too? Or do we need another R-b?

Best regards,
Bernhard

tagged, too.

FYI merged as commit ebd92d6de3.