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(0, bus->number, devfn, where, size, value);
35 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
37 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
40 struct pci_ops pci_root_ops = {
46 * legacy, numa, and acpi all want to call pcibios_scan_root
47 * from their initcalls. This flag prevents that.
52 * This interrupt-safe spinlock protects all accesses to PCI
53 * configuration space.
55 DEFINE_SPINLOCK(pci_config_lock);
58 * Several buggy motherboards address only 16 devices and mirror
59 * them to next 16 IDs. We try to detect this `feature' on all
60 * primary buses (those containing host bridges as they are
61 * expected to be unique) and remove the ghost devices.
64 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
66 struct list_head *ln, *mn;
67 struct pci_dev *d, *e;
68 int mirror = PCI_DEVFN(16,0);
69 int seen_host_bridge = 0;
72 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
73 list_for_each(ln, &b->devices) {
75 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
77 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
79 if (e->devfn != d->devfn + mirror ||
80 e->vendor != d->vendor ||
81 e->device != d->device ||
84 for(i=0; i<PCI_NUM_RESOURCES; i++)
85 if (e->resource[i].start != d->resource[i].start ||
86 e->resource[i].end != d->resource[i].end ||
87 e->resource[i].flags != d->resource[i].flags)
91 if (mn == &b->devices)
94 if (!seen_host_bridge)
96 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
99 while (ln->next != &b->devices) {
100 d = pci_dev_b(ln->next);
101 if (d->devfn >= mirror) {
102 list_del(&d->global_list);
103 list_del(&d->bus_list);
111 * Called after each bus is probed, but before its children
115 void __devinit pcibios_fixup_bus(struct pci_bus *b)
117 pcibios_fixup_ghosts(b);
118 pci_read_bridge_bases(b);
122 * Only use DMI information to set this if nothing was passed
123 * on the kernel command line (which was parsed earlier).
126 static int __devinit set_bf_sort(const struct dmi_system_id *d)
128 if (pci_bf_sort == pci_bf_sort_default) {
129 pci_bf_sort = pci_dmi_bf;
130 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
136 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
139 static int __devinit assign_all_busses(const struct dmi_system_id *d)
141 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
142 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
143 " (pci=assign-busses)\n", d->ident);
148 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
151 * Laptops which need pci=assign-busses to see Cardbus cards
154 .callback = assign_all_busses,
155 .ident = "Samsung X20 Laptop",
157 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
158 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
161 #endif /* __i386__ */
163 .callback = set_bf_sort,
164 .ident = "Dell PowerEdge 1950",
166 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
167 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
171 .callback = set_bf_sort,
172 .ident = "Dell PowerEdge 1955",
174 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
175 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
179 .callback = set_bf_sort,
180 .ident = "Dell PowerEdge 2900",
182 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
183 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
187 .callback = set_bf_sort,
188 .ident = "Dell PowerEdge 2950",
190 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
191 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
195 .callback = set_bf_sort,
196 .ident = "Dell PowerEdge R900",
198 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
199 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
203 .callback = set_bf_sort,
204 .ident = "HP ProLiant BL20p G3",
206 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
207 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
211 .callback = set_bf_sort,
212 .ident = "HP ProLiant BL20p G4",
214 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
215 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
219 .callback = set_bf_sort,
220 .ident = "HP ProLiant BL30p G1",
222 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
223 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
227 .callback = set_bf_sort,
228 .ident = "HP ProLiant BL25p G1",
230 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
231 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
235 .callback = set_bf_sort,
236 .ident = "HP ProLiant BL35p G1",
238 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
239 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
243 .callback = set_bf_sort,
244 .ident = "HP ProLiant BL45p G1",
246 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
247 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
251 .callback = set_bf_sort,
252 .ident = "HP ProLiant BL45p G2",
254 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
255 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
259 .callback = set_bf_sort,
260 .ident = "HP ProLiant BL460c G1",
262 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
263 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
267 .callback = set_bf_sort,
268 .ident = "HP ProLiant BL465c G1",
270 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
271 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
275 .callback = set_bf_sort,
276 .ident = "HP ProLiant BL480c G1",
278 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
279 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
283 .callback = set_bf_sort,
284 .ident = "HP ProLiant BL685c G1",
286 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
287 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
293 struct pci_bus * __devinit pcibios_scan_root(int busnum)
295 struct pci_bus *bus = NULL;
296 struct pci_sysdata *sd;
298 dmi_check_system(pciprobe_dmi_table);
300 while ((bus = pci_find_next_bus(bus)) != NULL) {
301 if (bus->number == busnum) {
302 /* Already scanned */
307 /* Allocate per-root-bus (not per bus) arch-specific data.
308 * TODO: leak; this memory is never freed.
309 * It's arguable whether it's worth the trouble to care.
311 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
313 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
317 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
319 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
322 extern u8 pci_cache_line_size;
324 static int __init pcibios_init(void)
326 struct cpuinfo_x86 *c = &boot_cpu_data;
329 printk(KERN_WARNING "PCI: System does not support PCI\n");
334 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
335 * and P4. It's also good for 386/486s (which actually have 16)
336 * as quite a few PCI devices do not support smaller values.
338 pci_cache_line_size = 32 >> 2;
339 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
340 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
341 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
342 pci_cache_line_size = 128 >> 2; /* P4 */
344 pcibios_resource_survey();
346 if (pci_bf_sort >= pci_force_bf)
347 pci_sort_breadthfirst();
348 #ifdef CONFIG_PCI_BIOS
349 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
355 subsys_initcall(pcibios_init);
357 char * __devinit pcibios_setup(char *str)
359 if (!strcmp(str, "off")) {
362 } else if (!strcmp(str, "bfsort")) {
363 pci_bf_sort = pci_force_bf;
365 } else if (!strcmp(str, "nobfsort")) {
366 pci_bf_sort = pci_force_nobf;
369 #ifdef CONFIG_PCI_BIOS
370 else if (!strcmp(str, "bios")) {
371 pci_probe = PCI_PROBE_BIOS;
373 } else if (!strcmp(str, "nobios")) {
374 pci_probe &= ~PCI_PROBE_BIOS;
376 } else if (!strcmp(str, "nosort")) {
377 pci_probe |= PCI_NO_SORT;
379 } else if (!strcmp(str, "biosirq")) {
380 pci_probe |= PCI_BIOS_IRQ_SCAN;
382 } else if (!strncmp(str, "pirqaddr=", 9)) {
383 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
387 #ifdef CONFIG_PCI_DIRECT
388 else if (!strcmp(str, "conf1")) {
389 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
392 else if (!strcmp(str, "conf2")) {
393 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
397 #ifdef CONFIG_PCI_MMCONFIG
398 else if (!strcmp(str, "nommconf")) {
399 pci_probe &= ~PCI_PROBE_MMCONF;
403 else if (!strcmp(str, "noacpi")) {
407 else if (!strcmp(str, "noearly")) {
408 pci_probe |= PCI_PROBE_NOEARLY;
411 #ifndef CONFIG_X86_VISWS
412 else if (!strcmp(str, "usepirqmask")) {
413 pci_probe |= PCI_USE_PIRQ_MASK;
415 } else if (!strncmp(str, "irqmask=", 8)) {
416 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
418 } else if (!strncmp(str, "lastbus=", 8)) {
419 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
423 else if (!strcmp(str, "rom")) {
424 pci_probe |= PCI_ASSIGN_ROMS;
426 } else if (!strcmp(str, "assign-busses")) {
427 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
429 } else if (!strcmp(str, "routeirq")) {
436 unsigned int pcibios_assign_all_busses(void)
438 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
441 int pcibios_enable_device(struct pci_dev *dev, int mask)
445 if ((err = pcibios_enable_resources(dev, mask)) < 0)
448 if (!dev->msi_enabled)
449 return pcibios_enable_irq(dev);
453 void pcibios_disable_device (struct pci_dev *dev)
455 if (!dev->msi_enabled && pcibios_disable_irq)
456 pcibios_disable_irq(dev);
459 struct pci_bus *pci_scan_bus_with_sysdata(int busno)
461 struct pci_bus *bus = NULL;
462 struct pci_sysdata *sd;
465 * Allocate per-root-bus (not per bus) arch-specific data.
466 * TODO: leak; this memory is never freed.
467 * It's arguable whether it's worth the trouble to care.
469 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
471 printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
475 bus = pci_scan_bus(busno, &pci_root_ops, sd);