Sophie

Sophie

distrib > Mandriva > current > x86_64 > by-pkgid > d41cc2729f5f0fbbd2607b14a49457f3 > files > 14

kernel-xen-2.6.32.11-2mdv2010.1.src.rpm

Subject: linux/pci: reserve io/memory space for bridge
From: http://xenbits.xensource.com/linux-2.6.18-xen.hg (tip 1010:10eae161c153)
Patch-mainline: n/a

reserve io/memory space for bridge which will be used later
by PCI hotplug.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Acked-by: jbeulich@novell.com

--- sle11sp1-2010-03-11.orig/Documentation/kernel-parameters.txt	2010-03-11 09:11:45.000000000 +0100
+++ sle11sp1-2010-03-11/Documentation/kernel-parameters.txt	2010-03-11 09:11:54.000000000 +0100
@@ -1994,6 +1994,13 @@ and is between 256 and 4096 characters. 
 				off: Turn ECRC off
 				on: Turn ECRC on.
 
+	pci_reserve=	[PCI]
+			Format: [<sbdf>[+IO<size>][+MEM<size>]][,<sbdf>...]
+			Format of sbdf: [<segment>:]<bus>:<dev>.<func>
+			Specifies the least reserved io size or memory size
+			which is assigned to PCI bridge even when no child
+			pci device exists. This is useful with PCI hotplug.
+
 	pcie_aspm=	[PCIE] Forcibly enable or disable PCIe Active State Power
 			Management.
 		off	Disable ASPM.
--- sle11sp1-2010-03-11.orig/drivers/pci/Kconfig	2009-12-04 10:27:46.000000000 +0100
+++ sle11sp1-2010-03-11/drivers/pci/Kconfig	2009-12-04 10:27:49.000000000 +0100
@@ -56,6 +56,13 @@ config PCI_IOMULTI
 	help
 	  Say Y here if you need io multiplexing.
 
+config PCI_RESERVE
+	bool "PCI IO/MEMORY space reserve"
+	depends on PCI && XEN_PRIVILEGED_GUEST
+	default y
+	help
+	  Say Y here if you need PCI IO/MEMORY space reserve
+
 config PCI_STUB
 	tristate "PCI Stub driver"
 	depends on PCI
--- sle11sp1-2010-03-11.orig/drivers/pci/Makefile	2009-12-04 10:27:46.000000000 +0100
+++ sle11sp1-2010-03-11/drivers/pci/Makefile	2009-12-04 10:27:49.000000000 +0100
@@ -9,6 +9,7 @@ obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_SYSFS) += slot.o
 obj-$(CONFIG_PCI_GUESTDEV) += guestdev.o
 obj-$(CONFIG_PCI_IOMULTI) += iomulti.o
+obj-$(CONFIG_PCI_RESERVE) += reserve.o
 
 obj-$(CONFIG_PCI_LEGACY) += legacy.o
 CFLAGS_legacy.o += -Wno-deprecated-declarations
