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>
13 #include <asm/segment.h>
19 #ifdef CONFIG_PCI_BIOS
20 extern void pcibios_sort(void);
23 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
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;
32 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
34 return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
37 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
39 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
42 struct pci_ops pci_root_ops = {
48 * legacy, numa, and acpi all want to call pcibios_scan_root
49 * from their initcalls. This flag prevents that.
54 * This interrupt-safe spinlock protects all accesses to PCI
55 * configuration space.
57 DEFINE_SPINLOCK(pci_config_lock);
60 * Several buggy motherboards address only 16 devices and mirror
61 * them to next 16 IDs. We try to detect this `feature' on all
62 * primary buses (those containing host bridges as they are
63 * expected to be unique) and remove the ghost devices.
66 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
68 struct list_head *ln, *mn;
69 struct pci_dev *d, *e;
70 int mirror = PCI_DEVFN(16,0);
71 int seen_host_bridge = 0;
74 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
75 list_for_each(ln, &b->devices) {
77 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
79 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
81 if (e->devfn != d->devfn + mirror ||
82 e->vendor != d->vendor ||
83 e->device != d->device ||
86 for(i=0; i<PCI_NUM_RESOURCES; i++)
87 if (e->resource[i].start != d->resource[i].start ||
88 e->resource[i].end != d->resource[i].end ||
89 e->resource[i].flags != d->resource[i].flags)
93 if (mn == &b->devices)
96 if (!seen_host_bridge)
98 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
101 while (ln->next != &b->devices) {
102 d = pci_dev_b(ln->next);
103 if (d->devfn >= mirror) {
104 list_del(&d->global_list);
105 list_del(&d->bus_list);
113 * Called after each bus is probed, but before its children
117 void __devinit pcibios_fixup_bus(struct pci_bus *b)
119 pcibios_fixup_ghosts(b);
120 pci_read_bridge_bases(b);
124 struct pci_bus * __devinit pcibios_scan_root(int busnum)
126 struct pci_bus *bus = NULL;
128 while ((bus = pci_find_next_bus(bus)) != NULL) {
129 if (bus->number == busnum) {
130 /* Already scanned */
135 printk("PCI: Probing PCI hardware (bus %02x)\n", busnum);
137 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
140 extern u8 pci_cache_line_size;
142 static int __init pcibios_init(void)
144 struct cpuinfo_x86 *c = &boot_cpu_data;
147 printk("PCI: System does not support PCI\n");
152 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
153 * and P4. It's also good for 386/486s (which actually have 16)
154 * as quite a few PCI devices do not support smaller values.
156 pci_cache_line_size = 32 >> 2;
157 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
158 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
159 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
160 pci_cache_line_size = 128 >> 2; /* P4 */
162 pcibios_resource_survey();
164 #ifdef CONFIG_PCI_BIOS
165 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
168 pci_assign_unassigned_resources();
172 subsys_initcall(pcibios_init);
174 char * __devinit pcibios_setup(char *str)
176 if (!strcmp(str, "off")) {
180 #ifdef CONFIG_PCI_BIOS
181 else if (!strcmp(str, "bios")) {
182 pci_probe = PCI_PROBE_BIOS;
184 } else if (!strcmp(str, "nobios")) {
185 pci_probe &= ~PCI_PROBE_BIOS;
187 } else if (!strcmp(str, "nosort")) {
188 pci_probe |= PCI_NO_SORT;
190 } else if (!strcmp(str, "biosirq")) {
191 pci_probe |= PCI_BIOS_IRQ_SCAN;
193 } else if (!strncmp(str, "pirqaddr=", 9)) {
194 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
198 #ifdef CONFIG_PCI_DIRECT
199 else if (!strcmp(str, "conf1")) {
200 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
203 else if (!strcmp(str, "conf2")) {
204 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
208 #ifdef CONFIG_PCI_MMCONFIG
209 else if (!strcmp(str, "nommconf")) {
210 pci_probe &= ~PCI_PROBE_MMCONF;
214 else if (!strcmp(str, "noacpi")) {
218 #ifndef CONFIG_X86_VISWS
219 else if (!strcmp(str, "usepirqmask")) {
220 pci_probe |= PCI_USE_PIRQ_MASK;
222 } else if (!strncmp(str, "irqmask=", 8)) {
223 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
225 } else if (!strncmp(str, "lastbus=", 8)) {
226 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
230 else if (!strcmp(str, "rom")) {
231 pci_probe |= PCI_ASSIGN_ROMS;
233 } else if (!strcmp(str, "assign-busses")) {
234 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
236 } else if (!strcmp(str, "routeirq")) {
243 unsigned int pcibios_assign_all_busses(void)
245 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
248 int pcibios_enable_device(struct pci_dev *dev, int mask)
252 if ((err = pcibios_enable_resources(dev, mask)) < 0)
255 return pcibios_enable_irq(dev);
258 void pcibios_disable_device (struct pci_dev *dev)
260 if (pcibios_disable_irq)
261 pcibios_disable_irq(dev);