]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/suse-2.6.27.25/patches.xen/pci-reassign-resources
Updated xen patches taken from suse.
[people/pmueller/ipfire-2.x.git] / src / patches / suse-2.6.27.25 / patches.xen / pci-reassign-resources
CommitLineData
cc90b958 1Subject: xen/dom0: Reassign memory resources to device for pci passthrough
00e5a55c 2From: http://xenbits.xensource.com/linux-2.6.18-xen.hg (tip 852:571229e265e2)
cc90b958
BS
3Patch-mainline: obsolete
4Acked-by: jbeulich@novell.com
5
00e5a55c
BS
6--- sle11-2009-04-09.orig/drivers/pci/Kconfig 2009-04-09 14:29:05.000000000 +0200
7+++ sle11-2009-04-09/drivers/pci/Kconfig 2008-11-10 11:49:15.000000000 +0100
8@@ -21,6 +21,9 @@ config PCI_MSI
9
10 If you don't know what to do here, say N.
11
12+config PCI_REASSIGN
13+ bool
14+
15 config PCI_LEGACY
16 bool "Enable deprecated pci_find_* API"
17 depends on PCI
18--- sle11-2009-04-09.orig/drivers/pci/Makefile 2009-04-09 14:29:05.000000000 +0200
19+++ sle11-2009-04-09/drivers/pci/Makefile 2008-10-21 13:09:46.000000000 +0200
cc90b958
BS
20@@ -4,6 +4,7 @@
21
22 obj-y += access.o bus.o probe.o remove.o pci.o quirks.o slot.o \
23 pci-driver.o search.o pci-sysfs.o rom.o setup-res.o
24+obj-$(CONFIG_PCI_REASSIGN) += reassigndev.o
25 obj-$(CONFIG_PROC_FS) += proc.o
26
27 # Build PCI Express stuff if needed
00e5a55c
BS
28--- sle11-2009-04-09.orig/drivers/pci/pci.h 2009-04-09 14:29:05.000000000 +0200
29+++ sle11-2009-04-09/drivers/pci/pci.h 2008-10-21 13:09:01.000000000 +0200
30@@ -145,3 +145,9 @@ struct pci_slot_attribute {
cc90b958
BS
31 };
32 #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
33
34+#ifdef CONFIG_PCI_REASSIGN
35+extern int is_reassigndev(struct pci_dev *dev);
36+extern void pci_disable_bridge_window(struct pci_dev *dev);
37+#else
38+#define is_reassigndev(dev) 0
39+#endif
00e5a55c
BS
40--- sle11-2009-04-09.orig/drivers/pci/quirks.c 2009-04-09 14:29:05.000000000 +0200
41+++ sle11-2009-04-09/drivers/pci/quirks.c 2009-04-09 14:34:32.000000000 +0200
42@@ -25,6 +25,57 @@
43 #include <linux/pci-aspm.h>
cc90b958
BS
44 #include "pci.h"
45
46+#ifdef CONFIG_PCI_REASSIGN
47+/*
00e5a55c
BS
48+ * This quirk function disables memory decoding and releases memory
49+ * resources which is specified by kernel's boot parameter 'reassigndev'.
cc90b958 50+ * Later on, kernel will assign page-aligned memory resource back
00e5a55c 51+ * to the device.
cc90b958
BS
52+ */
53+static void __devinit quirk_release_resources(struct pci_dev *dev)
54+{
55+ int i;
56+ struct resource *r;
00e5a55c 57+ u16 command;
cc90b958
BS
58+
59+ if (is_reassigndev(dev)) {
60+ if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL &&
61+ (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) {
62+ /* PCI Host Bridge isn't a target device */
63+ return;
64+ }
65+ printk(KERN_INFO
00e5a55c 66+ "PCI: Disable memory decoding and release memory resources [%s].\n",
cc90b958 67+ pci_name(dev));
00e5a55c
BS
68+ pci_read_config_word(dev, PCI_COMMAND, &command);
69+ command &= ~PCI_COMMAND_MEMORY;
70+ pci_write_config_word(dev, PCI_COMMAND, command);
cc90b958
BS
71+
72+ for (i=0; i < PCI_NUM_RESOURCES; i++) {
73+ r = &dev->resource[i];
74+ if (!(r->flags & IORESOURCE_MEM))
75+ continue;
76+
77+ r->end = r->end - r->start;
78+ r->start = 0;
79+
80+ if (i < PCI_BRIDGE_RESOURCES) {
81+ pci_update_resource(dev, r, i);
82+ }
83+ }
84+ /* need to disable bridge's resource window,
85+ * to make kernel enable to reassign new resource
86+ * window later on.
87+ */
88+ if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
89+ (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
90+ pci_disable_bridge_window(dev);
91+ }
92+ }
93+}
94+DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_release_resources);
95+#endif
96+
97 /* The Mellanox Tavor device gives false positive parity errors
98 * Mark this device with a broken_parity_status, to allow
99 * PCI scanning code to "skip" this now blacklisted device.
cc90b958 100--- /dev/null 1970-01-01 00:00:00.000000000 +0000
00e5a55c 101+++ sle11-2009-04-09/drivers/pci/reassigndev.c 2008-10-21 13:13:38.000000000 +0200
cc90b958
BS
102@@ -0,0 +1,80 @@
103+/*
104+ * Copyright (c) 2008, NEC Corporation.
105+ *
106+ * This program is free software; you can redistribute it and/or modify it
107+ * under the terms and conditions of the GNU General Public License,
108+ * version 2, as published by the Free Software Foundation.
109+ *
110+ * This program is distributed in the hope it will be useful, but WITHOUT
111+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
113+ * more details.
114+ *
115+ * You should have received a copy of the GNU General Public License along with
116+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
117+ * Place - Suite 330, Boston, MA 02111-1307 USA.
118+ */
119+
120+#include <linux/kernel.h>
121+#include <linux/pci.h>
122+#include <linux/string.h>
123+#include "pci.h"
124+
125+
126+#define REASSIGNDEV_PARAM_MAX (2048)
127+#define TOKEN_MAX (12) /* "SSSS:BB:DD.F" length is 12 */
128+
129+static char param_reassigndev[REASSIGNDEV_PARAM_MAX] = {0};
130+
131+static int __init reassigndev_setup(char *str)
132+{
133+ strncpy(param_reassigndev, str, REASSIGNDEV_PARAM_MAX);
134+ param_reassigndev[REASSIGNDEV_PARAM_MAX - 1] = '\0';
135+ return 1;
136+}
137+__setup("reassigndev=", reassigndev_setup);
138+
139+int is_reassigndev(struct pci_dev *dev)
140+{
141+ char dev_str[TOKEN_MAX+1];
142+ int seg, bus, slot, func;
143+ int len;
144+ char *p, *next_str;
145+
146+ p = param_reassigndev;
147+ for (; p; p = next_str + 1) {
148+ next_str = strpbrk(p, ",");
149+ if (next_str) {
150+ len = next_str - p;
151+ } else {
152+ len = strlen(p);
153+ }
154+ if (len > 0 && len <= TOKEN_MAX) {
155+ strncpy(dev_str, p, len);
156+ *(dev_str + len) = '\0';
157+
158+ if (sscanf(dev_str, "%x:%x:%x.%x",
159+ &seg, &bus, &slot, &func) != 4) {
160+ if (sscanf(dev_str, "%x:%x.%x",
161+ &bus, &slot, &func) == 3) {
162+ seg = 0;
163+ } else {
164+ /* failed to scan strings */
165+ seg = -1;
166+ bus = -1;
167+ }
168+ }
169+ if (seg == pci_domain_nr(dev->bus) &&
170+ bus == dev->bus->number &&
171+ slot == PCI_SLOT(dev->devfn) &&
172+ func == PCI_FUNC(dev->devfn)) {
173+ /* It's a target device */
174+ return 1;
175+ }
176+ }
177+ if (!next_str)
178+ break;
179+ }
180+
181+ return 0;
182+}
00e5a55c
BS
183--- sle11-2009-04-09.orig/drivers/pci/setup-bus.c 2009-04-09 14:29:05.000000000 +0200
184+++ sle11-2009-04-09/drivers/pci/setup-bus.c 2008-10-21 13:09:01.000000000 +0200
cc90b958
BS
185@@ -26,6 +26,7 @@
186 #include <linux/cache.h>
187 #include <linux/slab.h>
188
189+#include "pci.h"
190
191 static void pbus_assign_resources_sorted(struct pci_bus *bus)
192 {
193@@ -343,7 +344,8 @@ static int pbus_size_mem(struct pci_bus
194
195 list_for_each_entry(dev, &bus->devices, bus_list) {
196 int i;
197-
198+ int reassign = is_reassigndev(dev);
199+
200 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
201 struct resource *r = &dev->resource[i];
202 resource_size_t r_size;
203@@ -351,6 +353,10 @@ static int pbus_size_mem(struct pci_bus
204 if (r->parent || (r->flags & mask) != type)
205 continue;
206 r_size = r->end - r->start + 1;
207+
208+ if ((i < PCI_BRIDGE_RESOURCES) && reassign)
209+ r_size = ALIGN(r_size, PAGE_SIZE);
210+
211 /* For bridges size != alignment */
212 align = resource_alignment(r);
213 order = __ffs(align) - 20;
00e5a55c
BS
214--- sle11-2009-04-09.orig/drivers/pci/setup-res.c 2009-04-09 14:29:05.000000000 +0200
215+++ sle11-2009-04-09/drivers/pci/setup-res.c 2008-12-01 11:10:02.000000000 +0100
cc90b958
BS
216@@ -126,6 +126,21 @@ int pci_claim_resource(struct pci_dev *d
217 return err;
218 }
219
220+#ifdef CONFIG_PCI_REASSIGN
221+void pci_disable_bridge_window(struct pci_dev *dev)
222+{
223+ printk(KERN_DEBUG "PCI: Disable bridge window on %s\n", pci_name(dev));
224+
225+ /* MMIO Base/Limit */
226+ pci_write_config_dword(dev, PCI_MEMORY_BASE, 0x0000fff0);
227+
228+ /* Prefetchable MMIO Base/Limit */
229+ pci_write_config_dword(dev, PCI_PREF_LIMIT_UPPER32, 0);
230+ pci_write_config_dword(dev, PCI_PREF_MEMORY_BASE, 0x0000fff0);
231+ pci_write_config_dword(dev, PCI_PREF_BASE_UPPER32, 0xffffffff);
232+}
233+#endif
234+
235 int pci_assign_resource(struct pci_dev *dev, int resno)
236 {
237 struct pci_bus *bus = dev->bus;
238@@ -144,6 +159,10 @@ int pci_assign_resource(struct pci_dev *
239 (unsigned long long)res->end, res->flags);
240 return -EINVAL;
241 }
242+ if (resno < PCI_BRIDGE_RESOURCES
243+ && is_reassigndev(dev)
244+ && (res->flags & IORESOURCE_MEM))
245+ align = ALIGN(align, PAGE_SIZE);
246
247 /* First, try exact prefetching match.. */
248 ret = pci_bus_alloc_resource(bus, res, size, align, min,
249@@ -169,8 +188,15 @@ int pci_assign_resource(struct pci_dev *
250 (unsigned long long)res->end);
251 } else {
252 res->flags &= ~IORESOURCE_STARTALIGN;
253- if (resno < PCI_BRIDGE_RESOURCES)
254+ if (resno < PCI_BRIDGE_RESOURCES) {
255+#ifdef CONFIG_PCI_REASSIGN
256+ printk(KERN_DEBUG "PCI: Assign resource(%d) on %s "
257+ "%016llx - %016llx\n", resno, pci_name(dev),
258+ (unsigned long long)res->start,
259+ (unsigned long long)res->end);
260+#endif
261 pci_update_resource(dev, res, resno);
262+ }
263 }
264
265 return ret;
266@@ -208,6 +234,12 @@ int pci_assign_resource_fixed(struct pci
267 (unsigned long long)res->start,
268 (unsigned long long)res->end);
269 } else if (resno < PCI_BRIDGE_RESOURCES) {
270+#ifdef CONFIG_PCI_REASSIGN
271+ printk(KERN_DEBUG "PCI: Assign resource(%d) on %s "
272+ "%016llx - %016llx\n", resno, pci_name(dev),
273+ (unsigned long long)res->start,
274+ (unsigned long long)res->end);
275+#endif
276 pci_update_resource(dev, res, resno);
277 }
278
279@@ -220,6 +252,7 @@ EXPORT_SYMBOL_GPL(pci_assign_resource_fi
280 void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
281 {
282 int i;
283+ int reassigndev = is_reassigndev(dev);
284
285 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
286 struct resource *r;
287@@ -242,12 +275,22 @@ void pdev_sort_resources(struct pci_dev
288 (unsigned long long)r->end, r->flags);
289 continue;
290 }
291+ if (i < PCI_BRIDGE_RESOURCES && (r->flags & IORESOURCE_MEM) &&
292+ reassigndev)
293+ r_align = ALIGN(r_align, PAGE_SIZE);
294+
295 for (list = head; ; list = list->next) {
296 resource_size_t align = 0;
297 struct resource_list *ln = list->next;
298
299- if (ln)
300+ if (ln) {
301 align = resource_alignment(ln->res);
302+ if (ln->res - ln->dev->resource <
303+ PCI_BRIDGE_RESOURCES &&
304+ (ln->res->flags & IORESOURCE_MEM) &&
305+ is_reassigndev(ln->dev))
306+ align = ALIGN(align, PAGE_SIZE);
307+ }
308
309 if (r_align > align) {
310 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);