blob: c13668cf36d940473519e9dc3723e9fc0bd37710 [file] [log] [blame]
Paul Mackerrase05b3b42006-01-15 22:05:47 +11001/*
2 * Common pmac/prep/chrp pci routines. -- Cort
3 */
4
Paul Mackerrase05b3b42006-01-15 22:05:47 +11005#include <linux/kernel.h>
6#include <linux/pci.h>
7#include <linux/delay.h>
8#include <linux/string.h>
9#include <linux/init.h>
10#include <linux/capability.h>
11#include <linux/sched.h>
12#include <linux/errno.h>
13#include <linux/bootmem.h>
Benjamin Herrenschmidt6e99e452006-07-10 04:44:42 -070014#include <linux/irq.h>
Benjamin Herrenschmidtf90bb152006-11-11 17:24:51 +110015#include <linux/list.h>
Stephen Rothwell66524b22007-12-21 15:52:43 +110016#include <linux/of.h>
Paul Mackerrase05b3b42006-01-15 22:05:47 +110017
18#include <asm/processor.h>
19#include <asm/io.h>
20#include <asm/prom.h>
21#include <asm/sections.h>
22#include <asm/pci-bridge.h>
Milton Millerc3bd5172009-01-08 02:19:46 +000023#include <asm/ppc-pci.h>
Paul Mackerrase05b3b42006-01-15 22:05:47 +110024#include <asm/byteorder.h>
Paul Mackerrase05b3b42006-01-15 22:05:47 +110025#include <asm/uaccess.h>
26#include <asm/machdep.h>
27
28#undef DEBUG
29
Paul Mackerrase05b3b42006-01-15 22:05:47 +110030unsigned long isa_io_base = 0;
Paul Mackerrase05b3b42006-01-15 22:05:47 +110031unsigned long pci_dram_offset = 0;
32int pcibios_assign_bus_offset = 1;
33
34void pcibios_make_OF_bus_map(void);
35
Paul Mackerrase05b3b42006-01-15 22:05:47 +110036static void fixup_cpc710_pci64(struct pci_dev* dev);
Paul Mackerrase05b3b42006-01-15 22:05:47 +110037static u8* pci_to_OF_bus_map;
Paul Mackerrase05b3b42006-01-15 22:05:47 +110038
39/* By default, we don't re-assign bus numbers. We do this only on
40 * some pmacs
41 */
Benjamin Herrenschmidtfc3fb712007-12-20 14:54:46 +110042static int pci_assign_all_buses;
Paul Mackerrase05b3b42006-01-15 22:05:47 +110043
Paul Mackerrase05b3b42006-01-15 22:05:47 +110044static int pci_bus_count;
45
Benjamin Herrenschmidt7b6b5742008-10-13 17:51:46 +000046/* This will remain NULL for now, until isa-bridge.c is made common
47 * to both 32-bit and 64-bit.
48 */
49struct pci_dev *isa_bridge_pcidev;
50EXPORT_SYMBOL_GPL(isa_bridge_pcidev);
51
Paul Mackerrase05b3b42006-01-15 22:05:47 +110052static void
John Rigby4a015c32008-10-07 13:00:20 -060053fixup_hide_host_resource_fsl(struct pci_dev *dev)
Kumar Gala2052d6d2007-07-25 00:44:11 -050054{
55 int i, class = dev->class >> 8;
56
John Rigby4a015c32008-10-07 13:00:20 -060057 if ((class == PCI_CLASS_PROCESSOR_POWERPC ||
58 class == PCI_CLASS_BRIDGE_OTHER) &&
Kumar Gala2052d6d2007-07-25 00:44:11 -050059 (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) &&
60 (dev->bus->parent == NULL)) {
61 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
62 dev->resource[i].start = 0;
63 dev->resource[i].end = 0;
64 dev->resource[i].flags = 0;
65 }
66 }
67}
68DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MOTOROLA, PCI_ANY_ID, fixup_hide_host_resource_fsl);
69DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, fixup_hide_host_resource_fsl);
70
71static void
Paul Mackerrase05b3b42006-01-15 22:05:47 +110072fixup_cpc710_pci64(struct pci_dev* dev)
73{
74 /* Hide the PCI64 BARs from the kernel as their content doesn't
75 * fit well in the resource management
76 */
77 dev->resource[0].start = dev->resource[0].end = 0;
78 dev->resource[0].flags = 0;
79 dev->resource[1].start = dev->resource[1].end = 0;
80 dev->resource[1].flags = 0;
81}
82DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64);
83
Paul Mackerrase05b3b42006-01-15 22:05:47 +110084/*
85 * Functions below are used on OpenFirmware machines.
86 */
87static void
88make_one_node_map(struct device_node* node, u8 pci_bus)
89{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100090 const int *bus_range;
Paul Mackerrase05b3b42006-01-15 22:05:47 +110091 int len;
92
93 if (pci_bus >= pci_bus_count)
94 return;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100095 bus_range = of_get_property(node, "bus-range", &len);
Paul Mackerrase05b3b42006-01-15 22:05:47 +110096 if (bus_range == NULL || len < 2 * sizeof(int)) {
97 printk(KERN_WARNING "Can't get bus-range for %s, "
98 "assuming it starts at 0\n", node->full_name);
99 pci_to_OF_bus_map[pci_bus] = 0;
100 } else
101 pci_to_OF_bus_map[pci_bus] = bus_range[0];
102
Stephen Rothwell66524b22007-12-21 15:52:43 +1100103 for_each_child_of_node(node, node) {
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100104 struct pci_dev* dev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000105 const unsigned int *class_code, *reg;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100106
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000107 class_code = of_get_property(node, "class-code", NULL);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100108 if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
109 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
110 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000111 reg = of_get_property(node, "reg", NULL);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100112 if (!reg)
113 continue;
Alan Coxab462762007-04-23 14:47:59 +0100114 dev = pci_get_bus_and_slot(pci_bus, ((reg[0] >> 8) & 0xff));
115 if (!dev || !dev->subordinate) {
116 pci_dev_put(dev);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100117 continue;
Alan Coxab462762007-04-23 14:47:59 +0100118 }
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100119 make_one_node_map(node, dev->subordinate->number);
Alan Coxab462762007-04-23 14:47:59 +0100120 pci_dev_put(dev);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100121 }
122}
123
124void
125pcibios_make_OF_bus_map(void)
126{
127 int i;
Kumar Galaa4c9e322007-06-27 13:09:43 -0500128 struct pci_controller *hose, *tmp;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000129 struct property *map_prop;
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000130 struct device_node *dn;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100131
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800132 pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100133 if (!pci_to_OF_bus_map) {
134 printk(KERN_ERR "Can't allocate OF bus map !\n");
135 return;
136 }
137
138 /* We fill the bus map with invalid values, that helps
139 * debugging.
140 */
141 for (i=0; i<pci_bus_count; i++)
142 pci_to_OF_bus_map[i] = 0xff;
143
144 /* For each hose, we begin searching bridges */
Kumar Galaa4c9e322007-06-27 13:09:43 -0500145 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100146 struct device_node* node = hose->dn;
147
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100148 if (!node)
149 continue;
150 make_one_node_map(node, hose->first_busno);
151 }
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000152 dn = of_find_node_by_path("/");
153 map_prop = of_find_property(dn, "pci-OF-bus-map", NULL);
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000154 if (map_prop) {
155 BUG_ON(pci_bus_count > map_prop->length);
156 memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
157 }
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000158 of_node_put(dn);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100159#ifdef DEBUG
160 printk("PCI->OF bus map:\n");
161 for (i=0; i<pci_bus_count; i++) {
162 if (pci_to_OF_bus_map[i] == 0xff)
163 continue;
164 printk("%d -> %d\n", i, pci_to_OF_bus_map[i]);
165 }
166#endif
167}
168
169typedef int (*pci_OF_scan_iterator)(struct device_node* node, void* data);
170
171static struct device_node*
Stephen Rothwell66524b22007-12-21 15:52:43 +1100172scan_OF_pci_childs(struct device_node *parent, pci_OF_scan_iterator filter, void* data)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100173{
Stephen Rothwell66524b22007-12-21 15:52:43 +1100174 struct device_node *node;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100175 struct device_node* sub_node;
176
Stephen Rothwell66524b22007-12-21 15:52:43 +1100177 for_each_child_of_node(parent, node) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000178 const unsigned int *class_code;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100179
Stephen Rothwell66524b22007-12-21 15:52:43 +1100180 if (filter(node, data)) {
181 of_node_put(node);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100182 return node;
Stephen Rothwell66524b22007-12-21 15:52:43 +1100183 }
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100184
185 /* For PCI<->PCI bridges or CardBus bridges, we go down
186 * Note: some OFs create a parent node "multifunc-device" as
187 * a fake root for all functions of a multi-function device,
188 * we go down them as well.
189 */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000190 class_code = of_get_property(node, "class-code", NULL);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100191 if ((!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
192 (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS)) &&
193 strcmp(node->name, "multifunc-device"))
194 continue;
Stephen Rothwell66524b22007-12-21 15:52:43 +1100195 sub_node = scan_OF_pci_childs(node, filter, data);
196 if (sub_node) {
197 of_node_put(node);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100198 return sub_node;
Stephen Rothwell66524b22007-12-21 15:52:43 +1100199 }
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100200 }
201 return NULL;
202}
203
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100204static struct device_node *scan_OF_for_pci_dev(struct device_node *parent,
205 unsigned int devfn)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100206{
Tom Arbucklef8178692009-02-11 10:41:48 +0000207 struct device_node *np, *cnp;
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100208 const u32 *reg;
209 unsigned int psize;
210
Stephen Rothwell85e99b92008-01-03 15:13:37 +1100211 for_each_child_of_node(parent, np) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000212 reg = of_get_property(np, "reg", &psize);
Tom Arbucklef8178692009-02-11 10:41:48 +0000213 if (reg && psize >= 4 && ((reg[0] >> 8) & 0xff) == devfn)
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100214 return np;
Tom Arbucklef8178692009-02-11 10:41:48 +0000215
216 /* Note: some OFs create a parent node "multifunc-device" as
217 * a fake root for all functions of a multi-function device,
218 * we go down them as well. */
219 if (!strcmp(np->name, "multifunc-device")) {
220 cnp = scan_OF_for_pci_dev(np, devfn);
221 if (cnp)
222 return cnp;
223 }
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100224 }
225 return NULL;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100226}
227
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100228
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100229static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
230{
231 struct device_node *parent, *np;
232
233 /* Are we a root bus ? */
234 if (bus->self == NULL || bus->parent == NULL) {
Kumar Gala0b1d40c2007-06-27 10:27:33 -0500235 struct pci_controller *hose = pci_bus_to_host(bus);
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100236 if (hose == NULL)
237 return NULL;
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100238 return of_node_get(hose->dn);
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100239 }
240
241 /* not a root bus, we need to get our parent */
242 parent = scan_OF_for_pci_bus(bus->parent);
243 if (parent == NULL)
244 return NULL;
245
246 /* now iterate for children for a match */
247 np = scan_OF_for_pci_dev(parent, bus->self->devfn);
248 of_node_put(parent);
249
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100250 return np;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100251}
252
253/*
254 * Scans the OF tree for a device node matching a PCI device
255 */
256struct device_node *
257pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
258{
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100259 struct device_node *parent, *np;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100260
Benjamin Herrenschmidtb0494bc2008-10-27 19:48:22 +0000261 pr_debug("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn);
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100262 parent = scan_OF_for_pci_bus(bus);
263 if (parent == NULL)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100264 return NULL;
Benjamin Herrenschmidtb0494bc2008-10-27 19:48:22 +0000265 pr_debug(" parent is %s\n", parent ? parent->full_name : "<NULL>");
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100266 np = scan_OF_for_pci_dev(parent, devfn);
267 of_node_put(parent);
Benjamin Herrenschmidtb0494bc2008-10-27 19:48:22 +0000268 pr_debug(" result is %s\n", np ? np->full_name : "<NULL>");
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100269
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100270 /* XXX most callers don't release the returned node
271 * mostly because ppc64 doesn't increase the refcount,
272 * we need to fix that.
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100273 */
Benjamin Herrenschmidtdae48282006-12-11 14:09:07 +1100274 return np;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100275}
276EXPORT_SYMBOL(pci_busdev_to_OF_node);
277
278struct device_node*
279pci_device_to_OF_node(struct pci_dev *dev)
280{
281 return pci_busdev_to_OF_node(dev->bus, dev->devfn);
282}
283EXPORT_SYMBOL(pci_device_to_OF_node);
284
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100285static int
286find_OF_pci_device_filter(struct device_node* node, void* data)
287{
288 return ((void *)node == data);
289}
290
291/*
292 * Returns the PCI device matching a given OF node
293 */
294int
295pci_device_from_OF_node(struct device_node* node, u8* bus, u8* devfn)
296{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000297 const unsigned int *reg;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100298 struct pci_controller* hose;
299 struct pci_dev* dev = NULL;
300
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100301 /* Make sure it's really a PCI device */
302 hose = pci_find_hose_for_OF_device(node);
Stephen Rothwell44ef3392007-12-10 14:33:21 +1100303 if (!hose || !hose->dn)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100304 return -ENODEV;
Stephen Rothwell66524b22007-12-21 15:52:43 +1100305 if (!scan_OF_pci_childs(hose->dn,
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100306 find_OF_pci_device_filter, (void *)node))
307 return -ENODEV;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000308 reg = of_get_property(node, "reg", NULL);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100309 if (!reg)
310 return -ENODEV;
311 *bus = (reg[0] >> 16) & 0xff;
312 *devfn = ((reg[0] >> 8) & 0xff);
313
314 /* Ok, here we need some tweak. If we have already renumbered
315 * all busses, we can't rely on the OF bus number any more.
316 * the pci_to_OF_bus_map is not enough as several PCI busses
317 * may match the same OF bus number.
318 */
319 if (!pci_to_OF_bus_map)
320 return 0;
321
322 for_each_pci_dev(dev)
323 if (pci_to_OF_bus_map[dev->bus->number] == *bus &&
324 dev->devfn == *devfn) {
325 *bus = dev->bus->number;
326 pci_dev_put(dev);
327 return 0;
328 }
329
330 return -ENODEV;
331}
332EXPORT_SYMBOL(pci_device_from_OF_node);
333
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100334/* We create the "pci-OF-bus-map" property now so it appears in the
335 * /proc device tree
336 */
337void __init
338pci_create_OF_bus_map(void)
339{
340 struct property* of_prop;
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000341 struct device_node *dn;
342
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100343 of_prop = (struct property*) alloc_bootmem(sizeof(struct property) + 256);
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000344 if (!of_prop)
345 return;
346 dn = of_find_node_by_path("/");
347 if (dn) {
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100348 memset(of_prop, -1, sizeof(struct property) + 256);
349 of_prop->name = "pci-OF-bus-map";
350 of_prop->length = 256;
Stephen Rothwell1a381472007-04-03 10:58:52 +1000351 of_prop->value = &of_prop[1];
Stephen Rothwell8c8dc322007-04-24 13:50:55 +1000352 prom_add_property(dn, of_prop);
353 of_node_put(dn);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100354 }
355}
356
Grant Likely0ed2c722009-08-28 08:58:16 +0000357void __devinit pcibios_setup_phb_io_space(struct pci_controller *hose)
Benjamin Herrenschmidt53280322008-10-27 19:48:29 +0000358{
Benjamin Herrenschmidt53280322008-10-27 19:48:29 +0000359 unsigned long io_offset;
360 struct resource *res = &hose->io_resource;
361
Benjamin Herrenschmidt53280322008-10-27 19:48:29 +0000362 /* Fixup IO space offset */
363 io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
364 res->start = (res->start + io_offset) & 0xffffffffu;
365 res->end = (res->end + io_offset) & 0xffffffffu;
Benjamin Herrenschmidt53280322008-10-27 19:48:29 +0000366}
367
Benjamin Herrenschmidt3fd94c62007-12-20 14:54:53 +1100368static int __init pcibios_init(void)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100369{
Kumar Galaa4c9e322007-06-27 13:09:43 -0500370 struct pci_controller *hose, *tmp;
Kumar Galaa4c9e322007-06-27 13:09:43 -0500371 int next_busno = 0;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100372
373 printk(KERN_INFO "PCI: Probing PCI hardware\n");
374
Benjamin Herrenschmidtfc3fb712007-12-20 14:54:46 +1100375 if (ppc_pci_flags & PPC_PCI_REASSIGN_ALL_BUS)
376 pci_assign_all_buses = 1;
377
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100378 /* Scan all of the recorded PCI controllers. */
Kumar Galaa4c9e322007-06-27 13:09:43 -0500379 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100380 if (pci_assign_all_buses)
381 hose->first_busno = next_busno;
382 hose->last_busno = 0xff;
Grant Likely0ed2c722009-08-28 08:58:16 +0000383 pcibios_scan_phb(hose, hose);
Benjamin Herrenschmidt53280322008-10-27 19:48:29 +0000384 pci_bus_add_devices(hose->bus);
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100385 if (pci_assign_all_buses || next_busno <= hose->last_busno)
386 next_busno = hose->last_busno + pcibios_assign_bus_offset;
387 }
388 pci_bus_count = next_busno;
389
390 /* OpenFirmware based machines need a map of OF bus
391 * numbers vs. kernel bus numbers since we may have to
392 * remap them.
393 */
Anton Vorontsov6b82b3e2008-12-09 09:47:29 +0000394 if (pci_assign_all_buses)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100395 pcibios_make_OF_bus_map();
396
Benjamin Herrenschmidt3fd94c62007-12-20 14:54:53 +1100397 /* Call common code to handle resource allocation */
398 pcibios_resource_survey();
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100399
400 /* Call machine dependent post-init code */
401 if (ppc_md.pcibios_after_init)
402 ppc_md.pcibios_after_init();
403
404 return 0;
405}
406
407subsys_initcall(pcibios_init);
408
Kumar Gala0b1d40c2007-06-27 10:27:33 -0500409static struct pci_controller*
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100410pci_bus_to_hose(int bus)
411{
Kumar Galaa4c9e322007-06-27 13:09:43 -0500412 struct pci_controller *hose, *tmp;
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100413
Kumar Galaa4c9e322007-06-27 13:09:43 -0500414 list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100415 if (bus >= hose->first_busno && bus <= hose->last_busno)
416 return hose;
417 return NULL;
418}
419
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100420/* Provide information on locations of various I/O regions in physical
421 * memory. Do this on a per-card basis so that we choose the right
422 * root bridge.
423 * Note that the returned IO or memory base is a physical address
424 */
425
426long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
427{
428 struct pci_controller* hose;
429 long result = -EOPNOTSUPP;
430
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100431 hose = pci_bus_to_hose(bus);
432 if (!hose)
433 return -ENODEV;
434
435 switch (which) {
436 case IOBASE_BRIDGE_NUMBER:
437 return (long)hose->first_busno;
438 case IOBASE_MEMORY:
439 return (long)hose->pci_mem_offset;
440 case IOBASE_IO:
441 return (long)hose->io_base_phys;
442 case IOBASE_ISA_IO:
443 return (long)isa_io_base;
444 case IOBASE_ISA_MEM:
445 return (long)isa_mem_base;
446 }
447
448 return result;
449}
450
Paul Mackerrase05b3b42006-01-15 22:05:47 +1100451