ia64/linux-2.6.18-xen.hg

view drivers/pci/reassigndev.c @ 696:2b5cc22ab406

xen/dom0: Reassign memory resources to device for pci passthrough.

This patch adds the function that reassign page-aligned memory
resources, to dom0 linux. The function is useful when we assign I/O
device to HVM domain using pci passthrough.

When we assign a device to HVM domain using pci passthrough,
the device needs to be assigned page-aligned memory resources. If the
memory resource is not page-aligned, following error occurs.

Error: pci: 0000:00:1d.7: non-page-aligned MMIO BAR found.

On many system, BIOS assigns memory resources to the device and
enables it. So my patch disables the device, and releases resources,
Then it assigns page-aligned memory resource to the device.

To reassign resources, please add boot parameters of dom0 linux as
follows.

reassign_resources reassigndev=00:1d.7,01:00.0

reassign_resources
Enables reassigning resources.

reassigndev= Specifies devices include I/O device and
PCI-PCI
bridge to reassign resources. PCI-PCI bridge
can be specified, if resource windows need to
be expanded.

Signed-off-by: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Oct 09 11:10:43 2008 +0100 (2008-10-09)
parents
children 2fdc121e9b5d
line source
1 /*
2 * Copyright (c) 2008, NEC Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 */
18 #include <linux/kernel.h>
19 #include <linux/pci.h>
20 #include <linux/string.h>
21 #include "pci.h"
24 #define REASSIGNDEV_PARAM_MAX (2048)
25 #define TOKEN_MAX (12) /* "SSSS:BB:DD.F" length is 12 */
27 static char param_reassigndev[REASSIGNDEV_PARAM_MAX] = {0};
29 static int __init reassigndev_setup(char *str)
30 {
31 strncpy(param_reassigndev, str, REASSIGNDEV_PARAM_MAX);
32 param_reassigndev[REASSIGNDEV_PARAM_MAX - 1] = '\0';
33 return 1;
34 }
35 __setup("reassigndev=", reassigndev_setup);
37 int is_reassigndev(struct pci_dev *dev)
38 {
39 char dev_str[TOKEN_MAX+1];
40 int seg, bus, slot, func;
41 int len;
42 char *p, *next_str;
44 p = param_reassigndev;
45 for (; p; p = next_str + 1) {
46 next_str = strpbrk(p, ",");
47 if (next_str) {
48 len = next_str - p;
49 } else {
50 len = strlen(p);
51 }
52 if (len > 0 && len <= TOKEN_MAX) {
53 strncpy(dev_str, p, len);
54 *(dev_str + len) = '\0';
56 if (sscanf(dev_str, "%x:%x:%x.%x",
57 &seg, &bus, &slot, &func) != 4) {
58 if (sscanf(dev_str, "%x:%x.%x",
59 &bus, &slot, &func) == 3) {
60 seg = 0;
61 } else {
62 /* failed to scan strings */
63 seg = -1;
64 bus = -1;
65 }
66 }
67 if (seg == pci_domain_nr(dev->bus) &&
68 bus == dev->bus->number &&
69 slot == PCI_SLOT(dev->devfn) &&
70 func == PCI_FUNC(dev->devfn)) {
71 /* It's a target device */
72 return 1;
73 }
74 }
75 if (!next_str)
76 break;
77 }
79 return 0;
80 }