Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 2 | |
Felix Held | a90854d | 2021-02-10 04:05:27 +0100 | [diff] [blame^] | 3 | #include <amdblocks/smm.h> |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 4 | #include <assert.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 5 | #include <stdint.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 6 | #include <console/console.h> |
Marshall Dawson | 94ee937 | 2017-06-15 12:18:23 -0600 | [diff] [blame] | 7 | #include <cpu/x86/msr.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 8 | #include <cpu/x86/smm.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 9 | #include <cpu/amd/msr.h> |
Marshall Dawson | 94ee937 | 2017-06-15 12:18:23 -0600 | [diff] [blame] | 10 | #include <cpu/amd/mtrr.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 11 | #include <cbmem.h> |
Marshall Dawson | 4b0f6fa | 2018-09-04 13:08:25 -0600 | [diff] [blame] | 12 | #include <arch/bert_storage.h> |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 13 | #include <soc/northbridge.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 14 | #include <soc/iomap.h> |
Kyösti Mälkki | 2446c1e | 2020-07-09 07:13:37 +0300 | [diff] [blame] | 15 | #include <amdblocks/biosram.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 16 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 17 | #if CONFIG(ACPI_BERT) |
Marshall Dawson | f0de242 | 2018-09-10 13:28:49 -0600 | [diff] [blame] | 18 | #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 Dawson | 4b0f6fa | 2018-09-04 13:08:25 -0600 | [diff] [blame] | 24 | #else |
Marshall Dawson | f0de242 | 2018-09-10 13:28:49 -0600 | [diff] [blame] | 25 | #define BERT_REGION_MAX_SIZE 0 |
Marshall Dawson | 4b0f6fa | 2018-09-04 13:08:25 -0600 | [diff] [blame] | 26 | #endif |
| 27 | |
| 28 | void bert_reserved_region(void **start, size_t *size) |
| 29 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 30 | if (CONFIG(ACPI_BERT)) |
Marshall Dawson | 4b0f6fa | 2018-09-04 13:08:25 -0600 | [diff] [blame] | 31 | *start = cbmem_top(); |
| 32 | else |
Felix Held | 1b457f8 | 2020-04-19 00:02:01 +0200 | [diff] [blame] | 33 | *start = NULL; |
Marshall Dawson | 4b0f6fa | 2018-09-04 13:08:25 -0600 | [diff] [blame] | 34 | *size = BERT_REGION_MAX_SIZE; |
| 35 | } |
| 36 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 37 | void *cbmem_top_chipset(void) |
Marshall Dawson | 94ee937 | 2017-06-15 12:18:23 -0600 | [diff] [blame] | 38 | { |
| 39 | msr_t tom = rdmsr(TOP_MEM); |
| 40 | |
| 41 | if (!tom.lo) |
| 42 | return 0; |
Richard Spiegel | 8c614f2 | 2018-10-23 14:53:23 -0700 | [diff] [blame] | 43 | |
| 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 Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static uintptr_t smm_region_start(void) |
| 51 | { |
Marshall Dawson | 4b0f6fa | 2018-09-04 13:08:25 -0600 | [diff] [blame] | 52 | return (uintptr_t)cbmem_top() + BERT_REGION_MAX_SIZE; |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static size_t smm_region_size(void) |
| 56 | { |
| 57 | return CONFIG_SMM_TSEG_SIZE; |
| 58 | } |
| 59 | |
Kyösti Mälkki | 4913d8a | 2019-08-05 12:49:09 +0300 | [diff] [blame] | 60 | void smm_region(uintptr_t *start, size_t *size) |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 61 | { |
Kyösti Mälkki | 544369e | 2019-08-06 22:14:34 +0300 | [diff] [blame] | 62 | static int once; |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 63 | |
Kyösti Mälkki | 4913d8a | 2019-08-05 12:49:09 +0300 | [diff] [blame] | 64 | *start = smm_region_start(); |
| 65 | *size = smm_region_size(); |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 66 | |
Kyösti Mälkki | 544369e | 2019-08-06 22:14:34 +0300 | [diff] [blame] | 67 | if (!once) { |
| 68 | clear_tvalid(); |
| 69 | once = 1; |
| 70 | } |
Marshall Dawson | 94ee937 | 2017-06-15 12:18:23 -0600 | [diff] [blame] | 71 | } |