1fb9aa6f1SThomas Gleixner /* 2fb9aa6f1SThomas Gleixner * mmconfig-shared.c - Low-level direct PCI config space access via 3fb9aa6f1SThomas Gleixner * MMCONFIG - common code between i386 and x86-64. 4fb9aa6f1SThomas Gleixner * 5fb9aa6f1SThomas Gleixner * This code does: 6fb9aa6f1SThomas Gleixner * - known chipset handling 7fb9aa6f1SThomas Gleixner * - ACPI decoding and validation 8fb9aa6f1SThomas Gleixner * 9fb9aa6f1SThomas Gleixner * Per-architecture code takes care of the mappings and accesses 10fb9aa6f1SThomas Gleixner * themselves. 11fb9aa6f1SThomas Gleixner */ 12fb9aa6f1SThomas Gleixner 13fb9aa6f1SThomas Gleixner #include <linux/pci.h> 14fb9aa6f1SThomas Gleixner #include <linux/init.h> 15fb9aa6f1SThomas Gleixner #include <linux/acpi.h> 16fb9aa6f1SThomas Gleixner #include <linux/bitmap.h> 17fb9aa6f1SThomas Gleixner #include <asm/e820.h> 18fb9aa6f1SThomas Gleixner 19fb9aa6f1SThomas Gleixner #include "pci.h" 20fb9aa6f1SThomas Gleixner 21fb9aa6f1SThomas Gleixner /* aperture is up to 256MB but BIOS may reserve less */ 22fb9aa6f1SThomas Gleixner #define MMCONFIG_APER_MIN (2 * 1024*1024) 23fb9aa6f1SThomas Gleixner #define MMCONFIG_APER_MAX (256 * 1024*1024) 24fb9aa6f1SThomas Gleixner 25fb9aa6f1SThomas Gleixner /* Indicate if the mmcfg resources have been placed into the resource table. */ 26fb9aa6f1SThomas Gleixner static int __initdata pci_mmcfg_resources_inserted; 27fb9aa6f1SThomas Gleixner 28fb9aa6f1SThomas Gleixner static const char __init *pci_mmcfg_e7520(void) 29fb9aa6f1SThomas Gleixner { 30fb9aa6f1SThomas Gleixner u32 win; 31bb63b421SYinghai Lu raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0xce, 2, &win); 32fb9aa6f1SThomas Gleixner 33fb9aa6f1SThomas Gleixner win = win & 0xf000; 34fb9aa6f1SThomas Gleixner if(win == 0x0000 || win == 0xf000) 35fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 36fb9aa6f1SThomas Gleixner else { 37fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 1; 38fb9aa6f1SThomas Gleixner pci_mmcfg_config = kzalloc(sizeof(pci_mmcfg_config[0]), GFP_KERNEL); 39fb9aa6f1SThomas Gleixner if (!pci_mmcfg_config) 40fb9aa6f1SThomas Gleixner return NULL; 41fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].address = win << 16; 42fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].pci_segment = 0; 43fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].start_bus_number = 0; 44fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].end_bus_number = 255; 45fb9aa6f1SThomas Gleixner } 46fb9aa6f1SThomas Gleixner 47fb9aa6f1SThomas Gleixner return "Intel Corporation E7520 Memory Controller Hub"; 48fb9aa6f1SThomas Gleixner } 49fb9aa6f1SThomas Gleixner 50fb9aa6f1SThomas Gleixner static const char __init *pci_mmcfg_intel_945(void) 51fb9aa6f1SThomas Gleixner { 52fb9aa6f1SThomas Gleixner u32 pciexbar, mask = 0, len = 0; 53fb9aa6f1SThomas Gleixner 54fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 1; 55fb9aa6f1SThomas Gleixner 56bb63b421SYinghai Lu raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0x48, 4, &pciexbar); 57fb9aa6f1SThomas Gleixner 58fb9aa6f1SThomas Gleixner /* Enable bit */ 59fb9aa6f1SThomas Gleixner if (!(pciexbar & 1)) 60fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 61fb9aa6f1SThomas Gleixner 62fb9aa6f1SThomas Gleixner /* Size bits */ 63fb9aa6f1SThomas Gleixner switch ((pciexbar >> 1) & 3) { 64fb9aa6f1SThomas Gleixner case 0: 65fb9aa6f1SThomas Gleixner mask = 0xf0000000U; 66fb9aa6f1SThomas Gleixner len = 0x10000000U; 67fb9aa6f1SThomas Gleixner break; 68fb9aa6f1SThomas Gleixner case 1: 69fb9aa6f1SThomas Gleixner mask = 0xf8000000U; 70fb9aa6f1SThomas Gleixner len = 0x08000000U; 71fb9aa6f1SThomas Gleixner break; 72fb9aa6f1SThomas Gleixner case 2: 73fb9aa6f1SThomas Gleixner mask = 0xfc000000U; 74fb9aa6f1SThomas Gleixner len = 0x04000000U; 75fb9aa6f1SThomas Gleixner break; 76fb9aa6f1SThomas Gleixner default: 77fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 78fb9aa6f1SThomas Gleixner } 79fb9aa6f1SThomas Gleixner 80fb9aa6f1SThomas Gleixner /* Errata #2, things break when not aligned on a 256Mb boundary */ 81fb9aa6f1SThomas Gleixner /* Can only happen in 64M/128M mode */ 82fb9aa6f1SThomas Gleixner 83fb9aa6f1SThomas Gleixner if ((pciexbar & mask) & 0x0fffffffU) 84fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 85fb9aa6f1SThomas Gleixner 86fb9aa6f1SThomas Gleixner /* Don't hit the APIC registers and their friends */ 87fb9aa6f1SThomas Gleixner if ((pciexbar & mask) >= 0xf0000000U) 88fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 89fb9aa6f1SThomas Gleixner 90fb9aa6f1SThomas Gleixner if (pci_mmcfg_config_num) { 91fb9aa6f1SThomas Gleixner pci_mmcfg_config = kzalloc(sizeof(pci_mmcfg_config[0]), GFP_KERNEL); 92fb9aa6f1SThomas Gleixner if (!pci_mmcfg_config) 93fb9aa6f1SThomas Gleixner return NULL; 94fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].address = pciexbar & mask; 95fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].pci_segment = 0; 96fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].start_bus_number = 0; 97fb9aa6f1SThomas Gleixner pci_mmcfg_config[0].end_bus_number = (len >> 20) - 1; 98fb9aa6f1SThomas Gleixner } 99fb9aa6f1SThomas Gleixner 100fb9aa6f1SThomas Gleixner return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub"; 101fb9aa6f1SThomas Gleixner } 102fb9aa6f1SThomas Gleixner 1037fd0da40SYinghai Lu static const char __init *pci_mmcfg_amd_fam10h(void) 1047fd0da40SYinghai Lu { 1057fd0da40SYinghai Lu u32 low, high, address; 1067fd0da40SYinghai Lu u64 base, msr; 1077fd0da40SYinghai Lu int i; 1087fd0da40SYinghai Lu unsigned segnbits = 0, busnbits; 1097fd0da40SYinghai Lu 1105f0b2976SYinghai Lu if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF)) 1115f0b2976SYinghai Lu return NULL; 1125f0b2976SYinghai Lu 1137fd0da40SYinghai Lu address = MSR_FAM10H_MMIO_CONF_BASE; 1147fd0da40SYinghai Lu if (rdmsr_safe(address, &low, &high)) 1157fd0da40SYinghai Lu return NULL; 1167fd0da40SYinghai Lu 1177fd0da40SYinghai Lu msr = high; 1187fd0da40SYinghai Lu msr <<= 32; 1197fd0da40SYinghai Lu msr |= low; 1207fd0da40SYinghai Lu 1217fd0da40SYinghai Lu /* mmconfig is not enable */ 1227fd0da40SYinghai Lu if (!(msr & FAM10H_MMIO_CONF_ENABLE)) 1237fd0da40SYinghai Lu return NULL; 1247fd0da40SYinghai Lu 1257fd0da40SYinghai Lu base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT); 1267fd0da40SYinghai Lu 1277fd0da40SYinghai Lu busnbits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) & 1287fd0da40SYinghai Lu FAM10H_MMIO_CONF_BUSRANGE_MASK; 1297fd0da40SYinghai Lu 1307fd0da40SYinghai Lu /* 1317fd0da40SYinghai Lu * only handle bus 0 ? 1327fd0da40SYinghai Lu * need to skip it 1337fd0da40SYinghai Lu */ 1347fd0da40SYinghai Lu if (!busnbits) 1357fd0da40SYinghai Lu return NULL; 1367fd0da40SYinghai Lu 1377fd0da40SYinghai Lu if (busnbits > 8) { 1387fd0da40SYinghai Lu segnbits = busnbits - 8; 1397fd0da40SYinghai Lu busnbits = 8; 1407fd0da40SYinghai Lu } 1417fd0da40SYinghai Lu 1427fd0da40SYinghai Lu pci_mmcfg_config_num = (1 << segnbits); 1437fd0da40SYinghai Lu pci_mmcfg_config = kzalloc(sizeof(pci_mmcfg_config[0]) * 1447fd0da40SYinghai Lu pci_mmcfg_config_num, GFP_KERNEL); 1457fd0da40SYinghai Lu if (!pci_mmcfg_config) 1467fd0da40SYinghai Lu return NULL; 1477fd0da40SYinghai Lu 1487fd0da40SYinghai Lu for (i = 0; i < (1 << segnbits); i++) { 1497fd0da40SYinghai Lu pci_mmcfg_config[i].address = base + (1<<28) * i; 1507fd0da40SYinghai Lu pci_mmcfg_config[i].pci_segment = i; 1517fd0da40SYinghai Lu pci_mmcfg_config[i].start_bus_number = 0; 1527fd0da40SYinghai Lu pci_mmcfg_config[i].end_bus_number = (1 << busnbits) - 1; 1537fd0da40SYinghai Lu } 1547fd0da40SYinghai Lu 1557fd0da40SYinghai Lu return "AMD Family 10h NB"; 1567fd0da40SYinghai Lu } 1577fd0da40SYinghai Lu 158fb9aa6f1SThomas Gleixner struct pci_mmcfg_hostbridge_probe { 1597fd0da40SYinghai Lu u32 bus; 1607fd0da40SYinghai Lu u32 devfn; 161fb9aa6f1SThomas Gleixner u32 vendor; 162fb9aa6f1SThomas Gleixner u32 device; 163fb9aa6f1SThomas Gleixner const char *(*probe)(void); 164fb9aa6f1SThomas Gleixner }; 165fb9aa6f1SThomas Gleixner 166fb9aa6f1SThomas Gleixner static struct pci_mmcfg_hostbridge_probe pci_mmcfg_probes[] __initdata = { 1677fd0da40SYinghai Lu { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL, 1687fd0da40SYinghai Lu PCI_DEVICE_ID_INTEL_E7520_MCH, pci_mmcfg_e7520 }, 1697fd0da40SYinghai Lu { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL, 1707fd0da40SYinghai Lu PCI_DEVICE_ID_INTEL_82945G_HB, pci_mmcfg_intel_945 }, 1717fd0da40SYinghai Lu { 0, PCI_DEVFN(0x18, 0), PCI_VENDOR_ID_AMD, 1727fd0da40SYinghai Lu 0x1200, pci_mmcfg_amd_fam10h }, 1737fd0da40SYinghai Lu { 0xff, PCI_DEVFN(0, 0), PCI_VENDOR_ID_AMD, 1747fd0da40SYinghai Lu 0x1200, pci_mmcfg_amd_fam10h }, 175fb9aa6f1SThomas Gleixner }; 176fb9aa6f1SThomas Gleixner 177fb9aa6f1SThomas Gleixner static int __init pci_mmcfg_check_hostbridge(void) 178fb9aa6f1SThomas Gleixner { 179fb9aa6f1SThomas Gleixner u32 l; 1807fd0da40SYinghai Lu u32 bus, devfn; 181fb9aa6f1SThomas Gleixner u16 vendor, device; 182fb9aa6f1SThomas Gleixner int i; 183fb9aa6f1SThomas Gleixner const char *name; 184fb9aa6f1SThomas Gleixner 185bb63b421SYinghai Lu if (!raw_pci_ops) 186bb63b421SYinghai Lu return 0; 187bb63b421SYinghai Lu 188fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 189fb9aa6f1SThomas Gleixner pci_mmcfg_config = NULL; 190fb9aa6f1SThomas Gleixner name = NULL; 191fb9aa6f1SThomas Gleixner 192fb9aa6f1SThomas Gleixner for (i = 0; !name && i < ARRAY_SIZE(pci_mmcfg_probes); i++) { 1937fd0da40SYinghai Lu bus = pci_mmcfg_probes[i].bus; 1947fd0da40SYinghai Lu devfn = pci_mmcfg_probes[i].devfn; 195bb63b421SYinghai Lu raw_pci_ops->read(0, bus, devfn, 0, 4, &l); 1967fd0da40SYinghai Lu vendor = l & 0xffff; 1977fd0da40SYinghai Lu device = (l >> 16) & 0xffff; 1987fd0da40SYinghai Lu 199fb9aa6f1SThomas Gleixner if (pci_mmcfg_probes[i].vendor == vendor && 200fb9aa6f1SThomas Gleixner pci_mmcfg_probes[i].device == device) 201fb9aa6f1SThomas Gleixner name = pci_mmcfg_probes[i].probe(); 202fb9aa6f1SThomas Gleixner } 203fb9aa6f1SThomas Gleixner 204fb9aa6f1SThomas Gleixner if (name) { 205fb9aa6f1SThomas Gleixner printk(KERN_INFO "PCI: Found %s %s MMCONFIG support.\n", 206fb9aa6f1SThomas Gleixner name, pci_mmcfg_config_num ? "with" : "without"); 207fb9aa6f1SThomas Gleixner } 208fb9aa6f1SThomas Gleixner 209fb9aa6f1SThomas Gleixner return name != NULL; 210fb9aa6f1SThomas Gleixner } 211fb9aa6f1SThomas Gleixner 212*ebd60cd6SYinghai Lu static void __init pci_mmcfg_insert_resources(void) 213fb9aa6f1SThomas Gleixner { 214fb9aa6f1SThomas Gleixner #define PCI_MMCFG_RESOURCE_NAME_LEN 19 215fb9aa6f1SThomas Gleixner int i; 216fb9aa6f1SThomas Gleixner struct resource *res; 217fb9aa6f1SThomas Gleixner char *names; 218fb9aa6f1SThomas Gleixner unsigned num_buses; 219fb9aa6f1SThomas Gleixner 220fb9aa6f1SThomas Gleixner res = kcalloc(PCI_MMCFG_RESOURCE_NAME_LEN + sizeof(*res), 221fb9aa6f1SThomas Gleixner pci_mmcfg_config_num, GFP_KERNEL); 222fb9aa6f1SThomas Gleixner if (!res) { 223fb9aa6f1SThomas Gleixner printk(KERN_ERR "PCI: Unable to allocate MMCONFIG resources\n"); 224fb9aa6f1SThomas Gleixner return; 225fb9aa6f1SThomas Gleixner } 226fb9aa6f1SThomas Gleixner 227fb9aa6f1SThomas Gleixner names = (void *)&res[pci_mmcfg_config_num]; 228fb9aa6f1SThomas Gleixner for (i = 0; i < pci_mmcfg_config_num; i++, res++) { 229fb9aa6f1SThomas Gleixner struct acpi_mcfg_allocation *cfg = &pci_mmcfg_config[i]; 230fb9aa6f1SThomas Gleixner num_buses = cfg->end_bus_number - cfg->start_bus_number + 1; 231fb9aa6f1SThomas Gleixner res->name = names; 232fb9aa6f1SThomas Gleixner snprintf(names, PCI_MMCFG_RESOURCE_NAME_LEN, "PCI MMCONFIG %u", 233fb9aa6f1SThomas Gleixner cfg->pci_segment); 234fb9aa6f1SThomas Gleixner res->start = cfg->address; 235fb9aa6f1SThomas Gleixner res->end = res->start + (num_buses << 20) - 1; 236*ebd60cd6SYinghai Lu res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; 237fb9aa6f1SThomas Gleixner insert_resource(&iomem_resource, res); 238fb9aa6f1SThomas Gleixner names += PCI_MMCFG_RESOURCE_NAME_LEN; 239fb9aa6f1SThomas Gleixner } 240fb9aa6f1SThomas Gleixner 241fb9aa6f1SThomas Gleixner /* Mark that the resources have been inserted. */ 242fb9aa6f1SThomas Gleixner pci_mmcfg_resources_inserted = 1; 243fb9aa6f1SThomas Gleixner } 244fb9aa6f1SThomas Gleixner 2457752d5cfSRobert Hancock static acpi_status __init check_mcfg_resource(struct acpi_resource *res, 2467752d5cfSRobert Hancock void *data) 2477752d5cfSRobert Hancock { 2487752d5cfSRobert Hancock struct resource *mcfg_res = data; 2497752d5cfSRobert Hancock struct acpi_resource_address64 address; 2507752d5cfSRobert Hancock acpi_status status; 2517752d5cfSRobert Hancock 2527752d5cfSRobert Hancock if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) { 2537752d5cfSRobert Hancock struct acpi_resource_fixed_memory32 *fixmem32 = 2547752d5cfSRobert Hancock &res->data.fixed_memory32; 2557752d5cfSRobert Hancock if (!fixmem32) 2567752d5cfSRobert Hancock return AE_OK; 2577752d5cfSRobert Hancock if ((mcfg_res->start >= fixmem32->address) && 2587752d5cfSRobert Hancock (mcfg_res->end < (fixmem32->address + 2597752d5cfSRobert Hancock fixmem32->address_length))) { 2607752d5cfSRobert Hancock mcfg_res->flags = 1; 2617752d5cfSRobert Hancock return AE_CTRL_TERMINATE; 2627752d5cfSRobert Hancock } 2637752d5cfSRobert Hancock } 2647752d5cfSRobert Hancock if ((res->type != ACPI_RESOURCE_TYPE_ADDRESS32) && 2657752d5cfSRobert Hancock (res->type != ACPI_RESOURCE_TYPE_ADDRESS64)) 2667752d5cfSRobert Hancock return AE_OK; 2677752d5cfSRobert Hancock 2687752d5cfSRobert Hancock status = acpi_resource_to_address64(res, &address); 2697752d5cfSRobert Hancock if (ACPI_FAILURE(status) || 2707752d5cfSRobert Hancock (address.address_length <= 0) || 2717752d5cfSRobert Hancock (address.resource_type != ACPI_MEMORY_RANGE)) 2727752d5cfSRobert Hancock return AE_OK; 2737752d5cfSRobert Hancock 2747752d5cfSRobert Hancock if ((mcfg_res->start >= address.minimum) && 2757752d5cfSRobert Hancock (mcfg_res->end < (address.minimum + address.address_length))) { 2767752d5cfSRobert Hancock mcfg_res->flags = 1; 2777752d5cfSRobert Hancock return AE_CTRL_TERMINATE; 2787752d5cfSRobert Hancock } 2797752d5cfSRobert Hancock return AE_OK; 2807752d5cfSRobert Hancock } 2817752d5cfSRobert Hancock 2827752d5cfSRobert Hancock static acpi_status __init find_mboard_resource(acpi_handle handle, u32 lvl, 2837752d5cfSRobert Hancock void *context, void **rv) 2847752d5cfSRobert Hancock { 2857752d5cfSRobert Hancock struct resource *mcfg_res = context; 2867752d5cfSRobert Hancock 2877752d5cfSRobert Hancock acpi_walk_resources(handle, METHOD_NAME__CRS, 2887752d5cfSRobert Hancock check_mcfg_resource, context); 2897752d5cfSRobert Hancock 2907752d5cfSRobert Hancock if (mcfg_res->flags) 2917752d5cfSRobert Hancock return AE_CTRL_TERMINATE; 2927752d5cfSRobert Hancock 2937752d5cfSRobert Hancock return AE_OK; 2947752d5cfSRobert Hancock } 2957752d5cfSRobert Hancock 296a83fe32fSYinghai Lu static int __init is_acpi_reserved(u64 start, u64 end, unsigned not_used) 2977752d5cfSRobert Hancock { 2987752d5cfSRobert Hancock struct resource mcfg_res; 2997752d5cfSRobert Hancock 3007752d5cfSRobert Hancock mcfg_res.start = start; 3017752d5cfSRobert Hancock mcfg_res.end = end; 3027752d5cfSRobert Hancock mcfg_res.flags = 0; 3037752d5cfSRobert Hancock 3047752d5cfSRobert Hancock acpi_get_devices("PNP0C01", find_mboard_resource, &mcfg_res, NULL); 3057752d5cfSRobert Hancock 3067752d5cfSRobert Hancock if (!mcfg_res.flags) 3077752d5cfSRobert Hancock acpi_get_devices("PNP0C02", find_mboard_resource, &mcfg_res, 3087752d5cfSRobert Hancock NULL); 3097752d5cfSRobert Hancock 3107752d5cfSRobert Hancock return mcfg_res.flags; 3117752d5cfSRobert Hancock } 3127752d5cfSRobert Hancock 313a83fe32fSYinghai Lu typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type); 314a83fe32fSYinghai Lu 315a83fe32fSYinghai Lu static int __init is_mmconf_reserved(check_reserved_t is_reserved, 316a83fe32fSYinghai Lu u64 addr, u64 size, int i, 317a83fe32fSYinghai Lu typeof(pci_mmcfg_config[0]) *cfg, int with_e820) 318a83fe32fSYinghai Lu { 319a83fe32fSYinghai Lu u64 old_size = size; 320a83fe32fSYinghai Lu int valid = 0; 321a83fe32fSYinghai Lu 322a83fe32fSYinghai Lu while (!is_reserved(addr, addr + size - 1, E820_RESERVED)) { 323a83fe32fSYinghai Lu size >>= 1; 324a83fe32fSYinghai Lu if (size < (16UL<<20)) 325a83fe32fSYinghai Lu break; 326a83fe32fSYinghai Lu } 327a83fe32fSYinghai Lu 328a83fe32fSYinghai Lu if (size >= (16UL<<20) || size == old_size) { 329a83fe32fSYinghai Lu printk(KERN_NOTICE 330a83fe32fSYinghai Lu "PCI: MCFG area at %Lx reserved in %s\n", 331a83fe32fSYinghai Lu addr, with_e820?"E820":"ACPI motherboard resources"); 332a83fe32fSYinghai Lu valid = 1; 333a83fe32fSYinghai Lu 334a83fe32fSYinghai Lu if (old_size != size) { 335a83fe32fSYinghai Lu /* update end_bus_number */ 336a83fe32fSYinghai Lu cfg->end_bus_number = cfg->start_bus_number + ((size>>20) - 1); 337a83fe32fSYinghai Lu printk(KERN_NOTICE "PCI: updated MCFG configuration %d: base %lx " 338a83fe32fSYinghai Lu "segment %hu buses %u - %u\n", 339a83fe32fSYinghai Lu i, (unsigned long)cfg->address, cfg->pci_segment, 340a83fe32fSYinghai Lu (unsigned int)cfg->start_bus_number, 341a83fe32fSYinghai Lu (unsigned int)cfg->end_bus_number); 342a83fe32fSYinghai Lu } 343a83fe32fSYinghai Lu } 344a83fe32fSYinghai Lu 345a83fe32fSYinghai Lu return valid; 346a83fe32fSYinghai Lu } 347a83fe32fSYinghai Lu 348bb63b421SYinghai Lu static void __init pci_mmcfg_reject_broken(int early) 349fb9aa6f1SThomas Gleixner { 350fb9aa6f1SThomas Gleixner typeof(pci_mmcfg_config[0]) *cfg; 3517752d5cfSRobert Hancock int i; 352fb9aa6f1SThomas Gleixner 353fb9aa6f1SThomas Gleixner if ((pci_mmcfg_config_num == 0) || 354fb9aa6f1SThomas Gleixner (pci_mmcfg_config == NULL) || 355fb9aa6f1SThomas Gleixner (pci_mmcfg_config[0].address == 0)) 356fb9aa6f1SThomas Gleixner return; 357fb9aa6f1SThomas Gleixner 358fb9aa6f1SThomas Gleixner cfg = &pci_mmcfg_config[0]; 359fb9aa6f1SThomas Gleixner 3607752d5cfSRobert Hancock for (i = 0; i < pci_mmcfg_config_num; i++) { 36105c58b8aSYinghai Lu int valid = 0; 362a83fe32fSYinghai Lu u64 addr, size; 363a83fe32fSYinghai Lu 3647752d5cfSRobert Hancock cfg = &pci_mmcfg_config[i]; 365a83fe32fSYinghai Lu addr = cfg->start_bus_number; 366a83fe32fSYinghai Lu addr <<= 20; 367a83fe32fSYinghai Lu addr += cfg->address; 368a83fe32fSYinghai Lu size = cfg->end_bus_number + 1 - cfg->start_bus_number; 369a83fe32fSYinghai Lu size <<= 20; 37005c58b8aSYinghai Lu printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lx " 3717752d5cfSRobert Hancock "segment %hu buses %u - %u\n", 3727752d5cfSRobert Hancock i, (unsigned long)cfg->address, cfg->pci_segment, 3737752d5cfSRobert Hancock (unsigned int)cfg->start_bus_number, 3747752d5cfSRobert Hancock (unsigned int)cfg->end_bus_number); 37505c58b8aSYinghai Lu 376a83fe32fSYinghai Lu if (!early) 377a83fe32fSYinghai Lu valid = is_mmconf_reserved(is_acpi_reserved, addr, size, i, cfg, 0); 37805c58b8aSYinghai Lu 37905c58b8aSYinghai Lu if (valid) 38005c58b8aSYinghai Lu continue; 38105c58b8aSYinghai Lu 38205c58b8aSYinghai Lu if (!early) 383fb9aa6f1SThomas Gleixner printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %Lx is not" 3847752d5cfSRobert Hancock " reserved in ACPI motherboard resources\n", 3857752d5cfSRobert Hancock cfg->address); 386a83fe32fSYinghai Lu 3877752d5cfSRobert Hancock /* Don't try to do this check unless configuration 388bb63b421SYinghai Lu type 1 is available. how about type 2 ?*/ 389a83fe32fSYinghai Lu if (raw_pci_ops) 390a83fe32fSYinghai Lu valid = is_mmconf_reserved(e820_all_mapped, addr, size, i, cfg, 1); 39105c58b8aSYinghai Lu 39205c58b8aSYinghai Lu if (!valid) 39305c58b8aSYinghai Lu goto reject; 3947752d5cfSRobert Hancock } 3957752d5cfSRobert Hancock 396fb9aa6f1SThomas Gleixner return; 397fb9aa6f1SThomas Gleixner 398fb9aa6f1SThomas Gleixner reject: 399ef310237SDave Jones printk(KERN_INFO "PCI: Not using MMCONFIG.\n"); 4000b64ad71SYinghai Lu pci_mmcfg_arch_free(); 401fb9aa6f1SThomas Gleixner kfree(pci_mmcfg_config); 402fb9aa6f1SThomas Gleixner pci_mmcfg_config = NULL; 403fb9aa6f1SThomas Gleixner pci_mmcfg_config_num = 0; 404fb9aa6f1SThomas Gleixner } 405fb9aa6f1SThomas Gleixner 40605c58b8aSYinghai Lu static int __initdata known_bridge; 40705c58b8aSYinghai Lu 408968cbfadSThomas Gleixner static void __init __pci_mmcfg_init(int early) 409fb9aa6f1SThomas Gleixner { 4107752d5cfSRobert Hancock /* MMCONFIG disabled */ 4117752d5cfSRobert Hancock if ((pci_probe & PCI_PROBE_MMCONF) == 0) 4127752d5cfSRobert Hancock return; 4137752d5cfSRobert Hancock 4147752d5cfSRobert Hancock /* MMCONFIG already enabled */ 41505c58b8aSYinghai Lu if (!early && !(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF)) 4167752d5cfSRobert Hancock return; 4177752d5cfSRobert Hancock 41805c58b8aSYinghai Lu /* for late to exit */ 41905c58b8aSYinghai Lu if (known_bridge) 42005c58b8aSYinghai Lu return; 4217752d5cfSRobert Hancock 422bb63b421SYinghai Lu if (early) { 42305c58b8aSYinghai Lu if (pci_mmcfg_check_hostbridge()) 42405c58b8aSYinghai Lu known_bridge = 1; 42505c58b8aSYinghai Lu } 42605c58b8aSYinghai Lu 42705c58b8aSYinghai Lu if (!known_bridge) { 42805c58b8aSYinghai Lu acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg); 429bb63b421SYinghai Lu pci_mmcfg_reject_broken(early); 43005c58b8aSYinghai Lu } 4317752d5cfSRobert Hancock 432fb9aa6f1SThomas Gleixner if ((pci_mmcfg_config_num == 0) || 433fb9aa6f1SThomas Gleixner (pci_mmcfg_config == NULL) || 434fb9aa6f1SThomas Gleixner (pci_mmcfg_config[0].address == 0)) 435fb9aa6f1SThomas Gleixner return; 436fb9aa6f1SThomas Gleixner 437*ebd60cd6SYinghai Lu if (pci_mmcfg_arch_init()) 438fb9aa6f1SThomas Gleixner pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; 439*ebd60cd6SYinghai Lu else { 440fb9aa6f1SThomas Gleixner /* 441fb9aa6f1SThomas Gleixner * Signal not to attempt to insert mmcfg resources because 442fb9aa6f1SThomas Gleixner * the architecture mmcfg setup could not initialize. 443fb9aa6f1SThomas Gleixner */ 444fb9aa6f1SThomas Gleixner pci_mmcfg_resources_inserted = 1; 445fb9aa6f1SThomas Gleixner } 446fb9aa6f1SThomas Gleixner } 447fb9aa6f1SThomas Gleixner 448bb63b421SYinghai Lu void __init pci_mmcfg_early_init(void) 44905c58b8aSYinghai Lu { 450bb63b421SYinghai Lu __pci_mmcfg_init(1); 45105c58b8aSYinghai Lu } 45205c58b8aSYinghai Lu 45305c58b8aSYinghai Lu void __init pci_mmcfg_late_init(void) 45405c58b8aSYinghai Lu { 455bb63b421SYinghai Lu __pci_mmcfg_init(0); 45605c58b8aSYinghai Lu } 45705c58b8aSYinghai Lu 458fb9aa6f1SThomas Gleixner static int __init pci_mmcfg_late_insert_resources(void) 459fb9aa6f1SThomas Gleixner { 460fb9aa6f1SThomas Gleixner /* 461fb9aa6f1SThomas Gleixner * If resources are already inserted or we are not using MMCONFIG, 462fb9aa6f1SThomas Gleixner * don't insert the resources. 463fb9aa6f1SThomas Gleixner */ 464fb9aa6f1SThomas Gleixner if ((pci_mmcfg_resources_inserted == 1) || 465fb9aa6f1SThomas Gleixner (pci_probe & PCI_PROBE_MMCONF) == 0 || 466fb9aa6f1SThomas Gleixner (pci_mmcfg_config_num == 0) || 467fb9aa6f1SThomas Gleixner (pci_mmcfg_config == NULL) || 468fb9aa6f1SThomas Gleixner (pci_mmcfg_config[0].address == 0)) 469fb9aa6f1SThomas Gleixner return 1; 470fb9aa6f1SThomas Gleixner 471fb9aa6f1SThomas Gleixner /* 472fb9aa6f1SThomas Gleixner * Attempt to insert the mmcfg resources but not with the busy flag 473fb9aa6f1SThomas Gleixner * marked so it won't cause request errors when __request_region is 474fb9aa6f1SThomas Gleixner * called. 475fb9aa6f1SThomas Gleixner */ 476*ebd60cd6SYinghai Lu pci_mmcfg_insert_resources(); 477fb9aa6f1SThomas Gleixner 478fb9aa6f1SThomas Gleixner return 0; 479fb9aa6f1SThomas Gleixner } 480fb9aa6f1SThomas Gleixner 481fb9aa6f1SThomas Gleixner /* 482fb9aa6f1SThomas Gleixner * Perform MMCONFIG resource insertion after PCI initialization to allow for 483fb9aa6f1SThomas Gleixner * misprogrammed MCFG tables that state larger sizes but actually conflict 484fb9aa6f1SThomas Gleixner * with other system resources. 485fb9aa6f1SThomas Gleixner */ 486fb9aa6f1SThomas Gleixner late_initcall(pci_mmcfg_late_insert_resources); 487