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;
26 int pcibios_last_bus = -1;
27 unsigned long pirq_table_addr;
28 struct pci_bus *pci_root_bus;
29 struct pci_raw_ops *raw_pci_ops;
30 struct pci_raw_ops *raw_pci_ext_ops;
32 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
33 int reg, int len, u32 *val)
35 if (domain == 0 && reg < 256 && raw_pci_ops)
36 return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
38 return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
42 int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
43 int reg, int len, u32 val)
45 if (domain == 0 && reg < 256 && raw_pci_ops)
46 return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
48 return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
52 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
54 return raw_pci_read(pci_domain_nr(bus), bus->number,
55 devfn, where, size, value);
58 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
60 return raw_pci_write(pci_domain_nr(bus), bus->number,
61 devfn, where, size, value);
64 struct pci_ops pci_root_ops = {
70 * legacy, numa, and acpi all want to call pcibios_scan_root
71 * from their initcalls. This flag prevents that.
76 * This interrupt-safe spinlock protects all accesses to PCI
77 * configuration space.
79 DEFINE_SPINLOCK(pci_config_lock);
81 static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
83 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
84 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
88 static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
90 * Systems where PCI IO resource ISA alignment can be skipped
91 * when the ISA enable bit in the bridge control is not set
94 .callback = can_skip_ioresource_align,
95 .ident = "IBM System x3800",
97 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
98 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
102 .callback = can_skip_ioresource_align,
103 .ident = "IBM System x3850",
105 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
106 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
110 .callback = can_skip_ioresource_align,
111 .ident = "IBM System x3950",
113 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
114 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
120 void __init dmi_check_skip_isa_align(void)
122 dmi_check_system(can_skip_pciprobe_dmi_table);
125 static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
127 struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
129 if (pci_probe & PCI_NOASSIGN_ROMS) {
133 /* we deal with BIOS assigned ROM later */
136 rom_r->start = rom_r->end = rom_r->flags = 0;
141 * Called after each bus is probed, but before its children
145 void __devinit pcibios_fixup_bus(struct pci_bus *b)
149 pci_read_bridge_bases(b);
150 list_for_each_entry(dev, &b->devices, bus_list)
151 pcibios_fixup_device_resources(dev);
155 * Only use DMI information to set this if nothing was passed
156 * on the kernel command line (which was parsed earlier).
159 static int __devinit set_bf_sort(const struct dmi_system_id *d)
161 if (pci_bf_sort == pci_bf_sort_default) {
162 pci_bf_sort = pci_dmi_bf;
163 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
169 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
172 static int __devinit assign_all_busses(const struct dmi_system_id *d)
174 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
175 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
176 " (pci=assign-busses)\n", d->ident);
181 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
184 * Laptops which need pci=assign-busses to see Cardbus cards
187 .callback = assign_all_busses,
188 .ident = "Samsung X20 Laptop",
190 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
191 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
194 #endif /* __i386__ */
196 .callback = set_bf_sort,
197 .ident = "Dell PowerEdge 1950",
199 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
200 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
204 .callback = set_bf_sort,
205 .ident = "Dell PowerEdge 1955",
207 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
208 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
212 .callback = set_bf_sort,
213 .ident = "Dell PowerEdge 2900",
215 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
216 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
220 .callback = set_bf_sort,
221 .ident = "Dell PowerEdge 2950",
223 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
224 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
228 .callback = set_bf_sort,
229 .ident = "Dell PowerEdge R900",
231 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
232 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
236 .callback = set_bf_sort,
237 .ident = "HP ProLiant BL20p G3",
239 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
240 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
244 .callback = set_bf_sort,
245 .ident = "HP ProLiant BL20p G4",
247 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
248 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
252 .callback = set_bf_sort,
253 .ident = "HP ProLiant BL30p G1",
255 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
256 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
260 .callback = set_bf_sort,
261 .ident = "HP ProLiant BL25p G1",
263 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
264 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
268 .callback = set_bf_sort,
269 .ident = "HP ProLiant BL35p G1",
271 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
272 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
276 .callback = set_bf_sort,
277 .ident = "HP ProLiant BL45p G1",
279 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
280 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
284 .callback = set_bf_sort,
285 .ident = "HP ProLiant BL45p G2",
287 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
288 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
292 .callback = set_bf_sort,
293 .ident = "HP ProLiant BL460c G1",
295 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
296 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
300 .callback = set_bf_sort,
301 .ident = "HP ProLiant BL465c G1",
303 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
304 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
308 .callback = set_bf_sort,
309 .ident = "HP ProLiant BL480c G1",
311 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
312 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
316 .callback = set_bf_sort,
317 .ident = "HP ProLiant BL685c G1",
319 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
320 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
324 .callback = set_bf_sort,
325 .ident = "HP ProLiant DL360",
327 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
328 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
332 .callback = set_bf_sort,
333 .ident = "HP ProLiant DL380",
335 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
336 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
341 .callback = assign_all_busses,
342 .ident = "Compaq EVO N800c",
344 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
345 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
350 .callback = set_bf_sort,
351 .ident = "HP ProLiant DL385 G2",
353 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
354 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
358 .callback = set_bf_sort,
359 .ident = "HP ProLiant DL585 G2",
361 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
362 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
368 void __init dmi_check_pciprobe(void)
370 dmi_check_system(pciprobe_dmi_table);
373 struct pci_bus * __devinit pcibios_scan_root(int busnum)
375 struct pci_bus *bus = NULL;
376 struct pci_sysdata *sd;
378 while ((bus = pci_find_next_bus(bus)) != NULL) {
379 if (bus->number == busnum) {
380 /* Already scanned */
385 /* Allocate per-root-bus (not per bus) arch-specific data.
386 * TODO: leak; this memory is never freed.
387 * It's arguable whether it's worth the trouble to care.
389 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
391 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
395 sd->node = get_mp_bus_to_node(busnum);
397 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
398 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
405 extern u8 pci_cache_line_size;
407 static int __init pcibios_init(void)
409 struct cpuinfo_x86 *c = &boot_cpu_data;
412 printk(KERN_WARNING "PCI: System does not support PCI\n");
417 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
418 * and P4. It's also good for 386/486s (which actually have 16)
419 * as quite a few PCI devices do not support smaller values.
421 pci_cache_line_size = 32 >> 2;
422 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
423 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
424 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
425 pci_cache_line_size = 128 >> 2; /* P4 */
427 pcibios_resource_survey();
429 if (pci_bf_sort >= pci_force_bf)
430 pci_sort_breadthfirst();
434 subsys_initcall(pcibios_init);
436 char * __devinit pcibios_setup(char *str)
438 if (!strcmp(str, "off")) {
441 } else if (!strcmp(str, "bfsort")) {
442 pci_bf_sort = pci_force_bf;
444 } else if (!strcmp(str, "nobfsort")) {
445 pci_bf_sort = pci_force_nobf;
448 #ifdef CONFIG_PCI_BIOS
449 else if (!strcmp(str, "bios")) {
450 pci_probe = PCI_PROBE_BIOS;
452 } else if (!strcmp(str, "nobios")) {
453 pci_probe &= ~PCI_PROBE_BIOS;
455 } else if (!strcmp(str, "biosirq")) {
456 pci_probe |= PCI_BIOS_IRQ_SCAN;
458 } else if (!strncmp(str, "pirqaddr=", 9)) {
459 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
463 #ifdef CONFIG_PCI_DIRECT
464 else if (!strcmp(str, "conf1")) {
465 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
468 else if (!strcmp(str, "conf2")) {
469 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
473 #ifdef CONFIG_PCI_MMCONFIG
474 else if (!strcmp(str, "nommconf")) {
475 pci_probe &= ~PCI_PROBE_MMCONF;
478 else if (!strcmp(str, "check_enable_amd_mmconf")) {
479 pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
483 else if (!strcmp(str, "noacpi")) {
487 else if (!strcmp(str, "noearly")) {
488 pci_probe |= PCI_PROBE_NOEARLY;
491 #ifndef CONFIG_X86_VISWS
492 else if (!strcmp(str, "usepirqmask")) {
493 pci_probe |= PCI_USE_PIRQ_MASK;
495 } else if (!strncmp(str, "irqmask=", 8)) {
496 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
498 } else if (!strncmp(str, "lastbus=", 8)) {
499 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
503 else if (!strcmp(str, "rom")) {
504 pci_probe |= PCI_ASSIGN_ROMS;
506 } else if (!strcmp(str, "norom")) {
507 pci_probe |= PCI_NOASSIGN_ROMS;
509 } else if (!strcmp(str, "assign-busses")) {
510 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
512 } else if (!strcmp(str, "use_crs")) {
513 pci_probe |= PCI_USE__CRS;
515 } else if (!strcmp(str, "earlydump")) {
516 pci_early_dump_regs = 1;
518 } else if (!strcmp(str, "routeirq")) {
521 } else if (!strcmp(str, "skip_isa_align")) {
522 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
528 unsigned int pcibios_assign_all_busses(void)
530 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
533 int pcibios_enable_device(struct pci_dev *dev, int mask)
537 if ((err = pci_enable_resources(dev, mask)) < 0)
540 if (!dev->msi_enabled)
541 return pcibios_enable_irq(dev);
545 void pcibios_disable_device (struct pci_dev *dev)
547 if (!dev->msi_enabled && pcibios_disable_irq)
548 pcibios_disable_irq(dev);
551 struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
553 struct pci_bus *bus = NULL;
554 struct pci_sysdata *sd;
557 * Allocate per-root-bus (not per bus) arch-specific data.
558 * TODO: leak; this memory is never freed.
559 * It's arguable whether it's worth the trouble to care.
561 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
563 printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
567 bus = pci_scan_bus(busno, ops, sd);
574 struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno)
576 return pci_scan_bus_on_node(busno, &pci_root_ops, -1);