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 #ifdef CONFIG_PCI_BIOS
21 extern void pcibios_sort(void);
24 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
28 int pcibios_last_bus = -1;
29 unsigned long pirq_table_addr;
30 struct pci_bus *pci_root_bus;
31 struct pci_raw_ops *raw_pci_ops;
33 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
35 return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
38 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
40 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
43 struct pci_ops pci_root_ops = {
49 * legacy, numa, and acpi all want to call pcibios_scan_root
50 * from their initcalls. This flag prevents that.
55 * This interrupt-safe spinlock protects all accesses to PCI
56 * configuration space.
58 DEFINE_SPINLOCK(pci_config_lock);
61 * Several buggy motherboards address only 16 devices and mirror
62 * them to next 16 IDs. We try to detect this `feature' on all
63 * primary buses (those containing host bridges as they are
64 * expected to be unique) and remove the ghost devices.
67 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
69 struct list_head *ln, *mn;
70 struct pci_dev *d, *e;
71 int mirror = PCI_DEVFN(16,0);
72 int seen_host_bridge = 0;
75 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
76 list_for_each(ln, &b->devices) {
78 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
80 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
82 if (e->devfn != d->devfn + mirror ||
83 e->vendor != d->vendor ||
84 e->device != d->device ||
87 for(i=0; i<PCI_NUM_RESOURCES; i++)
88 if (e->resource[i].start != d->resource[i].start ||
89 e->resource[i].end != d->resource[i].end ||
90 e->resource[i].flags != d->resource[i].flags)
94 if (mn == &b->devices)
97 if (!seen_host_bridge)
99 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
102 while (ln->next != &b->devices) {
103 d = pci_dev_b(ln->next);
104 if (d->devfn >= mirror) {
105 list_del(&d->global_list);
106 list_del(&d->bus_list);
114 * Called after each bus is probed, but before its children
118 void __devinit pcibios_fixup_bus(struct pci_bus *b)
120 pcibios_fixup_ghosts(b);
121 pci_read_bridge_bases(b);
125 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
128 static int __devinit assign_all_busses(struct dmi_system_id *d)
130 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
131 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
132 " (pci=assign-busses)\n", d->ident);
138 * Laptops which need pci=assign-busses to see Cardbus cards
140 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
143 .callback = assign_all_busses,
144 .ident = "Samsung X20 Laptop",
146 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
147 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
150 #endif /* __i386__ */
154 struct pci_bus * __devinit pcibios_scan_root(int busnum)
156 struct pci_bus *bus = NULL;
158 dmi_check_system(pciprobe_dmi_table);
160 while ((bus = pci_find_next_bus(bus)) != NULL) {
161 if (bus->number == busnum) {
162 /* Already scanned */
167 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
169 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
172 extern u8 pci_cache_line_size;
174 static int __init pcibios_init(void)
176 struct cpuinfo_x86 *c = &boot_cpu_data;
179 printk(KERN_WARNING "PCI: System does not support PCI\n");
184 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
185 * and P4. It's also good for 386/486s (which actually have 16)
186 * as quite a few PCI devices do not support smaller values.
188 pci_cache_line_size = 32 >> 2;
189 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
190 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
191 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
192 pci_cache_line_size = 128 >> 2; /* P4 */
194 pcibios_resource_survey();
196 #ifdef CONFIG_PCI_BIOS
197 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
203 subsys_initcall(pcibios_init);
205 char * __devinit pcibios_setup(char *str)
207 if (!strcmp(str, "off")) {
211 #ifdef CONFIG_PCI_BIOS
212 else if (!strcmp(str, "bios")) {
213 pci_probe = PCI_PROBE_BIOS;
215 } else if (!strcmp(str, "nobios")) {
216 pci_probe &= ~PCI_PROBE_BIOS;
218 } else if (!strcmp(str, "nosort")) {
219 pci_probe |= PCI_NO_SORT;
221 } else if (!strcmp(str, "biosirq")) {
222 pci_probe |= PCI_BIOS_IRQ_SCAN;
224 } else if (!strncmp(str, "pirqaddr=", 9)) {
225 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
229 #ifdef CONFIG_PCI_DIRECT
230 else if (!strcmp(str, "conf1")) {
231 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
234 else if (!strcmp(str, "conf2")) {
235 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
239 #ifdef CONFIG_PCI_MMCONFIG
240 else if (!strcmp(str, "nommconf")) {
241 pci_probe &= ~PCI_PROBE_MMCONF;
245 else if (!strcmp(str, "noacpi")) {
249 #ifndef CONFIG_X86_VISWS
250 else if (!strcmp(str, "usepirqmask")) {
251 pci_probe |= PCI_USE_PIRQ_MASK;
253 } else if (!strncmp(str, "irqmask=", 8)) {
254 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
256 } else if (!strncmp(str, "lastbus=", 8)) {
257 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
261 else if (!strcmp(str, "rom")) {
262 pci_probe |= PCI_ASSIGN_ROMS;
264 } else if (!strcmp(str, "assign-busses")) {
265 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
267 } else if (!strcmp(str, "routeirq")) {
274 unsigned int pcibios_assign_all_busses(void)
276 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
279 int pcibios_enable_device(struct pci_dev *dev, int mask)
283 if ((err = pcibios_enable_resources(dev, mask)) < 0)
286 return pcibios_enable_irq(dev);
289 void pcibios_disable_device (struct pci_dev *dev)
291 pcibios_disable_resources(dev);
292 if (pcibios_disable_irq)
293 pcibios_disable_irq(dev);