ia64/linux-2.6.18-xen.hg

view drivers/xen/core/pci.c @ 593:bb937c2f7382

Hook Linux's PCI probe and remove callbacks

Hijack the pci_bus_type probe and remove callbacks. This option only
requires modification to the Xen specific part of Linux.

Signed-off-by: Joshua LeVasseur <joshua.levasseur@netronome.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jul 04 17:55:07 2008 +0100 (2008-07-04)
parents
children da710ff0899a
line source
1 /*
2 * vim:shiftwidth=8:noexpandtab
3 */
5 #include <linux/kernel.h>
6 #include <linux/init.h>
7 #include <linux/pci.h>
8 #include <xen/interface/physdev.h>
10 static int (*pci_bus_probe)(struct device *dev);
11 static int (*pci_bus_remove)(struct device *dev);
13 static int pci_bus_probe_wrapper(struct device *dev)
14 {
15 int r;
16 struct pci_dev *pci_dev = to_pci_dev(dev);
17 struct physdev_manage_pci manage_pci;
18 manage_pci.bus = pci_dev->bus->number;
19 manage_pci.devfn = pci_dev->devfn;
21 r = HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_add, &manage_pci);
22 if (r)
23 return r;
25 r = pci_bus_probe(dev);
26 if (r)
27 HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove, &manage_pci);
29 return r;
30 }
32 static int pci_bus_remove_wrapper(struct device *dev)
33 {
34 int r;
35 struct pci_dev *pci_dev = to_pci_dev(dev);
36 struct physdev_manage_pci manage_pci;
37 manage_pci.bus = pci_dev->bus->number;
38 manage_pci.devfn = pci_dev->devfn;
40 r = pci_bus_remove(dev);
41 /* dev and pci_dev are no longer valid!! */
43 HYPERVISOR_physdev_op(PHYSDEVOP_manage_pci_remove, &manage_pci);
44 return r;
45 }
47 static int __init hook_pci_bus(void)
48 {
49 if (!is_running_on_xen() || !is_initial_xendomain())
50 return 0;
52 pci_bus_probe = pci_bus_type.probe;
53 pci_bus_type.probe = pci_bus_probe_wrapper;
55 pci_bus_remove = pci_bus_type.remove;
56 pci_bus_type.remove = pci_bus_remove_wrapper;
58 return 0;
59 }
61 core_initcall(hook_pci_bus);