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