Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 3 | #include <cbmem.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 4 | #include <cpu/x86/smm.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 5 | #include <soc/iosf.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 7 | static size_t smm_region_size(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 8 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 9 | u32 smm_size; |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 10 | smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 11 | smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF; |
| 12 | smm_size = (smm_size + 1) << 20; |
| 13 | return smm_size; |
| 14 | } |
| 15 | |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 16 | void smm_region(uintptr_t *start, size_t *size) |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 17 | { |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 18 | *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 19 | *size = smm_region_size(); |
| 20 | } |
| 21 | |
Elyes Haouas | 799c321 | 2022-11-09 14:00:44 +0100 | [diff] [blame] | 22 | uintptr_t cbmem_top_chipset(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 23 | { |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 24 | uintptr_t smm_base; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 25 | size_t smm_size; |
| 26 | |
| 27 | /* |
| 28 | * +-------------------------+ Top of RAM (aligned) |
| 29 | * | System Management Mode | |
Martin Roth | 0639bff | 2020-11-09 13:13:27 -0700 | [diff] [blame] | 30 | * | code and data | Length: CONFIG_SMM_TSEG_SIZE |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 31 | * | (TSEG) | |
| 32 | * +-------------------------+ SMM base (aligned) |
| 33 | * | | |
Martin Roth | 0639bff | 2020-11-09 13:13:27 -0700 | [diff] [blame] | 34 | * | Chipset Reserved Memory | Length: Multiple of CONFIG_SMM_TSEG_SIZE |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 35 | * | | |
| 36 | * +-------------------------+ top_of_ram (aligned) |
| 37 | * | | |
| 38 | * | CBMEM Root | |
| 39 | * | | |
| 40 | * +-------------------------+ |
| 41 | * | | |
| 42 | * | FSP Reserved Memory | |
| 43 | * | | |
| 44 | * +-------------------------+ |
| 45 | * | | |
| 46 | * | Various CBMEM Entries | |
| 47 | * | | |
| 48 | * +-------------------------+ top_of_stack (8 byte aligned) |
| 49 | * | | |
| 50 | * | stack (CBMEM Entry) | |
| 51 | * | | |
| 52 | * +-------------------------+ |
| 53 | */ |
| 54 | |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 55 | smm_region(&smm_base, &smm_size); |
Elyes Haouas | 799c321 | 2022-11-09 14:00:44 +0100 | [diff] [blame] | 56 | return smm_base; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 57 | } |