[PATCH] x86: Move direct PCI scanning functions out of line
[deliverable/linux.git] / arch / i386 / pci / common.c
CommitLineData
1da177e4
LT
1/*
2 * Low-Level PCI Support for PC
3 *
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
5 */
6
7#include <linux/sched.h>
8#include <linux/pci.h>
9#include <linux/ioport.h>
10#include <linux/init.h>
8c4b2cf9 11#include <linux/dmi.h>
1da177e4
LT
12
13#include <asm/acpi.h>
14#include <asm/segment.h>
15#include <asm/io.h>
16#include <asm/smp.h>
17
18#include "pci.h"
19
1da177e4
LT
20unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
21 PCI_PROBE_MMCONF;
22
23int pci_routeirq;
24int pcibios_last_bus = -1;
120bb424 25unsigned long pirq_table_addr;
26struct pci_bus *pci_root_bus;
1da177e4
LT
27struct pci_raw_ops *raw_pci_ops;
28
29static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
30{
31 return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
32}
33
34static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
35{
36 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
37}
38
39struct pci_ops pci_root_ops = {
40 .read = pci_read,
41 .write = pci_write,
42};
43
44/*
45 * legacy, numa, and acpi all want to call pcibios_scan_root
46 * from their initcalls. This flag prevents that.
47 */
48int pcibios_scanned;
49
50/*
51 * This interrupt-safe spinlock protects all accesses to PCI
52 * configuration space.
53 */
54DEFINE_SPINLOCK(pci_config_lock);
55
56/*
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.
61 */
62
63static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
64{
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;
69 int i;
70
71 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
72 list_for_each(ln, &b->devices) {
73 d = pci_dev_b(ln);
74 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
75 seen_host_bridge++;
76 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
77 e = pci_dev_b(mn);
78 if (e->devfn != d->devfn + mirror ||
79 e->vendor != d->vendor ||
80 e->device != d->device ||
81 e->class != d->class)
82 continue;
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)
87 continue;
88 break;
89 }
90 if (mn == &b->devices)
91 return;
92 }
93 if (!seen_host_bridge)
94 return;
95 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
96
97 ln = &b->devices;
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);
103 kfree(d);
104 } else
105 ln = ln->next;
106 }
107}
108
109/*
110 * Called after each bus is probed, but before its children
111 * are examined.
112 */
113
114void __devinit pcibios_fixup_bus(struct pci_bus *b)
115{
116 pcibios_fixup_ghosts(b);
117 pci_read_bridge_bases(b);
118}
119
8c4b2cf9
BK
120/*
121 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
122 */
123#ifdef __i386__
124static int __devinit assign_all_busses(struct dmi_system_id *d)
125{
126 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
127 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
128 " (pci=assign-busses)\n", d->ident);
129 return 0;
130}
131#endif
132
133/*
134 * Laptops which need pci=assign-busses to see Cardbus cards
135 */
136static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
137#ifdef __i386__
138 {
139 .callback = assign_all_busses,
140 .ident = "Samsung X20 Laptop",
141 .matches = {
142 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
143 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
144 },
145 },
146#endif /* __i386__ */
147 {}
148};
1da177e4
LT
149
150struct pci_bus * __devinit pcibios_scan_root(int busnum)
151{
152 struct pci_bus *bus = NULL;
153
8c4b2cf9
BK
154 dmi_check_system(pciprobe_dmi_table);
155
1da177e4
LT
156 while ((bus = pci_find_next_bus(bus)) != NULL) {
157 if (bus->number == busnum) {
158 /* Already scanned */
159 return bus;
160 }
161 }
162