blob: 9da3e6522cf0292667957d386a2836beecf93f24 [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>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01006#include <console/console.h>
Marshall Dawson94ee9372017-06-15 12:18:23 -06007#include <cpu/x86/msr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03008#include <cpu/x86/smm.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +02009#include <cpu/amd/msr.h>
Marshall Dawson94ee9372017-06-15 12:18:23 -060010#include <cpu/amd/mtrr.h>
Marc Jones1587dc82017-05-15 18:55:11 -060011#include <cbmem.h>
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060012#include <arch/bert_storage.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060013#include <soc/northbridge.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060014#include <soc/iomap.h>
Kyösti Mälkki2446c1e2020-07-09 07:13:37 +030015#include <amdblocks/biosram.h>
Marc Jones1587dc82017-05-15 18:55:11 -060016
Julius Wernercd49cce2019-03-05 16:53:33 -080017#if CONFIG(ACPI_BERT)
Marshall Dawsonf0de2422018-09-10 13:28:49 -060018 #if CONFIG_SMM_TSEG_SIZE == 0x0
19 #define BERT_REGION_MAX_SIZE 0x100000
20 #else
21 /* SMM_TSEG_SIZE must stay on a boundary appropriate for its granularity */
22 #define BERT_REGION_MAX_SIZE CONFIG_SMM_TSEG_SIZE
23 #endif
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060024#else
Marshall Dawsonf0de2422018-09-10 13:28:49 -060025 #define BERT_REGION_MAX_SIZE 0
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060026#endif
27
28void bert_reserved_region(void **start, size_t *size)
29{
Julius Wernercd49cce2019-03-05 16:53:33 -080030 if (CONFIG(ACPI_BERT))
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060031 *start = cbmem_top();
32 else
Felix Held1b457f82020-04-19 00:02:01 +020033 *start = NULL;
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060034 *size = BERT_REGION_MAX_SIZE;
35}
36
Arthur Heymans340e4b82019-10-23 17:25:58 +020037void *cbmem_top_chipset(void)
Marshall Dawson94ee9372017-06-15 12:18:23 -060038{
39 msr_t tom = rdmsr(TOP_MEM);
40
41 if (!tom.lo)
42 return 0;
Richard Spiegel8c614f22018-10-23 14:53:23 -070043
44 /* 8MB alignment to keep MTRR usage low */
45 return (void *)ALIGN_DOWN(restore_top_of_low_cacheable()
46 - CONFIG_SMM_TSEG_SIZE
47 - BERT_REGION_MAX_SIZE, 8*MiB);
Marshall Dawsonb6172112017-09-13 17:47:31 -060048}
49
50static uintptr_t smm_region_start(void)
51{
Marshall Dawson4b0f6fa2018-09-04 13:08:25 -060052 return (uintptr_t)cbmem_top() + BERT_REGION_MAX_SIZE;
Marshall Dawsonb6172112017-09-13 17:47:31 -060053}
54
55static size_t smm_region_size(void)
56{
57 return CONFIG_SMM_TSEG_SIZE;
58}
59
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030060void smm_region(uintptr_t *start, size_t *size)
Marshall Dawsonb6172112017-09-13 17:47:31 -060061{
Kyösti Mälkki544369e2019-08-06 22:14:34 +030062 static int once;
Marshall Dawsonb6172112017-09-13 17:47:31 -060063
Kyösti Mälkki4913d8a2019-08-05 12:49:09 +030064 *start = smm_region_start();
65 *size = smm_region_size();
Marshall Dawsonb6172112017-09-13 17:47:31 -060066
Kyösti Mälkki544369e2019-08-06 22:14:34 +030067 if (!once) {
68 clear_tvalid();
69 once = 1;
70 }
Marshall Dawson94ee9372017-06-15 12:18:23 -060071}