blob: e411aa2ef3b88e54abbf486cf94857b50accb2d8 [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>
Elyes HAOUAS400ce552018-10-12 10:54:30 +02008#include <cpu/amd/msr.h>
Marshall Dawson94ee9372017-06-15 12:18:23 -06009#include <cpu/amd/mtrr.h>
Marc Jones1587dc82017-05-15 18:55:11 -060010#include <cbmem.h>
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060011#include <arch/bert_storage.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060012#include <soc/northbridge.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060013#include <soc/iomap.h>
Kyösti Mälkki2446c1e2020-07-09 07:13:37 +030014#include <amdblocks/biosram.h>
Marc Jones1587dc82017-05-15 18:55:11 -060015
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060016void bert_reserved_region(void **start, size_t *size)
17{
Arthur Heymansdd7ec092022-05-23 16:06:06 +020018 if (!CONFIG(ACPI_BERT)) {
Felix Held1b457f82020-04-19 00:02:01 +020019 *start = NULL;
Arthur Heymansdd7ec092022-05-23 16:06:06 +020020 *size = 0;
21 } else {
22 *start = cbmem_add(CBMEM_ID_ACPI_BERT, CONFIG_ACPI_BERT_SIZE);
23 *size = CONFIG_ACPI_BERT_SIZE;
24 }
25 printk(BIOS_INFO, "Reserved BERT region base: %p, size: 0x%zx\n", *start, *size);
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060026}
27
Arthur Heymans340e4b82019-10-23 17:25:58 +020028void *cbmem_top_chipset(void)
Marshall Dawson94ee9372017-06-15 12:18:23 -060029{
30 msr_t tom = rdmsr(TOP_MEM);
31
32 if (!tom.lo)
33 return 0;
Richard Spiegel8c614f22018-10-23 14:53:23 -070034
35 /* 8MB alignment to keep MTRR usage low */
36 return (void *)ALIGN_DOWN(restore_top_of_low_cacheable()
Arthur Heymansdd7ec092022-05-23 16:06:06 +020037 - CONFIG_SMM_TSEG_SIZE, 8*MiB);
Marshall Dawsonb6172112017-09-13 17:47:31 -060038}
39
40static uintptr_t smm_region_start(void)
41{
Arthur Heymansdd7ec092022-05-23 16:06:06 +020042 return (uintptr_t)cbmem_top();
Marshall Dawsonb6172112017-09-13 17:47:31 -060043}
44
45static size_t smm_region_size(void)
46{
47 return CONFIG_SMM_TSEG_SIZE;
48}
49
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030050void smm_region(uintptr_t *start, size_t *size)
Marshall Dawsonb6172112017-09-13 17:47:31 -060051{
Kyösti Mälkki544369e2019-08-06 22:14:34 +030052 static int once;
Marshall Dawsonb6172112017-09-13 17:47:31 -060053
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030054 *start = smm_region_start();
55 *size = smm_region_size();
Marshall Dawsonb6172112017-09-13 17:47:31 -060056
Kyösti Mälkki544369e2019-08-06 22:14:34 +030057 if (!once) {
58 clear_tvalid();
59 once = 1;
60 }
Marshall Dawson94ee9372017-06-15 12:18:23 -060061}