blob: 3c3ad74b713afd25035334ca23a7280f8003dad0 [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Lee Leahy77ff0b12015-05-05 15:07:29 -07003#include <cbmem.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03004#include <cpu/x86/smm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07005#include <soc/iosf.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07006
Lee Leahy32471722015-04-20 15:20:28 -07007static size_t smm_region_size(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -07008{
Lee Leahy32471722015-04-20 15:20:28 -07009 u32 smm_size;
Angel Ponsaee7ab22020-03-19 00:31:58 +010010 smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF;
Lee Leahy32471722015-04-20 15:20:28 -070011 smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF;
12 smm_size = (smm_size + 1) << 20;
13 return smm_size;
14}
15
Kyösti Mälkki14222d82019-08-05 15:10:18 +030016void smm_region(uintptr_t *start, size_t *size)
Lee Leahy32471722015-04-20 15:20:28 -070017{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030018 *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20;
Lee Leahy32471722015-04-20 15:20:28 -070019 *size = smm_region_size();
20}
21
Elyes Haouas799c3212022-11-09 14:00:44 +010022uintptr_t cbmem_top_chipset(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070023{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030024 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070025 size_t smm_size;
26
27 /*
28 * +-------------------------+ Top of RAM (aligned)
29 * | System Management Mode |
Martin Roth0639bff2020-11-09 13:13:27 -070030 * | code and data | Length: CONFIG_SMM_TSEG_SIZE
Lee Leahy32471722015-04-20 15:20:28 -070031 * | (TSEG) |
32 * +-------------------------+ SMM base (aligned)
33 * | |
Martin Roth0639bff2020-11-09 13:13:27 -070034 * | Chipset Reserved Memory | Length: Multiple of CONFIG_SMM_TSEG_SIZE
Lee Leahy32471722015-04-20 15:20:28 -070035 * | |
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älkki14222d82019-08-05 15:10:18 +030055 smm_region(&smm_base, &smm_size);
Elyes Haouas799c3212022-11-09 14:00:44 +010056 return smm_base;
Lee Leahy77ff0b12015-05-05 15:07:29 -070057}