coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smm_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cpu/x86/msr.h>
4 #include <cpu/x86/mtrr.h>
5 #include <cpu/amd/mtrr.h>
6 #include <cpu/amd/msr.h>
7 #include <cpu/x86/cache.h>
8 #include <cpu/x86/smm.h>
10 #include <string.h>
11 
12 void smm_init(void)
13 {
14  msr_t msr, syscfg_orig, mtrr_aseg_orig;
15 
16  /* Back up MSRs for later restore */
17  syscfg_orig = rdmsr(SYSCFG_MSR);
18  mtrr_aseg_orig = rdmsr(MTRR_FIX_16K_A0000);
19 
20  /* MTRR changes don't like an enabled cache */
21  disable_cache();
22 
23  msr = syscfg_orig;
24 
25  /* Allow changes to MTRR extended attributes */
27  /* turn the extended attributes off until we fix
28  * them so A0000 is routed to memory
29  */
31  wrmsr(SYSCFG_MSR, msr);
32 
33  /* set DRAM access to 0xa0000 */
34  msr.lo = 0x18181818;
35  msr.hi = 0x18181818;
37 
38  /* enable the extended features */
39  msr = syscfg_orig;
42  wrmsr(SYSCFG_MSR, msr);
43 
44  enable_cache();
45  /* copy the real SMM handler */
48  wbinvd();
49  disable_cache();
50 
51  /* Restore SYSCFG and MTRR */
52  wrmsr(SYSCFG_MSR, syscfg_orig);
53  wrmsr(MTRR_FIX_16K_A0000, mtrr_aseg_orig);
54  enable_cache();
55 
56  /* CPU MSR are set in CPU init */
57 }
58 
60 {
61 }
#define SYSCFG_MSR_MtrrFixDramModEn
Definition: mtrr.h:16
#define SYSCFG_MSR
Definition: mtrr.h:12
#define SYSCFG_MSR_MtrrFixDramEn
Definition: mtrr.h:17
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
static void wbinvd(void)
Definition: cache.h:15
static __always_inline void enable_cache(void)
Definition: cache.h:40
static __always_inline void disable_cache(void)
Definition: cache.h:48
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
static __always_inline void wrmsr(unsigned int index, msr_t msr)
Definition: msr.h:157
unsigned char _binary_smm_start[]
#define SMM_BASE
Definition: smm.h:14
unsigned char _binary_smm_end[]
void smm_init(void)
Definition: smm_init.c:12
void smm_init_completion(void)
Definition: smm_init.c:59
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111
#define MTRR_FIX_16K_A0000
Definition: mtrr.h:47