xref: /openbmc/linux/arch/powerpc/kernel/pci_32.c (revision 5d2eb73a)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e05b3b4aSPaul Mackerras /*
3e05b3b4aSPaul Mackerras  * Common pmac/prep/chrp pci routines. -- Cort
4e05b3b4aSPaul Mackerras  */
5e05b3b4aSPaul Mackerras 
6e05b3b4aSPaul Mackerras #include <linux/kernel.h>
7e05b3b4aSPaul Mackerras #include <linux/pci.h>
8e05b3b4aSPaul Mackerras #include <linux/delay.h>
9e05b3b4aSPaul Mackerras #include <linux/string.h>
10e05b3b4aSPaul Mackerras #include <linux/init.h>
11e05b3b4aSPaul Mackerras #include <linux/capability.h>
12e05b3b4aSPaul Mackerras #include <linux/sched.h>
13e05b3b4aSPaul Mackerras #include <linux/errno.h>
1457c8a661SMike Rapoport #include <linux/memblock.h>
15c89ca593SMathieu Malaterre #include <linux/syscalls.h>
166e99e458SBenjamin Herrenschmidt #include <linux/irq.h>
17f90bb153SBenjamin Herrenschmidt #include <linux/list.h>
1866524b22SStephen Rothwell #include <linux/of.h>
195a0e3ad6STejun Heo #include <linux/slab.h>
2093087948SPaul Gortmaker #include <linux/export.h>
21e05b3b4aSPaul Mackerras 
22e05b3b4aSPaul Mackerras #include <asm/processor.h>
23e05b3b4aSPaul Mackerras #include <asm/io.h>
24e05b3b4aSPaul Mackerras #include <asm/sections.h>
25e05b3b4aSPaul Mackerras #include <asm/pci-bridge.h>
26c3bd517dSMilton Miller #include <asm/ppc-pci.h>
27e05b3b4aSPaul Mackerras #include <asm/byteorder.h>
287c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
29e05b3b4aSPaul Mackerras #include <asm/machdep.h>
30e05b3b4aSPaul Mackerras 
31e05b3b4aSPaul Mackerras #undef DEBUG
32e05b3b4aSPaul Mackerras 
33e05b3b4aSPaul Mackerras unsigned long isa_io_base     = 0;
34e05b3b4aSPaul Mackerras unsigned long pci_dram_offset = 0;
35e05b3b4aSPaul Mackerras int pcibios_assign_bus_offset = 1;
369445aa1aSAl Viro EXPORT_SYMBOL(isa_io_base);
379445aa1aSAl Viro EXPORT_SYMBOL(pci_dram_offset);
38e05b3b4aSPaul Mackerras 
39e05b3b4aSPaul Mackerras static void fixup_cpc710_pci64(struct pci_dev* dev);
40e05b3b4aSPaul Mackerras 
41e05b3b4aSPaul Mackerras /* By default, we don't re-assign bus numbers. We do this only on
42e05b3b4aSPaul Mackerras  * some pmacs
43e05b3b4aSPaul Mackerras  */
44fc3fb71cSBenjamin Herrenschmidt static int pci_assign_all_buses;
45e05b3b4aSPaul Mackerras 
467b6b574cSBenjamin Herrenschmidt /* This will remain NULL for now, until isa-bridge.c is made common
477b6b574cSBenjamin Herrenschmidt  * to both 32-bit and 64-bit.
487b6b574cSBenjamin Herrenschmidt  */
497b6b574cSBenjamin Herrenschmidt struct pci_dev *isa_bridge_pcidev;
507b6b574cSBenjamin Herrenschmidt EXPORT_SYMBOL_GPL(isa_bridge_pcidev);
517b6b574cSBenjamin Herrenschmidt 
52e05b3b4aSPaul Mackerras static void
fixup_cpc710_pci64(struct pci_dev * dev)53e05b3b4aSPaul Mackerras fixup_cpc710_pci64(struct pci_dev* dev)
54e05b3b4aSPaul Mackerras {
55e05b3b4aSPaul Mackerras 	/* Hide the PCI64 BARs from the kernel as their content doesn't
56e05b3b4aSPaul Mackerras 	 * fit well in the resource management
57e05b3b4aSPaul Mackerras 	 */
58e05b3b4aSPaul Mackerras 	dev->resource[0].start = dev->resource[0].end = 0;
59e05b3b4aSPaul Mackerras 	dev->resource[0].flags = 0;
60e05b3b4aSPaul Mackerras 	dev->resource[1].start = dev->resource[1].end = 0;
61e05b3b4aSPaul Mackerras 	dev->resource[1].flags = 0;
62e05b3b4aSPaul Mackerras }
63e05b3b4aSPaul Mackerras DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM,	PCI_DEVICE_ID_IBM_CPC710_PCI64,	fixup_cpc710_pci64);
64e05b3b4aSPaul Mackerras 
65*5d2eb73aSPali Rohár #ifdef CONFIG_PPC_PCI_OF_BUS_MAP
667f102d61SPali Rohár 
677f102d61SPali Rohár static u8* pci_to_OF_bus_map;
687f102d61SPali Rohár static int pci_bus_count;
697f102d61SPali Rohár 
70e05b3b4aSPaul Mackerras /*
71e05b3b4aSPaul Mackerras  * Functions below are used on OpenFirmware machines.
72e05b3b4aSPaul Mackerras  */
73e05b3b4aSPaul Mackerras static void
make_one_node_map(struct device_node * node,u8 pci_bus)74e05b3b4aSPaul Mackerras make_one_node_map(struct device_node* node, u8 pci_bus)
75e05b3b4aSPaul Mackerras {
76a7f67bdfSJeremy Kerr 	const int *bus_range;
77e05b3b4aSPaul Mackerras 	int len;
78e05b3b4aSPaul Mackerras 
79e05b3b4aSPaul Mackerras 	if (pci_bus >= pci_bus_count)
80e05b3b4aSPaul Mackerras 		return;
81e2eb6392SStephen Rothwell 	bus_range = of_get_property(node, "bus-range", &len);
82e05b3b4aSPaul Mackerras 	if (bus_range == NULL || len < 2 * sizeof(int)) {
83b7c670d6SRob Herring 		printk(KERN_WARNING "Can't get bus-range for %pOF, "
84b7c670d6SRob Herring 		       "assuming it starts at 0\n", node);
85e05b3b4aSPaul Mackerras 		pci_to_OF_bus_map[pci_bus] = 0;
86e05b3b4aSPaul Mackerras 	} else
87e05b3b4aSPaul Mackerras 		pci_to_OF_bus_map[pci_bus] = bus_range[0];
88e05b3b4aSPaul Mackerras 
8966524b22SStephen Rothwell 	for_each_child_of_node(node, node) {
90e05b3b4aSPaul Mackerras 		struct pci_dev* dev;
91a7f67bdfSJeremy Kerr 		const unsigned int *class_code, *reg;
92e05b3b4aSPaul Mackerras 
93e2eb6392SStephen Rothwell 		class_code = of_get_property(node, "class-code", NULL);
94e05b3b4aSPaul Mackerras 		if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
95e05b3b4aSPaul Mackerras 			(*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
96e05b3b4aSPaul Mackerras 			continue;
97e2eb6392SStephen Rothwell 		reg = of_get_property(node, "reg", NULL);
98e05b3b4aSPaul Mackerras 		if (!reg)
99e05b3b4aSPaul Mackerras 			continue;
10050ed5780SSinan Kaya 		dev = pci_get_domain_bus_and_slot(0, pci_bus,
10150ed5780SSinan Kaya 						  ((reg[0] >> 8) & 0xff));
102ab462768SAlan Cox 		if (!dev || !dev->subordinate) {
103ab462768SAlan Cox 			pci_dev_put(dev);
104e05b3b4aSPaul Mackerras 			continue;
105ab462768SAlan Cox 		}
106e05b3b4aSPaul Mackerras 		make_one_node_map(node, dev->subordinate->number);
107ab462768SAlan Cox 		pci_dev_put(dev);
108e05b3b4aSPaul Mackerras 	}
109e05b3b4aSPaul Mackerras }
110e05b3b4aSPaul Mackerras 
111407a7671SPali Rohár static void __init
pcibios_make_OF_bus_map(void)112e05b3b4aSPaul Mackerras pcibios_make_OF_bus_map(void)
113e05b3b4aSPaul Mackerras {
114e05b3b4aSPaul Mackerras 	int i;
115a4c9e328SKumar Gala 	struct pci_controller *hose, *tmp;
116a7f67bdfSJeremy Kerr 	struct property *map_prop;
1178c8dc322SStephen Rothwell 	struct device_node *dn;
118e05b3b4aSPaul Mackerras 
1195cbded58SRobert P. J. Day 	pci_to_OF_bus_map = kmalloc(pci_bus_count, GFP_KERNEL);
120e05b3b4aSPaul Mackerras 	if (!pci_to_OF_bus_map) {
121e05b3b4aSPaul Mackerras 		printk(KERN_ERR "Can't allocate OF bus map !\n");
122e05b3b4aSPaul Mackerras 		return;
123e05b3b4aSPaul Mackerras 	}
124e05b3b4aSPaul Mackerras 
125e05b3b4aSPaul Mackerras 	/* We fill the bus map with invalid values, that helps
126e05b3b4aSPaul Mackerras 	 * debugging.
127e05b3b4aSPaul Mackerras 	 */
128e05b3b4aSPaul Mackerras 	for (i=0; i<pci_bus_count; i++)
129e05b3b4aSPaul Mackerras 		pci_to_OF_bus_map[i] = 0xff;
130e05b3b4aSPaul Mackerras 
131e05b3b4aSPaul Mackerras 	/* For each hose, we begin searching bridges */
132a4c9e328SKumar Gala 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
13344ef3390SStephen Rothwell 		struct device_node* node = hose->dn;
13444ef3390SStephen Rothwell 
135e05b3b4aSPaul Mackerras 		if (!node)
136e05b3b4aSPaul Mackerras 			continue;
137e05b3b4aSPaul Mackerras 		make_one_node_map(node, hose->first_busno);
138e05b3b4aSPaul Mackerras 	}
1398c8dc322SStephen Rothwell 	dn = of_find_node_by_path("/");
1408c8dc322SStephen Rothwell 	map_prop = of_find_property(dn, "pci-OF-bus-map", NULL);
141a7f67bdfSJeremy Kerr 	if (map_prop) {
142a7f67bdfSJeremy Kerr 		BUG_ON(pci_bus_count > map_prop->length);
143a7f67bdfSJeremy Kerr 		memcpy(map_prop->value, pci_to_OF_bus_map, pci_bus_count);
144a7f67bdfSJeremy Kerr 	}
1458c8dc322SStephen Rothwell 	of_node_put(dn);
146e05b3b4aSPaul Mackerras #ifdef DEBUG
147e05b3b4aSPaul Mackerras 	printk("PCI->OF bus map:\n");
148e05b3b4aSPaul Mackerras 	for (i=0; i<pci_bus_count; i++) {
149e05b3b4aSPaul Mackerras 		if (pci_to_OF_bus_map[i] == 0xff)
150e05b3b4aSPaul Mackerras 			continue;
151e05b3b4aSPaul Mackerras 		printk("%d -> %d\n", i, pci_to_OF_bus_map[i]);
152e05b3b4aSPaul Mackerras 	}
153e05b3b4aSPaul Mackerras #endif
154e05b3b4aSPaul Mackerras }
155*5d2eb73aSPali Rohár #endif // CONFIG_PPC_PCI_OF_BUS_MAP
156e05b3b4aSPaul Mackerras 
157e05b3b4aSPaul Mackerras 
158a2954a7eSPali Rohár #ifdef CONFIG_PPC_PMAC
159e05b3b4aSPaul Mackerras /*
160e05b3b4aSPaul Mackerras  * Returns the PCI device matching a given OF node
161e05b3b4aSPaul Mackerras  */
pci_device_from_OF_node(struct device_node * node,u8 * bus,u8 * devfn)16298d9f30cSBenjamin Herrenschmidt int pci_device_from_OF_node(struct device_node *node, u8 *bus, u8 *devfn)
163e05b3b4aSPaul Mackerras {
164*5d2eb73aSPali Rohár #ifdef CONFIG_PPC_PCI_OF_BUS_MAP
165e05b3b4aSPaul Mackerras 	struct pci_dev *dev = NULL;
166*5d2eb73aSPali Rohár #endif
16798d9f30cSBenjamin Herrenschmidt 	const __be32 *reg;
16898d9f30cSBenjamin Herrenschmidt 	int size;
169e05b3b4aSPaul Mackerras 
17098d9f30cSBenjamin Herrenschmidt 	/* Check if it might have a chance to be a PCI device */
17198d9f30cSBenjamin Herrenschmidt 	if (!pci_find_hose_for_OF_device(node))
172e05b3b4aSPaul Mackerras 		return -ENODEV;
17398d9f30cSBenjamin Herrenschmidt 
17498d9f30cSBenjamin Herrenschmidt 	reg = of_get_property(node, "reg", &size);
17598d9f30cSBenjamin Herrenschmidt 	if (!reg || size < 5 * sizeof(u32))
176e05b3b4aSPaul Mackerras 		return -ENODEV;
17798d9f30cSBenjamin Herrenschmidt 
17898d9f30cSBenjamin Herrenschmidt 	*bus = (be32_to_cpup(&reg[0]) >> 16) & 0xff;
17998d9f30cSBenjamin Herrenschmidt 	*devfn = (be32_to_cpup(&reg[0]) >> 8) & 0xff;
180e05b3b4aSPaul Mackerras 
181*5d2eb73aSPali Rohár #ifndef CONFIG_PPC_PCI_OF_BUS_MAP
182*5d2eb73aSPali Rohár 	return 0;
183*5d2eb73aSPali Rohár #else
184e05b3b4aSPaul Mackerras 	/* Ok, here we need some tweak. If we have already renumbered
185e05b3b4aSPaul Mackerras 	 * all busses, we can't rely on the OF bus number any more.
186e05b3b4aSPaul Mackerras 	 * the pci_to_OF_bus_map is not enough as several PCI busses
187e05b3b4aSPaul Mackerras 	 * may match the same OF bus number.
188e05b3b4aSPaul Mackerras 	 */
189e05b3b4aSPaul Mackerras 	if (!pci_to_OF_bus_map)
190e05b3b4aSPaul Mackerras 		return 0;
191e05b3b4aSPaul Mackerras 
192e05b3b4aSPaul Mackerras 	for_each_pci_dev(dev)
193e05b3b4aSPaul Mackerras 		if (pci_to_OF_bus_map[dev->bus->number] == *bus &&
194e05b3b4aSPaul Mackerras 				dev->devfn == *devfn) {
195e05b3b4aSPaul Mackerras 			*bus = dev->bus->number;
196e05b3b4aSPaul Mackerras 			pci_dev_put(dev);
197e05b3b4aSPaul Mackerras 			return 0;
198e05b3b4aSPaul Mackerras 		}
199e05b3b4aSPaul Mackerras 
200e05b3b4aSPaul Mackerras 	return -ENODEV;
201*5d2eb73aSPali Rohár #endif // CONFIG_PPC_PCI_OF_BUS_MAP
202e05b3b4aSPaul Mackerras }
203e05b3b4aSPaul Mackerras EXPORT_SYMBOL(pci_device_from_OF_node);
204a2954a7eSPali Rohár #endif
205e05b3b4aSPaul Mackerras 
206*5d2eb73aSPali Rohár #ifdef CONFIG_PPC_PCI_OF_BUS_MAP
207e05b3b4aSPaul Mackerras /* We create the "pci-OF-bus-map" property now so it appears in the
208e05b3b4aSPaul Mackerras  * /proc device tree
209e05b3b4aSPaul Mackerras  */
210e05b3b4aSPaul Mackerras void __init
pci_create_OF_bus_map(void)211e05b3b4aSPaul Mackerras pci_create_OF_bus_map(void)
212e05b3b4aSPaul Mackerras {
213e05b3b4aSPaul Mackerras 	struct property* of_prop;
2148c8dc322SStephen Rothwell 	struct device_node *dn;
215e05b3b4aSPaul Mackerras 
2167e1c4e27SMike Rapoport 	of_prop = memblock_alloc(sizeof(struct property) + 256,
2177e1c4e27SMike Rapoport 				 SMP_CACHE_BYTES);
2188a7f97b9SMike Rapoport 	if (!of_prop)
2198a7f97b9SMike Rapoport 		panic("%s: Failed to allocate %zu bytes\n", __func__,
2208a7f97b9SMike Rapoport 		      sizeof(struct property) + 256);
2218c8dc322SStephen Rothwell 	dn = of_find_node_by_path("/");
2228c8dc322SStephen Rothwell 	if (dn) {
223e05b3b4aSPaul Mackerras 		memset(of_prop, -1, sizeof(struct property) + 256);
224e05b3b4aSPaul Mackerras 		of_prop->name = "pci-OF-bus-map";
225e05b3b4aSPaul Mackerras 		of_prop->length = 256;
2261a38147eSStephen Rothwell 		of_prop->value = &of_prop[1];
22779d1c712SNathan Fontenot 		of_add_property(dn, of_prop);
2288c8dc322SStephen Rothwell 		of_node_put(dn);
229e05b3b4aSPaul Mackerras 	}
230e05b3b4aSPaul Mackerras }
231*5d2eb73aSPali Rohár #endif // CONFIG_PPC_PCI_OF_BUS_MAP
2327f102d61SPali Rohár 
pcibios_setup_phb_io_space(struct pci_controller * hose)233cad5cef6SGreg Kroah-Hartman void pcibios_setup_phb_io_space(struct pci_controller *hose)
23453280323SBenjamin Herrenschmidt {
23553280323SBenjamin Herrenschmidt 	unsigned long io_offset;
23653280323SBenjamin Herrenschmidt 	struct resource *res = &hose->io_resource;
23753280323SBenjamin Herrenschmidt 
23853280323SBenjamin Herrenschmidt 	/* Fixup IO space offset */
23938973ba7SBjorn Helgaas 	io_offset = pcibios_io_space_offset(hose);
24038973ba7SBjorn Helgaas 	res->start += io_offset;
24138973ba7SBjorn Helgaas 	res->end += io_offset;
24253280323SBenjamin Herrenschmidt }
24353280323SBenjamin Herrenschmidt 
pcibios_init(void)2443fd94c6bSBenjamin Herrenschmidt static int __init pcibios_init(void)
245e05b3b4aSPaul Mackerras {
246a4c9e328SKumar Gala 	struct pci_controller *hose, *tmp;
24756635681SPali Rohár #ifndef CONFIG_PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT
248a4c9e328SKumar Gala 	int next_busno = 0;
24956635681SPali Rohár #endif
250e05b3b4aSPaul Mackerras 
251e05b3b4aSPaul Mackerras 	printk(KERN_INFO "PCI: Probing PCI hardware\n");
252e05b3b4aSPaul Mackerras 
2530382a35bSPali Rohár #ifdef CONFIG_PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT
2540382a35bSPali Rohár 	/*
2550382a35bSPali Rohár 	 * Enable PCI domains in /proc when PCI bus numbers are not unique
2560382a35bSPali Rohár 	 * across all PCI domains to prevent conflicts. And keep PCI domain 0
2570382a35bSPali Rohár 	 * backward compatible in /proc for video cards.
2580382a35bSPali Rohár 	 */
2590382a35bSPali Rohár 	pci_add_flags(PCI_ENABLE_PROC_DOMAINS | PCI_COMPAT_DOMAIN_0);
2600382a35bSPali Rohár #endif
2610382a35bSPali Rohár 
2620e47ff1cSRob Herring 	if (pci_has_flag(PCI_REASSIGN_ALL_BUS))
263fc3fb71cSBenjamin Herrenschmidt 		pci_assign_all_buses = 1;
264fc3fb71cSBenjamin Herrenschmidt 
265e05b3b4aSPaul Mackerras 	/* Scan all of the recorded PCI controllers.  */
266a4c9e328SKumar Gala 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
26756635681SPali Rohár #ifndef CONFIG_PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT
268e05b3b4aSPaul Mackerras 		if (pci_assign_all_buses)
269e05b3b4aSPaul Mackerras 			hose->first_busno = next_busno;
27056635681SPali Rohár #endif
271e05b3b4aSPaul Mackerras 		hose->last_busno = 0xff;
272b5d937deSGrant Likely 		pcibios_scan_phb(hose);
27353280323SBenjamin Herrenschmidt 		pci_bus_add_devices(hose->bus);
27456635681SPali Rohár #ifndef CONFIG_PPC_PCI_BUS_NUM_DOMAIN_DEPENDENT
275e05b3b4aSPaul Mackerras 		if (pci_assign_all_buses || next_busno <= hose->last_busno)
276e05b3b4aSPaul Mackerras 			next_busno = hose->last_busno + pcibios_assign_bus_offset;
27756635681SPali Rohár #endif
278e05b3b4aSPaul Mackerras 	}
2797f102d61SPali Rohár 
2807f102d61SPali Rohár #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_CHRP)
281*5d2eb73aSPali Rohár #ifdef CONFIG_PPC_PCI_OF_BUS_MAP
282e05b3b4aSPaul Mackerras 	pci_bus_count = next_busno;
283e05b3b4aSPaul Mackerras 
284e05b3b4aSPaul Mackerras 	/* OpenFirmware based machines need a map of OF bus
285e05b3b4aSPaul Mackerras 	 * numbers vs. kernel bus numbers since we may have to
286e05b3b4aSPaul Mackerras 	 * remap them.
287e05b3b4aSPaul Mackerras 	 */
2886b82b3e4SAnton Vorontsov 	if (pci_assign_all_buses)
289e05b3b4aSPaul Mackerras 		pcibios_make_OF_bus_map();
2907f102d61SPali Rohár #endif
291*5d2eb73aSPali Rohár #endif
292e05b3b4aSPaul Mackerras 
2933fd94c6bSBenjamin Herrenschmidt 	/* Call common code to handle resource allocation */
2943fd94c6bSBenjamin Herrenschmidt 	pcibios_resource_survey();
295e05b3b4aSPaul Mackerras 
2963f068aaeSSam Bobroff 	/* Call machine dependent fixup */
2973f068aaeSSam Bobroff 	if (ppc_md.pcibios_fixup)
2983f068aaeSSam Bobroff 		ppc_md.pcibios_fixup();
2993f068aaeSSam Bobroff 
300e05b3b4aSPaul Mackerras 	/* Call machine dependent post-init code */
301e05b3b4aSPaul Mackerras 	if (ppc_md.pcibios_after_init)
302e05b3b4aSPaul Mackerras 		ppc_md.pcibios_after_init();
303e05b3b4aSPaul Mackerras 
304e05b3b4aSPaul Mackerras 	return 0;
305e05b3b4aSPaul Mackerras }
306e05b3b4aSPaul Mackerras 
307e05b3b4aSPaul Mackerras subsys_initcall(pcibios_init);
308e05b3b4aSPaul Mackerras 
3090b1d40c4SKumar Gala static struct pci_controller*
pci_bus_to_hose(int bus)310e05b3b4aSPaul Mackerras pci_bus_to_hose(int bus)
311e05b3b4aSPaul Mackerras {
312a4c9e328SKumar Gala 	struct pci_controller *hose, *tmp;
313e05b3b4aSPaul Mackerras 
314a4c9e328SKumar Gala 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
315e05b3b4aSPaul Mackerras 		if (bus >= hose->first_busno && bus <= hose->last_busno)
316e05b3b4aSPaul Mackerras 			return hose;
317e05b3b4aSPaul Mackerras 	return NULL;
318e05b3b4aSPaul Mackerras }
319e05b3b4aSPaul Mackerras 
320e05b3b4aSPaul Mackerras /* Provide information on locations of various I/O regions in physical
321e05b3b4aSPaul Mackerras  * memory.  Do this on a per-card basis so that we choose the right
322e05b3b4aSPaul Mackerras  * root bridge.
323e05b3b4aSPaul Mackerras  * Note that the returned IO or memory base is a physical address
324e05b3b4aSPaul Mackerras  */
325e05b3b4aSPaul Mackerras 
SYSCALL_DEFINE3(pciconfig_iobase,long,which,unsigned long,bus,unsigned long,devfn)3263691d614SAl Viro SYSCALL_DEFINE3(pciconfig_iobase, long, which,
3273691d614SAl Viro 		unsigned long, bus, unsigned long, devfn)
328e05b3b4aSPaul Mackerras {
329e05b3b4aSPaul Mackerras 	struct pci_controller* hose;
330e05b3b4aSPaul Mackerras 	long result = -EOPNOTSUPP;
331e05b3b4aSPaul Mackerras 
332e05b3b4aSPaul Mackerras 	hose = pci_bus_to_hose(bus);
333e05b3b4aSPaul Mackerras 	if (!hose)
334e05b3b4aSPaul Mackerras 		return -ENODEV;
335e05b3b4aSPaul Mackerras 
336e05b3b4aSPaul Mackerras 	switch (which) {
337e05b3b4aSPaul Mackerras 	case IOBASE_BRIDGE_NUMBER:
338e05b3b4aSPaul Mackerras 		return (long)hose->first_busno;
339e05b3b4aSPaul Mackerras 	case IOBASE_MEMORY:
3403fd47f06SBenjamin Herrenschmidt 		return (long)hose->mem_offset[0];
341e05b3b4aSPaul Mackerras 	case IOBASE_IO:
342e05b3b4aSPaul Mackerras 		return (long)hose->io_base_phys;
343e05b3b4aSPaul Mackerras 	case IOBASE_ISA_IO:
344e05b3b4aSPaul Mackerras 		return (long)isa_io_base;
345e05b3b4aSPaul Mackerras 	case IOBASE_ISA_MEM:
346e05b3b4aSPaul Mackerras 		return (long)isa_mem_base;
347e05b3b4aSPaul Mackerras 	}
348e05b3b4aSPaul Mackerras 
349e05b3b4aSPaul Mackerras 	return result;
350e05b3b4aSPaul Mackerras }
351