Skip to contentSkip to conversation

IRQ sharing in PCI bus

PATCH In review andrzej zaborowski 4 participants 6 messages Sep 23, 2006 – Sep 24, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IRQ sharing in PCI bus

This allows multiple PCI devices on a bus to use the same IRQ lines. The signals from all devices are ORed. It will only work if the guest OS'es drivers supports that.

Linux guest required that to have scsi disks and usb devices working at the same time on an emulated Versatile PB machine.

hw/pci.c +7 -1
diff -pNaur qemu-cvs-ts-orig/hw/pci.c qemu-cvs-ts/hw/pci.c
@@ -34,6 +34,7 @@ struct PCIBus {
     SetIRQFunc *low_set_irq;
     void *irq_opaque;
     PCIDevice *devices[256];
+    int irq_count[4];
 };
 
 static void pci_update_mappings(PCIDevice *d);
@@ -49,6 +50,7 @@ PCIBus *pci_register_bus(pci_set_irq_fn 
     bus->set_irq = set_irq;
     bus->irq_opaque = pic;
     bus->devfn_min = devfn_min;
+    memset(bus->irq_count, 0, sizeof(bus->irq_count));
     first_bus = bus;
     return bus;
 }
@@ -100,6 +102,7 @@ PCIDevice *pci_register_device(PCIBus *b
     pci_dev->bus = bus;
     pci_dev->devfn = devfn;
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
+    memset(pci_dev->irq_state, 0, sizeof(pci_dev->irq_state));
 
     if (!config_read)
         config_read = pci_default_read_config;
@@ -404,7 +407,10 @@ uint32_t pci_data_read(void *opaque, uin
 void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level)
 {
     PCIBus *bus = pci_dev->bus;
-    bus->set_irq(pci_dev, bus->irq_opaque, irq_num, level);
+    bus->irq_count[irq_num] += level - pci_dev->irq_state[irq_num];
+    pci_dev->irq_state[irq_num] = level;
+    bus->set_irq(pci_dev, bus->irq_opaque,
+                 irq_num, !!bus->irq_count[irq_num]);
 }
 
 /***********************************************************/
vl.h +3 -0
diff -pNaur qemu-cvs-ts-orig/vl.h qemu-cvs-ts/vl.h
@@ -733,6 +733,9 @@ struct PCIDevice {
     PCIConfigWriteFunc *config_write;
     /* ??? This is a PC-specific hack, and should be removed.  */
     int irq_index;
+
+    /* remember last irq levels */
+    int irq_state[4];
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
#1 lore raw
Quoted 6 lines · andrzej zaborowski

This allows multiple PCI devices on a bus to use the same IRQ lines. The signals from all devices are ORed. It will only work if the guest OS'es drivers supports that.

Linux guest required that to have scsi disks and usb devices working at the same time on an emulated Versatile PB machine.

PCI IRQ sharing is already implemented, at least for piix3. You should look at that code and try to fix the related code in other PCI controllers.

Regards,

Fabrice.

#2 lore raw
Quoted 10 lines · Fabrice Bellard
Quoted 6 lines · andrzej zaborowski

This allows multiple PCI devices on a bus to use the same IRQ lines. The signals from all devices are ORed. It will only work if the guest OS'es drivers supports that.

Linux guest required that to have scsi disks and usb devices working at the same time on an emulated Versatile PB machine.

PCI IRQ sharing is already implemented, at least for piix3. You should look at that code and try to fix the related code in other PCI controllers.

Seems silly to implement this several times rather than once in generic code.

Paul

#3 lore raw
Quoted 8 lines · Paul Brook
Quoted 6 lines · Fabrice Bellard
Quoted 4 lines · andrzej zaborowski

This allows multiple PCI devices on a bus to use the same IRQ lines. The signals from all devices are ORed. It will only work if the guest OS'es drivers supports that.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Linux guest required that to have scsi disks and usb devices working at the same time on an emulated Versatile PB machine.

PCI IRQ sharing is already implemented, at least for piix3. You should look at that code and try to fix the related code in other PCI controllers.

Seems silly to implement this several times rather than once in generic code.

Right. My comment did not exclude that :-)

Fabrice.

#4 lore raw
In reply to andrzej zaborowski
Quoted 1 line · andrzej zaborowski

This allows multiple PCI devices on a bus to use the same IRQ lines.

You patch was missing the mapping from device to bus IRQ lines. I applied a fix that includes this, and removes the hacks for PPC IRQ routing.

As mentioned in the comments for the new code it looks like sparc64 IRQs are totally busted. I couldn't figure out out what the correct implementation was supposed to be, so I made something up.

Paul

#5 lore raw
Quoted 3 lines

As mentioned in the comments for the new code it looks like sparc64 IRQs are totally busted. I couldn't figure out out what the correct implementation was supposed to be, so I made something up.

Sparc64 IRQs are completely unimplemented. I've postponed that until I get OpenBIOS to the point where it can do something sensible about this. The current OpenBIOS status is that the Unix port runs nicely on native HW, but under Qemu the bootable version crashes during Forth execution. But I'd say we are not too far from a working BIOS.

If you are interested, the IRQ definitions can be found in Sun document 805-0087 (UltraSPARC IIi User's Manual, http://www.sun.com/processors/manuals/805-0087.pdf), pages 107-126 for interrupt controller and 291-334 for PCI/IOMMU/interrupt definitions.

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/