blob: 8f859f31e3b53fd86caaa8f42538d02d276e57b4 [file] [log] [blame]
Stefan Reinauercadc5452010-12-18 23:29:37 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauercadc5452010-12-18 23:29:37 +00004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Stefan Reinauercadc5452010-12-18 23:29:37 +000012 */
13
Stefan Reinauercadc5452010-12-18 23:29:37 +000014#include <cpu/x86/lapic.h>
15#include <cpu/x86/msr.h>
16#include <cpu/x86/mtrr.h>
17#include <cpu/amd/mtrr.h>
Stefan Reinauer991f1842015-11-22 23:40:29 +010018#include <cpu/amd/msr.h>
Stefan Reinauercadc5452010-12-18 23:29:37 +000019#include <cpu/x86/cache.h>
20#include <cpu/x86/smm.h>
Kyösti Mälkkic4fdb7b2019-08-10 15:51:59 +030021#include <cpu/x86/smi_deprecated.h>
Stefan Reinauercadc5452010-12-18 23:29:37 +000022#include <string.h>
23
Stefan Reinauercadc5452010-12-18 23:29:37 +000024void smm_init(void)
25{
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020026 msr_t msr, syscfg_orig, mtrr_aseg_orig;
Stefan Reinauercadc5452010-12-18 23:29:37 +000027
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020028 /* Back up MSRs for later restore */
29 syscfg_orig = rdmsr(SYSCFG_MSR);
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070030 mtrr_aseg_orig = rdmsr(MTRR_FIX_16K_A0000);
Stefan Reinauercadc5452010-12-18 23:29:37 +000031
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020032 /* MTRR changes don't like an enabled cache */
33 disable_cache();
Stefan Reinauercadc5452010-12-18 23:29:37 +000034
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020035 msr = syscfg_orig;
Stefan Reinauercadc5452010-12-18 23:29:37 +000036
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020037 /* Allow changes to MTRR extended attributes */
38 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
39 /* turn the extended attributes off until we fix
40 * them so A0000 is routed to memory
41 */
42 msr.lo &= ~SYSCFG_MSR_MtrrFixDramEn;
43 wrmsr(SYSCFG_MSR, msr);
Stefan Reinauercadc5452010-12-18 23:29:37 +000044
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020045 /* set DRAM access to 0xa0000 */
46 msr.lo = 0x18181818;
47 msr.hi = 0x18181818;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070048 wrmsr(MTRR_FIX_16K_A0000, msr);
Rudolf Marek2c366272010-12-18 23:30:59 +000049
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020050 /* enable the extended features */
51 msr = syscfg_orig;
52 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
53 msr.lo |= SYSCFG_MSR_MtrrFixDramEn;
54 wrmsr(SYSCFG_MSR, msr);
Stefan Reinauercadc5452010-12-18 23:29:37 +000055
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020056 enable_cache();
57 /* copy the real SMM handler */
Kyösti Mälkki9d8adc02016-12-04 22:17:37 +020058 memcpy((void *)SMM_BASE, _binary_smm_start,
59 _binary_smm_end - _binary_smm_start);
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020060 wbinvd();
61 disable_cache();
Stefan Reinauercadc5452010-12-18 23:29:37 +000062
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020063 /* Restore SYSCFG and MTRR */
64 wrmsr(SYSCFG_MSR, syscfg_orig);
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070065 wrmsr(MTRR_FIX_16K_A0000, mtrr_aseg_orig);
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020066 enable_cache();
Stefan Reinauercadc5452010-12-18 23:29:37 +000067
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020068 /* CPU MSR are set in CPU init */
Stefan Reinauercadc5452010-12-18 23:29:37 +000069}
Rudolf Marek2c366272010-12-18 23:30:59 +000070
Kyösti Mälkkie09cd1b2017-08-18 20:58:33 +030071void smm_init_completion(void)
72{
73}