2 * Low-Level PCI Support for PC
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
7 #include <linux/sched.h>
9 #include <linux/ioport.h>
10 #include <linux/init.h>
11 #include <linux/dmi.h>
14 #include <asm/segment.h>
20 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
23 static int pci_bf_sort;
25 int pcibios_last_bus = -1;
26 unsigned long pirq_table_addr;
27 struct pci_bus *pci_root_bus;
28 struct pci_raw_ops *raw_pci_ops;
30 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
32 return raw_pci_ops->read(pci_domain_nr(bus), bus->number,
33 devfn, where, size, value);
36 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
38 return raw_pci_ops->write(pci_domain_nr(bus), bus->number,
39 devfn, where, size, value);
42 struct pci_ops pci_root_ops = {
48 * legacy, numa, and acpi all want to call pcibios_scan_root
49 * from their initcalls. This flag prevents that.
54 * This interrupt-safe spinlock protects all accesses to PCI
55 * configuration space.
57 DEFINE_SPINLOCK(pci_config_lock);
60 * Several buggy motherboards address only 16 devices and mirror
61 * them to next 16 IDs. We try to detect this `feature' on all
62 * primary buses (those containing host bridges as they are
63 * expected to be unique) and remove the ghost devices.
66 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
68 struct list_head *ln, *mn;
69 struct pci_dev *d, *e;
70 int mirror = PCI_DEVFN(16,0);
71 int seen_host_bridge = 0;
74 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
75 list_for_each(ln, &b->devices) {
77 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
79 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
81 if (e->devfn != d->devfn + mirror ||
82 e->vendor != d->vendor ||
83 e->device != d->device ||
86 for(i=0; i<PCI_NUM_RESOURCES; i++)
87 if (e->resource[i].start != d->resource[i].start ||
88 e->resource[i].end != d->resource[i].end ||
89 e->resource[i].flags != d->resource[i].flags)
93 if (mn == &b->devices)
96 if (!seen_host_bridge)
98 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
101 while (ln->next != &b->devices) {
102 d = pci_dev_b(ln->next);
103 if (d->devfn >= mirror) {
104 list_del(&d->global_list);
105 list_del(&d->bus_list);
113 * Called after each bus is probed, but before its children
117 void __devinit pcibios_fixup_bus(struct pci_bus *b)
119 pcibios_fixup_ghosts(b);
120 pci_read_bridge_bases(b);
124 * Only use DMI information to set this if nothing was passed
125 * on the kernel command line (which was parsed earlier).
128 static int __devinit set_bf_sort(const struct dmi_system_id *d)
130 if (pci_bf_sort == pci_bf_sort_default) {
131 pci_bf_sort = pci_dmi_bf;
132 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
138 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
141 static int __devinit assign_all_busses(const struct dmi_system_id *d)
143 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
144 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
145 " (pci=assign-busses)\n", d->ident);
150 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
153 * Laptops which need pci=assign-busses to see Cardbus cards
156 .callback = assign_all_busses,
157 .ident = "Samsung X20 Laptop",
159 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
160 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
163 #endif /* __i386__ */
165 .callback = set_bf_sort,
166 .ident = "Dell PowerEdge 1950",
168 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
169 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
173 .callback = set_bf_sort,
174 .ident = "Dell PowerEdge 1955",
176 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
177 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
181 .callback = set_bf_sort,
182 .ident = "Dell PowerEdge 2900",
184 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
185 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
189 .callback = set_bf_sort,
190 .ident = "Dell PowerEdge 2950",
192 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
193 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
197 .callback = set_bf_sort,
198 .ident = "Dell PowerEdge R900",
200 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
201 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
205 .callback = set_bf_sort,
206 .ident = "HP ProLiant BL20p G3",
208 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
209 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
213 .callback = set_bf_sort,
214 .ident = "HP ProLiant BL20p G4",
216 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
217 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
221 .callback = set_bf_sort,
222 .ident = "HP ProLiant BL30p G1",
224 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
225 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
229 .callback = set_bf_sort,
230 .ident = "HP ProLiant BL25p G1",
232 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
233 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
237 .callback = set_bf_sort,
238 .ident = "HP ProLiant BL35p G1",
240 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
241 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
245 .callback = set_bf_sort,
246 .ident = "HP ProLiant BL45p G1",
248 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
249 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
253 .callback = set_bf_sort,
254 .ident = "HP ProLiant BL45p G2",
256 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
257 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
261 .callback = set_bf_sort,
262 .ident = "HP ProLiant BL460c G1",
264 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
265 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
269 .callback = set_bf_sort,
270 .ident = "HP ProLiant BL465c G1",
272 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
273 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
277 .callback = set_bf_sort,
278 .ident = "HP ProLiant BL480c G1",
280 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
281 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
285 .callback = set_bf_sort,
286 .ident = "HP ProLiant BL685c G1",
288 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
289 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
294 .callback = assign_all_busses,
295 .ident = "Compaq EVO N800c",
297 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
298 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
305 struct pci_bus * __devinit pcibios_scan_root(int busnum)
307 struct pci_bus *bus = NULL;
308 struct pci_sysdata *sd;
310 dmi_check_system(pciprobe_dmi_table);
312 while ((bus = pci_find_next_bus(bus)) != NULL) {
313 if (bus->number == busnum) {
314 /* Already scanned */
319 /* Allocate per-root-bus (not per bus) arch-specific data.
320 * TODO: leak; this memory is never freed.
321 * It's arguable whether it's worth the trouble to care.
323 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
325 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
329 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
331 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
334 extern u8 pci_cache_line_size;
336 static int __init pcibios_init(void)
338 struct cpuinfo_x86 *c = &boot_cpu_data;
341 printk(KERN_WARNING "PCI: System does not support PCI\n");
346 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
347 * and P4. It's also good for 386/486s (which actually have 16)
348 * as quite a few PCI devices do not support smaller values.
350 pci_cache_line_size = 32 >> 2;
351 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
352 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
353 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
354 pci_cache_line_size = 128 >> 2; /* P4 */
356 pcibios_resource_survey();
358 if (pci_bf_sort >= pci_force_bf)
359 pci_sort_breadthfirst();
360 #ifdef CONFIG_PCI_BIOS
361 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
367 subsys_initcall(pcibios_init);
369 char * __devinit pcibios_setup(char *str)
371 if (!strcmp(str, "off")) {
374 } else if (!strcmp(str, "bfsort")) {
375 pci_bf_sort = pci_force_bf;
377 } else if (!strcmp(str, "nobfsort")) {
378 pci_bf_sort = pci_force_nobf;
381 #ifdef CONFIG_PCI_BIOS
382 else if (!strcmp(str, "bios")) {
383 pci_probe = PCI_PROBE_BIOS;
385 } else if (!strcmp(str, "nobios")) {
386 pci_probe &= ~PCI_PROBE_BIOS;
388 } else if (!strcmp(str, "nosort")) {
389 pci_probe |= PCI_NO_SORT;
391 } else if (!strcmp(str, "biosirq")) {
392 pci_probe |= PCI_BIOS_IRQ_SCAN;
394 } else if (!strncmp(str, "pirqaddr=", 9)) {
395 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
399 #ifdef CONFIG_PCI_DIRECT
400 else if (!strcmp(str, "conf1")) {
401 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
404 else if (!strcmp(str, "conf2")) {
405 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
409 #ifdef CONFIG_PCI_MMCONFIG
410 else if (!strcmp(str, "nommconf")) {
411 pci_probe &= ~PCI_PROBE_MMCONF;
415 else if (!strcmp(str, "noacpi")) {
419 else if (!strcmp(str, "noearly")) {
420 pci_probe |= PCI_PROBE_NOEARLY;
423 #ifndef CONFIG_X86_VISWS
424 else if (!strcmp(str, "usepirqmask")) {
425 pci_probe |= PCI_USE_PIRQ_MASK;
427 } else if (!strncmp(str, "irqmask=", 8)) {
428 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
430 } else if (!strncmp(str, "lastbus=", 8)) {
431 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
435 else if (!strcmp(str, "rom")) {
436 pci_probe |= PCI_ASSIGN_ROMS;
438 } else if (!strcmp(str, "assign-busses")) {
439 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
441 } else if (!strcmp(str, "use_crs")) {
442 pci_probe |= PCI_USE__CRS;
444 } else if (!strcmp(str, "routeirq")) {
451 unsigned int pcibios_assign_all_busses(void)
453 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
456 int pcibios_enable_device(struct pci_dev *dev, int mask)
460 if ((err = pcibios_enable_resources(dev, mask)) < 0)
463 if (!dev->msi_enabled)
464 return pcibios_enable_irq(dev);
468 void pcibios_disable_device (struct pci_dev *dev)
470 if (!dev->msi_enabled && pcibios_disable_irq)
471 pcibios_disable_irq(dev);
474 struct pci_bus *pci_scan_bus_with_sysdata(int busno)
476 struct pci_bus *bus = NULL;
477 struct pci_sysdata *sd;
480 * Allocate per-root-bus (not per bus) arch-specific data.
481 * TODO: leak; this memory is never freed.
482 * It's arguable whether it's worth the trouble to care.
484 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
486 printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
490 bus = pci_scan_bus(busno, &pci_root_ops, sd);