Debian Codegraph @

src/soc/amd/common/block/cpu/noncar/memmap.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <amdblocks/memmap.h>
4 #include <amdblocks/smm.h>
5 #include <arch/vga.h>
6 #include <console/console.h>
7 #include <cbmem.h>
8 #include <cpu/x86/smm.h>
9 #include <device/device.h>
10 #include <memrange.h>
11 #include <types.h>
12
13 struct memmap_early_dram {
14 /* fixed size types, so the layout in CBMEM won't change for 32 vs. 64 bit stages */
15 uint32_t base;
16 uint32_t size;
17 };
18
19 void memmap_stash_early_dram_usage(void)
20 {
21 struct memmap_early_dram *e;
22
23 e = cbmem_add(CBMEM_ID_CB_EARLY_DRAM, sizeof(*e));
24
25 if (!e)
26 die("ERROR: Failed to stash early dram usage!\n");
27
28 e->base = (uint32_t)(uintptr_t)_early_reserved_dram;
29 e->size = REGION_SIZE(early_reserved_dram);
30 }
31
32 static const struct memmap_early_dram *memmap_get_early_dram_usage(void)
33 {
34 struct memmap_early_dram *e = cbmem_find(CBMEM_ID_CB_EARLY_DRAM);
35
36 if (!e)
37 die("ERROR: Failed to read early dram usage!\n");
38
39 return e;
40 }
41
42 /* report SoC memory map up to cbmem_top */
43 void read_lower_soc_memmap_resources(struct device *dev, unsigned long *idx)
44 {
45 const uint32_t mem_usable = cbmem_top();
46 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
47 const uintptr_t early_reserved_dram_start = e->base;
48 const uintptr_t early_reserved_dram_end = e->base + e->size;
49
50 /* 0x0 - 0x9ffff */
51 ram_range(dev, (*idx)++, 0, VGA_MMIO_BASE);
52
53 /* 0xa0000 - 0xbffff: legacy VGA */
54 mmio_range(dev, (*idx)++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
55
56 /* 0xc0000 - 0xfffff: Option ROM */
57 reserved_ram_from_to(dev, (*idx)++, VGA_MMIO_BASE + VGA_MMIO_SIZE, 1 * MiB);
58
59 /* 1MiB - bottom of DRAM reserved for early coreboot usage */
60 ram_from_to(dev, (*idx)++, 1 * MiB, early_reserved_dram_start);
61
62 /* DRAM reserved for early coreboot usage */
63 reserved_ram_from_to(dev, (*idx)++, early_reserved_dram_start, early_reserved_dram_end);
64
65 /*
66 * top of DRAM consumed early - low top usable RAM
67 * cbmem_top() accounts for low UMA and TSEG if they are used.
68 */
69 ram_from_to(dev, (*idx)++, early_reserved_dram_end, mem_usable);
70 }
71
72 void smm_region(uintptr_t *start, size_t *size)
73 {
74 static int once;
75
76 if (CONFIG(PLATFORM_USES_FSP2_0)) {
77 fsp_get_smm_region(start, size);
78 } else {
79 *start = cbmem_top();
80 *size = CONFIG_SMM_TSEG_SIZE;
81 }
82
83 if (!once) {
84 clear_tvalid();
85 once = 1;
86 }
87 }