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;
26 int noioapicreroute = 1;
27 int pcibios_last_bus = -1;
28 unsigned long pirq_table_addr;
29 struct pci_bus *pci_root_bus;
30 struct pci_raw_ops *raw_pci_ops;
31 struct pci_raw_ops *raw_pci_ext_ops;
33 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
34 int reg, int len, u32 *val)
36 if (reg < 256 && raw_pci_ops)
37 return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
39 return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
43 int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
44 int reg, int len, u32 val)
46 if (reg < 256 && raw_pci_ops)
47 return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
49 return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
53 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
55 return raw_pci_read(pci_domain_nr(bus), bus->number,
56 devfn, where, size, value);
59 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
61 return raw_pci_write(pci_domain_nr(bus), bus->number,
62 devfn, where, size, value);
65 struct pci_ops pci_root_ops = {
71 * legacy, numa, and acpi all want to call pcibios_scan_root
72 * from their initcalls. This flag prevents that.
77 * This interrupt-safe spinlock protects all accesses to PCI
78 * configuration space.
80 DEFINE_SPINLOCK(pci_config_lock);
82 static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
84 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
85 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
89 static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
91 * Systems where PCI IO resource ISA alignment can be skipped
92 * when the ISA enable bit in the bridge control is not set
95 .callback = can_skip_ioresource_align,
96 .ident = "IBM System x3800",
98 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
99 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
103 .callback = can_skip_ioresource_align,
104 .ident = "IBM System x3850",
106 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
107 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
111 .callback = can_skip_ioresource_align,
112 .ident = "IBM System x3950",
114 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
115 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
121 void __init dmi_check_skip_isa_align(void)
123 dmi_check_system(can_skip_pciprobe_dmi_table);
127 * Called after each bus is probed, but before its children
131 void __devinit pcibios_fixup_bus(struct pci_bus *b)
133 pci_read_bridge_bases(b);
137 * Only use DMI information to set this if nothing was passed
138 * on the kernel command line (which was parsed earlier).
141 static int __devinit set_bf_sort(const struct dmi_system_id *d)
143 if (pci_bf_sort == pci_bf_sort_default) {
144 pci_bf_sort = pci_dmi_bf;
145 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
151 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
154 static int __devinit assign_all_busses(const struct dmi_system_id *d)
156 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
157 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
158 " (pci=assign-busses)\n", d->ident);
163 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
166 * Laptops which need pci=assign-busses to see Cardbus cards
169 .callback = assign_all_busses,
170 .ident = "Samsung X20 Laptop",
172 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
173 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
176 #endif /* __i386__ */
178 .callback = set_bf_sort,
179 .ident = "Dell PowerEdge 1950",
181 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
182 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
186 .callback = set_bf_sort,
187 .ident = "Dell PowerEdge 1955",
189 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
190 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
194 .callback = set_bf_sort,
195 .ident = "Dell PowerEdge 2900",
197 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
198 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
202 .callback = set_bf_sort,
203 .ident = "Dell PowerEdge 2950",
205 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
206 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
210 .callback = set_bf_sort,
211 .ident = "Dell PowerEdge R900",
213 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
214 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
218 .callback = set_bf_sort,
219 .ident = "HP ProLiant BL20p G3",
221 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
222 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
226 .callback = set_bf_sort,
227 .ident = "HP ProLiant BL20p G4",
229 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
230 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
234 .callback = set_bf_sort,
235 .ident = "HP ProLiant BL30p G1",
237 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
238 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
242 .callback = set_bf_sort,
243 .ident = "HP ProLiant BL25p G1",
245 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
246 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
250 .callback = set_bf_sort,
251 .ident = "HP ProLiant BL35p G1",
253 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
254 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
258 .callback = set_bf_sort,
259 .ident = "HP ProLiant BL45p G1",
261 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
262 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
266 .callback = set_bf_sort,
267 .ident = "HP ProLiant BL45p G2",
269 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
270 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
274 .callback = set_bf_sort,
275 .ident = "HP ProLiant BL460c G1",
277 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
278 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
282 .callback = set_bf_sort,
283 .ident = "HP ProLiant BL465c G1",
285 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
286 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
290 .callback = set_bf_sort,
291 .ident = "HP ProLiant BL480c G1",
293 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
294 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
298 .callback = set_bf_sort,
299 .ident = "HP ProLiant BL685c G1",
301 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
302 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
306 .callback = set_bf_sort,
307 .ident = "HP ProLiant DL360",
309 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
310 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
314 .callback = set_bf_sort,
315 .ident = "HP ProLiant DL380",
317 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
318 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
323 .callback = assign_all_busses,
324 .ident = "Compaq EVO N800c",
326 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
327 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
332 .callback = set_bf_sort,
333 .ident = "HP ProLiant DL385 G2",
335 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
336 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
340 .callback = set_bf_sort,
341 .ident = "HP ProLiant DL585 G2",
343 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
344 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
350 void __init dmi_check_pciprobe(void)
352 dmi_check_system(pciprobe_dmi_table);
355 struct pci_bus * __devinit pcibios_scan_root(int busnum)
357 struct pci_bus *bus = NULL;
358 struct pci_sysdata *sd;
360 while ((bus = pci_find_next_bus(bus)) != NULL) {
361 if (bus->number == busnum) {
362 /* Already scanned */
367 /* Allocate per-root-bus (not per bus) arch-specific data.
368 * TODO: leak; this memory is never freed.
369 * It's arguable whether it's worth the trouble to care.
371 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
373 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
377 sd->node = get_mp_bus_to_node(busnum);
379 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
380 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
387 extern u8 pci_cache_line_size;
389 static int __init pcibios_init(void)
391 struct cpuinfo_x86 *c = &boot_cpu_data;
394 printk(KERN_WARNING "PCI: System does not support PCI\n");
399 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
400 * and P4. It's also good for 386/486s (which actually have 16)
401 * as quite a few PCI devices do not support smaller values.
403 pci_cache_line_size = 32 >> 2;
404 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
405 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
406 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
407 pci_cache_line_size = 128 >> 2; /* P4 */
409 pcibios_resource_survey();
411 if (pci_bf_sort >= pci_force_bf)
412 pci_sort_breadthfirst();
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, "biosirq")) {
438 pci_probe |= PCI_BIOS_IRQ_SCAN;
440 } else if (!strncmp(str, "pirqaddr=", 9)) {
441 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
445 #ifdef CONFIG_PCI_DIRECT
446 else if (!strcmp(str, "conf1")) {
447 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
450 else if (!strcmp(str, "conf2")) {
451 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
455 #ifdef CONFIG_PCI_MMCONFIG
456 else if (!strcmp(str, "nommconf")) {
457 pci_probe &= ~PCI_PROBE_MMCONF;
460 else if (!strcmp(str, "check_enable_amd_mmconf")) {
461 pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
465 else if (!strcmp(str, "noacpi")) {
469 else if (!strcmp(str, "noearly")) {
470 pci_probe |= PCI_PROBE_NOEARLY;
473 #ifndef CONFIG_X86_VISWS
474 else if (!strcmp(str, "usepirqmask")) {
475 pci_probe |= PCI_USE_PIRQ_MASK;
477 } else if (!strncmp(str, "irqmask=", 8)) {
478 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
480 } else if (!strncmp(str, "lastbus=", 8)) {
481 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
485 else if (!strcmp(str, "rom")) {
486 pci_probe |= PCI_ASSIGN_ROMS;
488 } else if (!strcmp(str, "assign-busses")) {
489 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
491 } else if (!strcmp(str, "use_crs")) {
492 pci_probe |= PCI_USE__CRS;
494 } else if (!strcmp(str, "routeirq")) {
497 } else if (!strcmp(str, "skip_isa_align")) {
498 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
500 } else if (!strcmp(str, "noioapicquirk")) {
503 } else if (!strcmp(str, "ioapicreroute")) {
504 if (noioapicreroute != -1)
511 unsigned int pcibios_assign_all_busses(void)
513 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
516 int pcibios_enable_device(struct pci_dev *dev, int mask)
520 if ((err = pci_enable_resources(dev, mask)) < 0)
523 if (!dev->msi_enabled)
524 return pcibios_enable_irq(dev);
528 void pcibios_disable_device (struct pci_dev *dev)
530 if (!dev->msi_enabled && pcibios_disable_irq)
531 pcibios_disable_irq(dev);
534 struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
536 struct pci_bus *bus = NULL;
537 struct pci_sysdata *sd;
540 * Allocate per-root-bus (not per bus) arch-specific data.
541 * TODO: leak; this memory is never freed.
542 * It's arguable whether it's worth the trouble to care.
544 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
546 printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
550 bus = pci_scan_bus(busno, ops, sd);
557 struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno)
559 return pci_scan_bus_on_node(busno, &pci_root_ops, -1);