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;
29 struct pci_raw_ops *raw_pci_ext_ops;
31 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
32 int reg, int len, u32 *val)
34 if (reg < 256 && raw_pci_ops)
35 return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
37 return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
41 int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
42 int reg, int len, u32 val)
44 if (reg < 256 && raw_pci_ops)
45 return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
47 return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
51 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
53 return raw_pci_read(pci_domain_nr(bus), bus->number,
54 devfn, where, size, value);
57 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
59 return raw_pci_write(pci_domain_nr(bus), bus->number,
60 devfn, where, size, value);
63 struct pci_ops pci_root_ops = {
69 * legacy, numa, and acpi all want to call pcibios_scan_root
70 * from their initcalls. This flag prevents that.
75 * This interrupt-safe spinlock protects all accesses to PCI
76 * configuration space.
78 DEFINE_SPINLOCK(pci_config_lock);
80 static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
82 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
83 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
87 static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
89 * Systems where PCI IO resource ISA alignment can be skipped
90 * when the ISA enable bit in the bridge control is not set
93 .callback = can_skip_ioresource_align,
94 .ident = "IBM System x3800",
96 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
97 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
101 .callback = can_skip_ioresource_align,
102 .ident = "IBM System x3850",
104 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
105 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
109 .callback = can_skip_ioresource_align,
110 .ident = "IBM System x3950",
112 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
113 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
119 void __init dmi_check_skip_isa_align(void)
121 dmi_check_system(can_skip_pciprobe_dmi_table);
125 * Called after each bus is probed, but before its children
129 void __devinit pcibios_fixup_bus(struct pci_bus *b)
131 pci_read_bridge_bases(b);
135 * Only use DMI information to set this if nothing was passed
136 * on the kernel command line (which was parsed earlier).
139 static int __devinit set_bf_sort(const struct dmi_system_id *d)
141 if (pci_bf_sort == pci_bf_sort_default) {
142 pci_bf_sort = pci_dmi_bf;
143 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
149 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
152 static int __devinit assign_all_busses(const struct dmi_system_id *d)
154 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
155 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
156 " (pci=assign-busses)\n", d->ident);
161 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
164 * Laptops which need pci=assign-busses to see Cardbus cards
167 .callback = assign_all_busses,
168 .ident = "Samsung X20 Laptop",
170 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
171 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
174 #endif /* __i386__ */
176 .callback = set_bf_sort,
177 .ident = "Dell PowerEdge 1950",
179 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
180 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
184 .callback = set_bf_sort,
185 .ident = "Dell PowerEdge 1955",
187 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
188 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
192 .callback = set_bf_sort,
193 .ident = "Dell PowerEdge 2900",
195 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
196 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
200 .callback = set_bf_sort,
201 .ident = "Dell PowerEdge 2950",
203 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
204 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
208 .callback = set_bf_sort,
209 .ident = "Dell PowerEdge R900",
211 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
212 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
216 .callback = set_bf_sort,
217 .ident = "HP ProLiant BL20p G3",
219 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
220 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
224 .callback = set_bf_sort,
225 .ident = "HP ProLiant BL20p G4",
227 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
228 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
232 .callback = set_bf_sort,
233 .ident = "HP ProLiant BL30p G1",
235 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
236 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
240 .callback = set_bf_sort,
241 .ident = "HP ProLiant BL25p G1",
243 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
244 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
248 .callback = set_bf_sort,
249 .ident = "HP ProLiant BL35p G1",
251 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
252 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
256 .callback = set_bf_sort,
257 .ident = "HP ProLiant BL45p G1",
259 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
260 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
264 .callback = set_bf_sort,
265 .ident = "HP ProLiant BL45p G2",
267 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
268 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
272 .callback = set_bf_sort,
273 .ident = "HP ProLiant BL460c G1",
275 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
276 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
280 .callback = set_bf_sort,
281 .ident = "HP ProLiant BL465c G1",
283 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
284 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
288 .callback = set_bf_sort,
289 .ident = "HP ProLiant BL480c G1",
291 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
292 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
296 .callback = set_bf_sort,
297 .ident = "HP ProLiant BL685c G1",
299 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
300 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
304 .callback = set_bf_sort,
305 .ident = "HP ProLiant DL360",
307 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
308 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
312 .callback = set_bf_sort,
313 .ident = "HP ProLiant DL380",
315 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
316 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
321 .callback = assign_all_busses,
322 .ident = "Compaq EVO N800c",
324 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
325 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
330 .callback = set_bf_sort,
331 .ident = "HP ProLiant DL385 G2",
333 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
334 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
338 .callback = set_bf_sort,
339 .ident = "HP ProLiant DL585 G2",
341 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
342 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
348 void __init dmi_check_pciprobe(void)
350 dmi_check_system(pciprobe_dmi_table);
353 struct pci_bus * __devinit pcibios_scan_root(int busnum)
355 struct pci_bus *bus = NULL;
356 struct pci_sysdata *sd;
358 while ((bus = pci_find_next_bus(bus)) != NULL) {
359 if (bus->number == busnum) {
360 /* Already scanned */
365 /* Allocate per-root-bus (not per bus) arch-specific data.
366 * TODO: leak; this memory is never freed.
367 * It's arguable whether it's worth the trouble to care.
369 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
371 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
375 sd->node = get_mp_bus_to_node(busnum);
377 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
378 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
385 extern u8 pci_cache_line_size;
387 int __init pcibios_init(void)
389 struct cpuinfo_x86 *c = &boot_cpu_data;
392 printk(KERN_WARNING "PCI: System does not support PCI\n");
397 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
398 * and P4. It's also good for 386/486s (which actually have 16)
399 * as quite a few PCI devices do not support smaller values.
401 pci_cache_line_size = 32 >> 2;
402 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
403 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
404 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
405 pci_cache_line_size = 128 >> 2; /* P4 */
407 pcibios_resource_survey();
409 if (pci_bf_sort >= pci_force_bf)
410 pci_sort_breadthfirst();
414 char * __devinit pcibios_setup(char *str)
416 if (!strcmp(str, "off")) {
419 } else if (!strcmp(str, "bfsort")) {
420 pci_bf_sort = pci_force_bf;
422 } else if (!strcmp(str, "nobfsort")) {
423 pci_bf_sort = pci_force_nobf;
426 #ifdef CONFIG_PCI_BIOS
427 else if (!strcmp(str, "bios")) {
428 pci_probe = PCI_PROBE_BIOS;
430 } else if (!strcmp(str, "nobios")) {
431 pci_probe &= ~PCI_PROBE_BIOS;
433 } else if (!strcmp(str, "biosirq")) {
434 pci_probe |= PCI_BIOS_IRQ_SCAN;
436 } else if (!strncmp(str, "pirqaddr=", 9)) {
437 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
441 #ifdef CONFIG_PCI_DIRECT
442 else if (!strcmp(str, "conf1")) {
443 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
446 else if (!strcmp(str, "conf2")) {
447 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
451 #ifdef CONFIG_PCI_MMCONFIG
452 else if (!strcmp(str, "nommconf")) {
453 pci_probe &= ~PCI_PROBE_MMCONF;
456 else if (!strcmp(str, "check_enable_amd_mmconf")) {
457 pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
461 else if (!strcmp(str, "noacpi")) {
465 else if (!strcmp(str, "noearly")) {
466 pci_probe |= PCI_PROBE_NOEARLY;
469 #ifndef CONFIG_X86_VISWS
470 else if (!strcmp(str, "usepirqmask")) {
471 pci_probe |= PCI_USE_PIRQ_MASK;
473 } else if (!strncmp(str, "irqmask=", 8)) {
474 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
476 } else if (!strncmp(str, "lastbus=", 8)) {
477 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
481 else if (!strcmp(str, "rom")) {
482 pci_probe |= PCI_ASSIGN_ROMS;
484 } else if (!strcmp(str, "assign-busses")) {
485 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
487 } else if (!strcmp(str, "use_crs")) {
488 pci_probe |= PCI_USE__CRS;
490 } else if (!strcmp(str, "routeirq")) {
493 } else if (!strcmp(str, "skip_isa_align")) {
494 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
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 = pci_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 * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
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, ops, sd);
546 struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno)
548 return pci_scan_bus_on_node(busno, &pci_root_ops, -1);