1 #include <linux/pci.h> 2 #include <linux/acpi.h> 3 #include <linux/init.h> 4 #include <linux/irq.h> 5 #include <linux/dmi.h> 6 #include <asm/numa.h> 7 #include "pci.h" 8 9 static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d) 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 16 static struct dmi_system_id acpi_pciprobe_dmi_table[] = { 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 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 184 struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum) 185 { 186 struct pci_bus *bus; 187 struct pci_sysdata *sd; 188 int pxm; 189 190 dmi_check_system(acpi_pciprobe_dmi_table); 191 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 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); 205 return NULL; 206 } 207 208 sd->domain = domain; 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 221 #ifdef CONFIG_ACPI_NUMA 222 if (bus != NULL) { 223 if (pxm >= 0) { 224 printk("bus %d -> pxm %d -> node %d\n", 225 busnum, pxm, sd->node); 226 } 227 } 228 #endif 229 230 if (bus && (pci_probe & PCI_USE__CRS)) 231 get_current_resources(device, busnum, bus); 232 233 return bus; 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; 251 pcibios_disable_irq = acpi_pci_irq_disable; 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"); 260 for_each_pci_dev(dev) 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); 273