Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 coresystems GmbH |
| 5 | * Copyright (C) 2010 Rudolf Marek |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <arch/io.h> |
| 19 | #include <cpu/cpu.h> |
| 20 | #include <cpu/x86/lapic.h> |
| 21 | #include <cpu/x86/msr.h> |
| 22 | #include <cpu/x86/mtrr.h> |
| 23 | #include <cpu/amd/mtrr.h> |
Stefan Reinauer | 991f184 | 2015-11-22 23:40:29 +0100 | [diff] [blame] | 24 | #include <cpu/amd/msr.h> |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 25 | #include <cpu/x86/cache.h> |
| 26 | #include <cpu/x86/smm.h> |
| 27 | #include <string.h> |
| 28 | |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 29 | void smm_init(void) |
| 30 | { |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 31 | msr_t msr, syscfg_orig, mtrr_aseg_orig; |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 32 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 33 | /* Back up MSRs for later restore */ |
| 34 | syscfg_orig = rdmsr(SYSCFG_MSR); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 35 | mtrr_aseg_orig = rdmsr(MTRR_FIX_16K_A0000); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 36 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 37 | /* MTRR changes don't like an enabled cache */ |
| 38 | disable_cache(); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 39 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 40 | msr = syscfg_orig; |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 41 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 42 | /* Allow changes to MTRR extended attributes */ |
| 43 | msr.lo |= SYSCFG_MSR_MtrrFixDramModEn; |
| 44 | /* turn the extended attributes off until we fix |
| 45 | * them so A0000 is routed to memory |
| 46 | */ |
| 47 | msr.lo &= ~SYSCFG_MSR_MtrrFixDramEn; |
| 48 | wrmsr(SYSCFG_MSR, msr); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 49 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 50 | /* set DRAM access to 0xa0000 */ |
| 51 | msr.lo = 0x18181818; |
| 52 | msr.hi = 0x18181818; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 53 | wrmsr(MTRR_FIX_16K_A0000, msr); |
Rudolf Marek | 2c36627 | 2010-12-18 23:30:59 +0000 | [diff] [blame] | 54 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 55 | /* enable the extended features */ |
| 56 | msr = syscfg_orig; |
| 57 | msr.lo |= SYSCFG_MSR_MtrrFixDramModEn; |
| 58 | msr.lo |= SYSCFG_MSR_MtrrFixDramEn; |
| 59 | wrmsr(SYSCFG_MSR, msr); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 60 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 61 | enable_cache(); |
| 62 | /* copy the real SMM handler */ |
Kyösti Mälkki | 9d8adc0 | 2016-12-04 22:17:37 +0200 | [diff] [blame] | 63 | memcpy((void *)SMM_BASE, _binary_smm_start, |
| 64 | _binary_smm_end - _binary_smm_start); |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 65 | wbinvd(); |
| 66 | disable_cache(); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 67 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 68 | /* Restore SYSCFG and MTRR */ |
| 69 | wrmsr(SYSCFG_MSR, syscfg_orig); |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 70 | wrmsr(MTRR_FIX_16K_A0000, mtrr_aseg_orig); |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 71 | enable_cache(); |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 72 | |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 73 | /* CPU MSR are set in CPU init */ |
Stefan Reinauer | cadc545 | 2010-12-18 23:29:37 +0000 | [diff] [blame] | 74 | } |
Rudolf Marek | 2c36627 | 2010-12-18 23:30:59 +0000 | [diff] [blame] | 75 | |
| 76 | void smm_lock(void) |
| 77 | { |
Rudolf Marek | b5b3b3b | 2011-07-02 16:36:17 +0200 | [diff] [blame] | 78 | /* We lock SMM in CPU init */ |
Rudolf Marek | 2c36627 | 2010-12-18 23:30:59 +0000 | [diff] [blame] | 79 | } |
Kyösti Mälkki | e09cd1b | 2017-08-18 20:58:33 +0300 | [diff] [blame^] | 80 | |
| 81 | void smm_init_completion(void) |
| 82 | { |
| 83 | } |