xref: /openbmc/linux/arch/x86/pci/mmconfig-shared.c (revision 7752d5cfe3d11ca0bb9c673ec38bd78ba6578f8e)
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 
176*7752d5cfSRobert Hancock static acpi_status __init check_mcfg_resource(struct acpi_resource *res,
177*7752d5cfSRobert Hancock 					      void *data)
178*7752d5cfSRobert Hancock {
179*7752d5cfSRobert Hancock 	struct resource *mcfg_res = data;
180*7752d5cfSRobert Hancock 	struct acpi_resource_address64 address;
181*7752d5cfSRobert Hancock 	acpi_status status;
182*7752d5cfSRobert Hancock 
183*7752d5cfSRobert Hancock 	if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
184*7752d5cfSRobert Hancock 		struct acpi_resource_fixed_memory32 *fixmem32 =
185*7752d5cfSRobert Hancock 			&res->data.fixed_memory32;
186*7752d5cfSRobert Hancock 		if (!fixmem32)
187*7752d5cfSRobert Hancock 			return AE_OK;
188*7752d5cfSRobert Hancock 		if ((mcfg_res->start >= fixmem32->address) &&
189*7752d5cfSRobert Hancock 		    (mcfg_res->end < (fixmem32->address +
190*7752d5cfSRobert Hancock 				      fixmem32->address_length))) {
191*7752d5cfSRobert Hancock 			mcfg_res->flags = 1;
192*7752d5cfSRobert Hancock 			return AE_CTRL_TERMINATE;
193*7752d5cfSRobert Hancock 		}
194*7752d5cfSRobert Hancock 	}
195*7752d5cfSRobert Hancock 	if ((res->type != ACPI_RESOURCE_TYPE_ADDRESS32) &&
196*7752d5cfSRobert Hancock 	    (res->type != ACPI_RESOURCE_TYPE_ADDRESS64))
197*7752d5cfSRobert Hancock 		return AE_OK;
198*7752d5cfSRobert Hancock 
199*7752d5cfSRobert Hancock 	status = acpi_resource_to_address64(res, &address);
200*7752d5cfSRobert Hancock 	if (ACPI_FAILURE(status) ||
201*7752d5cfSRobert Hancock 	   (address.address_length <= 0) ||
202*7752d5cfSRobert Hancock 	   (address.resource_type != ACPI_MEMORY_RANGE))
203*7752d5cfSRobert Hancock 		return AE_OK;
204*7752d5cfSRobert Hancock 
205*7752d5cfSRobert Hancock 	if ((mcfg_res->start >= address.minimum) &&
206*7752d5cfSRobert Hancock 	    (mcfg_res->end < (address.minimum + address.address_length))) {
207*7752d5cfSRobert Hancock 		mcfg_res->flags = 1;
208*7752d5cfSRobert Hancock 		return AE_CTRL_TERMINATE;
209*7752d5cfSRobert Hancock 	}
210*7752d5cfSRobert Hancock 	return AE_OK;
211*7752d5cfSRobert Hancock }
212*7752d5cfSRobert Hancock 
213*7752d5cfSRobert Hancock static acpi_status __init find_mboard_resource(acpi_handle handle, u32 lvl,
214*7752d5cfSRobert Hancock 		void *context, void **rv)
215*7752d5cfSRobert Hancock {
216*7752d5cfSRobert Hancock 	struct resource *mcfg_res = context;
217*7752d5cfSRobert Hancock 
218*7752d5cfSRobert Hancock 	acpi_walk_resources(handle, METHOD_NAME__CRS,
219*7752d5cfSRobert Hancock 			    check_mcfg_resource, context);
220*7752d5cfSRobert Hancock 
221*7752d5cfSRobert Hancock 	if (mcfg_res->flags)
222*7752d5cfSRobert Hancock 		return AE_CTRL_TERMINATE;
223*7752d5cfSRobert Hancock 
224*7752d5cfSRobert Hancock 	return AE_OK;
225*7752d5cfSRobert Hancock }
226*7752d5cfSRobert Hancock 
227*7752d5cfSRobert Hancock static int __init is_acpi_reserved(unsigned long start, unsigned long end)
228*7752d5cfSRobert Hancock {
229*7752d5cfSRobert Hancock 	struct resource mcfg_res;
230*7752d5cfSRobert Hancock 
231*7752d5cfSRobert Hancock 	mcfg_res.start = start;
232*7752d5cfSRobert Hancock 	mcfg_res.end = end;
233*7752d5cfSRobert Hancock 	mcfg_res.flags = 0;
234*7752d5cfSRobert Hancock 
235*7752d5cfSRobert Hancock 	acpi_get_devices("PNP0C01", find_mboard_resource, &mcfg_res, NULL);
236*7752d5cfSRobert Hancock 
237*7752d5cfSRobert Hancock 	if (!mcfg_res.flags)
238*7752d5cfSRobert Hancock 		acpi_get_devices("PNP0C02", find_mboard_resource, &mcfg_res,
239*7752d5cfSRobert Hancock 				 NULL);
240*7752d5cfSRobert Hancock 
241*7752d5cfSRobert Hancock 	return mcfg_res.flags;
242*7752d5cfSRobert Hancock }
243*7752d5cfSRobert Hancock 
244*7752d5cfSRobert Hancock static void __init pci_mmcfg_reject_broken(void)
245fb9aa6f1SThomas Gleixner {
246fb9aa6f1SThomas Gleixner 	typeof(pci_mmcfg_config[0]) *cfg;
247*7752d5cfSRobert 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 
268*7752d5cfSRobert Hancock 	for (i = 0; i < pci_mmcfg_config_num; i++) {
269*7752d5cfSRobert Hancock 		u32 size = (cfg->end_bus_number + 1) << 20;
270*7752d5cfSRobert Hancock 		cfg = &pci_mmcfg_config[i];
271*7752d5cfSRobert Hancock 		printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lu "
272*7752d5cfSRobert Hancock 		       "segment %hu buses %u - %u\n",
273*7752d5cfSRobert Hancock 		       i, (unsigned long)cfg->address, cfg->pci_segment,
274*7752d5cfSRobert Hancock 		       (unsigned int)cfg->start_bus_number,
275*7752d5cfSRobert Hancock 		       (unsigned int)cfg->end_bus_number);
276*7752d5cfSRobert Hancock 		if (is_acpi_reserved(cfg->address, cfg->address + size - 1)) {
277*7752d5cfSRobert Hancock 			printk(KERN_NOTICE "PCI: MCFG area at %Lx reserved "
278*7752d5cfSRobert Hancock 			       "in ACPI motherboard resources\n",
279*7752d5cfSRobert Hancock 			       cfg->address);
280*7752d5cfSRobert Hancock 		} else {
281fb9aa6f1SThomas Gleixner 			printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %Lx is not"
282*7752d5cfSRobert Hancock 			       " reserved in ACPI motherboard resources\n",
283*7752d5cfSRobert Hancock 			       cfg->address);
284*7752d5cfSRobert Hancock 			/* Don't try to do this check unless configuration
285*7752d5cfSRobert Hancock 			   type 1 is available. */
286*7752d5cfSRobert Hancock 			if ((pci_probe & PCI_PROBE_CONF1) &&
287*7752d5cfSRobert Hancock 			    e820_all_mapped(cfg->address,
288*7752d5cfSRobert Hancock 					    cfg->address + size - 1,
289*7752d5cfSRobert Hancock 					    E820_RESERVED))
290*7752d5cfSRobert Hancock 				printk(KERN_NOTICE
291*7752d5cfSRobert Hancock 				       "PCI: MCFG area at %Lx reserved in "
292*7752d5cfSRobert Hancock 				       "E820\n",
293*7752d5cfSRobert Hancock 				       cfg->address);
294*7752d5cfSRobert Hancock 			else
295fb9aa6f1SThomas Gleixner 				goto reject;
296fb9aa6f1SThomas Gleixner 		}
297*7752d5cfSRobert Hancock 	}
298*7752d5cfSRobert Hancock 
299fb9aa6f1SThomas Gleixner 	return;
300fb9aa6f1SThomas Gleixner 
301fb9aa6f1SThomas Gleixner reject:
302fb9aa6f1SThomas Gleixner 	printk(KERN_ERR "PCI: Not using MMCONFIG.\n");
303fb9aa6f1SThomas Gleixner 	kfree(pci_mmcfg_config);
304fb9aa6f1SThomas Gleixner 	pci_mmcfg_config = NULL;
305fb9aa6f1SThomas Gleixner 	pci_mmcfg_config_num = 0;
306fb9aa6f1SThomas Gleixner }
307fb9aa6f1SThomas Gleixner 
308*7752d5cfSRobert Hancock void __init pci_mmcfg_early_init(int type)
309fb9aa6f1SThomas Gleixner {
310fb9aa6f1SThomas Gleixner 	if ((pci_probe & PCI_PROBE_MMCONF) == 0)
311fb9aa6f1SThomas Gleixner 		return;
312fb9aa6f1SThomas Gleixner 
313*7752d5cfSRobert Hancock 	/* If type 1 access is available, no need to enable MMCONFIG yet, we can
314*7752d5cfSRobert Hancock 	   defer until later when the ACPI interpreter is available to better
315*7752d5cfSRobert Hancock 	   validate things. */
316*7752d5cfSRobert Hancock 	if (type == 1)
317*7752d5cfSRobert Hancock 		return;
318fb9aa6f1SThomas Gleixner 
319fb9aa6f1SThomas Gleixner 	acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg);
320*7752d5cfSRobert Hancock 
321*7752d5cfSRobert Hancock 	if ((pci_mmcfg_config_num == 0) ||
322*7752d5cfSRobert Hancock 	    (pci_mmcfg_config == NULL) ||
323*7752d5cfSRobert Hancock 	    (pci_mmcfg_config[0].address == 0))
324*7752d5cfSRobert Hancock 		return;
325*7752d5cfSRobert Hancock 
326*7752d5cfSRobert Hancock 	if (pci_mmcfg_arch_init())
327*7752d5cfSRobert Hancock 		pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
328fb9aa6f1SThomas Gleixner }
329fb9aa6f1SThomas Gleixner 
330*7752d5cfSRobert Hancock void __init pci_mmcfg_late_init(void)
331*7752d5cfSRobert Hancock {
332*7752d5cfSRobert Hancock 	int known_bridge = 0;
333*7752d5cfSRobert Hancock 
334*7752d5cfSRobert Hancock 	/* MMCONFIG disabled */
335*7752d5cfSRobert Hancock 	if ((pci_probe & PCI_PROBE_MMCONF) == 0)
336*7752d5cfSRobert Hancock 		return;
337*7752d5cfSRobert Hancock 
338*7752d5cfSRobert Hancock 	/* MMCONFIG already enabled */
339*7752d5cfSRobert Hancock 	if (!(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF))
340*7752d5cfSRobert Hancock 		return;
341*7752d5cfSRobert Hancock 
342*7752d5cfSRobert Hancock 	if ((pci_probe & PCI_PROBE_CONF1) && pci_mmcfg_check_hostbridge())
343*7752d5cfSRobert Hancock 		known_bridge = 1;
344*7752d5cfSRobert Hancock 	else
345*7752d5cfSRobert Hancock 		acpi_table_parse(ACPI_SIG_MCFG, acpi_parse_mcfg);
346*7752d5cfSRobert Hancock 
347*7752d5cfSRobert Hancock 	pci_mmcfg_reject_broken();
348*7752d5cfSRobert Hancock 
349fb9aa6f1SThomas Gleixner 	if ((pci_mmcfg_config_num == 0) ||
350fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config == NULL) ||
351fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config[0].address == 0))
352fb9aa6f1SThomas Gleixner 		return;
353fb9aa6f1SThomas Gleixner 
354fb9aa6f1SThomas Gleixner 	if (pci_mmcfg_arch_init()) {
355fb9aa6f1SThomas Gleixner 		if (known_bridge)
356fb9aa6f1SThomas Gleixner 			pci_mmcfg_insert_resources(IORESOURCE_BUSY);
357fb9aa6f1SThomas Gleixner 		pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
358fb9aa6f1SThomas Gleixner 	} else {
359fb9aa6f1SThomas Gleixner 		/*
360fb9aa6f1SThomas Gleixner 		 * Signal not to attempt to insert mmcfg resources because
361fb9aa6f1SThomas Gleixner 		 * the architecture mmcfg setup could not initialize.
362fb9aa6f1SThomas Gleixner 		 */
363fb9aa6f1SThomas Gleixner 		pci_mmcfg_resources_inserted = 1;
364fb9aa6f1SThomas Gleixner 	}
365fb9aa6f1SThomas Gleixner }
366fb9aa6f1SThomas Gleixner 
367fb9aa6f1SThomas Gleixner static int __init pci_mmcfg_late_insert_resources(void)
368fb9aa6f1SThomas Gleixner {
369fb9aa6f1SThomas Gleixner 	/*
370fb9aa6f1SThomas Gleixner 	 * If resources are already inserted or we are not using MMCONFIG,
371fb9aa6f1SThomas Gleixner 	 * don't insert the resources.
372fb9aa6f1SThomas Gleixner 	 */
373fb9aa6f1SThomas Gleixner 	if ((pci_mmcfg_resources_inserted == 1) ||
374fb9aa6f1SThomas Gleixner 	    (pci_probe & PCI_PROBE_MMCONF) == 0 ||
375fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config_num == 0) ||
376fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config == NULL) ||
377fb9aa6f1SThomas Gleixner 	    (pci_mmcfg_config[0].address == 0))
378fb9aa6f1SThomas Gleixner 		return 1;
379fb9aa6f1SThomas Gleixner 
380fb9aa6f1SThomas Gleixner 	/*
381fb9aa6f1SThomas Gleixner 	 * Attempt to insert the mmcfg resources but not with the busy flag
382fb9aa6f1SThomas Gleixner 	 * marked so it won't cause request errors when __request_region is
383fb9aa6f1SThomas Gleixner 	 * called.
384fb9aa6f1SThomas Gleixner 	 */
385fb9aa6f1SThomas Gleixner 	pci_mmcfg_insert_resources(0);
386fb9aa6f1SThomas Gleixner 
387fb9aa6f1SThomas Gleixner 	return 0;
388fb9aa6f1SThomas Gleixner }
389fb9aa6f1SThomas Gleixner 
390fb9aa6f1SThomas Gleixner /*
391fb9aa6f1SThomas Gleixner  * Perform MMCONFIG resource insertion after PCI initialization to allow for
392fb9aa6f1SThomas Gleixner  * misprogrammed MCFG tables that state larger sizes but actually conflict
393fb9aa6f1SThomas Gleixner  * with other system resources.
394fb9aa6f1SThomas Gleixner  */
395fb9aa6f1SThomas Gleixner late_initcall(pci_mmcfg_late_insert_resources);
396