2 * This file is part of the coreboot project.
4 * Copyright (C) 2013 Google, Inc.
5 * Copyright (C) 2015 Intel Corp.
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.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
19 #include <console/console.h>
20 #include <fsp/memmap.h>
24 static size_t smm_region_size(void)
27 smm_size
= iosf_bunit_read(BUNIT_SMRRH
) & 0xFFFF;
28 smm_size
-= iosf_bunit_read(BUNIT_SMRRL
) & 0xFFFF;
29 smm_size
= (smm_size
+ 1) << 20;
33 void smm_region(void **start
, size_t *size
)
35 *start
= (void *)((iosf_bunit_read(BUNIT_SMRRL
) & 0xFFFF) << 20);
36 *size
= smm_region_size();
39 size_t mmap_region_granluarity(void)
41 /* Align to TSEG size when SMM is in use, and 8MiB by default */
42 return IS_ENABLED(CONFIG_HAVE_SMI_HANDLER
) ? smm_region_size()
47 * Subregions within SMM
48 * +-------------------------+ BUNIT_SMRRH
49 * | External Stage Cache | SMM_RESERVED_SIZE
50 * +-------------------------+
53 * +-------------------------+ BUNIT_SMRRL
55 int smm_subregion(int sub
, void **start
, size_t *size
)
60 const size_t cache_size
= CONFIG_SMM_RESERVED_SIZE
;
62 smm_region(&sub_ptr
, &sub_size
);
63 sub_base
= (uintptr_t)sub_ptr
;
66 case SMM_SUBREGION_HANDLER
:
67 /* Handler starts at the base of TSEG. */
68 sub_size
-= cache_size
;
70 case SMM_SUBREGION_CACHE
:
71 /* External cache is in the middle of TSEG. */
72 sub_base
+= sub_size
- cache_size
;
73 sub_size
= cache_size
;
79 *start
= (void *)sub_base
;
91 * +-------------------------+ Top of RAM (aligned)
92 * | System Management Mode |
93 * | code and data | Length: CONFIG_TSEG_SIZE
95 * +-------------------------+ SMM base (aligned)
97 * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
99 * +-------------------------+ top_of_ram (aligned)
103 * +-------------------------+
105 * | FSP Reserved Memory |
107 * +-------------------------+
109 * | Various CBMEM Entries |
111 * +-------------------------+ top_of_stack (8 byte aligned)
113 * | stack (CBMEM Entry) |
115 * +-------------------------+
118 smm_region((void **)&smm_base
, &smm_size
);
119 return (void *)smm_base
;