blob: 68bce194e688a1903480425b3db8dc37802127f0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Bernhard Kaindl8c4b2cf2006-02-18 01:36:55 -080011#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070020unsigned 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;
jayalk@intworks.biz120bb422005-03-21 20:20:42 -080025unsigned long pirq_table_addr;
26struct pci_bus *pci_root_bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027struct 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
Bernhard Kaindl8c4b2cf2006-02-18 01:36:55 -0800120/*
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};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150struct pci_bus * __devinit pcibios_scan_root(int busnum)
151{
152 struct pci_bus *bus = NULL;
153
Bernhard Kaindl8c4b2cf2006-02-18 01:36:55 -0800154 dmi_check_system(pciprobe_dmi_table);
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 while ((bus = pci_find_next_bus(bus)) != NULL) {
157 if (bus->number == busnum) {
158 /* Already scanned */
159 return bus;
160 }
161 }
162
Daniel Marjamäkiadcb89072005-11-23 15:44:49 -0800163 printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Rajesh Shahc431ada2005-04-28 00:25:45 -0700165 return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168extern u8 pci_cache_line_size;
169
170static int __init pcibios_init(void)
171{
172 struct cpuinfo_x86 *c = &boot_cpu_data;
173
174 if (!raw_pci_ops) {
Daniel Marjamäkiadcb89072005-11-23 15:44:49 -0800175 printk(KERN_WARNING "PCI: System does not support PCI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return 0;
177 }
178
179 /*
180 * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
181 * and P4. It's also good for 386/486s (which actually have 16)
182 * as quite a few PCI devices do not support smaller values.
183 */
184 pci_cache_line_size = 32 >> 2;
185 if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
186 pci_cache_line_size = 64 >> 2; /* K7 & K8 */
187 else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
188 pci_cache_line_size = 128 >> 2; /* P4 */
189
190 pcibios_resource_survey();
191
192#ifdef CONFIG_PCI_BIOS
193 if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
194 pcibios_sort();
195#endif
196 return 0;
197}
198
199subsys_initcall(pcibios_init);
200
201char * __devinit pcibios_setup(char *str)
202{
203 if (!strcmp(str, "off")) {
204 pci_probe = 0;
205 return NULL;
206 }
207#ifdef CONFIG_PCI_BIOS
208 else if (!strcmp(str, "bios")) {
209 pci_probe = PCI_PROBE_BIOS;
210 return NULL;
211 } else if (!strcmp(str, "nobios")) {
212 pci_probe &= ~PCI_PROBE_BIOS;
213 return NULL;
214 } else if (!strcmp(str, "nosort")) {
215 pci_probe |= PCI_NO_SORT;
216 return NULL;
217 } else if (!strcmp(str, "biosirq")) {
218 pci_probe |= PCI_BIOS_IRQ_SCAN;
219 return NULL;
jayalk@intworks.biz120bb422005-03-21 20:20:42 -0800220 } else if (!strncmp(str, "pirqaddr=", 9)) {
221 pirq_table_addr = simple_strtoul(str+9, NULL, 0);
222 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224#endif
225#ifdef CONFIG_PCI_DIRECT
226 else if (!strcmp(str, "conf1")) {
227 pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
228 return NULL;
229 }
230 else if (!strcmp(str, "conf2")) {
231 pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
232 return NULL;
233 }
234#endif
235#ifdef CONFIG_PCI_MMCONFIG
236 else if (!strcmp(str, "nommconf")) {
237 pci_probe &= ~PCI_PROBE_MMCONF;
238 return NULL;
239 }
240#endif
241 else if (!strcmp(str, "noacpi")) {
242 acpi_noirq_set();
243 return NULL;
244 }
Andi Kleen0637a702006-09-26 10:52:41 +0200245 else if (!strcmp(str, "noearly")) {
246 pci_probe |= PCI_PROBE_NOEARLY;
247 return NULL;
248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249#ifndef CONFIG_X86_VISWS
250 else if (!strcmp(str, "usepirqmask")) {
251 pci_probe |= PCI_USE_PIRQ_MASK;
252 return NULL;
253 } else if (!strncmp(str, "irqmask=", 8)) {
254 pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
255 return NULL;
256 } else if (!strncmp(str, "lastbus=", 8)) {
257 pcibios_last_bus = simple_strtol(str+8, NULL, 0);
258 return NULL;
259 }
260#endif
261 else if (!strcmp(str, "rom")) {
262 pci_probe |= PCI_ASSIGN_ROMS;
263 return NULL;
264 } else if (!strcmp(str, "assign-busses")) {
265 pci_probe |= PCI_ASSIGN_ALL_BUSSES;
266 return NULL;
267 } else if (!strcmp(str, "routeirq")) {
268 pci_routeirq = 1;
269 return NULL;
270 }
271 return str;
272}
273
274unsigned int pcibios_assign_all_busses(void)
275{
276 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
277}
278
279int pcibios_enable_device(struct pci_dev *dev, int mask)
280{
281 int err;
282
283 if ((err = pcibios_enable_resources(dev, mask)) < 0)
284 return err;
285
286 return pcibios_enable_irq(dev);
287}
David Shaohua Li87bec662005-07-27 23:02:00 -0400288
289void pcibios_disable_device (struct pci_dev *dev)
290{
Rajesh Shah53e4d302006-05-03 15:27:47 -0700291 pcibios_disable_resources(dev);
David Shaohua Li87bec662005-07-27 23:02:00 -0400292 if (pcibios_disable_irq)
293 pcibios_disable_irq(dev);
294}