blob: 52bba3e96f3098852cb04e230ed2004923d67e5c [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 Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 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 Leahy32471722015-04-20 15:20:28 -070012 * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty 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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgi25509ee2015-03-26 15:17:45 +010018 * Foundation, Inc.
Lee Leahy77ff0b12015-05-05 15:07:29 -070019 */
20
21#include <arch/io.h>
22#include <cbmem.h>
Lee Leahy32471722015-04-20 15:20:28 -070023#include <console/console.h>
24#include <soc/intel/common/memmap.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070025#include <soc/iosf.h>
26#include <soc/smm.h>
27
Lee Leahy32471722015-04-20 15:20:28 -070028static size_t smm_region_size(void)
Lee Leahy77ff0b12015-05-05 15:07:29 -070029{
Lee Leahy32471722015-04-20 15:20:28 -070030 u32 smm_size;
31 smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF;
32 smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF;
33 smm_size = (smm_size + 1) << 20;
34 return smm_size;
35}
36
37void smm_region(void **start, size_t *size)
38{
39 *start = (void *)((iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20);
40 *size = smm_region_size();
41}
42
43size_t mmap_region_granluarity(void)
44{
45 /* Align to TSEG size when SMM is in use, and 8MiB by default */
46 return IS_ENABLED(CONFIG_HAVE_SMI_HANDLER) ? smm_region_size()
47 : 8 << 20;
Lee Leahy77ff0b12015-05-05 15:07:29 -070048}
49
Aaron Durbinc43d4172015-08-05 14:51:48 -050050/*
51 * Subregions within SMM
52 * +-------------------------+ BUNIT_SMRRH
53 * | External Stage Cache | SMM_RESERVED_SIZE
54 * +-------------------------+
55 * | code and data |
56 * | (TSEG) |
57 * +-------------------------+ BUNIT_SMRRL
58 */
59int smm_subregion(int sub, void **start, size_t *size)
60{
61 uintptr_t sub_base;
62 void *sub_ptr;
63 size_t sub_size;
64 const size_t cache_size = CONFIG_SMM_RESERVED_SIZE;
65
66 smm_region(&sub_ptr, &sub_size);
67 sub_base = (uintptr_t)sub_ptr;
68
69 switch (sub) {
70 case SMM_SUBREGION_HANDLER:
71 /* Handler starts at the base of TSEG. */
72 sub_size -= cache_size;
73 break;
74 case SMM_SUBREGION_CACHE:
75 /* External cache is in the middle of TSEG. */
76 sub_base += sub_size - cache_size;
77 sub_size = cache_size;
78 break;
79 default:
80 return -1;
81 }
82
83 *start = (void *)sub_base;
84 *size = sub_size;
85
86 return 0;
87}
88
Lee Leahy77ff0b12015-05-05 15:07:29 -070089void *cbmem_top(void)
90{
Lee Leahy32471722015-04-20 15:20:28 -070091 char *smm_base;
92 size_t smm_size;
93
94 /*
95 * +-------------------------+ Top of RAM (aligned)
96 * | System Management Mode |
97 * | code and data | Length: CONFIG_TSEG_SIZE
98 * | (TSEG) |
99 * +-------------------------+ SMM base (aligned)
100 * | |
101 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
102 * | |
103 * +-------------------------+ top_of_ram (aligned)
104 * | |
105 * | CBMEM Root |
106 * | |
107 * +-------------------------+
108 * | |
109 * | FSP Reserved Memory |
110 * | |
111 * +-------------------------+
112 * | |
113 * | Various CBMEM Entries |
114 * | |
115 * +-------------------------+ top_of_stack (8 byte aligned)
116 * | |
117 * | stack (CBMEM Entry) |
118 * | |
119 * +-------------------------+
120 */
121
122 smm_region((void **)&smm_base, &smm_size);
Aaron Durbinbbbfbf22015-07-13 16:55:28 -0500123 return (void *)smm_base;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700124}