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 | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 11 | #include <soc/northbridge.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 12 | #include <soc/iomap.h> |
Kyösti Mälkki | 2446c1e | 2020-07-09 07:13:37 +0300 | [diff] [blame] | 13 | #include <amdblocks/biosram.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 14 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 15 | void *cbmem_top_chipset(void) |
Marshall Dawson | 94ee937 | 2017-06-15 12:18:23 -0600 | [diff] [blame] | 16 | { |
17 | msr_t tom = rdmsr(TOP_MEM); | ||||
18 | |||||
19 | if (!tom.lo) | ||||
20 | return 0; | ||||
Richard Spiegel | 8c614f2 | 2018-10-23 14:53:23 -0700 | [diff] [blame] | 21 | |
22 | /* 8MB alignment to keep MTRR usage low */ | ||||
23 | return (void *)ALIGN_DOWN(restore_top_of_low_cacheable() | ||||
Arthur Heymans | dd7ec09 | 2022-05-23 16:06:06 +0200 | [diff] [blame] | 24 | - CONFIG_SMM_TSEG_SIZE, 8*MiB); |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 25 | } |
26 | |||||
27 | static uintptr_t smm_region_start(void) | ||||
28 | { | ||||
Arthur Heymans | dd7ec09 | 2022-05-23 16:06:06 +0200 | [diff] [blame] | 29 | return (uintptr_t)cbmem_top(); |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 30 | } |
31 | |||||
32 | static size_t smm_region_size(void) | ||||
33 | { | ||||
34 | return CONFIG_SMM_TSEG_SIZE; | ||||
35 | } | ||||
36 | |||||
Kyösti Mälkki | 4913d8a | 2019-08-05 12:49:09 +0300 | [diff] [blame] | 37 | void smm_region(uintptr_t *start, size_t *size) |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 38 | { |
Kyösti Mälkki | 544369e | 2019-08-06 22:14:34 +0300 | [diff] [blame] | 39 | static int once; |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 40 | |
Kyösti Mälkki | 4913d8a | 2019-08-05 12:49:09 +0300 | [diff] [blame] | 41 | *start = smm_region_start(); |
42 | *size = smm_region_size(); | ||||
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 43 | |
Kyösti Mälkki | 544369e | 2019-08-06 22:14:34 +0300 | [diff] [blame] | 44 | if (!once) { |
45 | clear_tvalid(); | ||||
46 | once = 1; | ||||
47 | } | ||||
Marshall Dawson | 94ee937 | 2017-06-15 12:18:23 -0600 | [diff] [blame] | 48 | } |