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);
112 static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
114 struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
119 /* we deal with BIOS assigned ROM later */
121 if (!(pci_probe & PCI_ASSIGN_ROMS))
122 rom_r->start = rom_r->end = rom_r->flags = 0;
126 * Called after each bus is probed, but before its children
130 void __devinit pcibios_fixup_bus(struct pci_bus *b)
134 pcibios_fixup_ghosts(b);
135 pci_read_bridge_bases(b);
136 list_for_each_entry(dev, &b->devices, bus_list)
137 pcibios_fixup_device_resources(dev);
141 * Only use DMI information to set this if nothing was passed
142 * on the kernel command line (which was parsed earlier).
145 static int __devinit set_bf_sort(const struct dmi_system_id *d)
147 if (pci_bf_sort == pci_bf_sort_default) {
148 pci_bf_sort = pci_dmi_bf;
149 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
155 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
158 static int __devinit assign_all_busses(const struct dmi_system_id *d)
160 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
161 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
162 " (pci=assign-busses)\n", d->ident);
167 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
170 * Laptops which need pci=assign-busses to see Cardbus cards
173 .callback = assign_all_busses,
174 .ident = "Samsung X20 Laptop",
176 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
177 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
180 #endif /* __i386__ */
182 .callback = set_bf_sort,
183 .ident = "Dell PowerEdge 1950",
185 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
186 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
190 .callback = set_bf_sort,
191 .ident = "Dell PowerEdge 1955",
193 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
194 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
198 .callback = set_bf_sort,
199 .ident = "Dell PowerEdge 2900",
201 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
202 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
206 .callback = set_bf_sort,
207 .ident = "Dell PowerEdge 2950",
209 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
210 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
214 .callback = set_bf_sort,
215 .ident = "Dell PowerEdge R900",
217 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
218 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
222 .callback = set_bf_sort,
223 .ident = "HP ProLiant BL20p G3",
225 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
226 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
230 .callback = set_bf_sort,
231 .ident = "HP ProLiant BL20p G4",
233 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
234 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
238 .callback = set_bf_sort,
239 .ident = "HP ProLiant BL30p G1",
241 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
242 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
246 .callback = set_bf_sort,
247 .ident = "HP ProLiant BL25p G1",
249 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
250 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
254 .callback = set_bf_sort,
255 .ident = "HP ProLiant BL35p G1",
257 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
258 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
262 .callback = set_bf_sort,
263 .ident = "HP ProLiant BL45p G1",
265 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
266 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
270 .callback = set_bf_sort,
271 .ident = "HP ProLiant BL45p G2",
273 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
274 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
278 .callback = set_bf_sort,
279 .ident = "HP ProLiant BL460c G1",
281 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
282 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
286 .callback = set_bf_sort,
287 .ident = "HP ProLiant BL465c G1",
289 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
290 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
294 .callback = set_bf_sort,
295 .ident = "HP ProLiant BL480c G1",
297 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
298 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
302 .callback = set_bf_sort,
303 .ident = "HP ProLiant BL685c G1",
305 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
306 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
310 .callback = set_bf_sort,
311 .ident = "HP ProLiant DL385 G2",
313 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
314 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
318 .callback = set_bf_sort,
319 .ident = "HP ProLiant DL585 G2",
321 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
322 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
327 .callback = assign_all_busses,
328 .ident = "Compaq EVO N800c",
330 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
331 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
336 .callback = set_bf_sort,
337 .ident = "HP ProLiant DL385 G2",
339 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
340 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
344 .callback = set_bf_sort,
345 .ident = "HP ProLiant DL585 G2",
347 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
348 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
354 struct pci_bus * __devinit pcibios_scan_root(int busnum)
356 struct pci_bus *bus = NULL;
357 struct pci_sysdata *sd;
359 dmi_check_system(pciprobe_dmi_table);
361 while ((bus = pci_find_next_bus(bus)) != NULL) {
362 if (bus->number == busnum) {
363 /* Already scanned */
368 /* Allocate per-root-bus (not per bus) arch-specific data.
369 * TODO: leak; this memory is never freed.
370 * It's arguable whether it's worth the trouble to care.
372 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
374 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
378 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
380 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
383 extern u8 pci_cache_line_size;
385 static int __init pcibios_init(void)
387 struct cpuinfo_x86 *c = &boot_cpu_data;
390 printk(KERN_WARNING "PCI: System does not support PCI\n");
395 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
396 * and P4. It's also good for 386/486s (which actually have 16)
397 * as quite a few PCI devices do not support smaller values.
399 pci_cache_line_size = 32 >> 2;
400 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
401 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
402 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
403 pci_cache_line_size = 128 >> 2; /* P4 */
405 pcibios_resource_survey();
407 if (pci_bf_sort >= pci_force_bf)
408 pci_sort_breadthfirst();
409 #ifdef CONFIG_PCI_BIOS
410 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
416 subsys_initcall(pcibios_init);
418 char * __devinit pcibios_setup(char *str)
420 if (!strcmp(str, "off")) {
423 } else if (!strcmp(str, "bfsort")) {
424 pci_bf_sort = pci_force_bf;
426 } else if (!strcmp(str, "nobfsort")) {
427 pci_bf_sort = pci_force_nobf;
430 #ifdef CONFIG_PCI_BIOS
431 else if (!strcmp(str, "bios")) {
432 pci_probe = PCI_PROBE_BIOS;
434 } else if (!strcmp(str, "nobios")) {
435 pci_probe &= ~PCI_PROBE_BIOS;
437 } else if (!strcmp(str, "nosort")) {
438 pci_probe |= PCI_NO_SORT;
440 } else if (!strcmp(str, "biosirq")) {
441 pci_probe |= PCI_BIOS_IRQ_SCAN;
443 } else if (!strncmp(str, "pirqaddr=", 9)) {
444 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
448 #ifdef CONFIG_PCI_DIRECT
449 else if (!strcmp(str, "conf1")) {
450 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
453 else if (!strcmp(str, "conf2")) {
454 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
458 #ifdef CONFIG_PCI_MMCONFIG
459 else if (!strcmp(str, "nommconf")) {
460 pci_probe &= ~PCI_PROBE_MMCONF;
464 else if (!strcmp(str, "noacpi")) {
468 else if (!strcmp(str, "noearly")) {
469 pci_probe |= PCI_PROBE_NOEARLY;
472 #ifndef CONFIG_X86_VISWS
473 else if (!strcmp(str, "usepirqmask")) {
474 pci_probe |= PCI_USE_PIRQ_MASK;
476 } else if (!strncmp(str, "irqmask=", 8)) {
477 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
479 } else if (!strncmp(str, "lastbus=", 8)) {
480 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
484 else if (!strcmp(str, "rom")) {
485 pci_probe |= PCI_ASSIGN_ROMS;
487 } else if (!strcmp(str, "assign-busses")) {
488 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
490 } else if (!strcmp(str, "use_crs")) {
491 pci_probe |= PCI_USE__CRS;
493 } else if (!strcmp(str, "routeirq")) {
500 unsigned int pcibios_assign_all_busses(void)
502 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
505 int pcibios_enable_device(struct pci_dev *dev, int mask)
509 if ((err = pcibios_enable_resources(dev, mask)) < 0)
512 if (!dev->msi_enabled)
513 return pcibios_enable_irq(dev);
517 void pcibios_disable_device (struct pci_dev *dev)
519 if (!dev->msi_enabled && pcibios_disable_irq)
520 pcibios_disable_irq(dev);
523 struct pci_bus *pci_scan_bus_with_sysdata(int busno)
525 struct pci_bus *bus = NULL;
526 struct pci_sysdata *sd;
529 * Allocate per-root-bus (not per bus) arch-specific data.
530 * TODO: leak; this memory is never freed.
531 * It's arguable whether it's worth the trouble to care.
533 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
535 printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
539 bus = pci_scan_bus(busno, &pci_root_ops, sd);