| 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> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 6 | #include <linux/slab.h> | 
| Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 7 | #include <asm/numa.h> | 
| Jaswinder Singh Rajput | 8248771 | 2008-12-27 18:32:28 +0530 | [diff] [blame] | 8 | #include <asm/pci_x86.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 10 | struct pci_root_info { | 
| Bjorn Helgaas | 42887b2 | 2009-10-06 15:33:49 -0600 | [diff] [blame] | 11 | struct acpi_device *bridge; | 
| Yinghai Lu | fe05725 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 12 | char name[16]; | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 13 | unsigned int res_num; | 
|  | 14 | struct resource *res; | 
| Yinghai Lu | 35cb05e | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 15 | struct pci_sysdata sd; | 
| Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 16 | #ifdef	CONFIG_PCI_MMCONFIG | 
|  | 17 | bool mcfg_added; | 
|  | 18 | u16 segment; | 
|  | 19 | u8 start_bus; | 
|  | 20 | u8 end_bus; | 
|  | 21 | #endif | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 22 | }; | 
|  | 23 |  | 
| Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 24 | static bool pci_use_crs = true; | 
|  | 25 |  | 
|  | 26 | static int __init set_use_crs(const struct dmi_system_id *id) | 
|  | 27 | { | 
|  | 28 | pci_use_crs = true; | 
|  | 29 | return 0; | 
|  | 30 | } | 
|  | 31 |  | 
| Dave Jones | 28c3c05 | 2011-12-30 14:37:05 -0500 | [diff] [blame] | 32 | static int __init set_nouse_crs(const struct dmi_system_id *id) | 
|  | 33 | { | 
|  | 34 | pci_use_crs = false; | 
|  | 35 | return 0; | 
|  | 36 | } | 
|  | 37 |  | 
| Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 38 | static const struct dmi_system_id pci_use_crs_table[] __initconst = { | 
|  | 39 | /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */ | 
|  | 40 | { | 
|  | 41 | .callback = set_use_crs, | 
|  | 42 | .ident = "IBM System x3800", | 
|  | 43 | .matches = { | 
|  | 44 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), | 
|  | 45 | DMI_MATCH(DMI_PRODUCT_NAME, "x3800"), | 
|  | 46 | }, | 
|  | 47 | }, | 
| Bjorn Helgaas | 2491762 | 2010-07-23 12:53:27 -0600 | [diff] [blame] | 48 | /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */ | 
|  | 49 | /* 2006 AMD HT/VIA system with two host bridges */ | 
|  | 50 | { | 
|  | 51 | .callback = set_use_crs, | 
|  | 52 | .ident = "ASRock ALiveSATA2-GLAN", | 
|  | 53 | .matches = { | 
|  | 54 | DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"), | 
|  | 55 | }, | 
|  | 56 | }, | 
| Paul Menzel | 29cf7a3 | 2011-08-31 17:07:10 +0200 | [diff] [blame] | 57 | /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */ | 
|  | 58 | /* 2006 AMD HT/VIA system with two host bridges */ | 
|  | 59 | { | 
|  | 60 | .callback = set_use_crs, | 
|  | 61 | .ident = "ASUS M2V-MX SE", | 
|  | 62 | .matches = { | 
|  | 63 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), | 
|  | 64 | DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"), | 
|  | 65 | DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."), | 
|  | 66 | }, | 
|  | 67 | }, | 
| Jonathan Nieder | 8411371 | 2012-02-28 11:51:10 -0700 | [diff] [blame] | 68 | /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */ | 
|  | 69 | { | 
|  | 70 | .callback = set_use_crs, | 
|  | 71 | .ident = "MSI MS-7253", | 
|  | 72 | .matches = { | 
|  | 73 | DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"), | 
|  | 74 | DMI_MATCH(DMI_BOARD_NAME, "MS-7253"), | 
|  | 75 | DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"), | 
| Jonathan Nieder | 8411371 | 2012-02-28 11:51:10 -0700 | [diff] [blame] | 76 | }, | 
|  | 77 | }, | 
| Dave Jones | 28c3c05 | 2011-12-30 14:37:05 -0500 | [diff] [blame] | 78 |  | 
| Dave Jones | e702781 | 2012-01-04 11:33:12 -0500 | [diff] [blame] | 79 | /* Now for the blacklist.. */ | 
|  | 80 |  | 
|  | 81 | /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */ | 
|  | 82 | { | 
|  | 83 | .callback = set_nouse_crs, | 
|  | 84 | .ident = "Dell Studio 1557", | 
|  | 85 | .matches = { | 
|  | 86 | DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."), | 
|  | 87 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"), | 
|  | 88 | DMI_MATCH(DMI_BIOS_VERSION, "A09"), | 
|  | 89 | }, | 
|  | 90 | }, | 
| Dave Jones | 8b6a5af | 2012-01-04 11:30:52 -0500 | [diff] [blame] | 91 | /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */ | 
|  | 92 | { | 
|  | 93 | .callback = set_nouse_crs, | 
|  | 94 | .ident = "Thinkpad SL510", | 
|  | 95 | .matches = { | 
|  | 96 | DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), | 
|  | 97 | DMI_MATCH(DMI_BOARD_NAME, "2847DFG"), | 
|  | 98 | DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"), | 
|  | 99 | }, | 
|  | 100 | }, | 
| Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 101 | {} | 
|  | 102 | }; | 
|  | 103 |  | 
|  | 104 | void __init pci_acpi_crs_quirks(void) | 
|  | 105 | { | 
|  | 106 | int year; | 
|  | 107 |  | 
|  | 108 | if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008) | 
|  | 109 | pci_use_crs = false; | 
|  | 110 |  | 
|  | 111 | dmi_check_system(pci_use_crs_table); | 
|  | 112 |  | 
|  | 113 | /* | 
|  | 114 | * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that | 
|  | 115 | * takes precedence over anything we figured out above. | 
|  | 116 | */ | 
|  | 117 | if (pci_probe & PCI_ROOT_NO_CRS) | 
|  | 118 | pci_use_crs = false; | 
|  | 119 | else if (pci_probe & PCI_USE__CRS) | 
|  | 120 | pci_use_crs = true; | 
|  | 121 |  | 
|  | 122 | printk(KERN_INFO "PCI: %s host bridge windows from ACPI; " | 
|  | 123 | "if necessary, use \"pci=%s\" and report a bug\n", | 
|  | 124 | pci_use_crs ? "Using" : "Ignoring", | 
|  | 125 | pci_use_crs ? "nocrs" : "use_crs"); | 
|  | 126 | } | 
|  | 127 |  | 
| Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 128 | #ifdef	CONFIG_PCI_MMCONFIG | 
|  | 129 | static int __devinit check_segment(u16 seg, struct device *dev, char *estr) | 
|  | 130 | { | 
|  | 131 | if (seg) { | 
|  | 132 | dev_err(dev, | 
|  | 133 | "%s can't access PCI configuration " | 
|  | 134 | "space under this host bridge.\n", | 
|  | 135 | estr); | 
|  | 136 | return -EIO; | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | /* | 
|  | 140 | * Failure in adding MMCFG information is not fatal, | 
|  | 141 | * just can't access extended configuration space of | 
|  | 142 | * devices under this host bridge. | 
|  | 143 | */ | 
|  | 144 | dev_warn(dev, | 
|  | 145 | "%s can't access extended PCI configuration " | 
|  | 146 | "space under this bridge.\n", | 
|  | 147 | estr); | 
|  | 148 |  | 
|  | 149 | return 0; | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | static int __devinit setup_mcfg_map(struct pci_root_info *info, | 
|  | 153 | u16 seg, u8 start, u8 end, | 
|  | 154 | phys_addr_t addr) | 
|  | 155 | { | 
|  | 156 | int result; | 
|  | 157 | struct device *dev = &info->bridge->dev; | 
|  | 158 |  | 
|  | 159 | info->start_bus = start; | 
|  | 160 | info->end_bus = end; | 
|  | 161 | info->mcfg_added = false; | 
|  | 162 |  | 
|  | 163 | /* return success if MMCFG is not in use */ | 
|  | 164 | if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg) | 
|  | 165 | return 0; | 
|  | 166 |  | 
|  | 167 | if (!(pci_probe & PCI_PROBE_MMCONF)) | 
|  | 168 | return check_segment(seg, dev, "MMCONFIG is disabled,"); | 
|  | 169 |  | 
|  | 170 | result = pci_mmconfig_insert(dev, seg, start, end, addr); | 
|  | 171 | if (result == 0) { | 
|  | 172 | /* enable MMCFG if it hasn't been enabled yet */ | 
|  | 173 | if (raw_pci_ext_ops == NULL) | 
|  | 174 | raw_pci_ext_ops = &pci_mmcfg; | 
|  | 175 | info->mcfg_added = true; | 
|  | 176 | } else if (result != -EEXIST) | 
|  | 177 | return check_segment(seg, dev, | 
|  | 178 | "fail to add MMCONFIG information,"); | 
|  | 179 |  | 
|  | 180 | return 0; | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | static void teardown_mcfg_map(struct pci_root_info *info) | 
|  | 184 | { | 
|  | 185 | if (info->mcfg_added) { | 
|  | 186 | pci_mmconfig_delete(info->segment, info->start_bus, | 
|  | 187 | info->end_bus); | 
|  | 188 | info->mcfg_added = false; | 
|  | 189 | } | 
|  | 190 | } | 
|  | 191 | #else | 
|  | 192 | static int __devinit setup_mcfg_map(struct pci_root_info *info, | 
|  | 193 | u16 seg, u8 start, u8 end, | 
|  | 194 | phys_addr_t addr) | 
|  | 195 | { | 
|  | 196 | return 0; | 
|  | 197 | } | 
|  | 198 | static void teardown_mcfg_map(struct pci_root_info *info) | 
|  | 199 | { | 
|  | 200 | } | 
|  | 201 | #endif | 
|  | 202 |  | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 203 | static acpi_status | 
|  | 204 | resource_to_addr(struct acpi_resource *resource, | 
|  | 205 | struct acpi_resource_address64 *addr) | 
|  | 206 | { | 
|  | 207 | acpi_status status; | 
| Bjorn Helgaas | 66528fd | 2010-04-20 13:52:41 -0600 | [diff] [blame] | 208 | struct acpi_resource_memory24 *memory24; | 
|  | 209 | struct acpi_resource_memory32 *memory32; | 
|  | 210 | struct acpi_resource_fixed_memory32 *fixed_memory32; | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 211 |  | 
| Bjorn Helgaas | 66528fd | 2010-04-20 13:52:41 -0600 | [diff] [blame] | 212 | memset(addr, 0, sizeof(*addr)); | 
|  | 213 | switch (resource->type) { | 
|  | 214 | case ACPI_RESOURCE_TYPE_MEMORY24: | 
|  | 215 | memory24 = &resource->data.memory24; | 
|  | 216 | addr->resource_type = ACPI_MEMORY_RANGE; | 
|  | 217 | addr->minimum = memory24->minimum; | 
|  | 218 | addr->address_length = memory24->address_length; | 
|  | 219 | addr->maximum = addr->minimum + addr->address_length - 1; | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 220 | return AE_OK; | 
| Bjorn Helgaas | 66528fd | 2010-04-20 13:52:41 -0600 | [diff] [blame] | 221 | case ACPI_RESOURCE_TYPE_MEMORY32: | 
|  | 222 | memory32 = &resource->data.memory32; | 
|  | 223 | addr->resource_type = ACPI_MEMORY_RANGE; | 
|  | 224 | addr->minimum = memory32->minimum; | 
|  | 225 | addr->address_length = memory32->address_length; | 
|  | 226 | addr->maximum = addr->minimum + addr->address_length - 1; | 
|  | 227 | return AE_OK; | 
|  | 228 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: | 
|  | 229 | fixed_memory32 = &resource->data.fixed_memory32; | 
|  | 230 | addr->resource_type = ACPI_MEMORY_RANGE; | 
|  | 231 | addr->minimum = fixed_memory32->address; | 
|  | 232 | addr->address_length = fixed_memory32->address_length; | 
|  | 233 | addr->maximum = addr->minimum + addr->address_length - 1; | 
|  | 234 | return AE_OK; | 
|  | 235 | case ACPI_RESOURCE_TYPE_ADDRESS16: | 
|  | 236 | case ACPI_RESOURCE_TYPE_ADDRESS32: | 
|  | 237 | case ACPI_RESOURCE_TYPE_ADDRESS64: | 
|  | 238 | status = acpi_resource_to_address64(resource, addr); | 
|  | 239 | if (ACPI_SUCCESS(status) && | 
|  | 240 | (addr->resource_type == ACPI_MEMORY_RANGE || | 
|  | 241 | addr->resource_type == ACPI_IO_RANGE) && | 
|  | 242 | addr->address_length > 0) { | 
|  | 243 | return AE_OK; | 
|  | 244 | } | 
|  | 245 | break; | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 246 | } | 
|  | 247 | return AE_ERROR; | 
|  | 248 | } | 
|  | 249 |  | 
|  | 250 | static acpi_status | 
|  | 251 | count_resource(struct acpi_resource *acpi_res, void *data) | 
|  | 252 | { | 
|  | 253 | struct pci_root_info *info = data; | 
|  | 254 | struct acpi_resource_address64 addr; | 
|  | 255 | acpi_status status; | 
|  | 256 |  | 
|  | 257 | status = resource_to_addr(acpi_res, &addr); | 
|  | 258 | if (ACPI_SUCCESS(status)) | 
|  | 259 | info->res_num++; | 
|  | 260 | return AE_OK; | 
|  | 261 | } | 
|  | 262 |  | 
|  | 263 | static acpi_status | 
|  | 264 | setup_resource(struct acpi_resource *acpi_res, void *data) | 
|  | 265 | { | 
|  | 266 | struct pci_root_info *info = data; | 
|  | 267 | struct resource *res; | 
|  | 268 | struct acpi_resource_address64 addr; | 
|  | 269 | acpi_status status; | 
|  | 270 | unsigned long flags; | 
| Gary Hade | ae5cd86 | 2011-11-14 15:42:16 -0800 | [diff] [blame] | 271 | u64 start, orig_end, end; | 
| Yinghai Lu | 2cdb3f1 | 2009-06-24 19:01:19 -0700 | [diff] [blame] | 272 |  | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 273 | status = resource_to_addr(acpi_res, &addr); | 
|  | 274 | if (!ACPI_SUCCESS(status)) | 
|  | 275 | return AE_OK; | 
|  | 276 |  | 
|  | 277 | if (addr.resource_type == ACPI_MEMORY_RANGE) { | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 278 | flags = IORESOURCE_MEM; | 
|  | 279 | if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY) | 
|  | 280 | flags |= IORESOURCE_PREFETCH; | 
|  | 281 | } else if (addr.resource_type == ACPI_IO_RANGE) { | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 282 | flags = IORESOURCE_IO; | 
|  | 283 | } else | 
|  | 284 | return AE_OK; | 
|  | 285 |  | 
| Yinghai Lu | 2cdb3f1 | 2009-06-24 19:01:19 -0700 | [diff] [blame] | 286 | start = addr.minimum + addr.translation_offset; | 
| Gary Hade | ae5cd86 | 2011-11-14 15:42:16 -0800 | [diff] [blame] | 287 | orig_end = end = addr.maximum + addr.translation_offset; | 
|  | 288 |  | 
|  | 289 | /* Exclude non-addressable range or non-addressable portion of range */ | 
|  | 290 | end = min(end, (u64)iomem_resource.end); | 
|  | 291 | if (end <= start) { | 
|  | 292 | dev_info(&info->bridge->dev, | 
|  | 293 | "host bridge window [%#llx-%#llx] " | 
|  | 294 | "(ignored, not CPU addressable)\n", start, orig_end); | 
|  | 295 | return AE_OK; | 
|  | 296 | } else if (orig_end != end) { | 
|  | 297 | dev_info(&info->bridge->dev, | 
|  | 298 | "host bridge window [%#llx-%#llx] " | 
|  | 299 | "([%#llx-%#llx] ignored, not CPU addressable)\n", | 
|  | 300 | start, orig_end, end + 1, orig_end); | 
|  | 301 | } | 
| Gary Hade | f9cde5f | 2009-05-27 12:41:44 -0700 | [diff] [blame] | 302 |  | 
| Yinghai Lu | 2cdb3f1 | 2009-06-24 19:01:19 -0700 | [diff] [blame] | 303 | res = &info->res[info->res_num]; | 
|  | 304 | res->name = info->name; | 
|  | 305 | res->flags = flags; | 
|  | 306 | res->start = start; | 
|  | 307 | res->end = end; | 
| Yinghai Lu | 2cdb3f1 | 2009-06-24 19:01:19 -0700 | [diff] [blame] | 308 |  | 
| Bjorn Helgaas | 7bc5e3f | 2010-02-23 10:24:41 -0700 | [diff] [blame] | 309 | if (!pci_use_crs) { | 
| Bjorn Helgaas | f1db6fd | 2009-11-04 10:39:13 -0700 | [diff] [blame] | 310 | dev_printk(KERN_DEBUG, &info->bridge->dev, | 
|  | 311 | "host bridge window %pR (ignored)\n", res); | 
|  | 312 | return AE_OK; | 
|  | 313 | } | 
|  | 314 |  | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 315 | info->res_num++; | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 316 |  | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 317 | return AE_OK; | 
|  | 318 | } | 
|  | 319 |  | 
| Márton Németh | 6e33a85 | 2011-05-14 19:27:33 +0200 | [diff] [blame] | 320 | static void coalesce_windows(struct pci_root_info *info, unsigned long type) | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 321 | { | 
|  | 322 | int i, j; | 
|  | 323 | struct resource *res1, *res2; | 
|  | 324 |  | 
|  | 325 | for (i = 0; i < info->res_num; i++) { | 
|  | 326 | res1 = &info->res[i]; | 
|  | 327 | if (!(res1->flags & type)) | 
|  | 328 | continue; | 
|  | 329 |  | 
|  | 330 | for (j = i + 1; j < info->res_num; j++) { | 
|  | 331 | res2 = &info->res[j]; | 
|  | 332 | if (!(res2->flags & type)) | 
|  | 333 | continue; | 
|  | 334 |  | 
|  | 335 | /* | 
|  | 336 | * I don't like throwing away windows because then | 
|  | 337 | * our resources no longer match the ACPI _CRS, but | 
|  | 338 | * the kernel resource tree doesn't allow overlaps. | 
|  | 339 | */ | 
| Wei Yang | 74d24b2 | 2012-04-26 15:32:55 +0800 | [diff] [blame] | 340 | if (resource_overlaps(res1, res2)) { | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 341 | res1->start = min(res1->start, res2->start); | 
|  | 342 | res1->end = max(res1->end, res2->end); | 
|  | 343 | dev_info(&info->bridge->dev, | 
|  | 344 | "host bridge window expanded to %pR; %pR ignored\n", | 
|  | 345 | res1, res2); | 
|  | 346 | res2->flags = 0; | 
|  | 347 | } | 
|  | 348 | } | 
|  | 349 | } | 
|  | 350 | } | 
|  | 351 |  | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 352 | static void add_resources(struct pci_root_info *info, | 
|  | 353 | struct list_head *resources) | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 354 | { | 
|  | 355 | int i; | 
|  | 356 | struct resource *res, *root, *conflict; | 
|  | 357 |  | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 358 | coalesce_windows(info, IORESOURCE_MEM); | 
|  | 359 | coalesce_windows(info, IORESOURCE_IO); | 
|  | 360 |  | 
|  | 361 | for (i = 0; i < info->res_num; i++) { | 
|  | 362 | res = &info->res[i]; | 
|  | 363 |  | 
|  | 364 | if (res->flags & IORESOURCE_MEM) | 
|  | 365 | root = &iomem_resource; | 
|  | 366 | else if (res->flags & IORESOURCE_IO) | 
|  | 367 | root = &ioport_resource; | 
|  | 368 | else | 
|  | 369 | continue; | 
|  | 370 |  | 
|  | 371 | conflict = insert_resource_conflict(root, res); | 
|  | 372 | if (conflict) | 
| Bjorn Helgaas | 43d786e | 2011-07-02 10:47:12 -0600 | [diff] [blame] | 373 | dev_info(&info->bridge->dev, | 
|  | 374 | "ignoring host bridge window %pR (conflicts with %s %pR)\n", | 
|  | 375 | res, conflict->name, conflict); | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 376 | else | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 377 | pci_add_resource(resources, res); | 
| Bjorn Helgaas | 4723d0f | 2010-09-22 11:09:19 -0600 | [diff] [blame] | 378 | } | 
|  | 379 | } | 
|  | 380 |  | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 381 | static void free_pci_root_info_res(struct pci_root_info *info) | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 382 | { | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 383 | kfree(info->res); | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 384 | info->res = NULL; | 
|  | 385 | info->res_num = 0; | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | static void __release_pci_root_info(struct pci_root_info *info) | 
|  | 389 | { | 
|  | 390 | int i; | 
|  | 391 | struct resource *res; | 
|  | 392 |  | 
|  | 393 | for (i = 0; i < info->res_num; i++) { | 
|  | 394 | res = &info->res[i]; | 
|  | 395 |  | 
|  | 396 | if (!res->parent) | 
|  | 397 | continue; | 
|  | 398 |  | 
|  | 399 | if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) | 
|  | 400 | continue; | 
|  | 401 |  | 
|  | 402 | release_resource(res); | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | free_pci_root_info_res(info); | 
|  | 406 |  | 
| Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 407 | teardown_mcfg_map(info); | 
|  | 408 |  | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 409 | kfree(info); | 
|  | 410 | } | 
| Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 411 |  | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 412 | static void release_pci_root_info(struct pci_host_bridge *bridge) | 
|  | 413 | { | 
|  | 414 | struct pci_root_info *info = bridge->release_data; | 
|  | 415 |  | 
|  | 416 | __release_pci_root_info(info); | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 417 | } | 
|  | 418 |  | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 419 | static void | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 420 | probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device, | 
|  | 421 | int busnum, int domain) | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 422 | { | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 423 | size_t size; | 
|  | 424 |  | 
| Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 425 | sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum); | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 426 | info->bridge = device; | 
| Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 427 |  | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 428 | info->res_num = 0; | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 429 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource, | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 430 | info); | 
|  | 431 | if (!info->res_num) | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 432 | return; | 
|  | 433 |  | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 434 | size = sizeof(*info->res) * info->res_num; | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 435 | info->res_num = 0; | 
| Yinghai Lu | 4cd8daf | 2012-09-19 10:49:00 -0700 | [diff] [blame] | 436 | info->res = kzalloc(size, GFP_KERNEL); | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 437 | if (!info->res) | 
| Bjorn Helgaas | 2cd6975 | 2011-10-28 16:28:14 -0600 | [diff] [blame] | 438 | return; | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 439 |  | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 440 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource, | 
| Yinghai Lu | baa495d | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 441 | info); | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 442 | } | 
|  | 443 |  | 
| Bjorn Helgaas | 5728377 | 2010-03-11 12:20:11 -0700 | [diff] [blame] | 444 | struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { | 
| Bjorn Helgaas | 5728377 | 2010-03-11 12:20:11 -0700 | [diff] [blame] | 446 | struct acpi_device *device = root->device; | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 447 | struct pci_root_info *info = NULL; | 
| Bjorn Helgaas | 5728377 | 2010-03-11 12:20:11 -0700 | [diff] [blame] | 448 | int domain = root->segment; | 
|  | 449 | int busnum = root->secondary.start; | 
| Bjorn Helgaas | 2cd6975 | 2011-10-28 16:28:14 -0600 | [diff] [blame] | 450 | LIST_HEAD(resources); | 
| Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 451 | struct pci_bus *bus = NULL; | 
| Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 452 | struct pci_sysdata *sd; | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 453 | int node; | 
|  | 454 | #ifdef CONFIG_ACPI_NUMA | 
| Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 455 | int pxm; | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 456 | #endif | 
| Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 457 |  | 
| Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 458 | if (domain && !pci_domains_supported) { | 
| Bjorn Helgaas | 2a6bed8 | 2009-11-04 10:32:47 -0700 | [diff] [blame] | 459 | printk(KERN_WARNING "pci_bus %04x:%02x: " | 
|  | 460 | "ignored (multiple domains not supported)\n", | 
|  | 461 | domain, busnum); | 
| Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 462 | return NULL; | 
|  | 463 | } | 
|  | 464 |  | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 465 | node = -1; | 
|  | 466 | #ifdef CONFIG_ACPI_NUMA | 
|  | 467 | pxm = acpi_get_pxm(device->handle); | 
|  | 468 | if (pxm >= 0) | 
|  | 469 | node = pxm_to_node(pxm); | 
|  | 470 | if (node != -1) | 
|  | 471 | set_mp_bus_to_node(busnum, node); | 
|  | 472 | else | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 473 | #endif | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 474 | node = get_mp_bus_to_node(busnum); | 
| Yinghai Lu | b755de8 | 2008-02-20 12:41:52 -0800 | [diff] [blame] | 475 |  | 
|  | 476 | if (node != -1 && !node_online(node)) | 
|  | 477 | node = -1; | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 478 |  | 
| Yinghai Lu | 35cb05e | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 479 | info = kzalloc(sizeof(*info), GFP_KERNEL); | 
|  | 480 | if (!info) { | 
| Bjorn Helgaas | 2a6bed8 | 2009-11-04 10:32:47 -0700 | [diff] [blame] | 481 | printk(KERN_WARNING "pci_bus %04x:%02x: " | 
|  | 482 | "ignored (out of memory)\n", domain, busnum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return NULL; | 
|  | 484 | } | 
|  | 485 |  | 
| Yinghai Lu | 35cb05e | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 486 | sd = &info->sd; | 
| Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 487 | sd->domain = domain; | 
| Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 488 | sd->node = node; | 
| yakui.zhao@intel.com | b87e81e | 2008-04-15 14:34:49 -0700 | [diff] [blame] | 489 | /* | 
|  | 490 | * Maybe the desired pci bus has been already scanned. In such case | 
|  | 491 | * it is unnecessary to scan the pci bus with the given domain,busnum. | 
|  | 492 | */ | 
|  | 493 | bus = pci_find_bus(domain, busnum); | 
|  | 494 | if (bus) { | 
|  | 495 | /* | 
|  | 496 | * If the desired bus exits, the content of bus->sysdata will | 
|  | 497 | * be replaced by sd. | 
|  | 498 | */ | 
|  | 499 | memcpy(bus->sysdata, sd, sizeof(*sd)); | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 500 | kfree(info); | 
| Yinghai Lu | 626fdfe | 2009-06-24 20:00:12 -0700 | [diff] [blame] | 501 | } else { | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 502 | probe_pci_root_info(info, device, busnum, domain); | 
| Bjorn Helgaas | 316d86f | 2012-01-17 17:41:21 -0700 | [diff] [blame] | 503 |  | 
| Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 504 | /* insert busn res at first */ | 
|  | 505 | pci_add_resource(&resources,  &root->secondary); | 
| Bjorn Helgaas | 316d86f | 2012-01-17 17:41:21 -0700 | [diff] [blame] | 506 | /* | 
|  | 507 | * _CRS with no apertures is normal, so only fall back to | 
|  | 508 | * defaults or native bridge info if we're ignoring _CRS. | 
|  | 509 | */ | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 510 | if (pci_use_crs) | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 511 | add_resources(info, &resources); | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 512 | else { | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 513 | free_pci_root_info_res(info); | 
| Bjorn Helgaas | 2cd6975 | 2011-10-28 16:28:14 -0600 | [diff] [blame] | 514 | x86_pci_root_bus_resources(busnum, &resources); | 
| Yinghai Lu | 9a03d28 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 515 | } | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 516 |  | 
| Jiang Liu | c0fa407 | 2012-06-22 14:55:17 +0800 | [diff] [blame] | 517 | if (!setup_mcfg_map(info, domain, (u8)root->secondary.start, | 
|  | 518 | (u8)root->secondary.end, root->mcfg_addr)) | 
|  | 519 | bus = pci_create_root_bus(NULL, busnum, &pci_root_ops, | 
|  | 520 | sd, &resources); | 
|  | 521 |  | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 522 | if (bus) { | 
| Yinghai Lu | 5c1d81d | 2012-05-17 18:51:12 -0700 | [diff] [blame] | 523 | pci_scan_child_bus(bus); | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 524 | pci_set_host_bridge_release( | 
|  | 525 | to_pci_host_bridge(bus->bridge), | 
|  | 526 | release_pci_root_info, info); | 
|  | 527 | } else { | 
| Bjorn Helgaas | 2cd6975 | 2011-10-28 16:28:14 -0600 | [diff] [blame] | 528 | pci_free_resource_list(&resources); | 
| Yinghai Lu | fd3b0c1 | 2012-04-02 18:31:53 -0700 | [diff] [blame] | 529 | __release_pci_root_info(info); | 
|  | 530 | } | 
| Yinghai Lu | 626fdfe | 2009-06-24 20:00:12 -0700 | [diff] [blame] | 531 | } | 
| Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 532 |  | 
| Jon Mason | b03e749 | 2011-07-20 15:20:54 -0500 | [diff] [blame] | 533 | /* After the PCI-E bus has been walked and all devices discovered, | 
|  | 534 | * configure any settings of the fabric that might be necessary. | 
|  | 535 | */ | 
|  | 536 | if (bus) { | 
|  | 537 | struct pci_bus *child; | 
| Shyam Iyer | 5307f6d | 2011-09-08 16:41:17 -0500 | [diff] [blame] | 538 | list_for_each_entry(child, &bus->children, node) { | 
|  | 539 | struct pci_dev *self = child->self; | 
|  | 540 | if (!self) | 
|  | 541 | continue; | 
|  | 542 |  | 
|  | 543 | pcie_bus_configure_settings(child, self->pcie_mpss); | 
|  | 544 | } | 
| Jon Mason | b03e749 | 2011-07-20 15:20:54 -0500 | [diff] [blame] | 545 | } | 
|  | 546 |  | 
| Yinghai Lu | dbb6152 | 2008-04-19 01:30:16 -0700 | [diff] [blame] | 547 | if (bus && node != -1) { | 
| Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 548 | #ifdef CONFIG_ACPI_NUMA | 
| Yinghai Lu | dbb6152 | 2008-04-19 01:30:16 -0700 | [diff] [blame] | 549 | if (pxm >= 0) | 
| Bjorn Helgaas | 2b8c2ef | 2008-12-18 16:34:51 -0700 | [diff] [blame] | 550 | dev_printk(KERN_DEBUG, &bus->dev, | 
|  | 551 | "on NUMA node %d (pxm %d)\n", node, pxm); | 
| Yinghai Lu | dbb6152 | 2008-04-19 01:30:16 -0700 | [diff] [blame] | 552 | #else | 
| Bjorn Helgaas | 2b8c2ef | 2008-12-18 16:34:51 -0700 | [diff] [blame] | 553 | dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node); | 
| Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 554 | #endif | 
| Yinghai Lu | dbb6152 | 2008-04-19 01:30:16 -0700 | [diff] [blame] | 555 | } | 
| Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 556 |  | 
| Andi Kleen | 69e1a33 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 557 | return bus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } | 
|  | 559 |  | 
| Robert Richter | 8dd779b | 2008-07-02 22:50:29 +0200 | [diff] [blame] | 560 | int __init pci_acpi_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { | 
|  | 562 | struct pci_dev *dev = NULL; | 
|  | 563 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | if (acpi_noirq) | 
| Thomas Gleixner | b72d0db | 2009-08-29 16:24:51 +0200 | [diff] [blame] | 565 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 |  | 
|  | 567 | printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n"); | 
|  | 568 | acpi_irq_penalty_init(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | pcibios_enable_irq = acpi_pci_irq_enable; | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 570 | pcibios_disable_irq = acpi_pci_irq_disable; | 
| Thomas Gleixner | ab3b379 | 2009-08-29 17:47:33 +0200 | [diff] [blame] | 571 | x86_init.pci.init_irq = x86_init_noop; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 |  | 
|  | 573 | if (pci_routeirq) { | 
|  | 574 | /* | 
|  | 575 | * PCI IRQ routing is set up by pci_enable_device(), but we | 
|  | 576 | * also do it here in case there are still broken drivers that | 
|  | 577 | * don't use pci_enable_device(). | 
|  | 578 | */ | 
|  | 579 | 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] | 580 | for_each_pci_dev(dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | acpi_pci_irq_enable(dev); | 
| Bjorn Helgaas | 657472e | 2008-02-18 09:44:13 -0700 | [diff] [blame] | 582 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return 0; | 
|  | 585 | } |