xref: /openbmc/linux/arch/x86/pci/common.c (revision 5b1ea82f)
1fb9aa6f1SThomas Gleixner /*
2fb9aa6f1SThomas Gleixner  *	Low-Level PCI Support for PC
3fb9aa6f1SThomas Gleixner  *
4fb9aa6f1SThomas Gleixner  *	(c) 1999--2000 Martin Mares <mj@ucw.cz>
5fb9aa6f1SThomas Gleixner  */
6fb9aa6f1SThomas Gleixner 
7fb9aa6f1SThomas Gleixner #include <linux/sched.h>
8fb9aa6f1SThomas Gleixner #include <linux/pci.h>
9fb9aa6f1SThomas Gleixner #include <linux/ioport.h>
10fb9aa6f1SThomas Gleixner #include <linux/init.h>
11fb9aa6f1SThomas Gleixner #include <linux/dmi.h>
12fb9aa6f1SThomas Gleixner 
13fb9aa6f1SThomas Gleixner #include <asm/acpi.h>
14fb9aa6f1SThomas Gleixner #include <asm/segment.h>
15fb9aa6f1SThomas Gleixner #include <asm/io.h>
16fb9aa6f1SThomas Gleixner #include <asm/smp.h>
17fb9aa6f1SThomas Gleixner 
18fb9aa6f1SThomas Gleixner #include "pci.h"
19fb9aa6f1SThomas Gleixner 
20fb9aa6f1SThomas Gleixner unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
21fb9aa6f1SThomas Gleixner 				PCI_PROBE_MMCONF;
22fb9aa6f1SThomas Gleixner 
23fb9aa6f1SThomas Gleixner static int pci_bf_sort;
24fb9aa6f1SThomas Gleixner int pci_routeirq;
25fb9aa6f1SThomas Gleixner int pcibios_last_bus = -1;
26fb9aa6f1SThomas Gleixner unsigned long pirq_table_addr;
27fb9aa6f1SThomas Gleixner struct pci_bus *pci_root_bus;
28fb9aa6f1SThomas Gleixner struct pci_raw_ops *raw_pci_ops;
29fb9aa6f1SThomas Gleixner 
30fb9aa6f1SThomas Gleixner static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
31fb9aa6f1SThomas Gleixner {
32fb9aa6f1SThomas Gleixner 	return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
33fb9aa6f1SThomas Gleixner }
34fb9aa6f1SThomas Gleixner 
35fb9aa6f1SThomas Gleixner static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
36fb9aa6f1SThomas Gleixner {
37fb9aa6f1SThomas Gleixner 	return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
38fb9aa6f1SThomas Gleixner }
39fb9aa6f1SThomas Gleixner 
40fb9aa6f1SThomas Gleixner struct pci_ops pci_root_ops = {
41fb9aa6f1SThomas Gleixner 	.read = pci_read,
42fb9aa6f1SThomas Gleixner 	.write = pci_write,
43fb9aa6f1SThomas Gleixner };
44fb9aa6f1SThomas Gleixner 
45fb9aa6f1SThomas Gleixner /*
46fb9aa6f1SThomas Gleixner  * legacy, numa, and acpi all want to call pcibios_scan_root
47fb9aa6f1SThomas Gleixner  * from their initcalls. This flag prevents that.
48fb9aa6f1SThomas Gleixner  */
49fb9aa6f1SThomas Gleixner int pcibios_scanned;
50fb9aa6f1SThomas Gleixner 
51fb9aa6f1SThomas Gleixner /*
52fb9aa6f1SThomas Gleixner  * This interrupt-safe spinlock protects all accesses to PCI
53fb9aa6f1SThomas Gleixner  * configuration space.
54fb9aa6f1SThomas Gleixner  */
55fb9aa6f1SThomas Gleixner DEFINE_SPINLOCK(pci_config_lock);
56fb9aa6f1SThomas Gleixner 
57fb9aa6f1SThomas Gleixner /*
58fb9aa6f1SThomas Gleixner  * Several buggy motherboards address only 16 devices and mirror
59fb9aa6f1SThomas Gleixner  * them to next 16 IDs. We try to detect this `feature' on all
60fb9aa6f1SThomas Gleixner  * primary buses (those containing host bridges as they are
61fb9aa6f1SThomas Gleixner  * expected to be unique) and remove the ghost devices.
62fb9aa6f1SThomas Gleixner  */
63fb9aa6f1SThomas Gleixner 
64fb9aa6f1SThomas Gleixner static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
65fb9aa6f1SThomas Gleixner {
66fb9aa6f1SThomas Gleixner 	struct list_head *ln, *mn;
67fb9aa6f1SThomas Gleixner 	struct pci_dev *d, *e;
68fb9aa6f1SThomas Gleixner 	int mirror = PCI_DEVFN(16,0);
69fb9aa6f1SThomas Gleixner 	int seen_host_bridge = 0;
70fb9aa6f1SThomas Gleixner 	int i;
71fb9aa6f1SThomas Gleixner 
72fb9aa6f1SThomas Gleixner 	DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
73fb9aa6f1SThomas Gleixner 	list_for_each(ln, &b->devices) {
74fb9aa6f1SThomas Gleixner 		d = pci_dev_b(ln);
75fb9aa6f1SThomas Gleixner 		if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
76fb9aa6f1SThomas Gleixner 			seen_host_bridge++;
77fb9aa6f1SThomas Gleixner 		for (mn=ln->next; mn != &b->devices; mn=mn->next) {
78fb9aa6f1SThomas Gleixner 			e = pci_dev_b(mn);
79fb9aa6f1SThomas Gleixner 			if (e->devfn != d->devfn + mirror ||
80fb9aa6f1SThomas Gleixner 			    e->vendor != d->vendor ||
81fb9aa6f1SThomas Gleixner 			    e->device != d->device ||
82fb9aa6f1SThomas Gleixner 			    e->class != d->class)
83fb9aa6f1SThomas Gleixner 				continue;
84fb9aa6f1SThomas Gleixner 			for(i=0; i<PCI_NUM_RESOURCES; i++)
85fb9aa6f1SThomas Gleixner 				if (e->resource[i].start != d->resource[i].start ||
86fb9aa6f1SThomas Gleixner 				    e->resource[i].end != d->resource[i].end ||
87fb9aa6f1SThomas Gleixner 				    e->resource[i].flags != d->resource[i].flags)
88fb9aa6f1SThomas Gleixner 					continue;
89fb9aa6f1SThomas Gleixner 			break;
90fb9aa6f1SThomas Gleixner 		}
91fb9aa6f1SThomas Gleixner 		if (mn == &b->devices)
92fb9aa6f1SThomas Gleixner 			return;
93fb9aa6f1SThomas Gleixner 	}
94fb9aa6f1SThomas Gleixner 	if (!seen_host_bridge)
95fb9aa6f1SThomas Gleixner 		return;
96fb9aa6f1SThomas Gleixner 	printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
97fb9aa6f1SThomas Gleixner 
98fb9aa6f1SThomas Gleixner 	ln = &b->devices;
99fb9aa6f1SThomas Gleixner 	while (ln->next != &b->devices) {
100fb9aa6f1SThomas Gleixner 		d = pci_dev_b(ln->next);
101fb9aa6f1SThomas Gleixner 		if (d->devfn >= mirror) {
102fb9aa6f1SThomas Gleixner 			list_del(&d->global_list);
103fb9aa6f1SThomas Gleixner 			list_del(&d->bus_list);
104fb9aa6f1SThomas Gleixner 			kfree(d);
105fb9aa6f1SThomas Gleixner 		} else
106fb9aa6f1SThomas Gleixner 			ln = ln->next;
107fb9aa6f1SThomas Gleixner 	}
108fb9aa6f1SThomas Gleixner }
109fb9aa6f1SThomas Gleixner 
110fb9aa6f1SThomas Gleixner /*
111fb9aa6f1SThomas Gleixner  *  Called after each bus is probed, but before its children
112fb9aa6f1SThomas Gleixner  *  are examined.
113fb9aa6f1SThomas Gleixner  */
114fb9aa6f1SThomas Gleixner 
115fb9aa6f1SThomas Gleixner void __devinit  pcibios_fixup_bus(struct pci_bus *b)
116fb9aa6f1SThomas Gleixner {
117fb9aa6f1SThomas Gleixner 	pcibios_fixup_ghosts(b);
118fb9aa6f1SThomas Gleixner 	pci_read_bridge_bases(b);
119fb9aa6f1SThomas Gleixner }
120fb9aa6f1SThomas Gleixner 
121fb9aa6f1SThomas Gleixner /*
122fb9aa6f1SThomas Gleixner  * Only use DMI information to set this if nothing was passed
123fb9aa6f1SThomas Gleixner  * on the kernel command line (which was parsed earlier).
124fb9aa6f1SThomas Gleixner  */
125fb9aa6f1SThomas Gleixner 
12619ad7ae4SLinus Torvalds static int __devinit set_bf_sort(const struct dmi_system_id *d)
127fb9aa6f1SThomas Gleixner {
128fb9aa6f1SThomas Gleixner 	if (pci_bf_sort == pci_bf_sort_default) {
129fb9aa6f1SThomas Gleixner 		pci_bf_sort = pci_dmi_bf;
130fb9aa6f1SThomas Gleixner 		printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
131fb9aa6f1SThomas Gleixner 	}
132fb9aa6f1SThomas Gleixner 	return 0;
133fb9aa6f1SThomas Gleixner }
134fb9aa6f1SThomas Gleixner 
135fb9aa6f1SThomas Gleixner /*
136fb9aa6f1SThomas Gleixner  * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
137fb9aa6f1SThomas Gleixner  */
138fb9aa6f1SThomas Gleixner #ifdef __i386__
13919ad7ae4SLinus Torvalds static int __devinit assign_all_busses(const struct dmi_system_id *d)
140fb9aa6f1SThomas Gleixner {
141fb9aa6f1SThomas Gleixner 	pci_probe |= PCI_ASSIGN_ALL_BUSSES;
142fb9aa6f1SThomas Gleixner 	printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
143fb9aa6f1SThomas Gleixner 			" (pci=assign-busses)\n", d->ident);
144fb9aa6f1SThomas Gleixner 	return 0;
145fb9aa6f1SThomas Gleixner }
146fb9aa6f1SThomas Gleixner #endif
147fb9aa6f1SThomas Gleixner 
148fb9aa6f1SThomas Gleixner static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
149fb9aa6f1SThomas Gleixner #ifdef __i386__
150fb9aa6f1SThomas Gleixner /*
151fb9aa6f1SThomas Gleixner  * Laptops which need pci=assign-busses to see Cardbus cards
152fb9aa6f1SThomas Gleixner  */
153fb9aa6f1SThomas Gleixner 	{
154fb9aa6f1SThomas Gleixner 		.callback = assign_all_busses,
155fb9aa6f1SThomas Gleixner 		.ident = "Samsung X20 Laptop",
156fb9aa6f1SThomas Gleixner 		.matches = {
157fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
158fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
159fb9aa6f1SThomas Gleixner 		},
160fb9aa6f1SThomas Gleixner 	},
161fb9aa6f1SThomas Gleixner #endif		/* __i386__ */
162fb9aa6f1SThomas Gleixner 	{
163fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
164fb9aa6f1SThomas Gleixner 		.ident = "Dell PowerEdge 1950",
165fb9aa6f1SThomas Gleixner 		.matches = {
166fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
167fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
168fb9aa6f1SThomas Gleixner 		},
169fb9aa6f1SThomas Gleixner 	},
170fb9aa6f1SThomas Gleixner 	{
171fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
172fb9aa6f1SThomas Gleixner 		.ident = "Dell PowerEdge 1955",
173fb9aa6f1SThomas Gleixner 		.matches = {
174fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
175fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
176fb9aa6f1SThomas Gleixner 		},
177fb9aa6f1SThomas Gleixner 	},
178fb9aa6f1SThomas Gleixner 	{
179fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
180fb9aa6f1SThomas Gleixner 		.ident = "Dell PowerEdge 2900",
181fb9aa6f1SThomas Gleixner 		.matches = {
182fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
183fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
184fb9aa6f1SThomas Gleixner 		},
185fb9aa6f1SThomas Gleixner 	},
186fb9aa6f1SThomas Gleixner 	{
187fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
188fb9aa6f1SThomas Gleixner 		.ident = "Dell PowerEdge 2950",
189fb9aa6f1SThomas Gleixner 		.matches = {
190fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
191fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
192fb9aa6f1SThomas Gleixner 		},
193fb9aa6f1SThomas Gleixner 	},
194fb9aa6f1SThomas Gleixner 	{
195fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
196fb9aa6f1SThomas Gleixner 		.ident = "Dell PowerEdge R900",
197fb9aa6f1SThomas Gleixner 		.matches = {
198fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
199fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
200fb9aa6f1SThomas Gleixner 		},
201fb9aa6f1SThomas Gleixner 	},
202fb9aa6f1SThomas Gleixner 	{
203fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
204fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL20p G3",
205fb9aa6f1SThomas Gleixner 		.matches = {
206fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
207fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
208fb9aa6f1SThomas Gleixner 		},
209fb9aa6f1SThomas Gleixner 	},
210fb9aa6f1SThomas Gleixner 	{
211fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
212fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL20p G4",
213fb9aa6f1SThomas Gleixner 		.matches = {
214fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
215fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
216fb9aa6f1SThomas Gleixner 		},
217fb9aa6f1SThomas Gleixner 	},
218fb9aa6f1SThomas Gleixner 	{
219fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
220fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL30p G1",
221fb9aa6f1SThomas Gleixner 		.matches = {
222fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
223fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
224fb9aa6f1SThomas Gleixner 		},
225fb9aa6f1SThomas Gleixner 	},
226fb9aa6f1SThomas Gleixner 	{
227fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
228fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL25p G1",
229fb9aa6f1SThomas Gleixner 		.matches = {
230fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
231fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
232fb9aa6f1SThomas Gleixner 		},
233fb9aa6f1SThomas Gleixner 	},
234fb9aa6f1SThomas Gleixner 	{
235fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
236fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL35p G1",
237fb9aa6f1SThomas Gleixner 		.matches = {
238fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
239fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
240fb9aa6f1SThomas Gleixner 		},
241fb9aa6f1SThomas Gleixner 	},
242fb9aa6f1SThomas Gleixner 	{
243fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
244fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL45p G1",
245fb9aa6f1SThomas Gleixner 		.matches = {
246fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
247fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
248fb9aa6f1SThomas Gleixner 		},
249fb9aa6f1SThomas Gleixner 	},
250fb9aa6f1SThomas Gleixner 	{
251fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
252fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL45p G2",
253fb9aa6f1SThomas Gleixner 		.matches = {
254fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
255fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
256fb9aa6f1SThomas Gleixner 		},
257fb9aa6f1SThomas Gleixner 	},
258fb9aa6f1SThomas Gleixner 	{
259fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
260fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL460c G1",
261fb9aa6f1SThomas Gleixner 		.matches = {
262fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
263fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
264fb9aa6f1SThomas Gleixner 		},
265fb9aa6f1SThomas Gleixner 	},
266fb9aa6f1SThomas Gleixner 	{
267fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
268fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL465c G1",
269fb9aa6f1SThomas Gleixner 		.matches = {
270fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
271fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
272fb9aa6f1SThomas Gleixner 		},
273fb9aa6f1SThomas Gleixner 	},
274fb9aa6f1SThomas Gleixner 	{
275fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
276fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL480c G1",
277fb9aa6f1SThomas Gleixner 		.matches = {
278fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
279fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
280fb9aa6f1SThomas Gleixner 		},
281fb9aa6f1SThomas Gleixner 	},
282fb9aa6f1SThomas Gleixner 	{
283fb9aa6f1SThomas Gleixner 		.callback = set_bf_sort,
284fb9aa6f1SThomas Gleixner 		.ident = "HP ProLiant BL685c G1",
285fb9aa6f1SThomas Gleixner 		.matches = {
286fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
287fb9aa6f1SThomas Gleixner 			DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
288fb9aa6f1SThomas Gleixner 		},
289fb9aa6f1SThomas Gleixner 	},
2905b1ea82fSJuha Laiho #ifdef __i386__
2915b1ea82fSJuha Laiho 	{
2925b1ea82fSJuha Laiho 		.callback = assign_all_busses,
2935b1ea82fSJuha Laiho 		.ident = "Compaq EVO N800c",
2945b1ea82fSJuha Laiho 		.matches = {
2955b1ea82fSJuha Laiho 			DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
2965b1ea82fSJuha Laiho 			DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
2975b1ea82fSJuha Laiho 		},
2985b1ea82fSJuha Laiho 	},
2995b1ea82fSJuha Laiho #endif
300fb9aa6f1SThomas Gleixner 	{}
301fb9aa6f1SThomas Gleixner };
302fb9aa6f1SThomas Gleixner 
303fb9aa6f1SThomas Gleixner struct pci_bus * __devinit pcibios_scan_root(int busnum)
304fb9aa6f1SThomas Gleixner {
305fb9aa6f1SThomas Gleixner 	struct pci_bus *bus = NULL;
306fb9aa6f1SThomas Gleixner 	struct pci_sysdata *sd;
307fb9aa6f1SThomas Gleixner 
308fb9aa6f1SThomas Gleixner 	dmi_check_system(pciprobe_dmi_table);
309fb9aa6f1SThomas Gleixner 
310fb9aa6f1SThomas Gleixner 	while ((bus = pci_find_next_bus(bus)) != NULL) {
311fb9aa6f1SThomas Gleixner 		if (bus->number == busnum) {
312fb9aa6f1SThomas Gleixner 			/* Already scanned */
313fb9aa6f1SThomas Gleixner 			return bus;
314fb9aa6f1SThomas Gleixner 		}
315fb9aa6f1SThomas Gleixner 	}
316fb9aa6f1SThomas Gleixner 
317fb9aa6f1SThomas Gleixner 	/* Allocate per-root-bus (not per bus) arch-specific data.
318fb9aa6f1SThomas Gleixner 	 * TODO: leak; this memory is never freed.
319fb9aa6f1SThomas Gleixner 	 * It's arguable whether it's worth the trouble to care.
320fb9aa6f1SThomas Gleixner 	 */
321fb9aa6f1SThomas Gleixner 	sd = kzalloc(sizeof(*sd), GFP_KERNEL);
322fb9aa6f1SThomas Gleixner 	if (!sd) {
323fb9aa6f1SThomas Gleixner 		printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
324fb9aa6f1SThomas Gleixner 		return NULL;
325fb9aa6f1SThomas Gleixner 	}
326fb9aa6f1SThomas Gleixner 
327fb9aa6f1SThomas Gleixner 	printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
328fb9aa6f1SThomas Gleixner 
329fb9aa6f1SThomas Gleixner 	return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
330fb9aa6f1SThomas Gleixner }
331fb9aa6f1SThomas Gleixner 
332fb9aa6f1SThomas Gleixner extern u8 pci_cache_line_size;
333fb9aa6f1SThomas Gleixner 
334fb9aa6f1SThomas Gleixner static int __init pcibios_init(void)
335fb9aa6f1SThomas Gleixner {
336fb9aa6f1SThomas Gleixner 	struct cpuinfo_x86 *c = &boot_cpu_data;
337fb9aa6f1SThomas Gleixner 
338fb9aa6f1SThomas Gleixner 	if (!raw_pci_ops) {
339fb9aa6f1SThomas Gleixner 		printk(KERN_WARNING "PCI: System does not support PCI\n");
340fb9aa6f1SThomas Gleixner 		return 0;
341fb9aa6f1SThomas Gleixner 	}
342fb9aa6f1SThomas Gleixner 
343fb9aa6f1SThomas Gleixner 	/*
344fb9aa6f1SThomas Gleixner 	 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
345fb9aa6f1SThomas Gleixner 	 * and P4. It's also good for 386/486s (which actually have 16)
346fb9aa6f1SThomas Gleixner 	 * as quite a few PCI devices do not support smaller values.
347fb9aa6f1SThomas Gleixner 	 */
348fb9aa6f1SThomas Gleixner 	pci_cache_line_size = 32 >> 2;
349fb9aa6f1SThomas Gleixner 	if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
350fb9aa6f1SThomas Gleixner 		pci_cache_line_size = 64 >> 2;	/* K7 & K8 */
351fb9aa6f1SThomas Gleixner 	else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
352fb9aa6f1SThomas Gleixner 		pci_cache_line_size = 128 >> 2;	/* P4 */
353fb9aa6f1SThomas Gleixner 
354fb9aa6f1SThomas Gleixner 	pcibios_resource_survey();
355fb9aa6f1SThomas Gleixner 
356fb9aa6f1SThomas Gleixner 	if (pci_bf_sort >= pci_force_bf)
357fb9aa6f1SThomas Gleixner 		pci_sort_breadthfirst();
358fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_BIOS
359fb9aa6f1SThomas Gleixner 	if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
360fb9aa6f1SThomas Gleixner 		pcibios_sort();
361fb9aa6f1SThomas Gleixner #endif
362fb9aa6f1SThomas Gleixner 	return 0;
363fb9aa6f1SThomas Gleixner }
364fb9aa6f1SThomas Gleixner 
365fb9aa6f1SThomas Gleixner subsys_initcall(pcibios_init);
366fb9aa6f1SThomas Gleixner 
367fb9aa6f1SThomas Gleixner char * __devinit  pcibios_setup(char *str)
368fb9aa6f1SThomas Gleixner {
369fb9aa6f1SThomas Gleixner 	if (!strcmp(str, "off")) {
370fb9aa6f1SThomas Gleixner 		pci_probe = 0;
371fb9aa6f1SThomas Gleixner 		return NULL;
372fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "bfsort")) {
373fb9aa6f1SThomas Gleixner 		pci_bf_sort = pci_force_bf;
374fb9aa6f1SThomas Gleixner 		return NULL;
375fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "nobfsort")) {
376fb9aa6f1SThomas Gleixner 		pci_bf_sort = pci_force_nobf;
377fb9aa6f1SThomas Gleixner 		return NULL;
378fb9aa6f1SThomas Gleixner 	}
379fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_BIOS
380fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "bios")) {
381fb9aa6f1SThomas Gleixner 		pci_probe = PCI_PROBE_BIOS;
382fb9aa6f1SThomas Gleixner 		return NULL;
383fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "nobios")) {
384fb9aa6f1SThomas Gleixner 		pci_probe &= ~PCI_PROBE_BIOS;
385fb9aa6f1SThomas Gleixner 		return NULL;
386fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "nosort")) {
387fb9aa6f1SThomas Gleixner 		pci_probe |= PCI_NO_SORT;
388fb9aa6f1SThomas Gleixner 		return NULL;
389fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "biosirq")) {
390fb9aa6f1SThomas Gleixner 		pci_probe |= PCI_BIOS_IRQ_SCAN;
391fb9aa6f1SThomas Gleixner 		return NULL;
392fb9aa6f1SThomas Gleixner 	} else if (!strncmp(str, "pirqaddr=", 9)) {
393fb9aa6f1SThomas Gleixner 		pirq_table_addr = simple_strtoul(str+9, NULL, 0);
394fb9aa6f1SThomas Gleixner 		return NULL;
395fb9aa6f1SThomas Gleixner 	}
396fb9aa6f1SThomas Gleixner #endif
397fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_DIRECT
398fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "conf1")) {
399fb9aa6f1SThomas Gleixner 		pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
400fb9aa6f1SThomas Gleixner 		return NULL;
401fb9aa6f1SThomas Gleixner 	}
402fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "conf2")) {
403fb9aa6f1SThomas Gleixner 		pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
404fb9aa6f1SThomas Gleixner 		return NULL;
405fb9aa6f1SThomas Gleixner 	}
406fb9aa6f1SThomas Gleixner #endif
407fb9aa6f1SThomas Gleixner #ifdef CONFIG_PCI_MMCONFIG
408fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "nommconf")) {
409fb9aa6f1SThomas Gleixner 		pci_probe &= ~PCI_PROBE_MMCONF;
410fb9aa6f1SThomas Gleixner 		return NULL;
411fb9aa6f1SThomas Gleixner 	}
412fb9aa6f1SThomas Gleixner #endif
413fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "noacpi")) {
414fb9aa6f1SThomas Gleixner 		acpi_noirq_set();
415fb9aa6f1SThomas Gleixner 		return NULL;
416fb9aa6f1SThomas Gleixner 	}
417fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "noearly")) {
418fb9aa6f1SThomas Gleixner 		pci_probe |= PCI_PROBE_NOEARLY;
419fb9aa6f1SThomas Gleixner 		return NULL;
420fb9aa6f1SThomas Gleixner 	}
421fb9aa6f1SThomas Gleixner #ifndef CONFIG_X86_VISWS
422fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "usepirqmask")) {
423fb9aa6f1SThomas Gleixner 		pci_probe |= PCI_USE_PIRQ_MASK;
424fb9aa6f1SThomas Gleixner 		return NULL;
425fb9aa6f1SThomas Gleixner 	} else if (!strncmp(str, "irqmask=", 8)) {
426fb9aa6f1SThomas Gleixner 		pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
427fb9aa6f1SThomas Gleixner 		return NULL;
428fb9aa6f1SThomas Gleixner 	} else if (!strncmp(str, "lastbus=", 8)) {
429fb9aa6f1SThomas Gleixner 		pcibios_last_bus = simple_strtol(str+8, NULL, 0);
430fb9aa6f1SThomas Gleixner 		return NULL;
431fb9aa6f1SThomas Gleixner 	}
432fb9aa6f1SThomas Gleixner #endif
433fb9aa6f1SThomas Gleixner 	else if (!strcmp(str, "rom")) {
434fb9aa6f1SThomas Gleixner 		pci_probe |= PCI_ASSIGN_ROMS;
435fb9aa6f1SThomas Gleixner 		return NULL;
436fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "assign-busses")) {
437fb9aa6f1SThomas Gleixner 		pci_probe |= PCI_ASSIGN_ALL_BUSSES;
438fb9aa6f1SThomas Gleixner 		return NULL;
439fb9aa6f1SThomas Gleixner 	} else if (!strcmp(str, "routeirq")) {
440fb9aa6f1SThomas Gleixner 		pci_routeirq = 1;
441fb9aa6f1SThomas Gleixner 		return NULL;
442fb9aa6f1SThomas Gleixner 	}
443fb9aa6f1SThomas Gleixner 	return str;
444fb9aa6f1SThomas Gleixner }
445fb9aa6f1SThomas Gleixner 
446fb9aa6f1SThomas Gleixner unsigned int pcibios_assign_all_busses(void)
447fb9aa6f1SThomas Gleixner {
448fb9aa6f1SThomas Gleixner 	return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
449fb9aa6f1SThomas Gleixner }
450fb9aa6f1SThomas Gleixner 
451fb9aa6f1SThomas Gleixner int pcibios_enable_device(struct pci_dev *dev, int mask)
452fb9aa6f1SThomas Gleixner {
453fb9aa6f1SThomas Gleixner 	int err;
454fb9aa6f1SThomas Gleixner 
455fb9aa6f1SThomas Gleixner 	if ((err = pcibios_enable_resources(dev, mask)) < 0)
456fb9aa6f1SThomas Gleixner 		return err;
457fb9aa6f1SThomas Gleixner 
458fb9aa6f1SThomas Gleixner 	if (!dev->msi_enabled)
459fb9aa6f1SThomas Gleixner 		return pcibios_enable_irq(dev);
460fb9aa6f1SThomas Gleixner 	return 0;
461fb9aa6f1SThomas Gleixner }
462fb9aa6f1SThomas Gleixner 
463fb9aa6f1SThomas Gleixner void pcibios_disable_device (struct pci_dev *dev)
464fb9aa6f1SThomas Gleixner {
465fb9aa6f1SThomas Gleixner 	if (!dev->msi_enabled && pcibios_disable_irq)
466fb9aa6f1SThomas Gleixner 		pcibios_disable_irq(dev);
467fb9aa6f1SThomas Gleixner }
468fb9aa6f1SThomas Gleixner 
469fb9aa6f1SThomas Gleixner struct pci_bus *pci_scan_bus_with_sysdata(int busno)
470fb9aa6f1SThomas Gleixner {
471fb9aa6f1SThomas Gleixner 	struct pci_bus *bus = NULL;
472fb9aa6f1SThomas Gleixner 	struct pci_sysdata *sd;
473fb9aa6f1SThomas Gleixner 
474fb9aa6f1SThomas Gleixner 	/*
475fb9aa6f1SThomas Gleixner 	 * Allocate per-root-bus (not per bus) arch-specific data.
476fb9aa6f1SThomas Gleixner 	 * TODO: leak; this memory is never freed.
477fb9aa6f1SThomas Gleixner 	 * It's arguable whether it's worth the trouble to care.
478fb9aa6f1SThomas Gleixner 	 */
479fb9aa6f1SThomas Gleixner 	sd = kzalloc(sizeof(*sd), GFP_KERNEL);
480fb9aa6f1SThomas Gleixner 	if (!sd) {
481fb9aa6f1SThomas Gleixner 		printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
482fb9aa6f1SThomas Gleixner 		return NULL;
483fb9aa6f1SThomas Gleixner 	}
484fb9aa6f1SThomas Gleixner 	sd->node = -1;
485fb9aa6f1SThomas Gleixner 	bus = pci_scan_bus(busno, &pci_root_ops, sd);
486fb9aa6f1SThomas Gleixner 	if (!bus)
487fb9aa6f1SThomas Gleixner 		kfree(sd);
488fb9aa6f1SThomas Gleixner 
489fb9aa6f1SThomas Gleixner 	return bus;
490fb9aa6f1SThomas Gleixner }
491