blob: e43c5469f632f28cfd188ba996a0b6dfe270fd29 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google, Inc.
Lee Leahye0918bb2016-01-29 14:28:43 -08005 * Copyright (C) 2015-2016 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
Lee Leahye0918bb2016-01-29 14:28:43 -080012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070015 */
16
Lee Leahy77ff0b12015-05-05 15:07:29 -070017#include <cbmem.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030018#include <cpu/x86/smm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070019#include <soc/iosf.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070020
Lee Leahy32471722015-04-20 15:20:28 -070021static size_t smm_region_size(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070022{
Lee Leahy32471722015-04-20 15:20:28 -070023 u32 smm_size;
24 smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF;
25 smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF;
26 smm_size = (smm_size + 1) << 20;
27 return smm_size;
28}
29
Kyösti Mälkki14222d82019-08-05 15:10:18 +030030void smm_region(uintptr_t *start, size_t *size)
Lee Leahy32471722015-04-20 15:20:28 -070031{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030032 *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20;
Lee Leahy32471722015-04-20 15:20:28 -070033 *size = smm_region_size();
34}
35
Arthur Heymans340e4b82019-10-23 17:25:58 +020036void *cbmem_top_chipset(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070037{
Kyösti Mälkki14222d82019-08-05 15:10:18 +030038 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070039 size_t smm_size;
40
41 /*
42 * +-------------------------+ Top of RAM (aligned)
43 * | System Management Mode |
44 * | code and data | Length: CONFIG_TSEG_SIZE
45 * | (TSEG) |
46 * +-------------------------+ SMM base (aligned)
47 * | |
48 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
49 * | |
50 * +-------------------------+ top_of_ram (aligned)
51 * | |
52 * | CBMEM Root |
53 * | |
54 * +-------------------------+
55 * | |
56 * | FSP Reserved Memory |
57 * | |
58 * +-------------------------+
59 * | |
60 * | Various CBMEM Entries |
61 * | |
62 * +-------------------------+ top_of_stack (8 byte aligned)
63 * | |
64 * | stack (CBMEM Entry) |
65 * | |
66 * +-------------------------+
67 */
68
Kyösti Mälkki14222d82019-08-05 15:10:18 +030069 smm_region(&smm_base, &smm_size);
Aaron Durbinbbbfbf22015-07-13 16:55:28 -050070 return (void *)smm_base;
Lee Leahy77ff0b12015-05-05 15:07:29 -070071}