blob: 32d6d96a5bab8ae339eae44fab8b80c17e2038a1 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones1587dc82017-05-15 18:55:11 -06002
Felix Helda90854d2021-02-10 04:05:27 +01003#include <amdblocks/smm.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -06004#include <assert.h>
Marc Jones1587dc82017-05-15 18:55:11 -06005#include <stdint.h>
Marshall Dawson94ee9372017-06-15 12:18:23 -06006#include <cpu/x86/msr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03007#include <cpu/x86/smm.h>
Marshall Dawson94ee9372017-06-15 12:18:23 -06008#include <cpu/amd/mtrr.h>
Marc Jones1587dc82017-05-15 18:55:11 -06009#include <cbmem.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060010#include <soc/northbridge.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060011#include <soc/iomap.h>
Kyösti Mälkki2446c1e2020-07-09 07:13:37 +030012#include <amdblocks/biosram.h>
Marc Jones1587dc82017-05-15 18:55:11 -060013
Elyes Haouas799c3212022-11-09 14:00:44 +010014uintptr_t cbmem_top_chipset(void)
Marshall Dawson94ee9372017-06-15 12:18:23 -060015{
Felix Held59278732023-04-20 13:24:26 +020016 if (!get_top_of_mem_below_4gb())
Marshall Dawson94ee9372017-06-15 12:18:23 -060017 return 0;
Richard Spiegel8c614f22018-10-23 14:53:23 -070018
19 /* 8MB alignment to keep MTRR usage low */
Elyes Haouas799c3212022-11-09 14:00:44 +010020 return ALIGN_DOWN(restore_top_of_low_cacheable() - CONFIG_SMM_TSEG_SIZE, 8 * MiB);
Marshall Dawsonb6172112017-09-13 17:47:31 -060021}
22
23static uintptr_t smm_region_start(void)
24{
Arthur Heymansdd7ec092022-05-23 16:06:06 +020025 return (uintptr_t)cbmem_top();
Marshall Dawsonb6172112017-09-13 17:47:31 -060026}
27
28static size_t smm_region_size(void)
29{
30 return CONFIG_SMM_TSEG_SIZE;
31}
32
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030033void smm_region(uintptr_t *start, size_t *size)
Marshall Dawsonb6172112017-09-13 17:47:31 -060034{
Kyösti Mälkki544369e2019-08-06 22:14:34 +030035 static int once;
Marshall Dawsonb6172112017-09-13 17:47:31 -060036
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030037 *start = smm_region_start();
38 *size = smm_region_size();
Marshall Dawsonb6172112017-09-13 17:47:31 -060039
Kyösti Mälkki544369e2019-08-06 22:14:34 +030040 if (!once) {
41 clear_tvalid();
42 once = 1;
43 }
Marshall Dawson94ee9372017-06-15 12:18:23 -060044}