[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / i386 / pci / common.c
blob720975e1af5046cdcef151f57e68e94fd2378d82
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>
12 #include <asm/acpi.h>
13 #include <asm/segment.h>
14 #include <asm/io.h>
15 #include <asm/smp.h>
17 #include "pci.h"
19 #ifdef CONFIG_PCI_BIOS
20 extern void pcibios_sort(void);
21 #endif
23 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
24 PCI_PROBE_MMCONF;
26 int pci_routeirq;
27 int pcibios_last_bus = -1;
28 struct pci_bus *pci_root_bus = NULL;
29 struct pci_raw_ops *raw_pci_ops;
31 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
33 return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
36 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
38 return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
41 struct pci_ops pci_root_ops = {
42 .read = pci_read,
43 .write = pci_write,
47 * legacy, numa, and acpi all want to call pcibios_scan_root
48 * from their initcalls. This flag prevents that.
50 int pcibios_scanned;
53 * This interrupt-safe spinlock protects all accesses to PCI
54 * configuration space.
56 DEFINE_SPINLOCK(pci_config_lock);
59 * Several buggy motherboards address only 16 devices and mirror
60 * them to next 16 IDs. We try to detect this `feature' on all
61 * primary buses (those containing host bridges as they are
62 * expected to be unique) and remove the ghost devices.
65 static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
67 struct list_head *ln, *mn;
68 struct pci_dev *d, *e;
69 int mirror = PCI_DEVFN(16,0);
70 int seen_host_bridge = 0;
71 int i;
73 DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
74 list_for_each(ln, &b->devices) {
75 d = pci_dev_b(ln);
76 if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
77 seen_host_bridge++;
78 for (mn=ln->next; mn != &b->devices; mn=mn->next) {
79 e = pci_dev_b(mn);
80 if (e->devfn != d->devfn + mirror ||
81 e->vendor != d->vendor ||
82 e->device != d->device ||
83 e->class != d->class)
84 continue;
85 for(i=0; i<PCI_NUM_RESOURCES; i++)
86 if (e->resource[i].start != d->resource[i].start ||
87 e->resource[i].end != d->resource[i].end ||
88 e->resource[i].flags != d->resource[i].flags)
89 continue;
90 break;
92 if (mn == &b->devices)
93 return;
95 if (!seen_host_bridge)
96 return;
97 printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
99 ln = &b->devices;
100 while (ln->next != &b->devices) {
101 d = pci_dev_b(ln->next);
102 if (d->devfn >= mirror) {
103 list_del(&d->global_list);
104 list_del(&d->bus_list);
105 kfree(d);
106 } else
107 ln = ln->next;
112 * Called after each bus is probed, but before its children
113 * are examined.
116 void __devinit pcibios_fixup_bus(struct pci_bus *b)
118 pcibios_fixup_ghosts(b);
119 pci_read_bridge_bases(b);
123 struct pci_bus * __devinit pcibios_scan_root(int busnum)
125 struct pci_bus *bus = NULL;
127 while ((bus = pci_find_next_bus(bus)) != NULL) {
128 if (bus->number == busnum) {
129 /* Already scanned */
130 return bus;
134 printk("PCI: Probing PCI hardware (bus %02x)\n", busnum);
136 return pci_scan_bus(busnum, &pci_root_ops, NULL);
139 extern u8 pci_cache_line_size;
141 static int __init pcibios_init(void)
143 struct cpuinfo_x86 *c = &boot_cpu_data;
145 if (!raw_pci_ops) {
146 printk("PCI: System does not support PCI\n");
147 return 0;
151 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
152 * and P4. It's also good for 386/486s (which actually have 16)
153 * as quite a few PCI devices do not support smaller values.
155 pci_cache_line_size = 32 >> 2;
156 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
157 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
158 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
159 pci_cache_line_size = 128 >> 2; /* P4 */
161 pcibios_resource_survey();
163 #ifdef CONFIG_PCI_BIOS
164 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
165 pcibios_sort();
166 #endif
167 return 0;
170 subsys_initcall(pcibios_init);
172 char * __devinit pcibios_setup(char *str)
174 if (!strcmp(str, "off")) {
175 pci_probe = 0;
176 return NULL;
178 #ifdef CONFIG_PCI_BIOS
179 else if (!strcmp(str, "bios")) {
180 pci_probe = PCI_PROBE_BIOS;
181 return NULL;
182 } else if (!strcmp(str, "nobios")) {
183 pci_probe &= ~PCI_PROBE_BIOS;
184 return NULL;
185 } else if (!strcmp(str, "nosort")) {
186 pci_probe |= PCI_NO_SORT;
187 return NULL;
188 } else if (!strcmp(str, "biosirq")) {
189 pci_probe |= PCI_BIOS_IRQ_SCAN;
190 return NULL;
192 #endif
193 #ifdef CONFIG_PCI_DIRECT
194 else if (!strcmp(str, "conf1")) {
195 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
196 return NULL;
198 else if (!strcmp(str, "conf2")) {
199 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
200 return NULL;
202 #endif
203 #ifdef CONFIG_PCI_MMCONFIG
204 else if (!strcmp(str, "nommconf")) {
205 pci_probe &= ~PCI_PROBE_MMCONF;
206 return NULL;
208 #endif
209 else if (!strcmp(str, "noacpi")) {
210 acpi_noirq_set();
211 return NULL;
213 #ifndef CONFIG_X86_VISWS
214 else if (!strcmp(str, "usepirqmask")) {
215 pci_probe |= PCI_USE_PIRQ_MASK;
216 return NULL;
217 } else if (!strncmp(str, "irqmask=", 8)) {
218 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
219 return NULL;
220 } else if (!strncmp(str, "lastbus=", 8)) {
221 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
222 return NULL;
224 #endif
225 else if (!strcmp(str, "rom")) {
226 pci_probe |= PCI_ASSIGN_ROMS;
227 return NULL;
228 } else if (!strcmp(str, "assign-busses")) {
229 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
230 return NULL;
231 } else if (!strcmp(str, "routeirq")) {
232 pci_routeirq = 1;
233 return NULL;
235 return str;
238 unsigned int pcibios_assign_all_busses(void)
240 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
243 int pcibios_enable_device(struct pci_dev *dev, int mask)
245 int err;
247 if ((err = pcibios_enable_resources(dev, mask)) < 0)
248 return err;
250 return pcibios_enable_irq(dev);