2 #include <linux/acpi.h>
3 #include <linux/init.h>
6 #include <linux/slab.h>
8 #include <asm/pci_x86.h>
10 struct pci_root_info {
11 struct acpi_device *bridge;
19 static bool pci_use_crs = true;
21 static int __init set_use_crs(const struct dmi_system_id *id)
27 static int __init set_nouse_crs(const struct dmi_system_id *id)
33 static const struct dmi_system_id pci_use_crs_table[] __initconst = {
34 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
36 .callback = set_use_crs,
37 .ident = "IBM System x3800",
39 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
40 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
43 /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
44 /* 2006 AMD HT/VIA system with two host bridges */
46 .callback = set_use_crs,
47 .ident = "ASRock ALiveSATA2-GLAN",
49 DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
52 /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
53 /* 2006 AMD HT/VIA system with two host bridges */
55 .callback = set_use_crs,
56 .ident = "ASUS M2V-MX SE",
58 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
59 DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"),
60 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
67 void __init pci_acpi_crs_quirks(void)
71 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
74 dmi_check_system(pci_use_crs_table);
77 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
78 * takes precedence over anything we figured out above.
80 if (pci_probe & PCI_ROOT_NO_CRS)
82 else if (pci_probe & PCI_USE__CRS)
85 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
86 "if necessary, use \"pci=%s\" and report a bug\n",
87 pci_use_crs ? "Using" : "Ignoring",
88 pci_use_crs ? "nocrs" : "use_crs");
92 resource_to_addr(struct acpi_resource *resource,
93 struct acpi_resource_address64 *addr)
96 struct acpi_resource_memory24 *memory24;
97 struct acpi_resource_memory32 *memory32;
98 struct acpi_resource_fixed_memory32 *fixed_memory32;
100 memset(addr, 0, sizeof(*addr));
101 switch (resource->type) {
102 case ACPI_RESOURCE_TYPE_MEMORY24:
103 memory24 = &resource->data.memory24;
104 addr->resource_type = ACPI_MEMORY_RANGE;
105 addr->minimum = memory24->minimum;
106 addr->address_length = memory24->address_length;
107 addr->maximum = addr->minimum + addr->address_length - 1;
109 case ACPI_RESOURCE_TYPE_MEMORY32:
110 memory32 = &resource->data.memory32;
111 addr->resource_type = ACPI_MEMORY_RANGE;
112 addr->minimum = memory32->minimum;
113 addr->address_length = memory32->address_length;
114 addr->maximum = addr->minimum + addr->address_length - 1;
116 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
117 fixed_memory32 = &resource->data.fixed_memory32;
118 addr->resource_type = ACPI_MEMORY_RANGE;
119 addr->minimum = fixed_memory32->address;
120 addr->address_length = fixed_memory32->address_length;
121 addr->maximum = addr->minimum + addr->address_length - 1;
123 case ACPI_RESOURCE_TYPE_ADDRESS16:
124 case ACPI_RESOURCE_TYPE_ADDRESS32:
125 case ACPI_RESOURCE_TYPE_ADDRESS64:
126 status = acpi_resource_to_address64(resource, addr);
127 if (ACPI_SUCCESS(status) &&
128 (addr->resource_type == ACPI_MEMORY_RANGE ||
129 addr->resource_type == ACPI_IO_RANGE) &&
130 addr->address_length > 0) {
139 count_resource(struct acpi_resource *acpi_res, void *data)
141 struct pci_root_info *info = data;
142 struct acpi_resource_address64 addr;
145 status = resource_to_addr(acpi_res, &addr);
146 if (ACPI_SUCCESS(status))
152 setup_resource(struct acpi_resource *acpi_res, void *data)
154 struct pci_root_info *info = data;
155 struct resource *res;
156 struct acpi_resource_address64 addr;
161 status = resource_to_addr(acpi_res, &addr);
162 if (!ACPI_SUCCESS(status))
165 if (addr.resource_type == ACPI_MEMORY_RANGE) {
166 flags = IORESOURCE_MEM;
167 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
168 flags |= IORESOURCE_PREFETCH;
169 } else if (addr.resource_type == ACPI_IO_RANGE) {
170 flags = IORESOURCE_IO;
174 start = addr.minimum + addr.translation_offset;
175 end = addr.maximum + addr.translation_offset;
177 res = &info->res[info->res_num];
178 res->name = info->name;
185 dev_printk(KERN_DEBUG, &info->bridge->dev,
186 "host bridge window %pR (ignored)\n", res);
191 if (addr.translation_offset)
192 dev_info(&info->bridge->dev, "host bridge window %pR "
193 "(PCI address [%#llx-%#llx])\n",
194 res, res->start - addr.translation_offset,
195 res->end - addr.translation_offset);
197 dev_info(&info->bridge->dev, "host bridge window %pR\n", res);
202 static bool resource_contains(struct resource *res, resource_size_t point)
204 if (res->start <= point && point <= res->end)
209 static void coalesce_windows(struct pci_root_info *info, unsigned long type)
212 struct resource *res1, *res2;
214 for (i = 0; i < info->res_num; i++) {
215 res1 = &info->res[i];
216 if (!(res1->flags & type))
219 for (j = i + 1; j < info->res_num; j++) {
220 res2 = &info->res[j];
221 if (!(res2->flags & type))
225 * I don't like throwing away windows because then
226 * our resources no longer match the ACPI _CRS, but
227 * the kernel resource tree doesn't allow overlaps.
229 if (resource_contains(res1, res2->start) ||
230 resource_contains(res1, res2->end) ||
231 resource_contains(res2, res1->start) ||
232 resource_contains(res2, res1->end)) {
233 res1->start = min(res1->start, res2->start);
234 res1->end = max(res1->end, res2->end);
235 dev_info(&info->bridge->dev,
236 "host bridge window expanded to %pR; %pR ignored\n",
244 static void add_resources(struct pci_root_info *info)
247 struct resource *res, *root, *conflict;
252 coalesce_windows(info, IORESOURCE_MEM);
253 coalesce_windows(info, IORESOURCE_IO);
255 for (i = 0; i < info->res_num; i++) {
258 if (res->flags & IORESOURCE_MEM)
259 root = &iomem_resource;
260 else if (res->flags & IORESOURCE_IO)
261 root = &ioport_resource;
265 conflict = insert_resource_conflict(root, res);
267 dev_info(&info->bridge->dev,
268 "ignoring host bridge window %pR (conflicts with %s %pR)\n",
269 res, conflict->name, conflict);
271 pci_bus_add_resource(info->bus, res, 0);
276 get_current_resources(struct acpi_device *device, int busnum,
277 int domain, struct pci_bus *bus)
279 struct pci_root_info info;
283 pci_bus_remove_resources(bus);
285 info.bridge = device;
288 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
293 size = sizeof(*info.res) * info.res_num;
294 info.res = kmalloc(size, GFP_KERNEL);
298 info.name = kasprintf(GFP_KERNEL, "PCI Bus %04x:%02x", domain, busnum);
300 goto name_alloc_fail;
303 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
306 add_resources(&info);
315 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
317 struct acpi_device *device = root->device;
318 int domain = root->segment;
319 int busnum = root->secondary.start;
321 struct pci_sysdata *sd;
323 #ifdef CONFIG_ACPI_NUMA
327 if (domain && !pci_domains_supported) {
328 printk(KERN_WARNING "pci_bus %04x:%02x: "
329 "ignored (multiple domains not supported)\n",
335 #ifdef CONFIG_ACPI_NUMA
336 pxm = acpi_get_pxm(device->handle);
338 node = pxm_to_node(pxm);
340 set_mp_bus_to_node(busnum, node);
343 node = get_mp_bus_to_node(busnum);
345 if (node != -1 && !node_online(node))
348 /* Allocate per-root-bus (not per bus) arch-specific data.
349 * TODO: leak; this memory is never freed.
350 * It's arguable whether it's worth the trouble to care.
352 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
354 printk(KERN_WARNING "pci_bus %04x:%02x: "
355 "ignored (out of memory)\n", domain, busnum);
362 * Maybe the desired pci bus has been already scanned. In such case
363 * it is unnecessary to scan the pci bus with the given domain,busnum.
365 bus = pci_find_bus(domain, busnum);
368 * If the desired bus exits, the content of bus->sysdata will
371 memcpy(bus->sysdata, sd, sizeof(*sd));
374 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
376 get_current_resources(device, busnum, domain, bus);
377 bus->subordinate = pci_scan_child_bus(bus);
381 /* After the PCI-E bus has been walked and all devices discovered,
382 * configure any settings of the fabric that might be necessary.
385 struct pci_bus *child;
386 list_for_each_entry(child, &bus->children, node) {
387 struct pci_dev *self = child->self;
391 pcie_bus_configure_settings(child, self->pcie_mpss);
398 if (bus && node != -1) {
399 #ifdef CONFIG_ACPI_NUMA
401 dev_printk(KERN_DEBUG, &bus->dev,
402 "on NUMA node %d (pxm %d)\n", node, pxm);
404 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
411 int __init pci_acpi_init(void)
413 struct pci_dev *dev = NULL;
418 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
419 acpi_irq_penalty_init();
420 pcibios_enable_irq = acpi_pci_irq_enable;
421 pcibios_disable_irq = acpi_pci_irq_disable;
422 x86_init.pci.init_irq = x86_init_noop;
426 * PCI IRQ routing is set up by pci_enable_device(), but we
427 * also do it here in case there are still broken drivers that
428 * don't use pci_enable_device().
430 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
431 for_each_pci_dev(dev)
432 acpi_pci_irq_enable(dev);