mmconfig-shared.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * mmconfig-shared.c - Low-level direct PCI config space access via
  3. * MMCONFIG - common code between i386 and x86-64.
  4. *
  5. * This code does:
  6. * - known chipset handling
  7. * - ACPI decoding and validation
  8. *
  9. * Per-architecture code takes care of the mappings and accesses
  10. * themselves.
  11. */
  12. #include <linux/pci.h>
  13. #include <linux/init.h>
  14. #include <linux/acpi.h>
  15. #include <linux/sfi_acpi.h>
  16. #include <linux/bitmap.h>
  17. #include <linux/dmi.h>
  18. #include <linux/sort.h>
  19. #include <asm/e820.h>
  20. #include <asm/pci_x86.h>
  21. #include <asm/acpi.h>
  22. #define PREFIX "PCI: "
  23. /* aperture is up to 256MB but BIOS may reserve less */
  24. #define MMCONFIG_APER_MIN (2 * 1024*1024)
  25. #define MMCONFIG_APER_MAX (256 * 1024*1024)
  26. /* Indicate if the mmcfg resources have been placed into the resource table. */
  27. static int __initdata pci_mmcfg_resources_inserted;
  28. static __init int extend_mmcfg(int num)
  29. {
  30. struct acpi_mcfg_allocation *new;
  31. int new_num = pci_mmcfg_config_num + num;
  32. new = kzalloc(sizeof(pci_mmcfg_config[0]) * new_num, GFP_KERNEL);
  33. if (!new)
  34. return -1;
  35. if (pci_mmcfg_config) {
  36. memcpy(new, pci_mmcfg_config,
  37. sizeof(pci_mmcfg_config[0]) * new_num);
  38. kfree(pci_mmcfg_config);
  39. }
  40. pci_mmcfg_config = new;
  41. return 0;
  42. }
  43. static __init void fill_one_mmcfg(u64 addr, int segment, int start, int end)
  44. {
  45. int i = pci_mmcfg_config_num;
  46. pci_mmcfg_config_num++;
  47. pci_mmcfg_config[i].address = addr;
  48. pci_mmcfg_config[i].pci_segment = segment;
  49. pci_mmcfg_config[i].start_bus_number = start;
  50. pci_mmcfg_config[i].end_bus_number = end;
  51. }
  52. static const char __init *pci_mmcfg_e7520(void)
  53. {
  54. u32 win;
  55. raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0xce, 2, &win);
  56. win = win & 0xf000;
  57. if (win == 0x0000 || win == 0xf000)
  58. return NULL;
  59. if (extend_mmcfg(1) == -1)
  60. return NULL;
  61. fill_one_mmcfg(win << 16, 0, 0, 255);
  62. return "Intel Corporation E7520 Memory Controller Hub";
  63. }
  64. static const char __init *pci_mmcfg_intel_945(void)
  65. {
  66. u32 pciexbar, mask = 0, len = 0;
  67. raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0x48, 4, &pciexbar);
  68. /* Enable bit */
  69. if (!(pciexbar & 1))
  70. return NULL;
  71. /* Size bits */
  72. switch ((pciexbar >> 1) & 3) {
  73. case 0:
  74. mask = 0xf0000000U;
  75. len = 0x10000000U;
  76. break;
  77. case 1:
  78. mask = 0xf8000000U;
  79. len = 0x08000000U;
  80. break;
  81. case 2:
  82. mask = 0xfc000000U;
  83. len = 0x04000000U;
  84. break;
  85. default:
  86. return NULL;
  87. }
  88. /* Errata #2, things break when not aligned on a 256Mb boundary */
  89. /* Can only happen in 64M/128M mode */
  90. if ((pciexbar & mask) & 0x0fffffffU)
  91. return NULL;
  92. /* Don't hit the APIC registers and their friends */
  93. if ((pciexbar & mask) >= 0xf0000000U)
  94. return NULL;
  95. if (extend_mmcfg(1) == -1)
  96. return NULL;
  97. fill_one_mmcfg(pciexbar & mask, 0, 0, (len >> 20) - 1);
  98. return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub";
  99. }
  100. static const char __init *pci_mmcfg_amd_fam10h(void)
  101. {
  102. u32 low, high, address;
  103. u64 base, msr;
  104. int i;
  105. unsigned segnbits = 0, busnbits;
  106. if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF))
  107. return NULL;
  108. address = MSR_FAM10H_MMIO_CONF_BASE;
  109. if (rdmsr_safe(address, &low, &high))
  110. return NULL;
  111. msr = high;
  112. msr <<= 32;
  113. msr |= low;
  114. /* mmconfig is not enable */
  115. if (!(msr & FAM10H_MMIO_CONF_ENABLE))
  116. return NULL;
  117. base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT);
  118. busnbits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
  119. FAM10H_MMIO_CONF_BUSRANGE_MASK;
  120. /*
  121. * only handle bus 0 ?
  122. * need to skip it
  123. */
  124. if (!busnbits)
  125. return NULL;
  126. if (busnbits > 8) {
  127. segnbits = busnbits - 8;
  128. busnbits = 8;
  129. }
  130. if (extend_mmcfg(1 << segnbits) == -1)
  131. return NULL;
  132. for (i = 0; i < (1 << segnbits); i++)
  133. fill_one_mmcfg(base + (1<<28) * i, i, 0, (1 << busnbits) - 1);
  134. return "AMD Family 10h NB";
  135. }
  136. static bool __initdata mcp55_checked;
  137. static const char __init *pci_mmcfg_nvidia_mcp55(void)
  138. {
  139. int bus;
  140. int mcp55_mmconf_found = 0;
  141. static const u32 extcfg_regnum = 0x90;
  142. static const u32 extcfg_regsize = 4;
  143. static const u32 extcfg_enable_mask = 1<<31;
  144. static const u32 extcfg_start_mask = 0xff<<16;
  145. static const int extcfg_start_shift = 16;
  146. static const u32 extcfg_size_mask = 0x3<<28;
  147. static const int extcfg_size_shift = 28;
  148. static const int extcfg_sizebus[] = {0x100, 0x80, 0x40, 0x20};
  149. static const u32 extcfg_base_mask[] = {0x7ff8, 0x7ffc, 0x7ffe, 0x7fff};
  150. static const int extcfg_base_lshift = 25;
  151. /*
  152. * do check if amd fam10h already took over
  153. */
  154. if (!acpi_disabled || pci_mmcfg_config_num || mcp55_checked)
  155. return NULL;
  156. mcp55_checked = true;
  157. for (bus = 0; bus < 256; bus++) {
  158. u64 base;
  159. u32 l, extcfg;
  160. u16 vendor, device;
  161. int start, size_index, end;
  162. raw_pci_ops->read(0, bus, PCI_DEVFN(0, 0), 0, 4, &l);
  163. vendor = l & 0xffff;
  164. device = (l >> 16) & 0xffff;
  165. if (PCI_VENDOR_ID_NVIDIA != vendor || 0x0369 != device)
  166. continue;
  167. raw_pci_ops->read(0, bus, PCI_DEVFN(0, 0), extcfg_regnum,
  168. extcfg_regsize, &extcfg);
  169. if (!(extcfg & extcfg_enable_mask))
  170. continue;
  171. if (extend_mmcfg(1) == -1)
  172. continue;
  173. size_index = (extcfg & extcfg_size_mask) >> extcfg_size_shift;
  174. base = extcfg & extcfg_base_mask[size_index];
  175. /* base could > 4G */
  176. base <<= extcfg_base_lshift;
  177. start = (extcfg & extcfg_start_mask) >> extcfg_start_shift;
  178. end = start + extcfg_sizebus[size_index] - 1;
  179. fill_one_mmcfg(base, 0, start, end);
  180. mcp55_mmconf_found++;
  181. }
  182. if (!mcp55_mmconf_found)
  183. return NULL;
  184. return "nVidia MCP55";
  185. }
  186. struct pci_mmcfg_hostbridge_probe {
  187. u32 bus;
  188. u32 devfn;
  189. u32 vendor;
  190. u32 device;
  191. const char *(*probe)(void);
  192. };
  193. static struct pci_mmcfg_hostbridge_probe pci_mmcfg_probes[] __initdata = {
  194. { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL,
  195. PCI_DEVICE_ID_INTEL_E7520_MCH, pci_mmcfg_e7520 },
  196. { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL,
  197. PCI_DEVICE_ID_INTEL_82945G_HB, pci_mmcfg_intel_945 },
  198. { 0, PCI_DEVFN(0x18, 0), PCI_VENDOR_ID_AMD,
  199. 0x1200, pci_mmcfg_amd_fam10h },
  200. { 0xff, PCI_DEVFN(0, 0), PCI_VENDOR_ID_AMD,
  201. 0x1200, pci_mmcfg_amd_fam10h },
  202. { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_NVIDIA,
  203. 0x0369, pci_mmcfg_nvidia_mcp55 },
  204. };
  205. static int __init cmp_mmcfg(const void *x1, const void *x2)
  206. {
  207. const typeof(pci_mmcfg_config[0]) *m1 = x1;
  208. const typeof(pci_mmcfg_config[0]) *m2 = x2;
  209. int start1, start2;
  210. start1 = m1->start_bus_number;
  211. start2 = m2->start_bus_number;
  212. return start1 - start2;
  213. }
  214. static void __init pci_mmcfg_check_end_bus_number(void)
  215. {
  216. int i;
  217. typeof(pci_mmcfg_config[0]) *cfg, *cfgx;
  218. /* sort them at first */
  219. sort(pci_mmcfg_config, pci_mmcfg_config_num,
  220. sizeof(pci_mmcfg_config[0]), cmp_mmcfg, NULL);
  221. /* last one*/
  222. if (pci_mmcfg_config_num > 0) {
  223. i = pci_mmcfg_config_num - 1;
  224. cfg = &pci_mmcfg_config[i];
  225. if (cfg->end_bus_number < cfg->start_bus_number)
  226. cfg->end_bus_number = 255;
  227. }
  228. /* don't overlap please */
  229. for (i = 0; i < pci_mmcfg_config_num - 1; i++) {
  230. cfg = &pci_mmcfg_config[i];
  231. cfgx = &pci_mmcfg_config[i+1];
  232. if (cfg->end_bus_number < cfg->start_bus_number)
  233. cfg->end_bus_number = 255;
  234. if (cfg->end_bus_number >= cfgx->start_bus_number)
  235. cfg->end_bus_number = cfgx->start_bus_number - 1;
  236. }
  237. }
  238. static int __init pci_mmcfg_check_hostbridge(void)
  239. {
  240. u32 l;
  241. u32 bus, devfn;
  242. u16 vendor, device;
  243. int i;
  244. const char *name;
  245. if (!raw_pci_ops)
  246. return 0;
  247. pci_mmcfg_config_num = 0;
  248. pci_mmcfg_config = NULL;
  249. for (i = 0; i < ARRAY_SIZE(pci_mmcfg_probes); i++) {
  250. bus = pci_mmcfg_probes[i].bus;
  251. devfn = pci_mmcfg_probes[i].devfn;
  252. raw_pci_ops->read(0, bus, devfn, 0, 4, &l);
  253. vendor = l & 0xffff;
  254. device = (l >> 16) & 0xffff;
  255. name = NULL;
  256. if (pci_mmcfg_probes[i].vendor == vendor &&
  257. pci_mmcfg_probes[i].device == device)
  258. name = pci_mmcfg_probes[i].probe();
  259. if (name)
  260. printk(KERN_INFO "PCI: Found %s with MMCONFIG support.\n",
  261. name);
  262. }
  263. /* some end_bus_number is crazy, fix it */
  264. pci_mmcfg_check_end_bus_number();
  265. return pci_mmcfg_config_num != 0;
  266. }
  267. static void __init pci_mmcfg_insert_resources(void)
  268. {
  269. #define PCI_MMCFG_RESOURCE_NAME_LEN 24
  270. int i;
  271. struct resource *res;
  272. char *names;
  273. unsigned num_buses;
  274. res = kcalloc(PCI_MMCFG_RESOURCE_NAME_LEN + sizeof(*res),
  275. pci_mmcfg_config_num, GFP_KERNEL);
  276. if (!res) {
  277. printk(KERN_ERR "PCI: Unable to allocate MMCONFIG resources\n");
  278. return;
  279. }
  280. names = (void *)&res[pci_mmcfg_config_num];
  281. for (i = 0; i < pci_mmcfg_config_num; i++, res++) {
  282. struct acpi_mcfg_allocation *cfg = &pci_mmcfg_config[i];
  283. num_buses = cfg->end_bus_number - cfg->start_bus_number + 1;
  284. res->name = names;
  285. snprintf(names, PCI_MMCFG_RESOURCE_NAME_LEN,
  286. "PCI MMCONFIG %u [%02x-%02x]", cfg->pci_segment,
  287. cfg->start_bus_number, cfg->end_bus_number);
  288. res->start = cfg->address + (cfg->start_bus_number << 20);
  289. res->end = res->start + (num_buses << 20) - 1;
  290. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  291. insert_resource(&iomem_resource, res);
  292. names += PCI_MMCFG_RESOURCE_NAME_LEN;
  293. }
  294. /* Mark that the resources have been inserted. */
  295. pci_mmcfg_resources_inserted = 1;
  296. }
  297. static acpi_status __init check_mcfg_resource(struct acpi_resource *res,
  298. void *data)
  299. {
  300. struct resource *mcfg_res = data;
  301. struct acpi_resource_address64 address;
  302. acpi_status status;
  303. if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
  304. struct acpi_resource_fixed_memory32 *fixmem32 =
  305. &res->data.fixed_memory32;
  306. if (!fixmem32)
  307. return AE_OK;
  308. if ((mcfg_res->start >= fixmem32->address) &&
  309. (mcfg_res->end < (fixmem32->address +
  310. fixmem32->address_length))) {
  311. mcfg_res->flags = 1;
  312. return AE_CTRL_TERMINATE;
  313. }
  314. }
  315. if ((res->type != ACPI_RESOURCE_TYPE_ADDRESS32) &&
  316. (res->type != ACPI_RESOURCE_TYPE_ADDRESS64))
  317. return AE_OK;
  318. status = acpi_resource_to_address64(res, &address);
  319. if (ACPI_FAILURE(status) ||
  320. (address.address_length <= 0) ||
  321. (address.resource_type != ACPI_MEMORY_RANGE))
  322. return AE_OK;
  323. if ((mcfg_res->start >= address.minimum) &&
  324. (mcfg_res->end < (address.minimum + address.address_length))) {
  325. mcfg_res->flags = 1;
  326. return AE_CTRL_TERMINATE;
  327. }
  328. return AE_OK;
  329. }
  330. static acpi_status __init find_mboard_resource(acpi_handle handle, u32 lvl,
  331. void *context, void **rv)
  332. {
  333. struct resource *mcfg_res = context;
  334. acpi_walk_resources(handle, METHOD_NAME__CRS,
  335. check_mcfg_resource, context);
  336. if (mcfg_res->flags)
  337. return AE_CTRL_TERMINATE;
  338. return AE_OK;
  339. }
  340. static int __init is_acpi_reserved(u64 start, u64 end, unsigned not_used)
  341. {
  342. struct resource mcfg_res;
  343. mcfg_res.start = start;
  344. mcfg_res.end = end - 1;
  345. mcfg_res.flags = 0;
  346. acpi_get_devices("PNP0C01", find_mboard_resource, &mcfg_res, NULL);
  347. if (!mcfg_res.flags)
  348. acpi_get_devices("PNP0C02", find_mboard_resource, &mcfg_res,
  349. NULL);
  350. return mcfg_res.flags;
  351. }
  352. typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type);
  353. static int __init is_mmconf_reserved(check_reserved_t is_reserved,
  354. u64 addr, u64 size, int i,
  355. typeof(pci_mmcfg_config[0]) *cfg, int with_e820)
  356. {
  357. u64 old_size = size;
  358. int valid = 0;
  359. while (!is_reserved(addr, addr + size, E820_RESERVED)) {
  360. size >>= 1;
  361. if (size < (16UL<<20))
  362. break;
  363. }
  364. if (size >= (16UL<<20) || size == old_size) {
  365. printk(KERN_NOTICE
  366. "PCI: MCFG area at %Lx reserved in %s\n",
  367. addr, with_e820?"E820":"ACPI motherboard resources");
  368. valid = 1;
  369. if (old_size != size) {
  370. /* update end_bus_number */
  371. cfg->end_bus_number = cfg->start_bus_number + ((size>>20) - 1);
  372. printk(KERN_NOTICE "PCI: updated MCFG configuration %d: base %lx "
  373. "segment %hu buses %u - %u\n",
  374. i, (unsigned long)cfg->address, cfg->pci_segment,
  375. (unsigned int)cfg->start_bus_number,
  376. (unsigned int)cfg->end_bus_number);
  377. }
  378. }
  379. return valid;
  380. }
  381. static void __init pci_mmcfg_reject_broken(int early)
  382. {
  383. typeof(pci_mmcfg_config[0]) *cfg;
  384. int i;
  385. if ((pci_mmcfg_config_num == 0) ||
  386. (pci_mmcfg_config == NULL) ||
  387. (pci_mmcfg_config[0].address == 0))
  388. return;
  389. for (i = 0; i < pci_mmcfg_config_num; i++) {
  390. int valid = 0;
  391. u64 addr, size;
  392. cfg = &pci_mmcfg_config[i];
  393. addr = cfg->start_bus_number;
  394. addr <<= 20;
  395. addr += cfg->address;
  396. size = cfg->end_bus_number + 1 - cfg->start_bus_number;
  397. size <<= 20;
  398. printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lx "
  399. "segment %hu buses %u - %u\n",
  400. i, (unsigned long)cfg->address, cfg->pci_segment,
  401. (unsigned int)cfg->start_bus_number,
  402. (unsigned int)cfg->end_bus_number);
  403. if (!early && !acpi_disabled)
  404. valid = is_mmconf_reserved(is_acpi_reserved, addr, size, i, cfg, 0);
  405. if (valid)
  406. continue;
  407. if (!early)
  408. printk(KERN_ERR "PCI: BIOS Bug: MCFG area at %Lx is not"
  409. " reserved in ACPI motherboard resources\n",
  410. cfg->address);
  411. /* Don't try to do this check unless configuration
  412. type 1 is available. how about type 2 ?*/
  413. if (raw_pci_ops)
  414. valid = is_mmconf_reserved(e820_all_mapped, addr, size, i, cfg, 1);
  415. if (!valid)
  416. goto reject;
  417. }
  418. return;
  419. reject:
  420. printk(KERN_INFO "PCI: Not using MMCONFIG.\n");
  421. pci_mmcfg_arch_free();
  422. kfree(pci_mmcfg_config);
  423. pci_mmcfg_config = NULL;
  424. pci_mmcfg_config_num = 0;
  425. }
  426. static int __initdata known_bridge;
  427. /* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
  428. struct acpi_mcfg_allocation *pci_mmcfg_config;
  429. int pci_mmcfg_config_num;
  430. static int __init acpi_mcfg_check_entry(struct acpi_table_mcfg *mcfg,
  431. struct acpi_mcfg_allocation *cfg)
  432. {
  433. int year;
  434. if (cfg->address < 0xFFFFFFFF)
  435. return 0;
  436. if (!strcmp(mcfg->header.oem_id, "SGI"))
  437. return 0;
  438. if (mcfg->header.revision >= 1) {
  439. if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) &&
  440. year >= 2010)
  441. return 0;
  442. }
  443. printk(KERN_ERR PREFIX "MCFG region for %04x:%02x-%02x at %#llx "
  444. "is above 4GB, ignored\n", cfg->pci_segment,
  445. cfg->start_bus_number, cfg->end_bus_number, cfg->address);
  446. return -EINVAL;
  447. }
  448. static int __init pci_parse_mcfg(struct acpi_table_header *header)
  449. {
  450. struct acpi_table_mcfg *mcfg;
  451. unsigned long i;
  452. int config_size;
  453. if (!header)
  454. return -EINVAL;
  455. mcfg = (struct acpi_table_mcfg *)header;
  456. /* how many config structures do we have */
  457. pci_mmcfg_config_num = 0;
  458. i = header->length - sizeof(struct acpi_table_mcfg);
  459. while (i >= sizeof(struct acpi_mcfg_allocation)) {
  460. ++pci_mmcfg_config_num;
  461. i -= sizeof(struct acpi_mcfg_allocation);
  462. };
  463. if (pci_mmcfg_config_num == 0) {
  464. printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
  465. return -ENODEV;
  466. }
  467. config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
  468. pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
  469. if (!pci_mmcfg_config) {
  470. printk(KERN_WARNING PREFIX
  471. "No memory for MCFG config tables\n");
  472. return -ENOMEM;
  473. }
  474. memcpy(pci_mmcfg_config, &mcfg[1], config_size);
  475. for (i = 0; i < pci_mmcfg_config_num; ++i) {
  476. if (acpi_mcfg_check_entry(mcfg, &pci_mmcfg_config[i])) {
  477. kfree(pci_mmcfg_config);
  478. pci_mmcfg_config_num = 0;
  479. return -ENODEV;
  480. }
  481. }
  482. return 0;
  483. }
  484. static void __init __pci_mmcfg_init(int early)
  485. {
  486. /* MMCONFIG disabled */
  487. if ((pci_probe & PCI_PROBE_MMCONF) == 0)
  488. return;
  489. /* MMCONFIG already enabled */
  490. if (!early && !(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF))
  491. return;
  492. /* for late to exit */
  493. if (known_bridge)
  494. return;
  495. if (early) {
  496. if (pci_mmcfg_check_hostbridge())
  497. known_bridge = 1;
  498. }
  499. if (!known_bridge)
  500. acpi_sfi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg);
  501. pci_mmcfg_reject_broken(early);
  502. if ((pci_mmcfg_config_num == 0) ||
  503. (pci_mmcfg_config == NULL) ||
  504. (pci_mmcfg_config[0].address == 0))
  505. return;
  506. if (pci_mmcfg_arch_init())
  507. pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
  508. else {
  509. /*
  510. * Signal not to attempt to insert mmcfg resources because
  511. * the architecture mmcfg setup could not initialize.
  512. */
  513. pci_mmcfg_resources_inserted = 1;
  514. }
  515. }
  516. void __init pci_mmcfg_early_init(void)
  517. {
  518. __pci_mmcfg_init(1);
  519. }
  520. void __init pci_mmcfg_late_init(void)
  521. {
  522. __pci_mmcfg_init(0);
  523. }
  524. static int __init pci_mmcfg_late_insert_resources(void)
  525. {
  526. /*
  527. * If resources are already inserted or we are not using MMCONFIG,
  528. * don't insert the resources.
  529. */
  530. if ((pci_mmcfg_resources_inserted == 1) ||
  531. (pci_probe & PCI_PROBE_MMCONF) == 0 ||
  532. (pci_mmcfg_config_num == 0) ||
  533. (pci_mmcfg_config == NULL) ||
  534. (pci_mmcfg_config[0].address == 0))
  535. return 1;
  536. /*
  537. * Attempt to insert the mmcfg resources but not with the busy flag
  538. * marked so it won't cause request errors when __request_region is
  539. * called.
  540. */
  541. pci_mmcfg_insert_resources();
  542. return 0;
  543. }
  544. /*
  545. * Perform MMCONFIG resource insertion after PCI initialization to allow for
  546. * misprogrammed MCFG tables that state larger sizes but actually conflict
  547. * with other system resources.
  548. */
  549. late_initcall(pci_mmcfg_late_insert_resources);