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 |
24 int pcibios_last_bus = -1;
25 unsigned long pirq_table_addr;
26 struct pci_bus *pci_root_bus;
27 struct pci_raw_ops *raw_pci_ops;
29 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
31 return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
34 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
36 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
39 struct pci_ops pci_root_ops = {
45 * legacy, numa, and acpi all want to call pcibios_scan_root
46 * from their initcalls. This flag prevents that.
51 * This interrupt-safe spinlock protects all accesses to PCI
52 * configuration space.
54 DEFINE_SPINLOCK(pci_config_lock);
57 * Several buggy motherboards address only 16 devices and mirror
58 * them to next 16 IDs. We try to detect this `feature' on all
59 * primary buses (those containing host bridges as they are
60 * expected to be unique) and remove the ghost devices.
63 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
65 struct list_head *ln, *mn;
66 struct pci_dev *d, *e;
67 int mirror = PCI_DEVFN(16,0);
68 int seen_host_bridge = 0;
71 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
72 list_for_each(ln, &b->devices) {
74 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
76 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
78 if (e->devfn != d->devfn + mirror ||
79 e->vendor != d->vendor ||
80 e->device != d->device ||
83 for(i=0; i<PCI_NUM_RESOURCES; i++)
84 if (e->resource[i].start != d->resource[i].start ||
85 e->resource[i].end != d->resource[i].end ||
86 e->resource[i].flags != d->resource[i].flags)
90 if (mn == &b->devices)
93 if (!seen_host_bridge)
95 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
98 while (ln->next != &b->devices) {
99 d = pci_dev_b(ln->next);
100 if (d->devfn >= mirror) {
101 list_del(&d->global_list);
102 list_del(&d->bus_list);
110 * Called after each bus is probed, but before its children
114 void __devinit pcibios_fixup_bus(struct pci_bus *b)
116 pcibios_fixup_ghosts(b);
117 pci_read_bridge_bases(b);
121 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
124 static int __devinit assign_all_busses(struct dmi_system_id *d)
126 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
127 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
128 " (pci=assign-busses)\n", d->ident);
134 * Laptops which need pci=assign-busses to see Cardbus cards
136 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
139 .callback = assign_all_busses,
140 .ident = "Samsung X20 Laptop",
142 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
143 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
146 #endif /* __i386__ */
150 struct pci_bus * __devinit pcibios_scan_root(int busnum)
152 struct pci_bus *bus = NULL;
154 dmi_check_system(pciprobe_dmi_table);
156 while ((bus = pci_find_next_bus(bus)) != NULL) {
157 if (bus->number == busnum) {
158 /* Already scanned */
163 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
165 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
168 extern u8 pci_cache_line_size;
170 static int __init pcibios_init(void)
172 struct cpuinfo_x86 *c = &boot_cpu_data;
175 printk(KERN_WARNING "PCI: System does not support PCI\n");
180 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
181 * and P4. It's also good for 386/486s (which actually have 16)
182 * as quite a few PCI devices do not support smaller values.
184 pci_cache_line_size = 32 >> 2;
185 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
186 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
187 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
188 pci_cache_line_size = 128 >> 2; /* P4 */
190 pcibios_resource_survey();
192 #ifdef CONFIG_PCI_BIOS
193 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
199 subsys_initcall(pcibios_init);
201 char * __devinit pcibios_setup(char *str)
203 if (!strcmp(str, "off")) {
207 #ifdef CONFIG_PCI_BIOS
208 else if (!strcmp(str, "bios")) {
209 pci_probe = PCI_PROBE_BIOS;
211 } else if (!strcmp(str, "nobios")) {
212 pci_probe &= ~PCI_PROBE_BIOS;
214 } else if (!strcmp(str, "nosort")) {
215 pci_probe |= PCI_NO_SORT;
217 } else if (!strcmp(str, "biosirq")) {
218 pci_probe |= PCI_BIOS_IRQ_SCAN;
220 } else if (!strncmp(str, "pirqaddr=", 9)) {
221 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
225 #ifdef CONFIG_PCI_DIRECT
226 else if (!strcmp(str, "conf1")) {
227 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
230 else if (!strcmp(str, "conf2")) {
231 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
235 #ifdef CONFIG_PCI_MMCONFIG
236 else if (!strcmp(str, "nommconf")) {
237 pci_probe &= ~PCI_PROBE_MMCONF;
240 /* override DMI blacklist */
241 else if (!strcmp(str, "mmconf")) {
242 pci_probe |= PCI_PROBE_MMCONF_FORCE;
246 else if (!strcmp(str, "noacpi")) {
250 #ifndef CONFIG_X86_VISWS
251 else if (!strcmp(str, "usepirqmask")) {
252 pci_probe |= PCI_USE_PIRQ_MASK;
254 } else if (!strncmp(str, "irqmask=", 8)) {
255 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
257 } else if (!strncmp(str, "lastbus=", 8)) {
258 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
262 else if (!strcmp(str, "rom")) {
263 pci_probe |= PCI_ASSIGN_ROMS;
265 } else if (!strcmp(str, "assign-busses")) {
266 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
268 } else if (!strcmp(str, "routeirq")) {
275 unsigned int pcibios_assign_all_busses(void)
277 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
280 int pcibios_enable_device(struct pci_dev *dev, int mask)
284 if ((err = pcibios_enable_resources(dev, mask)) < 0)
287 return pcibios_enable_irq(dev);
290 void pcibios_disable_device (struct pci_dev *dev)
292 pcibios_disable_resources(dev);
293 if (pcibios_disable_irq)
294 pcibios_disable_irq(dev);