[EBTABLES]: Clean ebt_register_table() up.
[linux-2.6/kvm.git] / arch / i386 / pci / common.c
blob53ca6e897984a669e4a36ef23295bb0f9e30d561
1 /*
2 * Low-Level PCI Support for PC
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
5 */
7 #include <linux/sched.h>
8 #include <linux/pci.h>
9 #include <linux/ioport.h>
10 #include <linux/init.h>
11 #include <linux/dmi.h>
13 #include <asm/acpi.h>
14 #include <asm/segment.h>
15 #include <asm/io.h>
16 #include <asm/smp.h>
18 #include "pci.h"
20 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
21 PCI_PROBE_MMCONF;
23 static int pci_bf_sort;
24 int pci_routeirq;
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 = {
41 .read = pci_read,
42 .write = pci_write,
46 * legacy, numa, and acpi all want to call pcibios_scan_root
47 * from their initcalls. This flag prevents that.
49 int pcibios_scanned;
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;
70 int i;
72 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
73 list_for_each(ln, &b->devices) {
74 d = pci_dev_b(ln);
75 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
76 seen_host_bridge++;
77 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
78 e = pci_dev_b(mn);
79 if (e->devfn != d->devfn + mirror ||
80 e->vendor != d->vendor ||
81 e->device != d->device ||
82 e->class != d->class)
83 continue;
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)
88 continue;
89 break;
91 if (mn == &b->devices)
92 return;
94 if (!seen_host_bridge)
95 return;
96 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
98 ln = &b->devices;
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);
104 kfree(d);
105 } else
106 ln = ln->next;
111 * Called after each bus is probed, but before its children
112 * are examined.
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(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);
132 return 0;
136 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
138 #ifdef __i386__
139 static int __devinit assign_all_busses(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);
144 return 0;
146 #endif
148 static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
149 #ifdef __i386__
151 * Laptops which need pci=assign-busses to see Cardbus cards
154 .callback = assign_all_busses,
155 .ident = "Samsung X20 Laptop",
156 .matches = {
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",
165 .matches = {
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",
173 .matches = {
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",
181 .matches = {
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",
189 .matches = {
190 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
191 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
197 struct pci_bus * __devinit pcibios_scan_root(int busnum)
199 struct pci_bus *bus = NULL;
201 dmi_check_system(pciprobe_dmi_table);
203 while ((bus = pci_find_next_bus(bus)) != NULL) {
204 if (bus->number == busnum) {
205 /* Already scanned */
206 return bus;
210 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
212 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
215 extern u8 pci_cache_line_size;
217 static int __init pcibios_init(void)
219 struct cpuinfo_x86 *c = &boot_cpu_data;
221 if (!raw_pci_ops) {
222 printk(KERN_WARNING "PCI: System does not support PCI\n");
223 return 0;
227 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
228 * and P4. It's also good for 386/486s (which actually have 16)
229 * as quite a few PCI devices do not support smaller values.
231 pci_cache_line_size = 32 >> 2;
232 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
233 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
234 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
235 pci_cache_line_size = 128 >> 2; /* P4 */
237 pcibios_resource_survey();
239 if (pci_bf_sort >= pci_force_bf)
240 pci_sort_breadthfirst();
241 #ifdef CONFIG_PCI_BIOS
242 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
243 pcibios_sort();
244 #endif
245 return 0;
248 subsys_initcall(pcibios_init);
250 char * __devinit pcibios_setup(char *str)
252 if (!strcmp(str, "off")) {
253 pci_probe = 0;
254 return NULL;
255 } else if (!strcmp(str, "bfsort")) {
256 pci_bf_sort = pci_force_bf;
257 return NULL;
258 } else if (!strcmp(str, "nobfsort")) {
259 pci_bf_sort = pci_force_nobf;
260 return NULL;
262 #ifdef CONFIG_PCI_BIOS
263 else if (!strcmp(str, "bios")) {
264 pci_probe = PCI_PROBE_BIOS;
265 return NULL;
266 } else if (!strcmp(str, "nobios")) {
267 pci_probe &= ~PCI_PROBE_BIOS;
268 return NULL;
269 } else if (!strcmp(str, "nosort")) {
270 pci_probe |= PCI_NO_SORT;
271 return NULL;
272 } else if (!strcmp(str, "biosirq")) {
273 pci_probe |= PCI_BIOS_IRQ_SCAN;
274 return NULL;
275 } else if (!strncmp(str, "pirqaddr=", 9)) {
276 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
277 return NULL;
279 #endif
280 #ifdef CONFIG_PCI_DIRECT
281 else if (!strcmp(str, "conf1")) {
282 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
283 return NULL;
285 else if (!strcmp(str, "conf2")) {
286 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
287 return NULL;
289 #endif
290 #ifdef CONFIG_PCI_MMCONFIG
291 else if (!strcmp(str, "nommconf")) {
292 pci_probe &= ~PCI_PROBE_MMCONF;
293 return NULL;
295 #endif
296 else if (!strcmp(str, "noacpi")) {
297 acpi_noirq_set();
298 return NULL;
300 else if (!strcmp(str, "noearly")) {
301 pci_probe |= PCI_PROBE_NOEARLY;
302 return NULL;
304 #ifndef CONFIG_X86_VISWS
305 else if (!strcmp(str, "usepirqmask")) {
306 pci_probe |= PCI_USE_PIRQ_MASK;
307 return NULL;
308 } else if (!strncmp(str, "irqmask=", 8)) {
309 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
310 return NULL;
311 } else if (!strncmp(str, "lastbus=", 8)) {
312 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
313 return NULL;
315 #endif
316 else if (!strcmp(str, "rom")) {
317 pci_probe |= PCI_ASSIGN_ROMS;
318 return NULL;
319 } else if (!strcmp(str, "assign-busses")) {
320 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
321 return NULL;
322 } else if (!strcmp(str, "routeirq")) {
323 pci_routeirq = 1;
324 return NULL;
326 return str;
329 unsigned int pcibios_assign_all_busses(void)
331 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
334 int pcibios_enable_device(struct pci_dev *dev, int mask)
336 int err;
338 if ((err = pcibios_enable_resources(dev, mask)) < 0)
339 return err;
341 return pcibios_enable_irq(dev);
344 void pcibios_disable_device (struct pci_dev *dev)
346 if (pcibios_disable_irq)
347 pcibios_disable_irq(dev);