edac: e752x fsb ecc
[linux-2.6/x86.git] / arch / x86 / pci / acpi.c
blob6e22454bfaa6d51e4f22ce9eb5c379e1770319d6
1 #include <linux/pci.h>
2 #include <linux/acpi.h>
3 #include <linux/init.h>
4 #include <linux/irq.h>
5 #include <linux/dmi.h>
6 #include <asm/numa.h>
7 #include <asm/pci_x86.h>
9 struct pci_root_info {
10 struct acpi_device *bridge;
11 char *name;
12 unsigned int res_num;
13 struct resource *res;
14 struct pci_bus *bus;
15 int busnum;
18 static bool pci_use_crs = true;
20 static int __init set_use_crs(const struct dmi_system_id *id)
22 pci_use_crs = true;
23 return 0;
26 static const struct dmi_system_id pci_use_crs_table[] __initconst = {
27 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
29 .callback = set_use_crs,
30 .ident = "IBM System x3800",
31 .matches = {
32 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
33 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
39 void __init pci_acpi_crs_quirks(void)
41 int year;
43 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
44 pci_use_crs = false;
46 dmi_check_system(pci_use_crs_table);
49 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
50 * takes precedence over anything we figured out above.
52 if (pci_probe & PCI_ROOT_NO_CRS)
53 pci_use_crs = false;
54 else if (pci_probe & PCI_USE__CRS)
55 pci_use_crs = true;
57 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
58 "if necessary, use \"pci=%s\" and report a bug\n",
59 pci_use_crs ? "Using" : "Ignoring",
60 pci_use_crs ? "nocrs" : "use_crs");
63 static acpi_status
64 resource_to_addr(struct acpi_resource *resource,
65 struct acpi_resource_address64 *addr)
67 acpi_status status;
69 status = acpi_resource_to_address64(resource, addr);
70 if (ACPI_SUCCESS(status) &&
71 (addr->resource_type == ACPI_MEMORY_RANGE ||
72 addr->resource_type == ACPI_IO_RANGE) &&
73 addr->address_length > 0 &&
74 addr->producer_consumer == ACPI_PRODUCER) {
75 return AE_OK;
77 return AE_ERROR;
80 static acpi_status
81 count_resource(struct acpi_resource *acpi_res, void *data)
83 struct pci_root_info *info = data;
84 struct acpi_resource_address64 addr;
85 acpi_status status;
87 status = resource_to_addr(acpi_res, &addr);
88 if (ACPI_SUCCESS(status))
89 info->res_num++;
90 return AE_OK;
93 static void
94 align_resource(struct acpi_device *bridge, struct resource *res)
96 int align = (res->flags & IORESOURCE_MEM) ? 16 : 4;
99 * Host bridge windows are not BARs, but the decoders on the PCI side
100 * that claim this address space have starting alignment and length
101 * constraints, so fix any obvious BIOS goofs.
103 if (!IS_ALIGNED(res->start, align)) {
104 dev_printk(KERN_DEBUG, &bridge->dev,
105 "host bridge window %pR invalid; "
106 "aligning start to %d-byte boundary\n", res, align);
107 res->start &= ~(align - 1);
109 if (!IS_ALIGNED(res->end + 1, align)) {
110 dev_printk(KERN_DEBUG, &bridge->dev,
111 "host bridge window %pR invalid; "
112 "aligning end to %d-byte boundary\n", res, align);
113 res->end = ALIGN(res->end, align) - 1;
117 static acpi_status
118 setup_resource(struct acpi_resource *acpi_res, void *data)
120 struct pci_root_info *info = data;
121 struct resource *res;
122 struct acpi_resource_address64 addr;
123 acpi_status status;
124 unsigned long flags;
125 struct resource *root;
126 u64 start, end;
128 status = resource_to_addr(acpi_res, &addr);
129 if (!ACPI_SUCCESS(status))
130 return AE_OK;
132 if (addr.resource_type == ACPI_MEMORY_RANGE) {
133 root = &iomem_resource;
134 flags = IORESOURCE_MEM;
135 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
136 flags |= IORESOURCE_PREFETCH;
137 } else if (addr.resource_type == ACPI_IO_RANGE) {
138 root = &ioport_resource;
139 flags = IORESOURCE_IO;
140 } else
141 return AE_OK;
143 start = addr.minimum + addr.translation_offset;
144 end = start + addr.address_length - 1;
146 res = &info->res[info->res_num];
147 res->name = info->name;
148 res->flags = flags;
149 res->start = start;
150 res->end = end;
151 res->child = NULL;
152 align_resource(info->bridge, res);
154 if (!pci_use_crs) {
155 dev_printk(KERN_DEBUG, &info->bridge->dev,
156 "host bridge window %pR (ignored)\n", res);
157 return AE_OK;
160 if (insert_resource(root, res)) {
161 dev_err(&info->bridge->dev,
162 "can't allocate host bridge window %pR\n", res);
163 } else {
164 pci_bus_add_resource(info->bus, res, 0);
165 info->res_num++;
166 if (addr.translation_offset)
167 dev_info(&info->bridge->dev, "host bridge window %pR "
168 "(PCI address [%#llx-%#llx])\n",
169 res, res->start - addr.translation_offset,
170 res->end - addr.translation_offset);
171 else
172 dev_info(&info->bridge->dev,
173 "host bridge window %pR\n", res);
175 return AE_OK;
178 static void
179 get_current_resources(struct acpi_device *device, int busnum,
180 int domain, struct pci_bus *bus)
182 struct pci_root_info info;
183 size_t size;
185 if (pci_use_crs)
186 pci_bus_remove_resources(bus);
188 info.bridge = device;
189 info.bus = bus;
190 info.res_num = 0;
191 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
192 &info);
193 if (!info.res_num)
194 return;
196 size = sizeof(*info.res) * info.res_num;
197 info.res = kmalloc(size, GFP_KERNEL);
198 if (!info.res)
199 goto res_alloc_fail;
201 info.name = kmalloc(16, GFP_KERNEL);
202 if (!info.name)
203 goto name_alloc_fail;
204 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
206 info.res_num = 0;
207 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
208 &info);
210 return;
212 name_alloc_fail:
213 kfree(info.res);
214 res_alloc_fail:
215 return;
218 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
220 struct pci_bus *bus;
221 struct pci_sysdata *sd;
222 int node;
223 #ifdef CONFIG_ACPI_NUMA
224 int pxm;
225 #endif
227 if (domain && !pci_domains_supported) {
228 printk(KERN_WARNING "pci_bus %04x:%02x: "
229 "ignored (multiple domains not supported)\n",
230 domain, busnum);
231 return NULL;
234 node = -1;
235 #ifdef CONFIG_ACPI_NUMA
236 pxm = acpi_get_pxm(device->handle);
237 if (pxm >= 0)
238 node = pxm_to_node(pxm);
239 if (node != -1)
240 set_mp_bus_to_node(busnum, node);
241 else
242 #endif
243 node = get_mp_bus_to_node(busnum);
245 if (node != -1 && !node_online(node))
246 node = -1;
248 /* Allocate per-root-bus (not per bus) arch-specific data.
249 * TODO: leak; this memory is never freed.
250 * It's arguable whether it's worth the trouble to care.
252 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
253 if (!sd) {
254 printk(KERN_WARNING "pci_bus %04x:%02x: "
255 "ignored (out of memory)\n", domain, busnum);
256 return NULL;
259 sd->domain = domain;
260 sd->node = node;
262 * Maybe the desired pci bus has been already scanned. In such case
263 * it is unnecessary to scan the pci bus with the given domain,busnum.
265 bus = pci_find_bus(domain, busnum);
266 if (bus) {
268 * If the desired bus exits, the content of bus->sysdata will
269 * be replaced by sd.
271 memcpy(bus->sysdata, sd, sizeof(*sd));
272 kfree(sd);
273 } else {
274 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
275 if (bus) {
276 get_current_resources(device, busnum, domain, bus);
277 bus->subordinate = pci_scan_child_bus(bus);
281 if (!bus)
282 kfree(sd);
284 if (bus && node != -1) {
285 #ifdef CONFIG_ACPI_NUMA
286 if (pxm >= 0)
287 dev_printk(KERN_DEBUG, &bus->dev,
288 "on NUMA node %d (pxm %d)\n", node, pxm);
289 #else
290 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
291 #endif
294 return bus;
297 int __init pci_acpi_init(void)
299 struct pci_dev *dev = NULL;
301 if (acpi_noirq)
302 return -ENODEV;
304 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
305 acpi_irq_penalty_init();
306 pcibios_enable_irq = acpi_pci_irq_enable;
307 pcibios_disable_irq = acpi_pci_irq_disable;
308 x86_init.pci.init_irq = x86_init_noop;
310 if (pci_routeirq) {
312 * PCI IRQ routing is set up by pci_enable_device(), but we
313 * also do it here in case there are still broken drivers that
314 * don't use pci_enable_device().
316 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
317 for_each_pci_dev(dev)
318 acpi_pci_irq_enable(dev);
321 return 0;