Skip to contentSkip to conversation

Make MSI-X work with 64-bit BARs

PATCH In review Neil Turton 2 participants 2 messages May 14, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make MSI-X work with 64-bit BARs

The code for working out the base address of a 64-bit BAR currently puts the two halves together in the wrong order and leaves the type bits in
the resulting value. It also treats PCI_BASE_ADDRESS_MEM_TYPE_64 as an
flag rather than an enumeration value. This patch fixes these issues.

xen/arch/x86/msi.c +10 -7
diff -r 810d8c3ac992 xen/arch/x86/msi.c
@@ -521,17 +521,20 @@ static u64 pci_resource_start(struct pci
 static u64 pci_resource_start(struct pci_dev *dev, u8 bar_index)
 {
     u64 bar_base;
+    u32 reg_val;
     u8 bus = dev->bus;
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
 
-    bar_base = pci_conf_read32(bus, slot, func,
-                               PCI_BASE_ADDRESS_0 + 4 * bar_index);
-    if ( bar_base & PCI_BASE_ADDRESS_MEM_TYPE_64 )
-    {
-        bar_base <<= 32;
-        bar_base += pci_conf_read32(bus, slot, func,
-                               PCI_BASE_ADDRESS_0 + 4 * (bar_index + 1));
+    reg_val = pci_conf_read32(bus, slot, func,
+                              PCI_BASE_ADDRESS_0 + 4 * bar_index);
+    bar_base = reg_val & PCI_BASE_ADDRESS_MEM_MASK;
+    if ( ( reg_val & PCI_BASE_ADDRESS_MEM_TYPE_MASK ) ==
+         PCI_BASE_ADDRESS_MEM_TYPE_64 )
+    {
+        reg_val = pci_conf_read32(bus, slot, func,
+                                  PCI_BASE_ADDRESS_0 + 4 * (bar_index + 1));
+        bar_base |= ((u64)reg_val) << 32;
     }
 
     return bar_base;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Thanks!
It is so silly of me to make such a mistake in my patch.

2008/5/14 Neil Turton <[email protected]>:

Quoted 47 lines

The code for working out the base address of a 64-bit BAR currently puts the two halves together in the wrong order and leaves the type bits in
the resulting value. It also treats PCI_BASE_ADDRESS_MEM_TYPE_64 as an
flag rather than an enumeration value. This patch fixes these issues.

diff -r 810d8c3ac992 xen/arch/x86/msi.c

xen/arch/x86/msi.c Wed May 14 13:44:34 2008 +0100 renamed from xen/arch/x86/msi.c Thu May 08 16:58:33 2008 +0100 +10 -7
@@ -521,17 +521,20 @@ static u64 pci_resource_start(struct pci
 static u64 pci_resource_start(struct pci_dev *dev, u8 bar_index)
 {
    u64 bar_base;
+    u32 reg_val;
    u8 bus = dev->bus;
    u8 slot = PCI_SLOT(dev->devfn);
    u8 func = PCI_FUNC(dev->devfn);
 
-    bar_base = pci_conf_read32(bus, slot, func,
-                               PCI_BASE_ADDRESS_0 + 4 * bar_index);
-    if ( bar_base & PCI_BASE_ADDRESS_MEM_TYPE_64 )
-    {
-        bar_base <<= 32;
-        bar_base += pci_conf_read32(bus, slot, func,
-                               PCI_BASE_ADDRESS_0 + 4 * (bar_index + 1));
+    reg_val = pci_conf_read32(bus, slot, func,
+                              PCI_BASE_ADDRESS_0 + 4 * bar_index);
+    bar_base = reg_val & PCI_BASE_ADDRESS_MEM_MASK;
+    if ( ( reg_val & PCI_BASE_ADDRESS_MEM_TYPE_MASK ) ==
+         PCI_BASE_ADDRESS_MEM_TYPE_64 )
+    {
+        reg_val = pci_conf_read32(bus, slot, func,
+                                  PCI_BASE_ADDRESS_0 + 4 * (bar_index + 1));
+        bar_base |= ((u64)reg_val) << 32;
    }
 
    return bar_base;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel