ia64/linux-2.6.18-xen.hg

changeset 746:2268be46c75e

dom0 linux: Fix and cleanup reassigning memory resource code.

When we use PCI pass-through, we have to assign page-aligned resources
to device. To do this, we round up the alignment to PAGE_SIZE, if
device is specified by "reassigndev=" boot parameter.

"pdev_sort_resources" function uses the alignment. But it does not
round up the alignment to PAGE_SIZE. This patch makes
"pdev_sort_resources" function round up the alignment to PAGE_SIZE.

"pbus_size_mem" function round up the alignment of bridge's resource
window as well as that of normal resource. But we don't need to do
this. This patch makes "pbus_size_mem" function exclude bridges's
resource window.

This patch also cleanups code of reassigning memory resource.

Signed-off-by: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Nov 28 13:07:36 2008 +0000 (2008-11-28)
parents 0b859c9516ba
children d545a95fca73
files drivers/pci/pci.h drivers/pci/quirks.c drivers/pci/setup-bus.c drivers/pci/setup-res.c
line diff
     1.1 --- a/drivers/pci/pci.h	Wed Nov 26 11:13:49 2008 +0000
     1.2 +++ b/drivers/pci/pci.h	Fri Nov 28 13:07:36 2008 +0000
     1.3 @@ -104,5 +104,4 @@ extern int is_reassigndev(struct pci_dev
     1.4  extern void pci_disable_bridge_window(struct pci_dev *dev);
     1.5  #else
     1.6  #define is_reassigndev(dev) 0
     1.7 -static inline void pci_disable_bridge_window(struct pci_dev *dev) {}
     1.8  #endif
     2.1 --- a/drivers/pci/quirks.c	Wed Nov 26 11:13:49 2008 +0000
     2.2 +++ b/drivers/pci/quirks.c	Fri Nov 28 13:07:36 2008 +0000
     2.3 @@ -24,6 +24,7 @@
     2.4  #include "pci.h"
     2.5  
     2.6  
     2.7 +#ifdef CONFIG_PCI_REASSIGN
     2.8  /*
     2.9   * This quirk function disables the device and releases resources
    2.10   * which is specified by kernel's boot parameter 'reassigndev'.
    2.11 @@ -66,10 +67,10 @@ static void __devinit quirk_release_reso
    2.12  		    (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
    2.13  			pci_disable_bridge_window(dev);
    2.14  		}
    2.15 -		return;
    2.16  	}
    2.17  }
    2.18  DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_release_resources);
    2.19 +#endif  /* CONFIG_PCI_REASSIGN */
    2.20  
    2.21  /* The Mellanox Tavor device gives false positive parity errors
    2.22   * Mark this device with a broken_parity_status, to allow
     3.1 --- a/drivers/pci/setup-bus.c	Wed Nov 26 11:13:49 2008 +0000
     3.2 +++ b/drivers/pci/setup-bus.c	Fri Nov 28 13:07:36 2008 +0000
     3.3 @@ -355,7 +355,7 @@ pbus_size_mem(struct pci_bus *bus, unsig
     3.4  				continue;
     3.5  			r_size = r->end - r->start + 1;
     3.6  
     3.7 -			if (reassign)
     3.8 +			if ((i < PCI_BRIDGE_RESOURCES) && reassign)
     3.9  				r_size = ALIGN(r_size, PAGE_SIZE);
    3.10  
    3.11  			/* For bridges size != alignment */
     4.1 --- a/drivers/pci/setup-res.c	Wed Nov 26 11:13:49 2008 +0000
     4.2 +++ b/drivers/pci/setup-res.c	Fri Nov 28 13:07:36 2008 +0000
     4.3 @@ -234,6 +234,7 @@ void __devinit
     4.4  pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
     4.5  {
     4.6  	int i;
     4.7 +	int reassigndev = is_reassigndev(dev);
     4.8  
     4.9  	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
    4.10  		struct resource *r;
    4.11 @@ -245,6 +246,11 @@ pdev_sort_resources(struct pci_dev *dev,
    4.12  		
    4.13  		if (!(r->flags) || r->parent)
    4.14  			continue;
    4.15 +		
    4.16 +		if (i < PCI_BRIDGE_RESOURCES && (r->flags & IORESOURCE_MEM) &&
    4.17 +		    reassigndev)
    4.18 +			r_align = ALIGN(r_align, PAGE_SIZE);
    4.19 +
    4.20  		if (!r_align) {
    4.21  			printk(KERN_WARNING "PCI: Ignore bogus resource %d "
    4.22  				"[%llx:%llx] of %s\n",
    4.23 @@ -263,6 +269,10 @@ pdev_sort_resources(struct pci_dev *dev,
    4.24  				align = (idx < PCI_BRIDGE_RESOURCES) ?
    4.25  					ln->res->end - ln->res->start + 1 :
    4.26  					ln->res->start;
    4.27 +				if ((idx < PCI_BRIDGE_RESOURCES) &&
    4.28 +				    (ln->res->flags & IORESOURCE_MEM) &&
    4.29 +				    is_reassigndev(ln->dev))
    4.30 +					align = ALIGN(align, PAGE_SIZE);
    4.31  			}
    4.32  			if (r_align > align) {
    4.33  				tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);