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;
72 status = resource_to_addr(acpi_res, &addr);
73 if (!ACPI_SUCCESS(status))
76 if (addr.resource_type == ACPI_MEMORY_RANGE) {
77 root = &iomem_resource;
78 flags = IORESOURCE_MEM;
79 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
80 flags |= IORESOURCE_PREFETCH;
81 } else if (addr.resource_type == ACPI_IO_RANGE) {
82 root = &ioport_resource;
83 flags = IORESOURCE_IO;
87 res = &info->res[info->res_num];
88 res->name = info->name;
90 res->start = addr.minimum + addr.translation_offset;
91 res->end = res->start + addr.address_length - 1;
94 if (bus_has_transparent_bridge(info->bus))
95 max_root_bus_resources -= 3;
96 if (info->res_num >= max_root_bus_resources) {
97 printk(KERN_WARNING "PCI: Failed to allocate 0x%lx-0x%lx "
98 "from %s for %s due to _CRS returning more than "
99 "%d resource descriptors\n", (unsigned long) res->start,
100 (unsigned long) res->end, root->name, info->name,
101 max_root_bus_resources);
106 if (insert_resource(root, res)) {
107 printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx "
108 "from %s for %s\n", (unsigned long) res->start,
109 (unsigned long) res->end, root->name, info->name);
111 info->bus->resource[info->res_num] = res;
118 adjust_transparent_bridge_resources(struct pci_bus *bus)
122 list_for_each_entry(dev, &bus->devices, bus_list) {
124 u16 class = dev->class >> 8;
126 if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) {
127 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
128 dev->subordinate->resource[i] =
129 dev->bus->resource[i - 3];
135 get_current_resources(struct acpi_device *device, int busnum,
136 int domain, struct pci_bus *bus)
138 struct pci_root_info info;
143 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
148 size = sizeof(*info.res) * info.res_num;
149 info.res = kmalloc(size, GFP_KERNEL);
153 info.name = kmalloc(16, GFP_KERNEL);
155 goto name_alloc_fail;
156 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
159 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
162 adjust_transparent_bridge_resources(bus);
172 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
175 struct pci_sysdata *sd;
177 #ifdef CONFIG_ACPI_NUMA
181 if (domain && !pci_domains_supported) {
182 printk(KERN_WARNING "PCI: Multiple domains not supported "
183 "(dom %d, bus %d)\n", domain, busnum);
188 #ifdef CONFIG_ACPI_NUMA
189 pxm = acpi_get_pxm(device->handle);
191 node = pxm_to_node(pxm);
193 set_mp_bus_to_node(busnum, node);
196 node = get_mp_bus_to_node(busnum);
198 if (node != -1 && !node_online(node))
201 /* Allocate per-root-bus (not per bus) arch-specific data.
202 * TODO: leak; this memory is never freed.
203 * It's arguable whether it's worth the trouble to care.
205 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
207 printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
214 * Maybe the desired pci bus has been already scanned. In such case
215 * it is unnecessary to scan the pci bus with the given domain,busnum.
217 bus = pci_find_bus(domain, busnum);
220 * If the desired bus exits, the content of bus->sysdata will
223 memcpy(bus->sysdata, sd, sizeof(*sd));
226 bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
231 if (bus && node != -1) {
232 #ifdef CONFIG_ACPI_NUMA
234 dev_printk(KERN_DEBUG, &bus->dev,
235 "on NUMA node %d (pxm %d)\n", node, pxm);
237 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
241 if (bus && (pci_probe & PCI_USE__CRS))
242 get_current_resources(device, busnum, domain, bus);
246 int __init pci_acpi_init(void)
248 struct pci_dev *dev = NULL;
256 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
257 acpi_irq_penalty_init();
259 pcibios_enable_irq = acpi_pci_irq_enable;
260 pcibios_disable_irq = acpi_pci_irq_disable;
264 * PCI IRQ routing is set up by pci_enable_device(), but we
265 * also do it here in case there are still broken drivers that
266 * don't use pci_enable_device().
268 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
269 for_each_pci_dev(dev)
270 acpi_pci_irq_enable(dev);