Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 3 | |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 4 | #include <cpu/x86/lapic.h> |
| 5 | #include <cpu/x86/msr.h> |
| 6 | #include <cpu/x86/mtrr.h> |
| 7 | #include <cpu/amd/mtrr.h> |
Stefan Reinauer | 991f184 | 2015-11-22 23:40:29 +0100 | [diff] [blame] | 8 | #include <cpu/amd/msr.h> |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 9 | #include <cpu/x86/cache.h> |
| 10 | #include <cpu/x86/smm.h> |
Kyösti Mälkki | c4fdb7b | 2019-08-10 15:51:59 +0300 | [diff] [blame] | 11 | #include <cpu/x86/smi_deprecated.h> |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 12 | #include <string.h> |
| 13 | |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 14 | void smm_init(void) |
| 15 | { |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 16 | msr_t msr, syscfg_orig, mtrr_aseg_orig; |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 17 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 18 | /* Back up MSRs for later restore */ |
| 19 | syscfg_orig = rdmsr(SYSCFG_MSR); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 20 | mtrr_aseg_orig = rdmsr(MTRR_FIX_16K_A0000); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 21 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 22 | /* MTRR changes don't like an enabled cache */ |
| 23 | disable_cache(); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 24 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 25 | msr = syscfg_orig; |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 26 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 27 | /* Allow changes to MTRR extended attributes */ |
| 28 | msr.lo |= SYSCFG_MSR_MtrrFixDramModEn; |
| 29 | /* turn the extended attributes off until we fix |
| 30 | * them so A0000 is routed to memory |
| 31 | */ |
| 32 | msr.lo &= ~SYSCFG_MSR_MtrrFixDramEn; |
| 33 | wrmsr(SYSCFG_MSR, msr); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 34 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 35 | /* set DRAM access to 0xa0000 */ |
| 36 | msr.lo = 0x18181818; |
| 37 | msr.hi = 0x18181818; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 38 | wrmsr(MTRR_FIX_16K_A0000, msr); |
Rudolf Marek | 2c36627 | 2010-12-18 23:30:59 +0000 | [diff] [blame] | 39 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 40 | /* enable the extended features */ |
| 41 | msr = syscfg_orig; |
| 42 | msr.lo |= SYSCFG_MSR_MtrrFixDramModEn; |
| 43 | msr.lo |= SYSCFG_MSR_MtrrFixDramEn; |
| 44 | wrmsr(SYSCFG_MSR, msr); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 45 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 46 | enable_cache(); |
| 47 | /* copy the real SMM handler */ |
Kyösti Mälkki | 9d8adc0 | 2016-12-04 22:17:37 +0200 | [diff] [blame] | 48 | memcpy((void *)SMM_BASE, _binary_smm_start, |
| 49 | _binary_smm_end - _binary_smm_start); |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 50 | wbinvd(); |
| 51 | disable_cache(); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 52 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 53 | /* Restore SYSCFG and MTRR */ |
| 54 | wrmsr(SYSCFG_MSR, syscfg_orig); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 55 | wrmsr(MTRR_FIX_16K_A0000, mtrr_aseg_orig); |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 56 | enable_cache(); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 57 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 58 | /* CPU MSR are set in CPU init */ |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 59 | } |
Rudolf Marek | 2c36627 | 2010-12-18 23:30:59 +0000 | [diff] [blame] | 60 | |
Kyösti Mälkki | e09cd1b | 2017-08-18 20:58:33 +0300 | [diff] [blame] | 61 | void smm_init_completion(void) |
| 62 | { |
| 63 | } |