coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
model_15_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <cpu/x86/msr.h>
5 #include <cpu/amd/msr.h>
6 #include <cpu/x86/mtrr.h>
7 #include <cpu/amd/mtrr.h>
8 #include <cpu/x86/smm.h>
9 #include <device/device.h>
10 #include <cpu/x86/pae.h>
11 #include <cpu/cpu.h>
12 #include <cpu/x86/cache.h>
13 #include <acpi/acpi.h>
15 
16 static void model_15_init(struct device *dev)
17 {
18  printk(BIOS_DEBUG, "Model 15 Init.\n");
19 
20  msr_t msr;
21  int msrno;
22  unsigned int cpu_idx;
23 #if CONFIG(LOGICAL_CPUS)
24  u32 siblings;
25 #endif
26 
27  /*
28  * AGESA sets the MTRRs main MTRRs. The shadow area needs to be set
29  * by coreboot.
30  */
31  disable_cache();
32  /* Enable access to AMD RdDram and WrDram extension bits */
33  msr = rdmsr(SYSCFG_MSR);
36  wrmsr(SYSCFG_MSR, msr);
37 
38  // BSP: make a0000-bffff UC, c0000-fffff WB, same as OntarioApMtrrSettingsList for APs
39  msr.lo = msr.hi = 0;
41  msr.lo = msr.hi = 0x1e1e1e1e;
44  for (msrno = MTRR_FIX_4K_C0000; msrno <= MTRR_FIX_4K_F8000; msrno++)
45  wrmsr(msrno, msr);
46 
47  msr = rdmsr(SYSCFG_MSR);
50  wrmsr(SYSCFG_MSR, msr);
51 
52  if (acpi_is_wakeup_s3())
53  restore_mtrr();
54 
56  enable_cache();
57 
58  /* zero the machine check error status registers */
60 
61 #if CONFIG(LOGICAL_CPUS)
62  siblings = cpuid_ecx(0x80000008) & 0xff;
63 
64  if (siblings > 0) {
66  msr.lo |= 1 << 28;
68 
70  msr.hi |= 1 << (33 - 32);
72  }
73  printk(BIOS_DEBUG, "siblings = %02d, ", siblings);
74 #endif
75 
76  /* DisableCf8ExtCfg */
77  msr = rdmsr(NB_CFG_MSR);
78  msr.hi &= ~(1 << (46 - 32));
79  wrmsr(NB_CFG_MSR, msr);
80 
81  if (CONFIG(HAVE_SMI_HANDLER)) {
82  cpu_idx = cpu_info()->index;
83  printk(BIOS_INFO, "Initializing SMM for CPU %u\n", cpu_idx);
84 
85  /* Set SMM base address for this CPU */
86  msr = rdmsr(SMM_BASE_MSR);
87  msr.lo = SMM_BASE - (cpu_idx * 0x400);
88  wrmsr(SMM_BASE_MSR, msr);
89 
90  /* Enable the SMM memory window */
91  msr = rdmsr(SMM_MASK_MSR);
92  msr.lo |= (1 << 0); /* Enable ASEG SMRAM Range */
93  wrmsr(SMM_MASK_MSR, msr);
94  }
95 
96  /* Write protect SMM space with SMMLOCK. */
97  msr = rdmsr(HWCR_MSR);
98  msr.lo |= (1 << 0);
99  wrmsr(HWCR_MSR, msr);
100 }
101 
102 static struct device_operations cpu_dev_ops = {
103  .init = model_15_init,
104 };
105 
106 static const struct cpu_device_id cpu_table[] = {
107  { X86_VENDOR_AMD, 0x610f00 }, /* TN-A0 */
108  { X86_VENDOR_AMD, 0x610f31 }, /* RL-A1 (Richland) */
109  { 0, 0 },
110 };
111 
112 static const struct cpu_driver model_15 __cpu_driver = {
113  .ops = &cpu_dev_ops,
114  .id_table = cpu_table,
115 };
#define SYSCFG_MSR_MtrrFixDramModEn
Definition: mtrr.h:16
#define SYSCFG_MSR
Definition: mtrr.h:12
static __always_inline void wrmsr_amd(unsigned int index, msr_t msr)
Definition: mtrr.h:60
static __always_inline msr_t rdmsr_amd(unsigned int index)
Definition: mtrr.h:49
#define SYSCFG_MSR_MtrrFixDramEn
Definition: mtrr.h:17
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
static struct cpu_info * cpu_info(void)
Definition: cpu.h:252
static unsigned int cpuid_ecx(unsigned int op)
Definition: cpu.h:106
#define X86_VENDOR_AMD
Definition: cpu.h:140
#define printk(level,...)
Definition: stdlib.h:16
void x86_mtrr_check(void)
Definition: mtrr.c:836
@ CONFIG
Definition: dsi_common.h:201
#define CPU_ID_FEATURES_MSR
Definition: msr.h:65
#define NB_CFG_MSR
Definition: msr.h:19
#define SMM_BASE_MSR
Definition: msr.h:59
#define CPU_ID_EXT_FEATURES_MSR
Definition: msr.h:66
#define SMM_MASK_MSR
Definition: msr.h:61
#define HWCR_MSR
Definition: msr.h:17
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 void mca_clear_status(void)
Definition: msr.h:176
static __always_inline void wrmsr(unsigned int index, msr_t msr)
Definition: msr.h:157
#define SMM_BASE
Definition: smm.h:14
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
static const struct cpu_driver model_15 __cpu_driver
static const struct cpu_device_id cpu_table[]
static struct device_operations cpu_dev_ops
static void model_15_init(struct device *dev)
Definition: model_15_init.c:16
void restore_mtrr(void)
Definition: s3_mtrr.c:58
uint32_t u32
Definition: stdint.h:51
Definition: cpu.h:13
struct device_operations * ops
Definition: cpu.h:14
size_t index
Definition: cpu.h:232
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111
#define MTRR_FIX_64K_00000
Definition: mtrr.h:45
#define MTRR_FIX_16K_A0000
Definition: mtrr.h:47
#define MTRR_FIX_4K_C0000
Definition: mtrr.h:48
#define MTRR_FIX_16K_80000
Definition: mtrr.h:46
#define MTRR_FIX_4K_F8000
Definition: mtrr.h:55