Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 2 | |
Kyösti Mälkki | 81100bf | 2019-08-16 10:37:15 +0300 | [diff] [blame] | 3 | #include <arch/romstage.h> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 4 | #include <cbmem.h> |
Kyösti Mälkki | 81100bf | 2019-08-16 10:37:15 +0300 | [diff] [blame] | 5 | #include <cpu/x86/mtrr.h> |
Kyösti Mälkki | 568a42a | 2019-08-14 06:48:28 +0300 | [diff] [blame] | 6 | #include <cpu/x86/smm.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 7 | #include <soc/iosf.h> |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 8 | |
Kyösti Mälkki | 568a42a | 2019-08-14 06:48:28 +0300 | [diff] [blame] | 9 | static uintptr_t smm_region_start(void) |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 10 | { |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 11 | return (iosf_bunit_read(BUNIT_SMRRL) << 20); |
Aaron Durbin | 7837be6 | 2013-10-21 22:32:00 -0500 | [diff] [blame] | 12 | } |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 13 | |
Kyösti Mälkki | 568a42a | 2019-08-14 06:48:28 +0300 | [diff] [blame] | 14 | static size_t smm_region_size(void) |
| 15 | { |
| 16 | return CONFIG_SMM_TSEG_SIZE; |
| 17 | } |
| 18 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 19 | void *cbmem_top_chipset(void) |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 20 | { |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 21 | return (void *) smm_region_start(); |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 22 | } |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 23 | |
Kyösti Mälkki | 568a42a | 2019-08-14 06:48:28 +0300 | [diff] [blame] | 24 | void smm_region(uintptr_t *start, size_t *size) |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 25 | { |
Kyösti Mälkki | 568a42a | 2019-08-14 06:48:28 +0300 | [diff] [blame] | 26 | *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20; |
| 27 | *size = smm_region_size(); |
Kyösti Mälkki | 26a682c | 2019-08-02 06:13:22 +0300 | [diff] [blame] | 28 | } |
Kyösti Mälkki | 81100bf | 2019-08-16 10:37:15 +0300 | [diff] [blame] | 29 | |
| 30 | void fill_postcar_frame(struct postcar_frame *pcf) |
| 31 | { |
| 32 | uintptr_t top_of_ram; |
| 33 | |
| 34 | /* Cache at least 8 MiB below the top of ram, and at most 8 MiB |
| 35 | * above top of the ram. This satisfies MTRR alignment requirement |
| 36 | * with different TSEG size configurations. |
| 37 | */ |
| 38 | top_of_ram = ALIGN_DOWN((uintptr_t)cbmem_top(), 8*MiB); |
| 39 | postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 16*MiB, |
| 40 | MTRR_TYPE_WRBACK); |
| 41 | } |