xref: /openbmc/linux/arch/x86/pci/mmconfig-shared.c (revision 0b64ad7123eb013c3de26750f2d4c356cd566231)
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;
31b6ce068aSMatthew Wilcox 	pci_direct_conf1.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 
56b6ce068aSMatthew Wilcox 	pci_direct_conf1.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 
103fb9aa6f1SThomas Gleixner struct pci_mmcfg_hostbridge_probe {
104fb9aa6f1SThomas Gleixner 	u32 vendor;
105fb9aa6f1SThomas Gleixner 	u32 device;
106fb9aa6f1SThomas Gleixner 	const char *(*probe)(void);
107fb9aa6f1SThomas Gleixner };
108fb9aa6f1SThomas Gleixner 
109fb9aa6f1SThomas Gleixner static struct pci_mmcfg_hostbridge_probe pci_mmcfg_probes[] __initdata = {
110fb9aa6f1SThomas Gleixner 	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH, pci_mmcfg_e7520 },
111fb9aa6f1SThomas Gleixner 	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82945G_HB, pci_mmcfg_intel_945 },
112fb9aa6f1SThomas Gleixner };
113fb9aa6f1SThomas Gleixner 
114fb9aa6f1SThomas Gleixner static int __init pci_mmcfg_check_hostbridge(void)
115fb9aa6f1SThomas Gleixner {
116fb9aa6f1SThomas Gleixner 	u32 l;
117fb9aa6f1SThomas Gleixner 	u16 vendor, device;
118fb9aa6f1SThomas Gleixner 	int i;
119fb9aa6f1SThomas Gleixner 	const char *name;
120fb9aa6f1SThomas Gleixner 
121b6ce068aSMatthew Wilcox 	pci_direct_conf1.read(0, 0, PCI_DEVFN(0,0), 0, 4, &l);
122fb9aa6f1SThomas Gleixner 	vendor = l & 0xffff;
123fb9aa6f1SThomas Gleixner 	device = (l >> 16) & 0xffff;
124fb9aa6f1SThomas Gleixner 
125fb9aa6f1SThomas Gleixner 	pci_mmcfg_config_num = 0;
126fb9aa6f1SThomas Gleixner 	pci_mmcfg_config = NULL;
127fb9aa6f1SThomas Gleixner 	name = NULL;
128fb9aa6f1SThomas Gleixner 
129fb9aa6f1SThomas Gleixner 	for (i = 0; !name && i < ARRAY_SIZE(pci_mmcfg_probes); i++) {
130fb9aa6f1SThomas Gleixner 		if (pci_mmcfg_probes[i].vendor == vendor &&
131fb9aa6f1SThomas Gleixner 		    pci_mmcfg_probes[i].device == device)
132fb9aa6f1SThomas Gleixner 			name = pci_mmcfg_probes[i].probe();
133fb9aa6f1SThomas Gleixner 	}
134fb9aa6f1SThomas Gleixner 
135fb9aa6f1SThomas Gleixner 	if (name) {
136fb9aa6f1SThomas Gleixner 		printk(KERN_INFO "PCI: Found %s %s MMCONFIG support.\n",
137fb9aa6f1SThomas Gleixner 		       name, pci_mmcfg_config_num ? "with" : "without");
138fb9aa6f1SThomas Gleixner 	}
139fb9aa6f1SThomas Gleixner 
140fb9aa6f1SThomas Gleixner 	return name != NULL;
141fb9aa6f1SThomas Gleixner }
142fb9aa6f1SThomas Gleixner 
143fb9aa6f1SThomas Gleixner static void __init pci_mmcfg_insert_resources(unsigned long resource_flags)
144fb9aa6f1SThomas Gleixner {
145fb9aa6f1SThomas Gleixner #define PCI_MMCFG_RESOURCE_NAME_LEN 19
146fb9aa6f1SThomas Gleixner 	int i;
147fb9aa6f1SThomas Gleixner 	struct resource *res;
148fb9aa6f1SThomas Gleixner 	char *names;
149fb9aa6f1SThomas Gleixner 	unsigned num_buses;
150fb9aa6f1SThomas Gleixner 
151fb9aa6f1SThomas Gleixner 	res = kcalloc(PCI_MMCFG_RESOURCE_NAME_LEN + sizeof(*res),
152fb9aa6f1SThomas Gleixner 			pci_mmcfg_config_num, GFP_KERNEL);
153fb9aa6f1SThomas Gleixner 	if (!res) {
154fb9aa6f1SThomas Gleixner 		printk(KERN_ERR "PCI: Unable to allocate MMCONFIG resources\n");
155fb9aa6f1SThomas Gleixner 		return;
156fb9aa6f1SThomas Gleixner 	}
157fb9aa6f1SThomas Gleixner 
158fb9aa6f1SThomas Gleixner 	names = (void *)&res[pci_mmcfg_config_num];
159fb9aa6f1SThomas Gleixner 	for (i = 0; i < pci_mmcfg_config_num; i++, res++) {
160fb9aa6f1SThomas Gleixner 		struct acpi_mcfg_allocation *cfg = &pci_mmcfg_config[i];
161fb9aa6f1SThomas Gleixner 		num_buses = cfg->end_bus_number - cfg->start_bus_number + 1;
162fb9aa6f1SThomas Gleixner 		res->name = names;
163fb9aa6f1SThomas Gleixner 		snprintf(names, PCI_MMCFG_RESOURCE_NAME_LEN, "PCI MMCONFIG %u",
164fb9aa6f1SThomas Gleixner 			 cfg->pci_segment);
165fb9aa6f1SThomas Gleixner 		res->start = cfg->address;
166fb9aa6f1SThomas Gleixner 		res->end = res->start + (num_buses << 20) - 1;
167fb9aa6f1SThomas Gleixner 		res->flags = IORESOURCE_MEM | resource_flags;
168fb9aa6f1SThomas Gleixner 		insert_resource(&iomem_resource, res);
169fb9aa6f1SThomas Gleixner 		names += PCI_MMCFG_RESOURCE_NAME_LEN;
170fb9aa6f1SThomas Gleixner 	}
171fb9aa6f1SThomas Gleixner 
172fb9aa6f1SThomas Gleixner 	/* Mark that the resources have been inserted. */
173fb9aa6f1SThomas Gleixner 	pci_mmcfg_resources_inserted = 1;
174fb9aa6f1SThomas Gleixner }
175fb9aa6f1SThomas Gleixner 
1767752d5cfSRobert Hancock static acpi_status __init check_mcfg_resource(struct acpi_resource *res,
1777752d5cfSRobert Hancock 					      void *data)
1787752d5cfSRobert Hancock {
1797752d5cfSRobert Hancock 	struct resource *mcfg_res = data;
1807752d5cfSRobert Hancock 	struct acpi_resource_address64 address;
1817752d5cfSRobert Hancock 	acpi_status status;
1827752d5cfSRobert Hancock 
1837752d5cfSRobert Hancock 	if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
1847752d5cfSRobert Hancock 		struct acpi_resource_fixed_memory32 *fixmem32 =
1857752d5cfSRobert Hancock 			&res->data.fixed_memory32;
1867752d5cfSRobert Hancock 		if (!fixmem32)
1877752d5cfSRobert Hancock 			return AE_OK;
1887752d5cfSRobert Hancock 		if ((mcfg_res->start >= fixmem32->address) &&
1897752d5cfSRobert Hancock 		    (mcfg_res->end < (fixmem32->address +
1907752d5cfSRobert Hancock 				      fixmem32->address_length))) {
1917752d5cfSRobert Hancock 			mcfg_res->flags = 1;
1927752d5cfSRobert Hancock 			return AE_CTRL_TERMINATE;
1937752d5cfSRobert Hancock 		}
1947752d5cfSRobert Hancock 	}
1957752d5cfSRobert Hancock 	if ((res->type != ACPI_RESOURCE_TYPE_ADDRESS32) &&
1967752d5cfSRobert Hancock 	    (res->type != ACPI_RESOURCE_TYPE_ADDRESS64))
1977752d5cfSRobert Hancock 		return AE_OK;
1987752d5cfSRobert Hancock 
1997752d5cfSRobert Hancock 	status = acpi_resource_to_address64(res, &address);
2007752d5cfSRobert Hancock 	if (ACPI_FAILURE(status) ||
2017752d5cfSRobert Hancock 	   (address.address_length <= 0) ||
2027752d5cfSRobert Hancock 	   (address.resource_type != ACPI_MEMORY_RANGE))
2037752d5cfSRobert Hancock 		return AE_OK;
2047752d5cfSRobert Hancock 
2057752d5cfSRobert Hancock 	if ((mcfg_res->start >= address.minimum) &&
2067752d5cfSRobert Hancock 	    (mcfg_res->end < (address.minimum + address.address_length))) {
2077752d5cfSRobert Hancock 		mcfg_res->flags = 1;
2087752d5cfSRobert Hancock 		return AE_CTRL_TERMINATE;
2097752d5cfSRobert Hancock 	}
2107752d5cfSRobert Hancock 	return AE_OK;
2117752d5cfSRobert Hancock }
2127752d5cfSRobert Hancock 
2137752d5cfSRobert Hancock static acpi_status __init find_mboard_resource(acpi_handle handle, u32 lvl,
2147752d5cfSRobert Hancock 		void *context, void **rv)
2157752d5cfSRobert Hancock {
2167752d5cfSRobert Hancock 	struct resource *mcfg_res = context;
2177752d5cfSRobert Hancock 
2187752d5cfSRobert Hancock 	acpi_walk_resources(handle, METHOD_NAME__CRS,
2197752d5cfSRobert Hancock 			    check_mcfg_resource, context);
2207752d5cfSRobert Hancock 
2217752d5cfSRobert Hancock 	if (mcfg_res->flags)
2227752d5cfSRobert Hancock 		return AE_CTRL_TERMINATE;
2237752d5cfSRobert Hancock 
2247752d5cfSRobert Hancock 	return AE_OK;
2257752d5cfSRobert Hancock }
2267752d5cfSRobert Hancock 
2277752d5cfSRobert Hancock static int __init is_acpi_reserved(unsigned long start, unsigned long end)
2287752d5cfSRobert Hancock {
2297752d5cfSRobert Hancock 	struct resource mcfg_res;
2307752d5cfSRobert Hancock 
2317752d5cfSRobert Hancock 	mcfg_res.start = start;
2327752d5cfSRobert Hancock 	mcfg_res.end = end;
2337752d5cfSRobert Hancock 	mcfg_res.flags = 0;
2347752d5cfSRobert Hancock 
2357752d5cfSRobert Hancock 	acpi_get_devices("PNP0C01", find_mboard_resource, &mcfg_res, NULL);
2367752d5cfSRobert Hancock 
2377752d5cfSRobert Hancock 	if (!mcfg_res.flags)
2387752d5cfSRobert Hancock 		acpi_get_devices("PNP0C02", find_mboard_resource, &mcfg_res,
2397752d5cfSRobert Hancock 				 NULL);
2407752d5cfSRobert Hancock 
2417752d5cfSRobert Hancock 	return mcfg_res.flags;
2427752d5cfSRobert Hancock }
2437752d5cfSRobert Hancock 
2447752d5cfSRobert Hancock static void __init pci_mmcfg_reject_broken(void)
245fb9aa6f1SThomas Gleixner {
246fb9aa6f1SThomas Gleixner 	typeof(pci_mmcfg_config[0]) *cfg;
2477752d5cfSRobert Hancock 	int i;
248fb9aa6f1SThomas Gleixner 
249fb9aa6f1SThomas Gleixner 	if ((pci_mmcfg_config_num == 0) ||
250fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config == NULL) ||
251fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config[0].address == 0))
252fb9aa6f1SThomas Gleixner 		return;
253fb9aa6f1SThomas Gleixner 
254fb9aa6f1SThomas Gleixner 	cfg = &pci_mmcfg_config[0];
255fb9aa6f1SThomas Gleixner 
256fb9aa6f1SThomas Gleixner 	/*
257fb9aa6f1SThomas Gleixner 	 * Handle more broken MCFG tables on Asus etc.
258fb9aa6f1SThomas Gleixner 	 * They only contain a single entry for bus 0-0.
259fb9aa6f1SThomas Gleixner 	 */
260fb9aa6f1SThomas Gleixner 	if (pci_mmcfg_config_num == 1 &&
261fb9aa6f1SThomas Gleixner 	    cfg->pci_segment == 0 &&
262fb9aa6f1SThomas Gleixner 	    (cfg->start_bus_number | cfg->end_bus_number) == 0) {
263fb9aa6f1SThomas Gleixner 		printk(KERN_ERR "PCI: start and end of bus number is 0. "
264fb9aa6f1SThomas Gleixner 		       "Rejected as broken MCFG.\n");
265fb9aa6f1SThomas Gleixner 		goto reject;
266fb9aa6f1SThomas Gleixner 	}
267fb9aa6f1SThomas Gleixner 
2687752d5cfSRobert Hancock 	for (i = 0; i < pci_mmcfg_config_num; i++) {
2697752d5cfSRobert Hancock 		u32 size = (cfg->end_bus_number + 1) << 20;
2707752d5cfSRobert Hancock 		cfg = &pci_mmcfg_config[i];
2717752d5cfSRobert Hancock 		printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lu "
2727752d5cfSRobert Hancock 		       "segment %hu buses %u - %u\n",
2737752d5cfSRobert Hancock 		       i, (unsigned long)cfg->address, cfg->pci_segment,
2747752d5cfSRobert Hancock 		       (unsigned int)cfg->start_bus_number,
2757752d5cfSRobert Hancock 		       (unsigned int)cfg->end_bus_number);
2767752d5cfSRobert Hancock 		if (is_acpi_reserved(cfg->address, cfg->address + size - 1)) {
2777752d5cfSRobert Hancock 			printk(KERN_NOTICE "PCI: MCFG area at %Lx reserved "
2787752d5cfSRobert Hancock 			       "in ACPI motherboard resources\n",
2797752d5cfSRobert Hancock 			       cfg->address);
2807752d5cfSRobert Hancock 		} else {
281fb9aa6f1SThomas Gleixner 			printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %Lx is not"
2827752d5cfSRobert Hancock 			       " reserved in ACPI motherboard resources\n",
2837752d5cfSRobert Hancock 			       cfg->address);
2847752d5cfSRobert Hancock 			/* Don't try to do this check unless configuration
2857752d5cfSRobert Hancock 			   type 1 is available. */
2867752d5cfSRobert Hancock 			if ((pci_probe & PCI_PROBE_CONF1) &&
2877752d5cfSRobert Hancock 			    e820_all_mapped(cfg->address,
2887752d5cfSRobert Hancock 					    cfg->address + size - 1,
2897752d5cfSRobert Hancock 					    E820_RESERVED))
2907752d5cfSRobert Hancock 				printk(KERN_NOTICE
2917752d5cfSRobert Hancock 				       "PCI: MCFG area at %Lx reserved in "
2927752d5cfSRobert Hancock 				       "E820\n",
2937752d5cfSRobert Hancock 				       cfg->address);
2947752d5cfSRobert Hancock 			else
295fb9aa6f1SThomas Gleixner 				goto reject;
296fb9aa6f1SThomas Gleixner 		}
2977752d5cfSRobert Hancock 	}
2987752d5cfSRobert Hancock 
299fb9aa6f1SThomas Gleixner 	return;
300fb9aa6f1SThomas Gleixner 
301fb9aa6f1SThomas Gleixner reject:
302fb9aa6f1SThomas Gleixner 	printk(KERN_ERR "PCI: Not using MMCONFIG.\n");
303*0b64ad71SYinghai Lu 	pci_mmcfg_arch_free();
304fb9aa6f1SThomas Gleixner 	kfree(pci_mmcfg_config);
305fb9aa6f1SThomas Gleixner 	pci_mmcfg_config = NULL;
306fb9aa6f1SThomas Gleixner 	pci_mmcfg_config_num = 0;
307fb9aa6f1SThomas Gleixner }
308fb9aa6f1SThomas Gleixner 
3097752d5cfSRobert Hancock void __init pci_mmcfg_early_init(int type)
310fb9aa6f1SThomas Gleixner {
311fb9aa6f1SThomas Gleixner 	if ((pci_probe & PCI_PROBE_MMCONF) == 0)
312fb9aa6f1SThomas Gleixner 		return;
313fb9aa6f1SThomas Gleixner 
3147752d5cfSRobert Hancock 	/* If type 1 access is available, no need to enable MMCONFIG yet, we can
3157752d5cfSRobert Hancock 	   defer until later when the ACPI interpreter is available to better
3167752d5cfSRobert Hancock 	   validate things. */
3177752d5cfSRobert Hancock 	if (type == 1)
3187752d5cfSRobert Hancock 		return;
319fb9aa6f1SThomas Gleixner 
320fb9aa6f1SThomas Gleixner 	acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg);
3217752d5cfSRobert Hancock 
3227752d5cfSRobert Hancock 	if ((pci_mmcfg_config_num == 0) ||
3237752d5cfSRobert Hancock 	    (pci_mmcfg_config == NULL) ||
3247752d5cfSRobert Hancock 	    (pci_mmcfg_config[0].address == 0))
3257752d5cfSRobert Hancock 		return;
3267752d5cfSRobert Hancock 
3277752d5cfSRobert Hancock 	if (pci_mmcfg_arch_init())
3287752d5cfSRobert Hancock 		pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
329fb9aa6f1SThomas Gleixner }
330fb9aa6f1SThomas Gleixner 
3317752d5cfSRobert Hancock void __init pci_mmcfg_late_init(void)
3327752d5cfSRobert Hancock {
3337752d5cfSRobert Hancock 	int known_bridge = 0;
3347752d5cfSRobert Hancock 
3357752d5cfSRobert Hancock 	/* MMCONFIG disabled */
3367752d5cfSRobert Hancock 	if ((pci_probe & PCI_PROBE_MMCONF) == 0)
3377752d5cfSRobert Hancock 		return;
3387752d5cfSRobert Hancock 
3397752d5cfSRobert Hancock 	/* MMCONFIG already enabled */
3407752d5cfSRobert Hancock 	if (!(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF))
3417752d5cfSRobert Hancock 		return;
3427752d5cfSRobert Hancock 
3437752d5cfSRobert Hancock 	if ((pci_probe & PCI_PROBE_CONF1) && pci_mmcfg_check_hostbridge())
3447752d5cfSRobert Hancock 		known_bridge = 1;
3457752d5cfSRobert Hancock 	else
3467752d5cfSRobert Hancock 		acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg);
3477752d5cfSRobert Hancock 
3487752d5cfSRobert Hancock 	pci_mmcfg_reject_broken();
3497752d5cfSRobert Hancock 
350fb9aa6f1SThomas Gleixner 	if ((pci_mmcfg_config_num == 0) ||
351fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config == NULL) ||
352fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config[0].address == 0))
353fb9aa6f1SThomas Gleixner 		return;
354fb9aa6f1SThomas Gleixner 
355fb9aa6f1SThomas Gleixner 	if (pci_mmcfg_arch_init()) {
356fb9aa6f1SThomas Gleixner 		if (known_bridge)
357fb9aa6f1SThomas Gleixner 			pci_mmcfg_insert_resources(IORESOURCE_BUSY);
358fb9aa6f1SThomas Gleixner 		pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
359fb9aa6f1SThomas Gleixner 	} else {
360fb9aa6f1SThomas Gleixner 		/*
361fb9aa6f1SThomas Gleixner 		 * Signal not to attempt to insert mmcfg resources because
362fb9aa6f1SThomas Gleixner 		 * the architecture mmcfg setup could not initialize.
363fb9aa6f1SThomas Gleixner 		 */
364fb9aa6f1SThomas Gleixner 		pci_mmcfg_resources_inserted = 1;
365fb9aa6f1SThomas Gleixner 	}
366fb9aa6f1SThomas Gleixner }
367fb9aa6f1SThomas Gleixner 
368fb9aa6f1SThomas Gleixner static int __init pci_mmcfg_late_insert_resources(void)
369fb9aa6f1SThomas Gleixner {
370fb9aa6f1SThomas Gleixner 	/*
371fb9aa6f1SThomas Gleixner 	 * If resources are already inserted or we are not using MMCONFIG,
372fb9aa6f1SThomas Gleixner 	 * don't insert the resources.
373fb9aa6f1SThomas Gleixner 	 */
374fb9aa6f1SThomas Gleixner 	if ((pci_mmcfg_resources_inserted == 1) ||
375fb9aa6f1SThomas Gleixner 	    (pci_probe & PCI_PROBE_MMCONF) == 0 ||
376fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config_num == 0) ||
377fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config == NULL) ||
378fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config[0].address == 0))
379fb9aa6f1SThomas Gleixner 		return 1;
380fb9aa6f1SThomas Gleixner 
381fb9aa6f1SThomas Gleixner 	/*
382fb9aa6f1SThomas Gleixner 	 * Attempt to insert the mmcfg resources but not with the busy flag
383fb9aa6f1SThomas Gleixner 	 * marked so it won't cause request errors when __request_region is
384fb9aa6f1SThomas Gleixner 	 * called.
385fb9aa6f1SThomas Gleixner 	 */
386fb9aa6f1SThomas Gleixner 	pci_mmcfg_insert_resources(0);
387fb9aa6f1SThomas Gleixner 
388fb9aa6f1SThomas Gleixner 	return 0;
389fb9aa6f1SThomas Gleixner }
390fb9aa6f1SThomas Gleixner 
391fb9aa6f1SThomas Gleixner /*
392fb9aa6f1SThomas Gleixner  * Perform MMCONFIG resource insertion after PCI initialization to allow for
393fb9aa6f1SThomas Gleixner  * misprogrammed MCFG tables that state larger sizes but actually conflict
394fb9aa6f1SThomas Gleixner  * with other system resources.
395fb9aa6f1SThomas Gleixner  */
396fb9aa6f1SThomas Gleixner late_initcall(pci_mmcfg_late_insert_resources);
397