From: Keir Fraser Date: Wed, 31 Oct 2007 09:21:37 +0000 (+0000) Subject: Add boot parameter 'pci-mem-align' to page-align PCI memory regions. X-Git-Tag: xen-3.2.0~21^2^2~28^2^2~22^2^2~9^2~12^2 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=49bfe589c439bfe8a785a988e6c19d7ce25afea2;p=xenclient%2Fkernel.git Add boot parameter 'pci-mem-align' to page-align PCI memory regions. 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 Signed-off-by: Keir Fraser --- diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 5f7db9d2..6036149d 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -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) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 60b31acb..7b1721cb 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -23,6 +23,40 @@ #include #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.