mptable: Reset pinmask on new bus or device.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 3 Jan 2010 20:14:11 +0000 (15:14 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 3 Jan 2010 20:14:11 +0000 (15:14 -0500)
Fix small possibility of bus changing without device changing.

src/mptable.c
src/pci.h

index f87e6856df07f0b2ef69fa69261814aa61d3a620..eba7d97436727cfafffbdd2b4cae2635a5eab87f 100644 (file)
@@ -110,8 +110,8 @@ mptable_init(void)
         int irq = pci_config_readb(bdf, PCI_INTERRUPT_LINE);
         if (pin == 0)
             continue;
-        if (dev != pci_bdf_to_dev(bdf)) {
-            dev = pci_bdf_to_dev(bdf);
+        if (dev != pci_bdf_to_busdev(bdf)) {
+            dev = pci_bdf_to_busdev(bdf);
             pinmask = 0;
         }
         if (pinmask & (1 << pin)) /* pin was seen already */
@@ -123,7 +123,7 @@ mptable_init(void)
         intsrc->irqtype = 0; /* INT */
         intsrc->irqflag = 1; /* active high */
         intsrc->srcbus = pci_bdf_to_bus(bdf); /* PCI bus */
-        intsrc->srcbusirq = (dev << 2) | (pin - 1);
+        intsrc->srcbusirq = (pci_bdf_to_dev(bdf) << 2) | (pin - 1);
         intsrc->dstapic = ioapic_id;
         intsrc->dstirq = irq;
         intsrc++;
index a0b6b9c3e3c356ec5afefedda167550b73a31971..3c04529fae6177ca8e397c62b0e6a07db9392bfb 100644 (file)
--- a/src/pci.h
+++ b/src/pci.h
@@ -9,6 +9,9 @@ static inline u8 pci_bdf_to_bus(u16 bdf) {
 static inline u8 pci_bdf_to_devfn(u16 bdf) {
     return bdf & 0xff;
 }
+static inline u16 pci_bdf_to_busdev(u16 bdf) {
+    return bdf & ~0x07;
+}
 static inline u8 pci_bdf_to_dev(u16 bdf) {
     return (bdf >> 3) & 0x1f;
 }