aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/bus.c')
-rw-r--r--drivers/pci/bus.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index fb9a11243d2a..eed67d9e73bc 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -140,16 +140,65 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
140void pci_enable_bridges(struct pci_bus *bus) 140void pci_enable_bridges(struct pci_bus *bus)
141{ 141{
142 struct pci_dev *dev; 142 struct pci_dev *dev;
143 int retval;
143 144
144 list_for_each_entry(dev, &bus->devices, bus_list) { 145 list_for_each_entry(dev, &bus->devices, bus_list) {
145 if (dev->subordinate) { 146 if (dev->subordinate) {
146 pci_enable_device(dev); 147 retval = pci_enable_device(dev);
147 pci_set_master(dev); 148 pci_set_master(dev);
148 pci_enable_bridges(dev->subordinate); 149 pci_enable_bridges(dev->subordinate);
149 } 150 }
150 } 151 }
151} 152}
152 153
154/** pci_walk_bus - walk devices on/under bus, calling callback.
155 * @top bus whose devices should be walked
156 * @cb callback to be called for each device found
157 * @userdata arbitrary pointer to be passed to callback.
158 *
159 * Walk the given bus, including any bridged devices
160 * on buses under this bus. Call the provided callback
161 * on each device found.
162 */
163void pci_walk_bus(struct pci_bus *top, void (*cb)(struct pci_dev *, void *),
164 void *userdata)
165{
166 struct pci_dev *dev;
167 struct pci_bus *bus;
168 struct list_head *next;
169
170 bus = top;
171 spin_lock(&pci_bus_lock);
172 next = top->devices.next;
173 for (;;) {
174 if (next == &bus->devices) {
175 /* end of this bus, go up or finish */
176 if (bus == top)
177 break;
178 next = bus->self->bus_list.next;
179 bus = bus->self->bus;
180 continue;
181 }
182 dev = list_entry(next, struct pci_dev, bus_list);
183 pci_dev_get(dev);
184 if (dev->subordinate) {
185 /* this is a pci-pci bridge, do its devices next */
186 next = dev->subordinate->devices.next;
187 bus = dev->subordinate;
188 } else
189 next = dev->bus_list.next;
190 spin_unlock(&pci_bus_lock);
191
192 /* Run device routines with the bus unlocked */
193 cb(dev, userdata);
194
195 spin_lock(&pci_bus_lock);
196 pci_dev_put(dev);
197 }
198 spin_unlock(&pci_bus_lock);
199}
200EXPORT_SYMBOL_GPL(pci_walk_bus);
201
153EXPORT_SYMBOL(pci_bus_alloc_resource); 202EXPORT_SYMBOL(pci_bus_alloc_resource);
154EXPORT_SYMBOL_GPL(pci_bus_add_device); 203EXPORT_SYMBOL_GPL(pci_bus_add_device);
155EXPORT_SYMBOL(pci_bus_add_devices); 204EXPORT_SYMBOL(pci_bus_add_devices);