x86_64: pci-gart_64.c iommu_fullflush should be static
[deliverable/linux.git] / arch / x86 / 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
e3f2baeb 23unsigned int pci_early_dump_regs;
2b290da0 24static int pci_bf_sort;
1da177e4 25int pci_routeirq;
a9322f64 26int noioapicquirk;
41b9eb26
SA
27#ifdef CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS
28int noioapicreroute = 0;
29#else
9197979b 30int noioapicreroute = 1;
41b9eb26 31#endif
1da177e4 32int pcibios_last_bus = -1;
120bb424 33unsigned long pirq_table_addr;
34struct pci_bus *pci_root_bus;
1da177e4 35struct pci_raw_ops *raw_pci_ops;
b6ce068a
MW
36struct pci_raw_ops *raw_pci_ext_ops;
37
38int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
39 int reg, int len, u32 *val)
40{
beef3129 41 if (domain == 0 && reg < 256 && raw_pci_ops)
b6ce068a
MW
42 return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
43 if (raw_pci_ext_ops)
44 return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
45 return -EINVAL;
46}
47
48int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
49 int reg, int len, u32 val)
50{
beef3129 51 if (domain == 0 && reg < 256 && raw_pci_ops)
b6ce068a
MW
52 return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
53 if (raw_pci_ext_ops)
54 return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
55 return -EINVAL;
56}
1da177e4
LT
57
58static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
59{
b6ce068a 60 return raw_pci_read(pci_domain_nr(bus), bus->number,
a79e4198 61 devfn, where, size, value);
1da177e4
LT
62}
63
64static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
65{
b6ce068a 66 return raw_pci_write(pci_domain_nr(bus), bus->number,
a79e4198 67 devfn, where, size, value);
1da177e4
LT
68}
69
70struct pci_ops pci_root_ops = {
71 .read = pci_read,
72 .write = pci_write,
73};
74
75/*
76 * legacy, numa, and acpi all want to call pcibios_scan_root
77 * from their initcalls. This flag prevents that.
78 */
79int pcibios_scanned;
80
81/*
82 * This interrupt-safe spinlock protects all accesses to PCI
83 * configuration space.
84 */
85DEFINE_SPINLOCK(pci_config_lock);
86
13a6ddb0
YL
87static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
88{
89 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
90 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
91 return 0;
92}
93
94static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
95/*
96 * Systems where PCI IO resource ISA alignment can be skipped
97 * when the ISA enable bit in the bridge control is not set
98 */
99 {
100 .callback = can_skip_ioresource_align,
101 .ident = "IBM System x3800",
102 .matches = {
103 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
104 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
105 },
106 },
107 {
108 .callback = can_skip_ioresource_align,
109 .ident = "IBM System x3850",
110 .matches = {
111 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
112 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
113 },
114 },
115 {
116 .callback = can_skip_ioresource_align,
117 .ident = "IBM System x3950",
118 .matches = {
119 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
120 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
121 },
122 },
123 {}
124};
125
126void __init dmi_check_skip_isa_align(void)
127{
128 dmi_check_system(can_skip_pciprobe_dmi_table);
129}
130
bb71ad88
GH
131static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
132{
133 struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
134
135 if (pci_probe & PCI_NOASSIGN_ROMS) {
136 if (rom_r->parent)
137 return;
138 if (rom_r->start) {
139 /* we deal with BIOS assigned ROM later */
140 return;
141 }
142 rom_r->start = rom_r->end = rom_r->flags = 0;
143 }
144}
145
1da177e4
LT
146/*
147 * Called after each bus is probed, but before its children
148 * are examined.
149 */
150
151void __devinit pcibios_fixup_bus(struct pci_bus *b)
152{
bb71ad88
GH
153 struct pci_dev *dev;
154
1da177e4 155 pci_read_bridge_bases(b);
bb71ad88
GH
156 list_for_each_entry(dev, &b->devices, bus_list)
157 pcibios_fixup_device_resources(dev);
1da177e4
LT
158}
159
6b4b78fe
MD
160/*
161 * Only use DMI information to set this if nothing was passed
162 * on the kernel command line (which was parsed earlier).
163 */
164
1855256c 165static int __devinit set_bf_sort(const struct dmi_system_id *d)
6b4b78fe
MD
166{
167 if (pci_bf_sort == pci_bf_sort_default) {
168 pci_bf_sort = pci_dmi_bf;
169 printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
170 }
171 return 0;
172}
173
8c4b2cf9
BK
174/*
175 * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
176 */
177#ifdef __i386__
1855256c 178static int __devinit assign_all_busses(const struct dmi_system_id *d)
8c4b2cf9
BK
179{
180 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
181 printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
182 " (pci=assign-busses)\n", d->ident);
183 return 0;
184}
185#endif
186
6b4b78fe
MD
187static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
188#ifdef __i386__
8c4b2cf9
BK
189/*
190 * Laptops which need pci=assign-busses to see Cardbus cards
191 */
8c4b2cf9
BK
192 {
193 .callback = assign_all_busses,
194 .ident = "Samsung X20 Laptop",
195 .matches = {
196 DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
197 DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
198 },
199 },
200#endif /* __i386__ */
6b4b78fe
MD
201 {
202 .callback = set_bf_sort,
203 .ident = "Dell PowerEdge 1950",
204 .matches = {
205 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
206 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
207 },
208 },
209 {
210 .callback = set_bf_sort,
211 .ident = "Dell PowerEdge 1955",
212 .matches = {
213 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
214 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
215 },
216 },
217 {
218 .callback = set_bf_sort,
219 .ident = "Dell PowerEdge 2900",
220 .matches = {
221 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
222 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
223 },
224 },
225 {
226 .callback = set_bf_sort,
227 .ident = "Dell PowerEdge 2950",
228 .matches = {
229 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
230 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
231 },
232 },
f7a9dae7
MD
233 {
234 .callback = set_bf_sort,
235 .ident = "Dell PowerEdge R900",
236 .matches = {
237 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
238 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
239 },
240 },
f52383d3
AG
241 {
242 .callback = set_bf_sort,
243 .ident = "HP ProLiant BL20p G3",
244 .matches = {
245 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
246 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
247 },
248 },
249 {
250 .callback = set_bf_sort,
251 .ident = "HP ProLiant BL20p G4",
252 .matches = {
253 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
254 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
255 },
256 },
257 {
258 .callback = set_bf_sort,
259 .ident = "HP ProLiant BL30p G1",
260 .matches = {
261 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
262 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
263 },
264 },
265 {
266 .callback = set_bf_sort,
267 .ident = "HP ProLiant BL25p G1",
268 .matches = {
269 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
270 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
271 },
272 },
273 {
274 .callback = set_bf_sort,
275 .ident = "HP ProLiant BL35p G1",
276 .matches = {
277 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
278 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
279 },
280 },
281 {
282 .callback = set_bf_sort,
283 .ident = "HP ProLiant BL45p G1",
284 .matches = {
285 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
286 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
287 },
288 },
289 {
290 .callback = set_bf_sort,
291 .ident = "HP ProLiant BL45p G2",
292 .matches = {
293 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
294 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
295 },
296 },
297 {
298 .callback = set_bf_sort,
299 .ident = "HP ProLiant BL460c G1",
300 .matches = {
301 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
302 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
303 },
304 },
305 {
306 .callback = set_bf_sort,
307 .ident = "HP ProLiant BL465c G1",
308 .matches = {
309 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
310 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
311 },
312 },
313 {
314 .callback = set_bf_sort,
315 .ident = "HP ProLiant BL480c G1",
316 .matches = {
317 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
318 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
319 },
320 },
321 {
322 .callback = set_bf_sort,
323 .ident = "HP ProLiant BL685c G1",
324 .matches = {
325 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
326 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
327 },
328 },
8f8ae1a7
MS
329 {
330 .callback = set_bf_sort,
8d64c781 331 .ident = "HP ProLiant DL360",
8f8ae1a7
MS
332 .matches = {
333 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
8d64c781 334 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
8f8ae1a7
MS
335 },
336 },
337 {
338 .callback = set_bf_sort,
8d64c781 339 .ident = "HP ProLiant DL380",
8f8ae1a7
MS
340 .matches = {
341 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
8d64c781 342 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
8f8ae1a7
MS
343 },
344 },
5b1ea82f
JL
345#ifdef __i386__
346 {
347 .callback = assign_all_busses,
348 .ident = "Compaq EVO N800c",
349 .matches = {
350 DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
351 DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
352 },
353 },
354#endif
c82bc5ad
MS
355 {
356 .callback = set_bf_sort,
739db07f 357 .ident = "HP ProLiant DL385 G2",
c82bc5ad
MS
358 .matches = {
359 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
739db07f 360 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
c82bc5ad
MS
361 },
362 },
363 {
364 .callback = set_bf_sort,
739db07f 365 .ident = "HP ProLiant DL585 G2",
c82bc5ad
MS
366 .matches = {
367 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
739db07f 368 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
c82bc5ad
MS
369 },
370 },
8c4b2cf9
BK
371 {}
372};
1da177e4 373
0df18ff3
YL
374void __init dmi_check_pciprobe(void)
375{
376 dmi_check_system(pciprobe_dmi_table);
377}
378
1da177e4
LT
379struct pci_bus * __devinit pcibios_scan_root(int busnum)
380{
381 struct pci_bus *bus = NULL;
08f1c192 382 struct pci_sysdata *sd;
1da177e4
LT
383
384 while ((bus = pci_find_next_bus(bus)) != NULL) {
385 if (bus->number == busnum) {
386 /* Already scanned */
387 return bus;
388 }
389 }
390
08f1c192
MBY
391 /* Allocate per-root-bus (not per bus) arch-specific data.
392 * TODO: leak; this memory is never freed.
393 * It's arguable whether it's worth the trouble to care.
394 */
395 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
396 if (!sd) {
397 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
398 return NULL;
399 }
400
871d5f8d
YL
401 sd->node = get_mp_bus_to_node(busnum);
402