]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/x86/pci/acpi.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[net-next-2.6.git] / arch / x86 / pci / acpi.c
CommitLineData
1da177e4
LT
1#include <linux/pci.h>
2#include <linux/acpi.h>
3#include <linux/init.h>
b33fa1f3 4#include <linux/irq.h>
036fff4c 5#include <linux/dmi.h>
5a0e3ad6 6#include <linux/slab.h>
69e1a33f 7#include <asm/numa.h>
82487711 8#include <asm/pci_x86.h>
1da177e4 9
62f420f8 10struct pci_root_info {
42887b29 11 struct acpi_device *bridge;
62f420f8
GH
12 char *name;
13 unsigned int res_num;
14 struct resource *res;
15 struct pci_bus *bus;
16 int busnum;
17};
18
7bc5e3f2
BH
19static bool pci_use_crs = true;
20
21static int __init set_use_crs(const struct dmi_system_id *id)
22{
23 pci_use_crs = true;
24 return 0;
25}
26
27static const struct dmi_system_id pci_use_crs_table[] __initconst = {
28 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
29 {
30 .callback = set_use_crs,
31 .ident = "IBM System x3800",
32 .matches = {
33 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
34 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
35 },
36 },
37 {}
38};
39
40void __init pci_acpi_crs_quirks(void)
41{
42 int year;
43
44 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
45 pci_use_crs = false;
46
47 dmi_check_system(pci_use_crs_table);
48
49 /*
50 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
51 * takes precedence over anything we figured out above.
52 */
53 if (pci_probe & PCI_ROOT_NO_CRS)
54 pci_use_crs = false;
55 else if (pci_probe & PCI_USE__CRS)
56 pci_use_crs = true;
57
58 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
59 "if necessary, use \"pci=%s\" and report a bug\n",
60 pci_use_crs ? "Using" : "Ignoring",
61 pci_use_crs ? "nocrs" : "use_crs");
62}
63
62f420f8
GH
64static acpi_status
65resource_to_addr(struct acpi_resource *resource,
66 struct acpi_resource_address64 *addr)
67{
68 acpi_status status;
69
70 status = acpi_resource_to_address64(resource, addr);
71 if (ACPI_SUCCESS(status) &&
72 (addr->resource_type == ACPI_MEMORY_RANGE ||
73 addr->resource_type == ACPI_IO_RANGE) &&
74 addr->address_length > 0 &&
75 addr->producer_consumer == ACPI_PRODUCER) {
76 return AE_OK;
77 }
78 return AE_ERROR;
79}
80
81static acpi_status
82count_resource(struct acpi_resource *acpi_res, void *data)
83{
84 struct pci_root_info *info = data;
85 struct acpi_resource_address64 addr;
86 acpi_status status;
87
88 status = resource_to_addr(acpi_res, &addr);
89 if (ACPI_SUCCESS(status))
90 info->res_num++;
91 return AE_OK;
92}
93
03db42ad
BH
94static void
95align_resource(struct acpi_device *bridge, struct resource *res)
96{
97 int align = (res->flags & IORESOURCE_MEM) ? 16 : 4;
98
99 /*
100 * Host bridge windows are not BARs, but the decoders on the PCI side
101 * that claim this address space have starting alignment and length
102 * constraints, so fix any obvious BIOS goofs.
103 */
ea7f1b6e 104 if (!IS_ALIGNED(res->start, align)) {
03db42ad
BH
105 dev_printk(KERN_DEBUG, &bridge->dev,
106 "host bridge window %pR invalid; "
107 "aligning start to %d-byte boundary\n", res, align);
108 res->start &= ~(align - 1);
109 }
ea7f1b6e 110 if (!IS_ALIGNED(res->end + 1, align)) {
03db42ad
BH
111 dev_printk(KERN_DEBUG, &bridge->dev,
112 "host bridge window %pR invalid; "
113 "aligning end to %d-byte boundary\n", res, align);
ea7f1b6e 114 res->end = ALIGN(res->end, align) - 1;
03db42ad
BH
115 }
116}
117
62f420f8
GH
118static acpi_status
119setup_resource(struct acpi_resource *acpi_res, void *data)
120{
121 struct pci_root_info *info = data;
122 struct resource *res;
123 struct acpi_resource_address64 addr;
124 acpi_status status;
125 unsigned long flags;
eb9fc8ef 126 struct resource *root, *conflict;
d558b483 127 u64 start, end, max_len;
2cdb3f1d 128
62f420f8
GH
129 status = resource_to_addr(acpi_res, &addr);
130 if (!ACPI_SUCCESS(status))
131 return AE_OK;
132
133 if (addr.resource_type == ACPI_MEMORY_RANGE) {
134 root = &iomem_resource;
135 flags = IORESOURCE_MEM;
136 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
137 flags |= IORESOURCE_PREFETCH;
138 } else if (addr.resource_type == ACPI_IO_RANGE) {
139 root = &ioport_resource;
140 flags = IORESOURCE_IO;
141 } else
142 return AE_OK;
143
d558b483
BH
144 max_len = addr.maximum - addr.minimum + 1;
145 if (addr.address_length > max_len) {
146 dev_printk(KERN_DEBUG, &info->bridge->dev,
147 "host bridge window length %#llx doesn't fit in "
148 "%#llx-%#llx, trimming\n",
149 (unsigned long long) addr.address_length,
150 (unsigned long long) addr.minimum,
151 (unsigned long long) addr.maximum);
152 addr.address_length = max_len;
153 }
154
2cdb3f1d
YL
155 start = addr.minimum + addr.translation_offset;
156 end = start + addr.address_length - 1;
f9cde5ff 157
2cdb3f1d
YL
158 res = &info->res[info->res_num];
159 res->name = info->name;
160 res->flags = flags;
161 res->start = start;
162 res->end = end;
163 res->child = NULL;
03db42ad 164 align_resource(info->bridge, res);
2cdb3f1d 165
7bc5e3f2 166 if (!pci_use_crs) {
f1db6fde
BH
167 dev_printk(KERN_DEBUG, &info->bridge->dev,
168 "host bridge window %pR (ignored)\n", res);
169 return AE_OK;
170 }
171
eb9fc8ef
BH
172 conflict = insert_resource_conflict(root, res);
173 if (conflict) {
c7dabef8 174 dev_err(&info->bridge->dev,
eb9fc8ef
BH
175 "address space collision: host bridge window %pR "
176 "conflicts with %s %pR\n",
177 res, conflict->name, conflict);
62f420f8 178 } else {
2fe2abf8 179 pci_bus_add_resource(info->bus, res, 0);
62f420f8 180 info->res_num++;
42887b29 181 if (addr.translation_offset)
c7dabef8 182 dev_info(&info->bridge->dev, "host bridge window %pR "
42887b29
BH
183 "(PCI address [%#llx-%#llx])\n",
184 res, res->start - addr.translation_offset,
185 res->end - addr.translation_offset);
186 else
187 dev_info(&info->bridge->dev,
c7dabef8 188 "host bridge window %pR\n", res);
62f420f8
GH
189 }
190 return AE_OK;
191}
192
62f420f8
GH
193static void
194get_current_resources(struct acpi_device *device, int busnum,
cb3576fa 195 int domain, struct pci_bus *bus)
62f420f8
GH
196{
197 struct pci_root_info info;
198 size_t size;
199
7bc5e3f2 200 if (pci_use_crs)
2fe2abf8 201 pci_bus_remove_resources(bus);
f1db6fde 202
42887b29 203 info.bridge = device;
62f420f8
GH
204 info.bus = bus;
205 info.res_num = 0;
206 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
207 &info);
208 if (!info.res_num)
209 return;
210
211 size = sizeof(*info.res) * info.res_num;
212 info.res = kmalloc(size, GFP_KERNEL);
213 if (!info.res)
214 goto res_alloc_fail;
215
cb3576fa 216 info.name = kmalloc(16, GFP_KERNEL);
62f420f8
GH
217 if (!info.name)
218 goto name_alloc_fail;
cb3576fa 219 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
62f420f8
GH
220
221 info.res_num = 0;
222 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
223 &info);
62f420f8
GH
224
225 return;
226
227name_alloc_fail:
228 kfree(info.res);
229res_alloc_fail:
230 return;
231}
232
1da177e4
LT
233struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
234{
69e1a33f 235 struct pci_bus *bus;
08f1c192 236 struct pci_sysdata *sd;
871d5f8d
YL
237 int node;
238#ifdef CONFIG_ACPI_NUMA
08f1c192 239 int pxm;
871d5f8d 240#endif
08f1c192 241
a79e4198 242 if (domain && !pci_domains_supported) {
2a6bed83
BH
243 printk(KERN_WARNING "pci_bus %04x:%02x: "
244 "ignored (multiple domains not supported)\n",
245 domain, busnum);
a79e4198
JG
246 return NULL;
247 }
248
871d5f8d
YL
249 node = -1;
250#ifdef CONFIG_ACPI_NUMA
251 pxm = acpi_get_pxm(device->handle);
252 if (pxm >= 0)
253 node = pxm_to_node(pxm);
254 if (node != -1)
255 set_mp_bus_to_node(busnum, node);
256 else
871d5f8d 257#endif
871d5f8d 258 node = get_mp_bus_to_node(busnum);
b755de8d
YL
259
260 if (node != -1 && !node_online(node))
261 node = -1;
871d5f8d 262
08f1c192
MBY
263 /* Allocate per-root-bus (not per bus) arch-specific data.
264 * TODO: leak; this memory is never freed.
265 * It's arguable whether it's worth the trouble to care.
266 */
267 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
268 if (!sd) {
2a6bed83
BH
269 printk(KERN_WARNING "pci_bus %04x:%02x: "
270 "ignored (out of memory)\n", domain, busnum);
08f1c192
MBY
271 return NULL;
272 }
69e1a33f 273
a79e4198 274 sd->domain = domain;
871d5f8d 275 sd->node = node;
b87e81e5 276 /*
277 * Maybe the desired pci bus has been already scanned. In such case
278 * it is unnecessary to scan the pci bus with the given domain,busnum.
279 */
280 bus = pci_find_bus(domain, busnum);
281 if (bus) {
282 /*
283 * If the desired bus exits, the content of bus->sysdata will
284 * be replaced by sd.
285 */
286 memcpy(bus->sysdata, sd, sizeof(*sd));
287 kfree(sd);
626fdfec
YL
288 } else {
289 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
290 if (bus) {
f1db6fde 291 get_current_resources(device, busnum, domain, bus);
626fdfec
YL
292 bus->subordinate = pci_scan_child_bus(bus);
293 }
294 }
08f1c192 295
08f1c192
MBY
296 if (!bus)
297 kfree(sd);
298
dbb6152e 299 if (bus && node != -1) {
69e1a33f 300#ifdef CONFIG_ACPI_NUMA
dbb6152e 301 if (pxm >= 0)
2b8c2efe
BH
302 dev_printk(KERN_DEBUG, &bus->dev,
303 "on NUMA node %d (pxm %d)\n", node, pxm);
dbb6152e 304#else
2b8c2efe 305 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
69e1a33f 306#endif
dbb6152e 307 }
62f420f8 308
69e1a33f 309 return bus;
1da177e4
LT
310}
311
8dd779b1 312int __init pci_acpi_init(void)
1da177e4
LT
313{
314 struct pci_dev *dev = NULL;
315
1da177e4 316 if (acpi_noirq)
b72d0db9 317 return -ENODEV;
1da177e4
LT
318
319 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
320 acpi_irq_penalty_init();
1da177e4 321 pcibios_enable_irq = acpi_pci_irq_enable;
87bec66b 322 pcibios_disable_irq = acpi_pci_irq_disable;
ab3b3793 323 x86_init.pci.init_irq = x86_init_noop;
1da177e4
LT
324
325 if (pci_routeirq) {
326 /*
327 * PCI IRQ routing is set up by pci_enable_device(), but we
328 * also do it here in case there are still broken drivers that
329 * don't use pci_enable_device().
330 */
331 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
fb37fb96 332 for_each_pci_dev(dev)
1da177e4 333 acpi_pci_irq_enable(dev);
657472e9 334 }
1da177e4 335
1da177e4
LT
336 return 0;
337}