2 #include <linux/acpi.h>
3 #include <linux/init.h>
7 #include <asm/pci_x86.h>
10 struct acpi_device *bridge;
19 resource_to_addr(struct acpi_resource *resource,
20 struct acpi_resource_address64 *addr)
24 status = acpi_resource_to_address64(resource, addr);
25 if (ACPI_SUCCESS(status) &&
26 (addr->resource_type == ACPI_MEMORY_RANGE ||
27 addr->resource_type == ACPI_IO_RANGE) &&
28 addr->address_length > 0 &&
29 addr->producer_consumer == ACPI_PRODUCER) {
36 count_resource(struct acpi_resource *acpi_res, void *data)
38 struct pci_root_info *info = data;
39 struct acpi_resource_address64 addr;
42 status = resource_to_addr(acpi_res, &addr);
43 if (ACPI_SUCCESS(status))
49 bus_has_transparent_bridge(struct pci_bus *bus)
53 list_for_each_entry(dev, &bus->devices, bus_list) {
54 u16 class = dev->class >> 8;
56 if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent)
63 setup_resource(struct acpi_resource *acpi_res, void *data)
65 struct pci_root_info *info = data;
67 struct acpi_resource_address64 addr;
70 struct resource *root;
71 int max_root_bus_resources = PCI_BUS_NUM_RESOURCES;
74 if (bus_has_transparent_bridge(info->bus))
75 max_root_bus_resources -= 3;
77 status = resource_to_addr(acpi_res, &addr);
78 if (!ACPI_SUCCESS(status))
81 if (addr.resource_type == ACPI_MEMORY_RANGE) {
82 root = &iomem_resource;
83 flags = IORESOURCE_MEM;
84 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
85 flags |= IORESOURCE_PREFETCH;
86 } else if (addr.resource_type == ACPI_IO_RANGE) {
87 root = &ioport_resource;
88 flags = IORESOURCE_IO;
92 start = addr.minimum + addr.translation_offset;
93 end = start + addr.address_length - 1;
94 if (info->res_num >= max_root_bus_resources) {
95 if (pci_probe & PCI_USE__CRS)
96 printk(KERN_WARNING "PCI: Failed to allocate "
97 "0x%lx-0x%lx from %s for %s due to _CRS "
98 "returning more than %d resource descriptors\n",
99 (unsigned long) start, (unsigned long) end,
100 root->name, info->name, max_root_bus_resources);
104 res = &info->res[info->res_num];
105 res->name = info->name;
111 if (!(pci_probe & PCI_USE__CRS)) {
112 dev_printk(KERN_DEBUG, &info->bridge->dev,
113 "host bridge window %pR (ignored)\n", res);
117 if (insert_resource(root, res)) {
118 dev_err(&info->bridge->dev,
119 "can't allocate host bridge window %pR\n", res);
121 info->bus->resource[info->res_num] = res;
123 if (addr.translation_offset)
124 dev_info(&info->bridge->dev, "host bridge window %pR "
125 "(PCI address [%#llx-%#llx])\n",
126 res, res->start - addr.translation_offset,
127 res->end - addr.translation_offset);
129 dev_info(&info->bridge->dev,
130 "host bridge window %pR\n", res);
136 get_current_resources(struct acpi_device *device, int busnum,
137 int domain, struct pci_bus *bus)
139 struct pci_root_info info;
142 if (!(pci_probe & PCI_USE__CRS))
143 dev_info(&device->dev,
144 "ignoring host bridge windows from ACPI; "
145 "boot with \"pci=use_crs\" to use them\n");
147 info.bridge = device;
150 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
155 size = sizeof(*info.res) * info.res_num;
156 info.res = kmalloc(size, GFP_KERNEL);
160 info.name = kmalloc(16, GFP_KERNEL);
162 goto name_alloc_fail;
163 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
166 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
177 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
180 struct pci_sysdata *sd;
182 #ifdef CONFIG_ACPI_NUMA
186 if (domain && !pci_domains_supported) {
187 printk(KERN_WARNING "pci_bus %04x:%02x: "
188 "ignored (multiple domains not supported)\n",
194 #ifdef CONFIG_ACPI_NUMA
195 pxm = acpi_get_pxm(device->handle);
197 node = pxm_to_node(pxm);
199 set_mp_bus_to_node(busnum, node);
202 node = get_mp_bus_to_node(busnum);
204 if (node != -1 && !node_online(node))
207 /* Allocate per-root-bus (not per bus) arch-specific data.
208 * TODO: leak; this memory is never freed.
209 * It's arguable whether it's worth the trouble to care.
211 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
213 printk(KERN_WARNING "pci_bus %04x:%02x: "
214 "ignored (out of memory)\n", domain, busnum);
221 * Maybe the desired pci bus has been already scanned. In such case
222 * it is unnecessary to scan the pci bus with the given domain,busnum.
224 bus = pci_find_bus(domain, busnum);
227 * If the desired bus exits, the content of bus->sysdata will
230 memcpy(bus->sysdata, sd, sizeof(*sd));
233 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
235 get_current_resources(device, busnum, domain, bus);
236 bus->subordinate = pci_scan_child_bus(bus);
243 if (bus && node != -1) {
244 #ifdef CONFIG_ACPI_NUMA
246 dev_printk(KERN_DEBUG, &bus->dev,
247 "on NUMA node %d (pxm %d)\n", node, pxm);
249 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
256 int __init pci_acpi_init(void)
258 struct pci_dev *dev = NULL;
266 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
267 acpi_irq_penalty_init();
269 pcibios_enable_irq = acpi_pci_irq_enable;
270 pcibios_disable_irq = acpi_pci_irq_disable;
274 * PCI IRQ routing is set up by pci_enable_device(), but we
275 * also do it here in case there are still broken drivers that
276 * don't use pci_enable_device().
278 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
279 for_each_pci_dev(dev)
280 acpi_pci_irq_enable(dev);