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