2 #include <linux/module.h>
8 #define DBG(x...) printk(x)
13 int pci_hotplug (struct device *dev, char **envp, int num_envp,
14 char *buffer, int buffer_size)
24 pdev = to_pci_dev(dev);
30 /* stuff we want to pass to /sbin/hotplug */
32 length += scnprintf (scratch, buffer_size - length, "PCI_CLASS=%04X",
34 if ((buffer_size - length <= 0) || (i >= num_envp))
40 length += scnprintf (scratch, buffer_size - length, "PCI_ID=%04X:%04X",
41 pdev->vendor, pdev->device);
42 if ((buffer_size - length <= 0) || (i >= num_envp))
48 length += scnprintf (scratch, buffer_size - length,
49 "PCI_SUBSYS_ID=%04X:%04X", pdev->subsystem_vendor,
50 pdev->subsystem_device);
51 if ((buffer_size - length <= 0) || (i >= num_envp))
57 length += scnprintf (scratch, buffer_size - length, "PCI_SLOT_NAME=%s",
59 if ((buffer_size - length <= 0) || (i >= num_envp))
67 static int pci_visit_bus (struct pci_visit * fn, struct pci_bus_wrapped *wrapped_bus, struct pci_dev_wrapped *wrapped_parent)
71 struct pci_dev_wrapped wrapped_dev;
74 DBG("scanning bus %02x\n", wrapped_bus->bus->number);
76 if (fn->pre_visit_pci_bus) {
77 result = fn->pre_visit_pci_bus(wrapped_bus, wrapped_parent);
82 ln = wrapped_bus->bus->devices.next;
83 while (ln != &wrapped_bus->bus->devices) {
87 memset(&wrapped_dev, 0, sizeof(struct pci_dev_wrapped));
88 wrapped_dev.dev = dev;
90 result = pci_visit_dev(fn, &wrapped_dev, wrapped_bus);
95 if (fn->post_visit_pci_bus)
96 result = fn->post_visit_pci_bus(wrapped_bus, wrapped_parent);
101 static int pci_visit_bridge (struct pci_visit * fn,
102 struct pci_dev_wrapped *wrapped_dev,
103 struct pci_bus_wrapped *wrapped_parent)
106 struct pci_bus_wrapped wrapped_bus;
109 DBG("scanning bridge %02x, %02x\n", PCI_SLOT(wrapped_dev->dev->devfn),
110 PCI_FUNC(wrapped_dev->dev->devfn));
112 if (fn->visit_pci_dev) {
113 result = fn->visit_pci_dev(wrapped_dev, wrapped_parent);
118 bus = wrapped_dev->dev->subordinate;
120 memset(&wrapped_bus, 0, sizeof(struct pci_bus_wrapped));
121 wrapped_bus.bus = bus;
123 result = pci_visit_bus(fn, &wrapped_bus, wrapped_dev);
129 * pci_visit_dev - scans the pci buses.
130 * Every bus and every function is presented to a custom
131 * function that can act upon it.
133 int pci_visit_dev(struct pci_visit *fn, struct pci_dev_wrapped *wrapped_dev,
134 struct pci_bus_wrapped *wrapped_parent)
136 struct pci_dev* dev = wrapped_dev ? wrapped_dev->dev : NULL;
142 if (fn->pre_visit_pci_dev) {
143 result = fn->pre_visit_pci_dev(wrapped_dev, wrapped_parent);
148 switch (dev->class >> 8) {
149 case PCI_CLASS_BRIDGE_PCI:
150 result = pci_visit_bridge(fn, wrapped_dev,
156 DBG("scanning device %02x, %02x\n",
157 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
158 if (fn->visit_pci_dev) {
159 result = fn->visit_pci_dev (wrapped_dev,
166 if (fn->post_visit_pci_dev)
167 result = fn->post_visit_pci_dev(wrapped_dev, wrapped_parent);
171 EXPORT_SYMBOL(pci_visit_dev);