Simplify pci_slot_get_irq().
authorKevin O'Connor <kevin@koconnor.net>
Sat, 1 Oct 2011 18:52:35 +0000 (14:52 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 14 Oct 2011 03:20:57 +0000 (23:20 -0400)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/pciinit.c

index 66577a3b31dc3cc11441e095f23f1164d63266d1..3c12602b3814a9f014f6c7d209cab57c4a7705ad 100644 (file)
@@ -101,13 +101,11 @@ const u8 pci_irqs[4] = {
     10, 10, 11, 11
 };
 
-/* return the global irq number corresponding to a given device irq
-   pin. We could also use the bus number to have a more precise
-   mapping. */
-static int pci_slot_get_pirq(u16 bdf, int irq_num)
+// Return the global irq number corresponding to a host bus device irq pin.
+static int pci_slot_get_irq(u16 bdf, int pin)
 {
     int slot_addend = pci_bdf_to_dev(bdf) - 1;
-    return (irq_num + slot_addend) & 3;
+    return pci_irqs[(pin - 1 + slot_addend) & 3];
 }
 
 /* PIIX3/PIIX4 PCI to ISA bridge */
@@ -215,23 +213,19 @@ static const struct pci_device_id pci_device_tbl[] = {
 static void pci_bios_init_device(struct pci_device *pci)
 {
     u16 bdf = pci->bdf;
-    int pin, pic_irq;
-
     dprintf(1, "PCI: init bdf=%02x:%02x.%x id=%04x:%04x\n"
             , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf)
             , pci->vendor, pci->device);
+
     pci_init_device(pci_class_tbl, pci, NULL);
 
     /* enable memory mappings */
     pci_config_maskw(bdf, PCI_COMMAND, 0, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
 
     /* map the interrupt */
-    pin = pci_config_readb(bdf, PCI_INTERRUPT_PIN);
-    if (pin != 0) {
-        pin = pci_slot_get_pirq(bdf, pin - 1);
-        pic_irq = pci_irqs[pin];
-        pci_config_writeb(bdf, PCI_INTERRUPT_LINE, pic_irq);
-    }
+    int pin = pci_config_readb(bdf, PCI_INTERRUPT_PIN);
+    if (pin != 0)
+        pci_config_writeb(bdf, PCI_INTERRUPT_LINE, pci_slot_get_irq(bdf, pin));
 
     pci_init_device(pci_device_tbl, pci, NULL);
 }