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 align_resource(struct acpi_device *bridge, struct resource *res)
65 int align = (res->flags & IORESOURCE_MEM) ? 16 : 4;
68 * Host bridge windows are not BARs, but the decoders on the PCI side
69 * that claim this address space have starting alignment and length
70 * constraints, so fix any obvious BIOS goofs.
72 if (!IS_ALIGNED(res->start, align)) {
73 dev_printk(KERN_DEBUG, &bridge->dev,
74 "host bridge window %pR invalid; "
75 "aligning start to %d-byte boundary\n", res, align);
76 res->start &= ~(align - 1);
78 if (!IS_ALIGNED(res->end + 1, align)) {
79 dev_printk(KERN_DEBUG, &bridge->dev,
80 "host bridge window %pR invalid; "
81 "aligning end to %d-byte boundary\n", res, align);
82 res->end = ALIGN(res->end, align) - 1;
87 setup_resource(struct acpi_resource *acpi_res, void *data)
89 struct pci_root_info *info = data;
91 struct acpi_resource_address64 addr;
94 struct resource *root;
95 int max_root_bus_resources = PCI_BUS_NUM_RESOURCES;
98 if (bus_has_transparent_bridge(info->bus))
99 max_root_bus_resources -= 3;
101 status = resource_to_addr(acpi_res, &addr);
102 if (!ACPI_SUCCESS(status))
105 if (addr.resource_type == ACPI_MEMORY_RANGE) {
106 root = &iomem_resource;
107 flags = IORESOURCE_MEM;
108 if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
109 flags |= IORESOURCE_PREFETCH;
110 } else if (addr.resource_type == ACPI_IO_RANGE) {
111 root = &ioport_resource;
112 flags = IORESOURCE_IO;
116 start = addr.minimum + addr.translation_offset;
117 end = start + addr.address_length - 1;
118 if (info->res_num >= max_root_bus_resources) {
119 if (pci_probe & PCI_USE__CRS)
120 printk(KERN_WARNING "PCI: Failed to allocate "
121 "0x%lx-0x%lx from %s for %s due to _CRS "
122 "returning more than %d resource descriptors\n",
123 (unsigned long) start, (unsigned long) end,
124 root->name, info->name, max_root_bus_resources);
128 res = &info->res[info->res_num];
129 res->name = info->name;
134 align_resource(info->bridge, res);
136 if (!(pci_probe & PCI_USE__CRS)) {
137 dev_printk(KERN_DEBUG, &info->bridge->dev,
138 "host bridge window %pR (ignored)\n", res);
142 if (insert_resource(root, res)) {
143 dev_err(&info->bridge->dev,
144 "can't allocate host bridge window %pR\n", res);
146 info->bus->resource[info->res_num] = res;
148 if (addr.translation_offset)
149 dev_info(&info->bridge->dev, "host bridge window %pR "
150 "(PCI address [%#llx-%#llx])\n",
151 res, res->start - addr.translation_offset,
152 res->end - addr.translation_offset);
154 dev_info(&info->bridge->dev,
155 "host bridge window %pR\n", res);
161 get_current_resources(struct acpi_device *device, int busnum,
162 int domain, struct pci_bus *bus)
164 struct pci_root_info info;
167 if (!(pci_probe & PCI_USE__CRS))
168 dev_info(&device->dev,
169 "ignoring host bridge windows from ACPI; "
170 "boot with \"pci=use_crs\" to use them\n");
172 info.bridge = device;
175 acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
180 size = sizeof(*info.res) * info.res_num;
181 info.res = kmalloc(size, GFP_KERNEL);
185 info.name = kmalloc(16, GFP_KERNEL);
187 goto name_alloc_fail;
188 sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
191 acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
202 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
205 struct pci_sysdata *sd;
207 #ifdef CONFIG_ACPI_NUMA
211 if (domain && !pci_domains_supported) {
212 printk(KERN_WARNING "pci_bus %04x:%02x: "
213 "ignored (multiple domains not supported)\n",
219 #ifdef CONFIG_ACPI_NUMA
220 pxm = acpi_get_pxm(device->handle);
222 node = pxm_to_node(pxm);
224 set_mp_bus_to_node(busnum, node);
227 node = get_mp_bus_to_node(busnum);
229 if (node != -1 && !node_online(node))
232 /* Allocate per-root-bus (not per bus) arch-specific data.
233 * TODO: leak; this memory is never freed.
234 * It's arguable whether it's worth the trouble to care.
236 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
238 printk(KERN_WARNING "pci_bus %04x:%02x: "
239 "ignored (out of memory)\n", domain, busnum);
246 * Maybe the desired pci bus has been already scanned. In such case
247 * it is unnecessary to scan the pci bus with the given domain,busnum.
249 bus = pci_find_bus(domain, busnum);
252 * If the desired bus exits, the content of bus->sysdata will
255 memcpy(bus->sysdata, sd, sizeof(*sd));
258 bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
260 get_current_resources(device, busnum, domain, bus);
261 bus->subordinate = pci_scan_child_bus(bus);
268 if (bus && node != -1) {
269 #ifdef CONFIG_ACPI_NUMA
271 dev_printk(KERN_DEBUG, &bus->dev,
272 "on NUMA node %d (pxm %d)\n", node, pxm);
274 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
281 int __init pci_acpi_init(void)
283 struct pci_dev *dev = NULL;
291 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
292 acpi_irq_penalty_init();
294 pcibios_enable_irq = acpi_pci_irq_enable;
295 pcibios_disable_irq = acpi_pci_irq_disable;
299 * PCI IRQ routing is set up by pci_enable_device(), but we
300 * also do it here in case there are still broken drivers that
301 * don't use pci_enable_device().
303 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
304 for_each_pci_dev(dev)
305 acpi_pci_irq_enable(dev);