--- sle11sp1-2010-03-11.orig/drivers/pci/pci.h	2009-12-04 10:27:46.000000000 +0100
+++ sle11sp1-2010-03-11/drivers/pci/pci.h	2009-12-04 10:27:49.000000000 +0100
@@ -318,4 +318,19 @@ extern int pci_is_iomuldev(struct pci_de
 #define pci_is_iomuldev(dev)	0
 #endif
 
+#ifdef CONFIG_PCI_RESERVE
+unsigned long pci_reserve_size_io(struct pci_bus *bus);
+unsigned long pci_reserve_size_mem(struct pci_bus *bus);
+#else
+static inline unsigned long pci_reserve_size_io(struct pci_bus *bus)
+{
+	return 0;
+}
+
+static inline unsigned long pci_reserve_size_mem(struct pci_bus *bus)
+{
+	return 0;
+}
+#endif /* CONFIG_PCI_RESERVE */
+
 #endif /* DRIVERS_PCI_H */
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ sle11sp1-2010-03-11/drivers/pci/reserve.c	2010-03-24 14:00:05.000000000 +0100
@@ -0,0 +1,138 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (c) 2009 Isaku Yamahata
+ *                    VA Linux Systems Japan K.K.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/pci.h>
+
+#include <asm/setup.h>
+
+static char pci_reserve_param[COMMAND_LINE_SIZE];
+
+/* pci_reserve=	[PCI]
+ * Format: [<sbdf>[+IO<size>][+MEM<size>]][,<sbdf>...]
+ * Format of sbdf: [<segment>:]<bus>:<dev>.<func>
+ */
+static int pci_reserve_parse_size(const char *str,
+				  unsigned long *io_size,
+				  unsigned long *mem_size)
+{
+	if (sscanf(str, "io%lx", io_size) == 1 ||
+	    sscanf(str, "IO%lx", io_size) == 1)
+		return 0;
+
+	if (sscanf(str, "mem%lx", mem_size) == 1 ||
+	    sscanf(str, "MEM%lx", mem_size) == 1)
+		return 0;
+
+	return -EINVAL;
+}
+
+static int pci_reserve_parse_one(const char *str,
+				 int *seg, int *bus, int *dev, int *func,
+				 unsigned long *io_size,
+				 unsigned long *mem_size)
+{
+	char *p;
+
+	*io_size = 0;
+	*mem_size = 0;
+
+	if (sscanf(str, "%x:%x:%x.%x", seg, bus, dev, func) != 4) {
+		*seg = 0;
+		if (sscanf(str, "%x:%x.%x", bus, dev, func) != 3) {
+			return -EINVAL;
+		}
+	}
+
+	p = strchr(str, '+');
+	if (p == NULL)
+		return -EINVAL;
+	if (pci_reserve_parse_size(++p, io_size, mem_size))
+		return -EINVAL;
+
+	p = strchr(p, '+');
+	return p ? pci_reserve_parse_size(p + 1, io_size, mem_size) : 0;
+}
+
+static unsigned long pci_reserve_size(struct pci_bus *pbus, int flags)
+{
+	char *sp;
+	char *ep;
+
+	int seg;
+	int bus;
+	int dev;
+	int func;
+
+	unsigned long io_size;
+	unsigned long mem_size;
+
+	sp = pci_reserve_param;
+
+	do {
+		ep = strchr(sp, ',');
+		if (ep)
+			*ep = '\0';	/* chomp */
+
+		if (pci_reserve_parse_one(sp, &seg, &bus, &dev, &func,
+					  &io_size, &mem_size) == 0) {
+			if (pci_domain_nr(pbus) == seg &&
+			    pbus->number == bus &&
+			    PCI_SLOT(pbus->self->devfn) == dev &&
+			    PCI_FUNC(pbus->self->devfn) == func) {
+				switch (flags) {
+				case IORESOURCE_IO:
+					return io_size;
+				case IORESOURCE_MEM:
+					return mem_size;
+				default:
+					break;
+				}
+			}
+		}
+
+		if (ep) {
+			*ep = ',';	/* restore chomp'ed ',' for later */
+			ep++;
+		}
+		sp = ep;
+	} while (ep);
+
+	return 0;
+}
+
+unsigned long pci_reserve_size_io(struct pci_bus *pbus)
+{
+	return pci_reserve_size(pbus, IORESOURCE_IO);
+}
+
+unsigned long pci_reserve_size_mem(struct pci_bus *pbus)
+{
+	return pci_reserve_size(pbus, IORESOURCE_MEM);
+}
+
+static int __init pci_reserve_setup(char *str)
+{
+	if (strlen(str) >= sizeof(pci_reserve_param))
+		return 0;
+	strlcpy(pci_reserve_param, str, sizeof(pci_reserve_param));
+	return 1;
+}
+__setup("pci_reserve=", pci_reserve_setup);
--- sle11sp1-2010-03-11.orig/drivers/pci/setup-bus.c	2010-03-11 09:10:12.000000000 +0100
+++ sle11sp1-2010-03-11/drivers/pci/setup-bus.c	2010-03-11 09:12:00.000000000 +0100
@@ -337,7 +337,7 @@ static void pbus_size_io(struct pci_bus 
 #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
 	size = (size & 0xff) + ((size & ~0xffUL) << 2);
 #endif
-	size = ALIGN(size + size1, 4096);
+	size = ALIGN(max(size + size1, pci_reserve_size_io(bus)), 4096);
 	if (!size) {
 		b_res->flags = 0;
 		return;
@@ -417,7 +417,8 @@ static int pbus_size_mem(struct pci_bus 
 			min_align = align1 >> 1;
 		align += aligns[order];
 	}
-	size = ALIGN(size, min_align);
+	size = ALIGN(max(size, (resource_size_t)pci_reserve_size_mem(bus)),
+		     min_align);
 	if (!size) {
 		b_res->flags = 0;
 		return 1;