]> xenbits.xensource.com Git - xenclient/kernel.git/commitdiff
Add boot parameter 'pci-mem-align' to page-align PCI memory regions.
authorKeir Fraser <keir@xensource.com>
Wed, 31 Oct 2007 09:21:37 +0000 (09:21 +0000)
committerKeir Fraser <keir@xensource.com>
Wed, 31 Oct 2007 09:21:37 +0000 (09:21 +0000)
In PCI pass-through the mmio resources are mapped/translated from pfns
to mfns (page size), so mmio resources should be at least
page-aligned.

Signed-off-by: Barak Fargoun <barak@neocleus.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
drivers/pci/bus.c
drivers/pci/quirks.c

index 5f7db9d2436e76141e15d50a44e9f1fc38e54378..6036149d3c4b82dfef3dddf52eaa9fe80a2c45d8 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "pci.h"
 
+extern int pci_mem_align;
+
 /**
  * pci_bus_alloc_resource - allocate a resource from a parent bus
  * @bus: PCI bus
@@ -44,6 +46,11 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
 
        type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
 
+       /* If the boot parameter 'pci-mem-align' was specified then we need to 
+          align the memory addresses, at page size alignment. */
+       if (pci_mem_align && (align < (PAGE_SIZE-1)))
+               align = PAGE_SIZE - 1;
+
        for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
                struct resource *r = bus->resource[i];
                if (!r)
index 60b31acb736a29b4c109ee3d0bba8d7724fe397d..7b1721cbf0386b35ec02932af494848c48016d1e 100644 (file)
 #include <linux/acpi.h>
 #include "pci.h"
 
+/* A global flag which signals if we should page-align PCI mem windows. */
+int pci_mem_align = 0;
+
+static int __init set_pci_mem_align(char *str)
+{
+       pci_mem_align = 1;
+       return 1;
+}
+__setup("pci-mem-align", set_pci_mem_align);
+
+/* This quirk function enables us to force all memory resources which are 
+ * assigned to PCI devices, to be page-aligned.
+ */
+static void __devinit quirk_align_mem_resources(struct pci_dev *dev)
+{
+       int i;
+       struct resource *r;
+       resource_size_t old_start;
+
+       if (!pci_mem_align)
+               return;
+
+       for (i=0; i < DEVICE_COUNT_RESOURCE; i++) {
+               r = &dev->resource[i];
+               if ((r == NULL) || !(r->flags & IORESOURCE_MEM))
+                       continue;
+
+               old_start = r->start;
+               r->start = (r->start + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+               r->end = r->end - (old_start - r->start);
+       }
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_align_mem_resources);
+
 /* The Mellanox Tavor device gives false positive parity errors
  * Mark this device with a broken_parity_status, to allow
  * PCI scanning code to "skip" this now blacklisted device.