Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/pci.h> |
| 2 | #include <linux/acpi.h> |
| 3 | #include <linux/init.h> |
Nick Piggin | b33fa1f | 2005-10-01 02:34:42 +1000 | [diff] [blame] | 4 | #include <linux/irq.h> |
Gary Hade | 036fff4 | 2007-10-03 15:56:14 -0700 | [diff] [blame] | 5 | #include <linux/dmi.h> |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 6 | #include <asm/numa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "pci.h" |
| 8 | |
Jeff Garzik | 752097c | 2007-10-12 22:34:40 -0400 | [diff] [blame] | 9 | static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d) |
Gary Hade | 036fff4 | 2007-10-03 15:56:14 -0700 | [diff] [blame] | 10 | { |
| 11 | pci_probe |= PCI_CAN_SKIP_ISA_ALIGN; |
| 12 | printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident); |
| 13 | return 0; |
| 14 | } |
| 15 | |
Adrian Bunk | 55b8d50 | 2007-11-09 07:02:11 +0100 | [diff] [blame^] | 16 | static struct dmi_system_id acpi_pciprobe_dmi_table[] __devinitdata = { |
Gary Hade | 036fff4 | 2007-10-03 15:56:14 -0700 | [diff] [blame] | 17 | /* |
| 18 | * Systems where PCI IO resource ISA alignment can be skipped |
| 19 | * when the ISA enable bit in the bridge control is not set |
| 20 | */ |
| 21 | { |
| 22 | .callback = can_skip_ioresource_align, |
| 23 | .ident = "IBM System x3800", |
| 24 | .matches = { |
| 25 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 26 | DMI_MATCH(DMI_PRODUCT_NAME, "x3800"), |
| 27 | }, |
| 28 | }, |
| 29 | { |
| 30 | .callback = can_skip_ioresource_align, |
| 31 | .ident = "IBM System x3850", |
| 32 | .matches = { |
| 33 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 34 | DMI_MATCH(DMI_PRODUCT_NAME, "x3850"), |
| 35 | }, |
| 36 | }, |
| 37 | { |
| 38 | .callback = can_skip_ioresource_align, |
| 39 | .ident = "IBM System x3950", |
| 40 | .matches = { |
| 41 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 42 | DMI_MATCH(DMI_PRODUCT_NAME, "x3950"), |
| 43 | }, |
| 44 | }, |
| 45 | {} |
| 46 | }; |
| 47 | |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 48 | struct pci_root_info { |
| 49 | char *name; |
| 50 | unsigned int res_num; |
| 51 | struct resource *res; |
| 52 | struct pci_bus *bus; |
| 53 | int busnum; |
| 54 | }; |
| 55 | |
| 56 | static acpi_status |
| 57 | resource_to_addr(struct acpi_resource *resource, |
| 58 | struct acpi_resource_address64 *addr) |
| 59 | { |
| 60 | acpi_status status; |
| 61 | |
| 62 | status = acpi_resource_to_address64(resource, addr); |
| 63 | if (ACPI_SUCCESS(status) && |
| 64 | (addr->resource_type == ACPI_MEMORY_RANGE || |
| 65 | addr->resource_type == ACPI_IO_RANGE) && |
| 66 | addr->address_length > 0 && |
| 67 | addr->producer_consumer == ACPI_PRODUCER) { |
| 68 | return AE_OK; |
| 69 | } |
| 70 | return AE_ERROR; |
| 71 | } |
| 72 | |
| 73 | static acpi_status |
| 74 | count_resource(struct acpi_resource *acpi_res, void *data) |
| 75 | { |
| 76 | struct pci_root_info *info = data; |
| 77 | struct acpi_resource_address64 addr; |
| 78 | acpi_status status; |
| 79 | |
| 80 | status = resource_to_addr(acpi_res, &addr); |
| 81 | if (ACPI_SUCCESS(status)) |
| 82 | info->res_num++; |
| 83 | return AE_OK; |
| 84 | } |
| 85 | |
| 86 | static acpi_status |
| 87 | setup_resource(struct acpi_resource *acpi_res, void *data) |
| 88 | { |
| 89 | struct pci_root_info *info = data; |
| 90 | struct resource *res; |
| 91 | struct acpi_resource_address64 addr; |
| 92 | acpi_status status; |
| 93 | unsigned long flags; |
| 94 | struct resource *root; |
| 95 | |
| 96 | status = resource_to_addr(acpi_res, &addr); |
| 97 | if (!ACPI_SUCCESS(status)) |
| 98 | return AE_OK; |
| 99 | |
| 100 | if (addr.resource_type == ACPI_MEMORY_RANGE) { |
| 101 | root = &iomem_resource; |
| 102 | flags = IORESOURCE_MEM; |
| 103 | if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY) |
| 104 | flags |= IORESOURCE_PREFETCH; |
| 105 | } else if (addr.resource_type == ACPI_IO_RANGE) { |
| 106 | root = &ioport_resource; |
| 107 | flags = IORESOURCE_IO; |
| 108 | } else |
| 109 | return AE_OK; |
| 110 | |
| 111 | res = &info->res[info->res_num]; |
| 112 | res->name = info->name; |
| 113 | res->flags = flags; |
| 114 | res->start = addr.minimum + addr.translation_offset; |
| 115 | res->end = res->start + addr.address_length - 1; |
| 116 | res->child = NULL; |
| 117 | |
| 118 | if (insert_resource(root, res)) { |
| 119 | printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx " |
| 120 | "from %s for %s\n", (unsigned long) res->start, |
| 121 | (unsigned long) res->end, root->name, info->name); |
| 122 | } else { |
| 123 | info->bus->resource[info->res_num] = res; |
| 124 | info->res_num++; |
| 125 | } |
| 126 | return AE_OK; |
| 127 | } |
| 128 | |
| 129 | static void |
| 130 | adjust_transparent_bridge_resources(struct pci_bus *bus) |
| 131 | { |
| 132 | struct pci_dev *dev; |
| 133 | |
| 134 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 135 | int i; |
| 136 | u16 class = dev->class >> 8; |
| 137 | |
| 138 | if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) { |
| 139 | for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++) |
| 140 | dev->subordinate->resource[i] = |
| 141 | dev->bus->resource[i - 3]; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | static void |
| 147 | get_current_resources(struct acpi_device *device, int busnum, |
| 148 | struct pci_bus *bus) |
| 149 | { |
| 150 | struct pci_root_info info; |
| 151 | size_t size; |
| 152 | |
| 153 | info.bus = bus; |
| 154 | info.res_num = 0; |
| 155 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource, |
| 156 | &info); |
| 157 | if (!info.res_num) |
| 158 | return; |
| 159 | |
| 160 | size = sizeof(*info.res) * info.res_num; |
| 161 | info.res = kmalloc(size, GFP_KERNEL); |
| 162 | if (!info.res) |
| 163 | goto res_alloc_fail; |
| 164 | |
| 165 | info.name = kmalloc(12, GFP_KERNEL); |
| 166 | if (!info.name) |
| 167 | goto name_alloc_fail; |
| 168 | sprintf(info.name, "PCI Bus #%02x", busnum); |
| 169 | |
| 170 | info.res_num = 0; |
| 171 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource, |
| 172 | &info); |
| 173 | if (info.res_num) |
| 174 | adjust_transparent_bridge_resources(bus); |
| 175 | |
| 176 | return; |
| 177 | |
| 178 | name_alloc_fail: |
| 179 | kfree(info.res); |
| 180 | res_alloc_fail: |
| 181 | return; |
| 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum) |
| 185 | { |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 186 | struct pci_bus *bus; |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 187 | struct pci_sysdata *sd; |
| 188 | int pxm; |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 189 | |
Gary Hade | 036fff4 | 2007-10-03 15:56:14 -0700 | [diff] [blame] | 190 | dmi_check_system(acpi_pciprobe_dmi_table); |
| 191 | |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 192 | if (domain && !pci_domains_supported) { |
| 193 | printk(KERN_WARNING "PCI: Multiple domains not supported " |
| 194 | "(dom %d, bus %d)\n", domain, busnum); |
| 195 | return NULL; |
| 196 | } |
| 197 | |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 198 | /* Allocate per-root-bus (not per bus) arch-specific data. |
| 199 | * TODO: leak; this memory is never freed. |
| 200 | * It's arguable whether it's worth the trouble to care. |
| 201 | */ |
| 202 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); |
| 203 | if (!sd) { |
| 204 | printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return NULL; |
| 206 | } |
| 207 | |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 208 | sd->domain = domain; |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 209 | sd->node = -1; |
| 210 | |
| 211 | pxm = acpi_get_pxm(device->handle); |
| 212 | #ifdef CONFIG_ACPI_NUMA |
| 213 | if (pxm >= 0) |
| 214 | sd->node = pxm_to_node(pxm); |
| 215 | #endif |
| 216 | |
| 217 | bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd); |
| 218 | if (!bus) |
| 219 | kfree(sd); |
| 220 | |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 221 | #ifdef CONFIG_ACPI_NUMA |
| 222 | if (bus != NULL) { |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 223 | if (pxm >= 0) { |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 224 | printk("bus %d -> pxm %d -> node %d\n", |
| 225 | busnum, pxm, sd->node); |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | #endif |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 229 | |
| 230 | if (bus && (pci_probe & PCI_USE__CRS)) |
| 231 | get_current_resources(device, busnum, bus); |
Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 232 | |
| 233 | return bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | extern int pci_routeirq; |
| 237 | static int __init pci_acpi_init(void) |
| 238 | { |
| 239 | struct pci_dev *dev = NULL; |
| 240 | |
| 241 | if (pcibios_scanned) |
| 242 | return 0; |
| 243 | |
| 244 | if (acpi_noirq) |
| 245 | return 0; |
| 246 | |
| 247 | printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n"); |
| 248 | acpi_irq_penalty_init(); |
| 249 | pcibios_scanned++; |
| 250 | pcibios_enable_irq = acpi_pci_irq_enable; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 251 | pcibios_disable_irq = acpi_pci_irq_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | if (pci_routeirq) { |
| 254 | /* |
| 255 | * PCI IRQ routing is set up by pci_enable_device(), but we |
| 256 | * also do it here in case there are still broken drivers that |
| 257 | * don't use pci_enable_device(). |
| 258 | */ |
| 259 | printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n"); |
Hanna Linder | fb37fb9 | 2005-11-06 23:39:36 -0800 | [diff] [blame] | 260 | for_each_pci_dev(dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | acpi_pci_irq_enable(dev); |
| 262 | } else |
| 263 | printk(KERN_INFO "PCI: If a device doesn't work, try \"pci=routeirq\". If it helps, post a report\n"); |
| 264 | |
| 265 | #ifdef CONFIG_X86_IO_APIC |
| 266 | if (acpi_ioapic) |
| 267 | print_IO_APIC(); |
| 268 | #endif |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | subsys_initcall(pci_acpi_init); |