| 1 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 51 |
ram_range(dev, (*idx)++, 0, VGA_MMIO_BASE); |
| 52 |
|
| 53 |
|
| 54 |
mmio_range(dev, (*idx)++, VGA_MMIO_BASE, VGA_MMIO_SIZE); |
| 55 |
|
| 56 |
|
| 57 |
reserved_ram_from_to(dev, (*idx)++, VGA_MMIO_BASE + VGA_MMIO_SIZE, 1 * MiB); |
| 58 |
|
| 59 |
|
| 60 |
ram_from_to(dev, (*idx)++, 1 * MiB, early_reserved_dram_start); |
| 61 |
|
| 62 |
|
| 63 |
reserved_ram_from_to(dev, (*idx)++, early_reserved_dram_start, early_reserved_dram_end); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 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 |
} |