blob: a7536dcc2acfd85b70925683318b27410185cb4f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/pci.h>
2#include <linux/acpi.h>
3#include <linux/init.h>
Nick Pigginb33fa1f2005-10-01 02:34:42 +10004#include <linux/irq.h>
Gary Hade036fff42007-10-03 15:56:14 -07005#include <linux/dmi.h>
Andi Kleen69e1a332005-09-12 18:49:24 +02006#include <asm/numa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include "pci.h"
8
Jeff Garzik752097c2007-10-12 22:34:40 -04009static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
Gary Hade036fff42007-10-03 15:56:14 -070010{
11 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
12 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
13 return 0;
14}
15
Adrian Bunk55b8d502007-11-09 07:02:11 +010016static struct dmi_system_id acpi_pciprobe_dmi_table[] __devinitdata = {
Gary Hade036fff42007-10-03 15:56:14 -070017/*
18 * Systems where PCI IO resource ISA alignment can be skipped
19 * when the ISA enable bit in the bridge control is not set
20 */
21 {
22 .callback = can_skip_ioresource_align,
23 .ident = "IBM System x3800",
24 .matches = {
25 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
26 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
27 },
28 },
29 {
30 .callback = can_skip_ioresource_align,
31 .ident = "IBM System x3850",
32 .matches = {
33 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
34 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
35 },
36 },
37 {
38 .callback = can_skip_ioresource_align,
39 .ident = "IBM System x3950",
40 .matches = {
41 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
42 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
43 },
44 },
45 {}
46};
47
Gary Hade62f420f2007-10-03 15:56:51 -070048struct pci_root_info {
49 char *name;
50 unsigned int res_num;
51 struct resource *res;
52 struct pci_bus *bus;
53 int busnum;
54};
55
56static acpi_status
57resource_to_addr(struct acpi_resource *resource,
58 struct acpi_resource_address64 *addr)
59{
60 acpi_status status;
61
62 status = acpi_resource_to_address64(resource, addr);
63 if (ACPI_SUCCESS(status) &&
64 (addr->resource_type == ACPI_MEMORY_RANGE ||
65 addr->resource_type == ACPI_IO_RANGE) &&
66 addr->address_length > 0 &&
67 addr->producer_consumer == ACPI_PRODUCER) {
68 return AE_OK;
69 }
70 return AE_ERROR;
71}
72
73static acpi_status
74count_resource(struct acpi_resource *acpi_res, void *data)
75{
76 struct pci_root_info *info = data;
77 struct acpi_resource_address64 addr;
78 acpi_status status;
79
80 status = resource_to_addr(acpi_res, &addr);
81 if (ACPI_SUCCESS(status))
82 info->res_num++;
83 return AE_OK;
84}
85
86static acpi_status
87setup_resource(struct acpi_resource *acpi_res, void *data)
88{
89 struct pci_root_info *info = data;
90 struct resource *res;
91 struct acpi_resource_address64 addr;
92 acpi_status status;
93 unsigned long flags;
94 struct resource *root;
95
96 status = resource_to_addr(acpi_res, &addr);
97 if (!ACPI_SUCCESS(status))
98 return AE_OK;
99
100 if (addr.resource_type == ACPI_MEMORY_RANGE) {
101 root = &iomem_resource;
102 flags = IORESOURCE_MEM;
103 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
104 flags |= IORESOURCE_PREFETCH;
105 } else if (addr.resource_type == ACPI_IO_RANGE) {
106 root = &ioport_resource;
107 flags = IORESOURCE_IO;
108 } else
109 return AE_OK;
110
111 res = &info->res[info->res_num];
112 res->name = info->name;
113 res->flags = flags;
114 res->start = addr.minimum + addr.translation_offset;
115 res->end = res->start + addr.address_length - 1;
116 res->child = NULL;
117
118 if (insert_resource(root, res)) {
119 printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx "
120 "from %s for %s\n", (unsigned long) res->start,
121 (unsigned long) res->end, root->name, info->name);
122 } else {
123 info->bus->resource[info->res_num] = res;
124 info->res_num++;
125 }
126 return AE_OK;
127}
128
129static void
130adjust_transparent_bridge_resources(struct pci_bus *bus)
131{
132 struct pci_dev *dev;
133
134 list_for_each_entry(dev, &bus->devices, bus_list) {
135 int i;
136 u16 class = dev->class >> 8;
137
138 if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) {
139 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
140 dev->subordinate->resource[i] =
141 dev->bus->resource[i - 3];
142 }
143 }
144}
145
146static void
147get_current_resources(struct acpi_device *device, int busnum,
148 struct pci_bus *bus)
149{
150 struct pci_root_info info;
151 size_t size;
152
153 info.bus = bus;
154 info.res_num = 0;
155 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
156 &info);
157 if (!info.res_num)
158 return;
159
160 size = sizeof(*info.res) * info.res_num;
161 info.res = kmalloc(size, GFP_KERNEL);
162 if (!info.res)
163 goto res_alloc_fail;
164
165 info.name = kmalloc(12, GFP_KERNEL);
166 if (!info.name)
167 goto name_alloc_fail;
168 sprintf(info.name, "PCI Bus #%02x", busnum);
169
170 info.res_num = 0;
171 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
172 &info);
173 if (info.res_num)
174 adjust_transparent_bridge_resources(bus);
175
176 return;
177
178name_alloc_fail:
179 kfree(info.res);
180res_alloc_fail:
181 return;
182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
185{
Andi Kleen69e1a332005-09-12 18:49:24 +0200186 struct pci_bus *bus;
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300187 struct pci_sysdata *sd;
188 int pxm;
Andi Kleen69e1a332005-09-12 18:49:24 +0200189
Gary Hade036fff42007-10-03 15:56:14 -0700190 dmi_check_system(acpi_pciprobe_dmi_table);
191
Jeff Garzika79e4192007-10-11 16:58:30 -0400192 if (domain && !pci_domains_supported) {
193 printk(KERN_WARNING "PCI: Multiple domains not supported "
194 "(dom %d, bus %d)\n", domain, busnum);
195 return NULL;
196 }
197
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300198 /* Allocate per-root-bus (not per bus) arch-specific data.
199 * TODO: leak; this memory is never freed.
200 * It's arguable whether it's worth the trouble to care.
201 */
202 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
203 if (!sd) {
204 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return NULL;
206 }
207
Jeff Garzika79e4192007-10-11 16:58:30 -0400208 sd->domain = domain;
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300209 sd->node = -1;
210
211 pxm = acpi_get_pxm(device->handle);
212#ifdef CONFIG_ACPI_NUMA
213 if (pxm >= 0)
214 sd->node = pxm_to_node(pxm);
215#endif
216
217 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
218 if (!bus)
219 kfree(sd);
220
Andi Kleen69e1a332005-09-12 18:49:24 +0200221#ifdef CONFIG_ACPI_NUMA
222 if (bus != NULL) {
Andi Kleen69e1a332005-09-12 18:49:24 +0200223 if (pxm >= 0) {
Muli Ben-Yehuda08f1c192007-07-22 00:23:39 +0300224 printk("bus %d -> pxm %d -> node %d\n",
225 busnum, pxm, sd->node);
Andi Kleen69e1a332005-09-12 18:49:24 +0200226 }
227 }
228#endif
Gary Hade62f420f2007-10-03 15:56:51 -0700229
230 if (bus && (pci_probe & PCI_USE__CRS))
231 get_current_resources(device, busnum, bus);
Andi Kleen69e1a332005-09-12 18:49:24 +0200232
233 return bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236extern int pci_routeirq;
237static int __init pci_acpi_init(void)
238{
239 struct pci_dev *dev = NULL;
240
241 if (pcibios_scanned)
242 return 0;
243
244 if (acpi_noirq)
245 return 0;
246
247 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
248 acpi_irq_penalty_init();
249 pcibios_scanned++;
250 pcibios_enable_irq = acpi_pci_irq_enable;
David Shaohua Li87bec662005-07-27 23:02:00 -0400251 pcibios_disable_irq = acpi_pci_irq_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 if (pci_routeirq) {
254 /*
255 * PCI IRQ routing is set up by pci_enable_device(), but we
256 * also do it here in case there are still broken drivers that
257 * don't use pci_enable_device().
258 */
259 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
Hanna Linderfb37fb92005-11-06 23:39:36 -0800260 for_each_pci_dev(dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 acpi_pci_irq_enable(dev);
262 } else
263 printk(KERN_INFO "PCI: If a device doesn't work, try \"pci=routeirq\". If it helps, post a report\n");
264
265#ifdef CONFIG_X86_IO_APIC
266 if (acpi_ioapic)
267 print_IO_APIC();
268#endif
269
270 return 0;
271}
272subsys_initcall(pci_acpi_init);