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 unsigned int pci_early_dump_regs;
24 static int pci_bf_sort;
27 #ifdef CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS
28 int noioapicreroute = 0;
30 int noioapicreroute = 1;
32 int pcibios_last_bus = -1;
33 unsigned long pirq_table_addr;
34 struct pci_bus *pci_root_bus;
35 struct pci_raw_ops *raw_pci_ops;
36 struct pci_raw_ops *raw_pci_ext_ops;
38 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
39 int reg, int len, u32 *val)
41 if (domain == 0 && reg < 256 && raw_pci_ops)
42 return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
44 return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
48 int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
49 int reg, int len, u32 val)
51 if (domain == 0 && reg < 256 && raw_pci_ops)
52 return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
54 return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
58 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
60 return raw_pci_read(pci_domain_nr(bus), bus->number,
61 devfn, where, size, value);
64 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
66 return raw_pci_write(pci_domain_nr(bus), bus->number,
67 devfn, where, size, value);
70 struct pci_ops pci_root_ops = {
76 * legacy, numa, and acpi all want to call pcibios_scan_root
77 * from their initcalls. This flag prevents that.
82 * This interrupt-safe spinlock protects all accesses to PCI
83 * configuration space.
85 DEFINE_SPINLOCK(pci_config_lock);
87 static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
89 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
90 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
94 static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
96 * Systems where PCI IO resource ISA alignment can be skipped
97 * when the ISA enable bit in the bridge control is not set
100 .callback = can_skip_ioresource_align,
101 .ident = "IBM System x3800",
103 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
104 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
108 .callback = can_skip_ioresource_align,
109 .ident = "IBM System x3850",
111 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
112 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
116 .callback = can_skip_ioresource_align,
117 .ident = "IBM System x3950",
119 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
120 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
126 void __init dmi_check_skip_isa_align(void)
128 dmi_check_system(can_skip_pciprobe_dmi_table);
131 static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
133 struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
135 if (pci_probe & PCI_NOASSIGN_ROMS) {
139 /* we deal with BIOS assigned ROM later */
142 rom_r->start = rom_r->end = rom_r->flags = 0;
147 * Called after each bus is probed, but before its children
151 void __devinit pcibios_fixup_bus(struct pci_bus *b)
155 pci_read_bridge_bases(b);
156 list_for_each_entry(dev, &b->devices, bus_list)
157 pcibios_fixup_device_resources(dev);
161 * Only use DMI information to set this if nothing was passed
162 * on the kernel command line (which was parsed earlier).
165 static int __devinit set_bf_sort(const struct dmi_system_id *d)
167 if (pci_bf_sort == pci_bf_sort_default) {
168 pci_bf_sort = pci_dmi_bf;
169 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
175 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
178 static int __devinit assign_all_busses(const struct dmi_system_id *d)
180 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
181 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
182 " (pci=assign-busses)\n", d->ident);
187 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
190 * Laptops which need pci=assign-busses to see Cardbus cards
193 .callback = assign_all_busses,
194 .ident = "Samsung X20 Laptop",
196 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
197 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
200 #endif /* __i386__ */
202 .callback = set_bf_sort,
203 .ident = "Dell PowerEdge 1950",
205 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
206 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
210 .callback = set_bf_sort,
211 .ident = "Dell PowerEdge 1955",
213 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
214 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
218 .callback = set_bf_sort,
219 .ident = "Dell PowerEdge 2900",
221 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
222 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
226 .callback = set_bf_sort,
227 .ident = "Dell PowerEdge 2950",
229 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
230 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
234 .callback = set_bf_sort,
235 .ident = "Dell PowerEdge R900",
237 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
238 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
242 .callback = set_bf_sort,
243 .ident = "HP ProLiant BL20p G3",
245 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
246 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
250 .callback = set_bf_sort,
251 .ident = "HP ProLiant BL20p G4",
253 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
254 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
258 .callback = set_bf_sort,
259 .ident = "HP ProLiant BL30p G1",
261 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
262 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
266 .callback = set_bf_sort,
267 .ident = "HP ProLiant BL25p G1",
269 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
270 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
274 .callback = set_bf_sort,
275 .ident = "HP ProLiant BL35p G1",
277 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
278 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
282 .callback = set_bf_sort,
283 .ident = "HP ProLiant BL45p G1",
285 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
286 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
290 .callback = set_bf_sort,
291 .ident = "HP ProLiant BL45p G2",
293 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
294 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
298 .callback = set_bf_sort,
299 .ident = "HP ProLiant BL460c G1",
301 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
302 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
306 .callback = set_bf_sort,
307 .ident = "HP ProLiant BL465c G1",
309 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
310 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
314 .callback = set_bf_sort,
315 .ident = "HP ProLiant BL480c G1",
317 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
318 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
322 .callback = set_bf_sort,
323 .ident = "HP ProLiant BL685c G1",
325 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
326 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
330 .callback = set_bf_sort,
331 .ident = "HP ProLiant DL360",
333 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
334 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
338 .callback = set_bf_sort,
339 .ident = "HP ProLiant DL380",
341 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
342 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
347 .callback = assign_all_busses,
348 .ident = "Compaq EVO N800c",
350 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
351 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
356 .callback = set_bf_sort,
357 .ident = "HP ProLiant DL385 G2",
359 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
360 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
364 .callback = set_bf_sort,
365 .ident = "HP ProLiant DL585 G2",
367 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
368 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
374 void __init dmi_check_pciprobe(void)
376 dmi_check_system(pciprobe_dmi_table);
379 struct pci_bus * __devinit pcibios_scan_root(int busnum)
381 struct pci_bus *bus = NULL;
382 struct pci_sysdata *sd;
384 while ((bus = pci_find_next_bus(bus)) != NULL) {
385 if (bus->number == busnum) {
386 /* Already scanned */
391 /* Allocate per-root-bus (not per bus) arch-specific data.
392 * TODO: leak; this memory is never freed.
393 * It's arguable whether it's worth the trouble to care.
395 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
397 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
401 sd->node = get_mp_bus_to_node(busnum);
403 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
404 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
411 extern u8 pci_cache_line_size;
413 int __init pcibios_init(void)
415 struct cpuinfo_x86 *c = &boot_cpu_data;
418 printk(KERN_WARNING "PCI: System does not support PCI\n");
423 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
424 * and P4. It's also good for 386/486s (which actually have 16)
425 * as quite a few PCI devices do not support smaller values.
427 pci_cache_line_size = 32 >> 2;
428 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
429 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
430 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
431 pci_cache_line_size = 128 >> 2; /* P4 */
433 pcibios_resource_survey();
435 if (pci_bf_sort >= pci_force_bf)
436 pci_sort_breadthfirst();
440 char * __devinit pcibios_setup(char *str)
442 if (!strcmp(str, "off")) {
445 } else if (!strcmp(str, "bfsort")) {
446 pci_bf_sort = pci_force_bf;
448 } else if (!strcmp(str, "nobfsort")) {
449 pci_bf_sort = pci_force_nobf;
452 #ifdef CONFIG_PCI_BIOS
453 else if (!strcmp(str, "bios")) {
454 pci_probe = PCI_PROBE_BIOS;
456 } else if (!strcmp(str, "nobios")) {
457 pci_probe &= ~PCI_PROBE_BIOS;
459 } else if (!strcmp(str, "biosirq")) {
460 pci_probe |= PCI_BIOS_IRQ_SCAN;
462 } else if (!strncmp(str, "pirqaddr=", 9)) {
463 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
467 #ifdef CONFIG_PCI_DIRECT
468 else if (!strcmp(str, "conf1")) {
469 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
472 else if (!strcmp(str, "conf2")) {
473 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
477 #ifdef CONFIG_PCI_MMCONFIG
478 else if (!strcmp(str, "nommconf")) {
479 pci_probe &= ~PCI_PROBE_MMCONF;
482 else if (!strcmp(str, "check_enable_amd_mmconf")) {
483 pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
487 else if (!strcmp(str, "noacpi")) {
491 else if (!strcmp(str, "noearly")) {
492 pci_probe |= PCI_PROBE_NOEARLY;
495 #ifndef CONFIG_X86_VISWS
496 else if (!strcmp(str, "usepirqmask")) {
497 pci_probe |= PCI_USE_PIRQ_MASK;
499 } else if (!strncmp(str, "irqmask=", 8)) {
500 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
502 } else if (!strncmp(str, "lastbus=", 8)) {
503 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
507 else if (!strcmp(str, "rom")) {
508 pci_probe |= PCI_ASSIGN_ROMS;
510 } else if (!strcmp(str, "norom")) {
511 pci_probe |= PCI_NOASSIGN_ROMS;
513 } else if (!strcmp(str, "assign-busses")) {
514 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
516 } else if (!strcmp(str, "use_crs")) {
517 pci_probe |= PCI_USE__CRS;
519 } else if (!strcmp(str, "earlydump")) {
520 pci_early_dump_regs = 1;
522 } else if (!strcmp(str, "routeirq")) {
525 } else if (!strcmp(str, "skip_isa_align")) {
526 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
528 } else if (!strcmp(str, "noioapicquirk")) {
531 } else if (!strcmp(str, "ioapicreroute")) {
532 if (noioapicreroute != -1)
535 } else if (!strcmp(str, "noioapicreroute")) {
536 if (noioapicreroute != -1)
543 unsigned int pcibios_assign_all_busses(void)
545 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
548 int pcibios_enable_device(struct pci_dev *dev, int mask)
552 if ((err = pci_enable_resources(dev, mask)) < 0)
555 if (!dev->msi_enabled)
556 return pcibios_enable_irq(dev);
560 void pcibios_disable_device (struct pci_dev *dev)
562 if (!dev->msi_enabled && pcibios_disable_irq)
563 pcibios_disable_irq(dev);
566 struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
568 struct pci_bus *bus = NULL;
569 struct pci_sysdata *sd;
572 * Allocate per-root-bus (not per bus) arch-specific data.
573 * TODO: leak; this memory is never freed.
574 * It's arguable whether it's worth the trouble to care.
576 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
578 printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
582 bus = pci_scan_bus(busno, ops, sd);
589 struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno)
591 return pci_scan_bus_on_node(busno, &pci_root_ops, -1);