blob: 28b9e0e5e6f1161d4fb396495437517342934d1c [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy77ff0b12015-05-05 15:07:29 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
Lee Leahye0918bb2016-01-29 14:28:43 -080010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Lee Leahy77ff0b12015-05-05 15:07:29 -070011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 */
14
Lee Leahy77ff0b12015-05-05 15:07:29 -070015#include <cbmem.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030016#include <cpu/x86/smm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070017#include <soc/iosf.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070018
Lee Leahy32471722015-04-20 15:20:28 -070019static size_t smm_region_size(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070020{
Lee Leahy32471722015-04-20 15:20:28 -070021 u32 smm_size;
Angel Ponsaee7ab22020-03-19 00:31:58 +010022 smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF;
Lee Leahy32471722015-04-20 15:20:28 -070023 smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF;
24 smm_size = (smm_size + 1) << 20;
25 return smm_size;
26}
27
Kyösti Mälkki14222d82019-08-05 15:10:18 +030028void smm_region(uintptr_t *start, size_t *size)
Lee Leahy32471722015-04-20 15:20:28 -070029{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030030 *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20;
Lee Leahy32471722015-04-20 15:20:28 -070031 *size = smm_region_size();
32}
33
Arthur Heymans340e4b82019-10-23 17:25:58 +020034void *cbmem_top_chipset(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070035{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030036 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070037 size_t smm_size;
38
39 /*
40 * +-------------------------+ Top of RAM (aligned)
41 * | System Management Mode |
42 * | code and data | Length: CONFIG_TSEG_SIZE
43 * | (TSEG) |
44 * +-------------------------+ SMM base (aligned)
45 * | |
46 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
47 * | |
48 * +-------------------------+ top_of_ram (aligned)
49 * | |
50 * | CBMEM Root |
51 * | |
52 * +-------------------------+
53 * | |
54 * | FSP Reserved Memory |
55 * | |
56 * +-------------------------+
57 * | |
58 * | Various CBMEM Entries |
59 * | |
60 * +-------------------------+ top_of_stack (8 byte aligned)
61 * | |
62 * | stack (CBMEM Entry) |
63 * | |
64 * +-------------------------+
65 */
66
Kyösti Mälkki14222d82019-08-05 15:10:18 +030067 smm_region(&smm_base, &smm_size);
Aaron Durbinbbbfbf22015-07-13 16:55:28 -050068 return (void *)smm_base;
Lee Leahy77ff0b12015-05-05 15:07:29 -070069}