2 #include <linux/acpi.h>
3 #include <linux/init.h>
7 #include <asm/pci_x86.h>
18 resource_to_addr(struct acpi_resource *resource,
19 struct acpi_resource_address64 *addr)
23 status = acpi_resource_to_address64(resource, addr);
24 if (ACPI_SUCCESS(status) &&
25 (addr->resource_type == ACPI_MEMORY_RANGE ||
26 addr->resource_type == ACPI_IO_RANGE) &&
27 addr->address_length > 0 &&
28 addr->producer_consumer == ACPI_PRODUCER) {
35 count_resource(struct acpi_resource *acpi_res, void *data)
37 struct pci_root_info *info = data;
38 struct acpi_resource_address64 addr;
41 status = resource_to_addr(acpi_res, &addr);
42 if (ACPI_SUCCESS(status))
48 bus_has_transparent_bridge(struct pci_bus *bus)
52 list_for_each_entry(dev, &bus->devices, bus_list) {
53 u16 class = dev->class >> 8;
55 if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent)
62 setup_resource(struct acpi_resource *acpi_res, void *data)
64 struct pci_root_info *info = data;
66 struct acpi_resource_address64 addr;
69 struct resource *root;
70 int max_root_bus_resources = PCI_BUS_NUM_RESOURCES;
73 if (bus_has_transparent_bridge(info->bus))
74 max_root_bus_resources -= 3;
76 status = resource_to_addr(acpi_res, &addr);
77 if (!ACPI_SUCCESS(status))
80 if (addr.resource_type == ACPI_MEMORY_RANGE) {
81 root = &iomem_resource;
82 flags = IORESOURCE_MEM;
83 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
84 flags |= IORESOURCE_PREFETCH;
85 } else if (addr.resource_type == ACPI_IO_RANGE) {
86 root = &ioport_resource;
87 flags = IORESOURCE_IO;
91 start = addr.minimum + addr.translation_offset;
92 end = start + addr.address_length - 1;
93 if (info->res_num >= max_root_bus_resources) {
94 printk(KERN_WARNING "PCI: Failed to allocate 0x%lx-0x%lx "
95 "from %s for %s due to _CRS returning more than "
96 "%d resource descriptors\n", (unsigned long) start,
97 (unsigned long) end, root->name, info->name,
98 max_root_bus_resources);
102 res = &info->res[info->res_num];
103 res->name = info->name;
109 if (insert_resource(root, res)) {
110 printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx "
111 "from %s for %s\n", (unsigned long) res->start,
112 (unsigned long) res->end, root->name, info->name);
114 info->bus->resource[info->res_num] = res;
121 get_current_resources(struct acpi_device *device, int busnum,
122 int domain, struct pci_bus *bus)
124 struct pci_root_info info;
129 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
134 size = sizeof(*info.res) * info.res_num;
135 info.res = kmalloc(size, GFP_KERNEL);
139 info.name = kmalloc(16, GFP_KERNEL);
141 goto name_alloc_fail;
142 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
145 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
156 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
159 struct pci_sysdata *sd;
161 #ifdef CONFIG_ACPI_NUMA
165 if (domain && !pci_domains_supported) {
166 printk(KERN_WARNING "PCI: Multiple domains not supported "
167 "(dom %d, bus %d)\n", domain, busnum);
172 #ifdef CONFIG_ACPI_NUMA
173 pxm = acpi_get_pxm(device->handle);
175 node = pxm_to_node(pxm);
177 set_mp_bus_to_node(busnum, node);
180 node = get_mp_bus_to_node(busnum);
182 if (node != -1 && !node_online(node))
185 /* Allocate per-root-bus (not per bus) arch-specific data.
186 * TODO: leak; this memory is never freed.
187 * It's arguable whether it's worth the trouble to care.
189 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
191 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
198 * Maybe the desired pci bus has been already scanned. In such case
199 * it is unnecessary to scan the pci bus with the given domain,busnum.
201 bus = pci_find_bus(domain, busnum);
204 * If the desired bus exits, the content of bus->sysdata will
207 memcpy(bus->sysdata, sd, sizeof(*sd));
210 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
212 if (pci_probe & PCI_USE__CRS)
213 get_current_resources(device, busnum, domain,
215 bus->subordinate = pci_scan_child_bus(bus);
222 if (bus && node != -1) {
223 #ifdef CONFIG_ACPI_NUMA
225 dev_printk(KERN_DEBUG, &bus->dev,
226 "on NUMA node %d (pxm %d)\n", node, pxm);
228 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
235 int __init pci_acpi_init(void)
237 struct pci_dev *dev = NULL;
245 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
246 acpi_irq_penalty_init();
248 pcibios_enable_irq = acpi_pci_irq_enable;
249 pcibios_disable_irq = acpi_pci_irq_disable;
253 * PCI IRQ routing is set up by pci_enable_device(), but we
254 * also do it here in case there are still broken drivers that
255 * don't use pci_enable_device().
257 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
258 for_each_pci_dev(dev)
259 acpi_pci_irq_enable(dev);