- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / pci / mmconfig-shared.c
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
13 #include <linux/pci.h>
14 #include <linux/init.h>
15 #include <linux/acpi.h>
16 #include <linux/sfi_acpi.h>
17 #include <linux/bitmap.h>
18 #include <linux/dmi.h>
19 #include <linux/slab.h>
20 #include <asm/e820.h>
21 #include <asm/pci_x86.h>
22 #include <asm/acpi.h>
23
24 #ifdef CONFIG_XEN
25 #include <xen/interface/physdev.h>
26 #endif
27
28 #define PREFIX "PCI: "
29
30 /* Indicate if the mmcfg resources have been placed into the resource table. */
31 static int __initdata pci_mmcfg_resources_inserted;
32
33 LIST_HEAD(pci_mmcfg_list);
34
35 static __init void pci_mmconfig_remove(struct pci_mmcfg_region *cfg)
36 {
37         if (cfg->res.parent)
38                 release_resource(&cfg->res);
39         list_del(&cfg->list);
40         kfree(cfg);
41 }
42
43 static __init void free_all_mmcfg(void)
44 {
45         struct pci_mmcfg_region *cfg, *tmp;
46
47         pci_mmcfg_arch_free();
48         list_for_each_entry_safe(cfg, tmp, &pci_mmcfg_list, list)
49                 pci_mmconfig_remove(cfg);
50 }
51
52 static __init void list_add_sorted(struct pci_mmcfg_region *new)
53 {
54         struct pci_mmcfg_region *cfg;
55
56         /* keep list sorted by segment and starting bus number */
57         list_for_each_entry(cfg, &pci_mmcfg_list, list) {
58                 if (cfg->segment > new->segment ||
59                     (cfg->segment == new->segment &&
60                      cfg->start_bus >= new->start_bus)) {
61                         list_add_tail(&new->list, &cfg->list);
62                         return;
63                 }
64         }
65         list_add_tail(&new->list, &pci_mmcfg_list);
66 }
67
68 static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start,
69                                                         int end, u64 addr)
70 {
71         struct pci_mmcfg_region *new;
72         struct resource *res;
73
74         if (addr == 0)
75                 return NULL;
76
77         new = kzalloc(sizeof(*new), GFP_KERNEL);
78         if (!new)
79                 return NULL;
80
81         new->address = addr;
82         new->segment = segment;
83         new->start_bus = start;
84         new->end_bus = end;
85
86         list_add_sorted(new);
87
88         res = &new->res;
89         res->start = addr + PCI_MMCFG_BUS_OFFSET(start);
90         res->end = addr + PCI_MMCFG_BUS_OFFSET(end + 1) - 1;
91         res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
92         snprintf(new->name, PCI_MMCFG_RESOURCE_NAME_LEN,
93                  "PCI MMCONFIG %04x [bus %02x-%02x]", segment, start, end);
94         res->name = new->name;
95
96         printk(KERN_INFO PREFIX "MMCONFIG for domain %04x [bus %02x-%02x] at "
97                "%pR (base %#lx)\n", segment, start, end, &new->res,
98                (unsigned long) addr);
99
100         return new;
101 }
102
103 struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus)
104 {
105         struct pci_mmcfg_region *cfg;
106
107         list_for_each_entry(cfg, &pci_mmcfg_list, list)
108                 if (cfg->segment == segment &&
109                     cfg->start_bus <= bus && bus <= cfg->end_bus)
110                         return cfg;
111
112         return NULL;
113 }
114
115 static const char __init *pci_mmcfg_e7520(void)
116 {
117         u32 win;
118         raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0xce, 2, &win);
119
120         win = win & 0xf000;
121         if (win == 0x0000 || win == 0xf000)
122                 return NULL;
123
124         if (pci_mmconfig_add(0, 0, 255, win << 16) == NULL)
125                 return NULL;
126
127         return "Intel Corporation E7520 Memory Controller Hub";
128 }
129
130 static const char __init *pci_mmcfg_intel_945(void)
131 {
132         u32 pciexbar, mask = 0, len = 0;
133
134         raw_pci_ops->read(0, 0, PCI_DEVFN(0, 0), 0x48, 4, &pciexbar);
135
136         /* Enable bit */
137         if (!(pciexbar & 1))
138                 return NULL;
139
140         /* Size bits */
141         switch ((pciexbar >> 1) & 3) {
142         case 0:
143                 mask = 0xf0000000U;
144                 len  = 0x10000000U;
145                 break;
146         case 1:
147                 mask = 0xf8000000U;
148                 len  = 0x08000000U;
149                 break;
150         case 2:
151                 mask = 0xfc000000U;
152                 len  = 0x04000000U;
153                 break;
154         default:
155                 return NULL;
156         }
157
158         /* Errata #2, things break when not aligned on a 256Mb boundary */
159         /* Can only happen in 64M/128M mode */
160
161         if ((pciexbar & mask) & 0x0fffffffU)
162                 return NULL;
163
164         /* Don't hit the APIC registers and their friends */
165         if ((pciexbar & mask) >= 0xf0000000U)
166                 return NULL;
167
168         if (pci_mmconfig_add(0, 0, (len >> 20) - 1, pciexbar & mask) == NULL)
169                 return NULL;
170
171         return "Intel Corporation 945G/GZ/P/PL Express Memory Controller Hub";
172 }
173
174 static const char __init *pci_mmcfg_amd_fam10h(void)
175 {
176         u32 low, high, address;
177         u64 base, msr;
178         int i;
179         unsigned segnbits = 0, busnbits, end_bus;
180
181         if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF))
182                 return NULL;
183
184         address = MSR_FAM10H_MMIO_CONF_BASE;
185         if (rdmsr_safe(address, &low, &high))
186                 return NULL;
187
188         msr = high;
189         msr <<= 32;
190         msr |= low;
191
192         /* mmconfig is not enable */
193         if (!(msr & FAM10H_MMIO_CONF_ENABLE))
194                 return NULL;
195
196         base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT);
197
198         busnbits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
199                          FAM10H_MMIO_CONF_BUSRANGE_MASK;
200
201         /*
202          * only handle bus 0 ?
203          * need to skip it
204          */
205         if (!busnbits)
206                 return NULL;
207
208         if (busnbits > 8) {
209                 segnbits = busnbits - 8;
210                 busnbits = 8;
211         }
212
213         end_bus = (1 << busnbits) - 1;
214         for (i = 0; i < (1 << segnbits); i++)
215                 if (pci_mmconfig_add(i, 0, end_bus,
216                                      base + (1<<28) * i) == NULL) {
217                         free_all_mmcfg();
218                         return NULL;
219                 }
220
221         return "AMD Family 10h NB";
222 }
223
224 static bool __initdata mcp55_checked;
225 static const char __init *pci_mmcfg_nvidia_mcp55(void)
226 {
227         int bus;
228         int mcp55_mmconf_found = 0;
229
230         static const u32 extcfg_regnum          = 0x90;
231         static const u32 extcfg_regsize         = 4;
232         static const u32 extcfg_enable_mask     = 1<<31;
233         static const u32 extcfg_start_mask      = 0xff<<16;
234         static const int extcfg_start_shift     = 16;
235         static const u32 extcfg_size_mask       = 0x3<<28;
236         static const int extcfg_size_shift      = 28;
237         static const int extcfg_sizebus[]       = {0x100, 0x80, 0x40, 0x20};
238         static const u32 extcfg_base_mask[]     = {0x7ff8, 0x7ffc, 0x7ffe, 0x7fff};
239         static const int extcfg_base_lshift     = 25;
240
241         /*
242          * do check if amd fam10h already took over
243          */
244         if (!acpi_disabled || !list_empty(&pci_mmcfg_list) || mcp55_checked)
245                 return NULL;
246
247         mcp55_checked = true;
248         for (bus = 0; bus < 256; bus++) {
249                 u64 base;
250                 u32 l, extcfg;
251                 u16 vendor, device;
252                 int start, size_index, end;
253
254                 raw_pci_ops->read(0, bus, PCI_DEVFN(0, 0), 0, 4, &l);
255                 vendor = l & 0xffff;
256                 device = (l >> 16) & 0xffff;
257
258                 if (PCI_VENDOR_ID_NVIDIA != vendor || 0x0369 != device)
259                         continue;
260
261                 raw_pci_ops->read(0, bus, PCI_DEVFN(0, 0), extcfg_regnum,
262                                   extcfg_regsize, &extcfg);
263
264                 if (!(extcfg & extcfg_enable_mask))
265                         continue;
266
267                 size_index = (extcfg & extcfg_size_mask) >> extcfg_size_shift;
268                 base = extcfg & extcfg_base_mask[size_index];
269                 /* base could > 4G */
270                 base <<= extcfg_base_lshift;
271                 start = (extcfg & extcfg_start_mask) >> extcfg_start_shift;
272                 end = start + extcfg_sizebus[size_index] - 1;
273                 if (pci_mmconfig_add(0, start, end, base) == NULL)
274                         continue;
275                 mcp55_mmconf_found++;
276         }
277
278         if (!mcp55_mmconf_found)
279                 return NULL;
280
281         return "nVidia MCP55";
282 }
283
284 struct pci_mmcfg_hostbridge_probe {
285         u32 bus;
286         u32 devfn;
287         u32 vendor;
288         u32 device;
289         const char *(*probe)(void);
290 };
291
292 static struct pci_mmcfg_hostbridge_probe pci_mmcfg_probes[] __initdata = {
293         { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL,
294           PCI_DEVICE_ID_INTEL_E7520_MCH, pci_mmcfg_e7520 },
295         { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_INTEL,
296           PCI_DEVICE_ID_INTEL_82945G_HB, pci_mmcfg_intel_945 },
297         { 0, PCI_DEVFN(0x18, 0), PCI_VENDOR_ID_AMD,
298           0x1200, pci_mmcfg_amd_fam10h },
299         { 0xff, PCI_DEVFN(0, 0), PCI_VENDOR_ID_AMD,
300           0x1200, pci_mmcfg_amd_fam10h },
301         { 0, PCI_DEVFN(0, 0), PCI_VENDOR_ID_NVIDIA,
302           0x0369, pci_mmcfg_nvidia_mcp55 },
303 };
304
305 static void __init pci_mmcfg_check_end_bus_number(void)
306 {
307         struct pci_mmcfg_region *cfg, *cfgx;
308
309         /* Fixup overlaps */
310         list_for_each_entry(cfg, &pci_mmcfg_list, list) {
311                 if (cfg->end_bus < cfg->start_bus)
312                         cfg->end_bus = 255;
313
314                 /* Don't access the list head ! */
315                 if (cfg->list.next == &pci_mmcfg_list)
316                         break;
317
318                 cfgx = list_entry(cfg->list.next, typeof(*cfg), list);
319                 if (cfg->end_bus >= cfgx->start_bus)
320                         cfg->end_bus = cfgx->start_bus - 1;
321         }
322 }
323
324 static int __init pci_mmcfg_check_hostbridge(void)
325 {
326         u32 l;
327         u32 bus, devfn;
328         u16 vendor, device;
329         int i;
330         const char *name;
331
332         if (!raw_pci_ops)
333                 return 0;
334
335         free_all_mmcfg();
336
337         for (i = 0; i < ARRAY_SIZE(pci_mmcfg_probes); i++) {
338                 bus =  pci_mmcfg_probes[i].bus;
339                 devfn = pci_mmcfg_probes[i].devfn;
340                 raw_pci_ops->read(0, bus, devfn, 0, 4, &l);
341                 vendor = l & 0xffff;
342                 device = (l >> 16) & 0xffff;
343
344                 name = NULL;
345                 if (pci_mmcfg_probes[i].vendor == vendor &&
346                     pci_mmcfg_probes[i].device == device)
347                         name = pci_mmcfg_probes[i].probe();
348
349                 if (name)
350                         printk(KERN_INFO PREFIX "%s with MMCONFIG support\n",
351                                name);
352         }
353
354         /* some end_bus_number is crazy, fix it */
355         pci_mmcfg_check_end_bus_number();
356
357         return !list_empty(&pci_mmcfg_list);
358 }
359
360 static void __init pci_mmcfg_insert_resources(void)
361 {
362         struct pci_mmcfg_region *cfg;
363
364         list_for_each_entry(cfg, &pci_mmcfg_list, list)
365                 insert_resource(&iomem_resource, &cfg->res);
366
367         /* Mark that the resources have been inserted. */
368         pci_mmcfg_resources_inserted = 1;
369 }
370
371 static acpi_status __init check_mcfg_resource(struct acpi_resource *res,
372                                               void *data)
373 {
374         struct resource *mcfg_res = data;
375         struct acpi_resource_address64 address;
376         acpi_status status;
377
378         if (res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
379                 struct acpi_resource_fixed_memory32 *fixmem32 =
380                         &res->data.fixed_memory32;
381                 if (!fixmem32)
382                         return AE_OK;
383                 if ((mcfg_res->start >= fixmem32->address) &&
384                     (mcfg_res->end < (fixmem32->address +
385                                       fixmem32->address_length))) {
386                         mcfg_res->flags = 1;
387                         return AE_CTRL_TERMINATE;
388                 }
389         }
390         if ((res->type != ACPI_RESOURCE_TYPE_ADDRESS32) &&
391             (res->type != ACPI_RESOURCE_TYPE_ADDRESS64))
392                 return AE_OK;
393
394         status = acpi_resource_to_address64(res, &address);
395         if (ACPI_FAILURE(status) ||
396            (address.address_length <= 0) ||
397            (address.resource_type != ACPI_MEMORY_RANGE))
398                 return AE_OK;
399
400         if ((mcfg_res->start >= address.minimum) &&
401             (mcfg_res->end < (address.minimum + address.address_length))) {
402                 mcfg_res->flags = 1;
403                 return AE_CTRL_TERMINATE;
404         }
405         return AE_OK;
406 }
407
408 static acpi_status __init find_mboard_resource(acpi_handle handle, u32 lvl,
409                 void *context, void **rv)
410 {
411         struct resource *mcfg_res = context;
412
413         acpi_walk_resources(handle, METHOD_NAME__CRS,
414                             check_mcfg_resource, context);
415
416         if (mcfg_res->flags)
417                 return AE_CTRL_TERMINATE;
418
419         return AE_OK;
420 }
421
422 static int __init is_acpi_reserved(u64 start, u64 end, unsigned not_used)
423 {
424         struct resource mcfg_res;
425
426         mcfg_res.start = start;
427         mcfg_res.end = end - 1;
428         mcfg_res.flags = 0;
429
430         acpi_get_devices("PNP0C01", find_mboard_resource, &mcfg_res, NULL);
431
432         if (!mcfg_res.flags)
433                 acpi_get_devices("PNP0C02", find_mboard_resource, &mcfg_res,
434                                  NULL);
435
436         return mcfg_res.flags;
437 }
438
439 typedef int (*check_reserved_t)(u64 start, u64 end, unsigned type);
440
441 static int __init is_mmconf_reserved(check_reserved_t is_reserved,
442                                     struct pci_mmcfg_region *cfg, int with_e820)
443 {
444         u64 addr = cfg->res.start;
445         u64 size = resource_size(&cfg->res);
446         u64 old_size = size;
447         int valid = 0, num_buses;
448
449         while (!is_reserved(addr, addr + size, E820_RESERVED)) {
450                 size >>= 1;
451                 if (size < (16UL<<20))
452                         break;
453         }
454
455         if (size >= (16UL<<20) || size == old_size) {
456                 printk(KERN_INFO PREFIX "MMCONFIG at %pR reserved in %s\n",
457                        &cfg->res,
458                        with_e820 ? "E820" : "ACPI motherboard resources");
459                 valid = 1;
460
461                 if (old_size != size) {
462                         /* update end_bus */
463                         cfg->end_bus = cfg->start_bus + ((size>>20) - 1);
464                         num_buses = cfg->end_bus - cfg->start_bus + 1;
465                         cfg->res.end = cfg->res.start +
466                             PCI_MMCFG_BUS_OFFSET(num_buses) - 1;
467                         snprintf(cfg->name, PCI_MMCFG_RESOURCE_NAME_LEN,
468                                  "PCI MMCONFIG %04x [bus %02x-%02x]",
469                                  cfg->segment, cfg->start_bus, cfg->end_bus);
470                         printk(KERN_INFO PREFIX
471                                "MMCONFIG for %04x [bus%02x-%02x] "
472                                "at %pR (base %#lx) (size reduced!)\n",
473                                cfg->segment, cfg->start_bus, cfg->end_bus,
474                                &cfg->res, (unsigned long) cfg->address);
475                 }
476         }
477
478 #ifdef CONFIG_XEN
479         if (!with_e820) {
480                 struct physdev_pci_mmcfg_reserved r = {
481                         .address = cfg->address,
482                         .segment = cfg->segment,
483                         .start_bus = cfg->start_bus,
484                         .end_bus = cfg->end_bus,
485                         .flags = valid ? XEN_PCI_MMCFG_RESERVED : 0
486                 };
487                 int rc;
488
489                 rc = HYPERVISOR_physdev_op(PHYSDEVOP_pci_mmcfg_reserved, &r);
490                 switch (rc) {
491                 case 0: case -ENOSYS:
492                         break;
493                 default:
494                         pr_warn(PREFIX "Failed to report MMCONFIG reservation"
495                                 " state for %04x [bus%02x-%02x] to hypervisor"
496                                 " (%d)\n",
497                                 cfg->segment, cfg->start_bus, cfg->end_bus,
498                                 rc);
499                 }
500         }
501 #endif
502
503         return valid;
504 }
505
506 static void __init pci_mmcfg_reject_broken(int early)
507 {
508         struct pci_mmcfg_region *cfg;
509
510         list_for_each_entry(cfg, &pci_mmcfg_list, list) {
511                 int valid = 0;
512
513                 if (!early && !acpi_disabled) {
514                         valid = is_mmconf_reserved(is_acpi_reserved, cfg, 0);
515
516                         if (valid)
517                                 continue;
518                         else
519                                 printk(KERN_ERR FW_BUG PREFIX
520                                        "MMCONFIG at %pR not reserved in "
521                                        "ACPI motherboard resources\n",
522                                        &cfg->res);
523                 }
524
525                 /* Don't try to do this check unless configuration
526                    type 1 is available. how about type 2 ?*/
527                 if (raw_pci_ops)
528                         valid = is_mmconf_reserved(e820_all_mapped, cfg, 1);
529
530                 if (!valid)
531                         goto reject;
532         }
533
534         return;
535
536 reject:
537         printk(KERN_INFO PREFIX "not using MMCONFIG\n");
538         free_all_mmcfg();
539 }
540
541 static int __initdata known_bridge;
542
543 static int __init acpi_mcfg_check_entry(struct acpi_table_mcfg *mcfg,
544                                         struct acpi_mcfg_allocation *cfg)
545 {
546         int year;
547
548         if (cfg->address < 0xFFFFFFFF)
549                 return 0;
550
551         if (!strcmp(mcfg->header.oem_id, "SGI") ||
552                         !strcmp(mcfg->header.oem_id, "SGI2"))
553                 return 0;
554
555         if (mcfg->header.revision >= 1) {
556                 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) &&
557                     year >= 2010)
558                         return 0;
559         }
560
561         printk(KERN_ERR PREFIX "MCFG region for %04x [bus %02x-%02x] at %#llx "
562                "is above 4GB, ignored\n", cfg->pci_segment,
563                cfg->start_bus_number, cfg->end_bus_number, cfg->address);
564         return -EINVAL;
565 }
566
567 static int __init pci_parse_mcfg(struct acpi_table_header *header)
568 {
569         struct acpi_table_mcfg *mcfg;
570         struct acpi_mcfg_allocation *cfg_table, *cfg;
571         unsigned long i;
572         int entries;
573
574         if (!header)
575                 return -EINVAL;
576
577         mcfg = (struct acpi_table_mcfg *)header;
578
579         /* how many config structures do we have */
580         free_all_mmcfg();
581         entries = 0;
582         i = header->length - sizeof(struct acpi_table_mcfg);
583         while (i >= sizeof(struct acpi_mcfg_allocation)) {
584                 entries++;
585                 i -= sizeof(struct acpi_mcfg_allocation);
586         };
587         if (entries == 0) {
588                 printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
589                 return -ENODEV;
590         }
591
592         cfg_table = (struct acpi_mcfg_allocation *) &mcfg[1];
593         for (i = 0; i < entries; i++) {
594                 cfg = &cfg_table[i];
595                 if (acpi_mcfg_check_entry(mcfg, cfg)) {
596                         free_all_mmcfg();
597                         return -ENODEV;
598                 }
599
600                 if (pci_mmconfig_add(cfg->pci_segment, cfg->start_bus_number,
601                                    cfg->end_bus_number, cfg->address) == NULL) {
602                         printk(KERN_WARNING PREFIX
603                                "no memory for MCFG entries\n");
604                         free_all_mmcfg();
605                         return -ENOMEM;
606                 }
607         }
608
609         return 0;
610 }
611
612 static void __init __pci_mmcfg_init(int early)
613 {
614         /* MMCONFIG disabled */
615         if ((pci_probe & PCI_PROBE_MMCONF) == 0)
616                 return;
617
618         /* MMCONFIG already enabled */
619         if (!early && !(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF))
620                 return;
621
622         /* for late to exit */
623         if (known_bridge)
624                 return;
625
626         if (early) {
627                 if (pci_mmcfg_check_hostbridge())
628                         known_bridge = 1;
629         }
630
631         if (!known_bridge)
632                 acpi_sfi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg);
633
634         pci_mmcfg_reject_broken(early);
635
636         if (list_empty(&pci_mmcfg_list))
637                 return;
638
639         if (pcibios_last_bus < 0) {
640                 const struct pci_mmcfg_region *cfg;
641
642                 list_for_each_entry(cfg, &pci_mmcfg_list, list) {
643                         if (cfg->segment)
644                                 break;
645                         pcibios_last_bus = cfg->end_bus;
646                 }
647         }
648
649         if (pci_mmcfg_arch_init())
650                 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
651         else {
652                 /*
653                  * Signal not to attempt to insert mmcfg resources because
654                  * the architecture mmcfg setup could not initialize.
655                  */
656                 pci_mmcfg_resources_inserted = 1;
657         }
658 }
659
660 void __init pci_mmcfg_early_init(void)
661 {
662         __pci_mmcfg_init(1);
663 }
664
665 void __init pci_mmcfg_late_init(void)
666 {
667         __pci_mmcfg_init(0);
668 }
669
670 static int __init pci_mmcfg_late_insert_resources(void)
671 {
672         /*
673          * If resources are already inserted or we are not using MMCONFIG,
674          * don't insert the resources.
675          */
676         if ((pci_mmcfg_resources_inserted == 1) ||
677             (pci_probe & PCI_PROBE_MMCONF) == 0 ||
678             list_empty(&pci_mmcfg_list))
679                 return 1;
680
681         /*
682          * Attempt to insert the mmcfg resources but not with the busy flag
683          * marked so it won't cause request errors when __request_region is
684          * called.
685          */
686         pci_mmcfg_insert_resources();
687
688         return 0;
689 }
690
691 /*
692  * Perform MMCONFIG resource insertion after PCI initialization to allow for
693  * misprogrammed MCFG tables that state larger sizes but actually conflict
694  * with other system resources.
695  */
696 late_initcall(pci_mmcfg_late_insert_resources);