blob: 5b5c5729d50e0fbbd400b6a1465b4ac0c97d4d9c [file] [log] [blame]
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +03001/*
2 * This file is part of the coreboot project.
3 *
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +03004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <assert.h>
15#include <commonlib/helpers.h>
16#include <console/console.h>
17#include <cpu/x86/smm.h>
18#include <stage_cache.h>
19#include <types.h>
Jacob Garber06f2fcc2019-11-04 09:35:15 -070020#include <inttypes.h>
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030021
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030022/*
23 * Subregions within SMM
24 * +-------------------------+
25 * | IED | IED_REGION_SIZE
26 * +-------------------------+
27 * | External Stage Cache | SMM_RESERVED_SIZE
28 * +-------------------------+
29 * | code and data |
30 * | (TSEG) |
31 * +-------------------------+ TSEG
32 */
33int smm_subregion(int sub, uintptr_t *start, size_t *size)
34{
35 uintptr_t sub_base;
36 size_t sub_size;
37 const size_t ied_size = CONFIG_IED_REGION_SIZE;
38 const size_t cache_size = CONFIG_SMM_RESERVED_SIZE;
39
40 smm_region(&sub_base, &sub_size);
41
42 ASSERT(IS_ALIGNED(sub_base, sub_size));
43 ASSERT(sub_size > (cache_size + ied_size));
44
45 switch (sub) {
46 case SMM_SUBREGION_HANDLER:
47 /* Handler starts at the base of TSEG. */
48 sub_size -= ied_size;
49 sub_size -= cache_size;
50 break;
51 case SMM_SUBREGION_CACHE:
52 /* External cache is in the middle of TSEG. */
53 sub_base += sub_size - (ied_size + cache_size);
54 sub_size = cache_size;
55 break;
56 case SMM_SUBREGION_CHIPSET:
57 /* IED is at the top. */
58 sub_base += sub_size - ied_size;
59 sub_size = ied_size;
60 break;
61 default:
62 *start = 0;
63 *size = 0;
64 return -1;
65 }
66
67 *start = sub_base;
68 *size = sub_size;
69 return 0;
70}
71
Kyösti Mälkki59d57312019-08-04 21:16:34 +030072void stage_cache_external_region(void **base, size_t *size)
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030073{
74 if (smm_subregion(SMM_SUBREGION_CACHE, (uintptr_t *)base, size)) {
75 printk(BIOS_ERR, "ERROR: No cache SMM subregion.\n");
76 *base = NULL;
77 *size = 0;
78 }
79}
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030080
81void smm_list_regions(void)
82{
83 uintptr_t base;
84 size_t size;
85 int i;
86
87 smm_region(&base, &size);
88 if (!size)
89 return;
90
91 printk(BIOS_DEBUG, "SMM Memory Map\n");
Jacob Garber06f2fcc2019-11-04 09:35:15 -070092 printk(BIOS_DEBUG, "SMRAM : 0x%" PRIxPTR " 0x%zx\n", base, size);
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030093
94 for (i = 0; i < SMM_SUBREGION_NUM; i++) {
95 if (smm_subregion(i, &base, &size))
96 continue;
Jacob Garber06f2fcc2019-11-04 09:35:15 -070097 printk(BIOS_DEBUG, " Subregion %d: 0x%" PRIxPTR " 0x%zx\n", i, base, size);
Kyösti Mälkki7cdb0472019-08-08 11:16:06 +030098 }
99}