blob: 7af8808c62ab4a85e75b25b11132ccbb9bcd76ca [file] [log] [blame]
Stefan Reinauercadc5452010-12-18 23:29:37 +00001/*
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 Reinauercadc5452010-12-18 23:29:37 +000015 */
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 Reinauer991f1842015-11-22 23:40:29 +010024#include <cpu/amd/msr.h>
Stefan Reinauercadc5452010-12-18 23:29:37 +000025#include <cpu/x86/cache.h>
26#include <cpu/x86/smm.h>
27#include <string.h>
28
Stefan Reinauercadc5452010-12-18 23:29:37 +000029void smm_init(void)
30{
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020031 msr_t msr, syscfg_orig, mtrr_aseg_orig;
Stefan Reinauercadc5452010-12-18 23:29:37 +000032
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020033 /* Back up MSRs for later restore */
34 syscfg_orig = rdmsr(SYSCFG_MSR);
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070035 mtrr_aseg_orig = rdmsr(MTRR_FIX_16K_A0000);
Stefan Reinauercadc5452010-12-18 23:29:37 +000036
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020037 /* MTRR changes don't like an enabled cache */
38 disable_cache();
Stefan Reinauercadc5452010-12-18 23:29:37 +000039
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020040 msr = syscfg_orig;
Stefan Reinauercadc5452010-12-18 23:29:37 +000041
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020042 /* 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 Reinauercadc5452010-12-18 23:29:37 +000049
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020050 /* set DRAM access to 0xa0000 */
51 msr.lo = 0x18181818;
52 msr.hi = 0x18181818;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070053 wrmsr(MTRR_FIX_16K_A0000, msr);
Rudolf Marek2c366272010-12-18 23:30:59 +000054
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020055 /* 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 Reinauercadc5452010-12-18 23:29:37 +000060
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020061 enable_cache();
62 /* copy the real SMM handler */
Kyösti Mälkki9d8adc02016-12-04 22:17:37 +020063 memcpy((void *)SMM_BASE, _binary_smm_start,
64 _binary_smm_end - _binary_smm_start);
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020065 wbinvd();
66 disable_cache();
Stefan Reinauercadc5452010-12-18 23:29:37 +000067
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020068 /* Restore SYSCFG and MTRR */
69 wrmsr(SYSCFG_MSR, syscfg_orig);
Alexandru Gagniuc86091f92015-09-30 20:23:09 -070070 wrmsr(MTRR_FIX_16K_A0000, mtrr_aseg_orig);
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020071 enable_cache();
Stefan Reinauercadc5452010-12-18 23:29:37 +000072
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020073 /* CPU MSR are set in CPU init */
Stefan Reinauercadc5452010-12-18 23:29:37 +000074}
Rudolf Marek2c366272010-12-18 23:30:59 +000075
76void smm_lock(void)
77{
Rudolf Marekb5b3b3b2011-07-02 16:36:17 +020078 /* We lock SMM in CPU init */
Rudolf Marek2c366272010-12-18 23:30:59 +000079}
Kyösti Mälkkie09cd1b2017-08-18 20:58:33 +030080
81void smm_init_completion(void)
82{
83}