coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
model_14_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 <device/device.h>
9 #include <cpu/x86/pae.h>
10 #include <cpu/cpu.h>
11 #include <cpu/x86/cache.h>
12 #include <acpi/acpi.h>
14 
15 static void model_14_init(struct device *dev)
16 {
17  msr_t msr;
18  int msrno;
19 #if CONFIG(LOGICAL_CPUS)
20  u32 siblings;
21 #endif
22  printk(BIOS_DEBUG, "Model 14 Init.\n");
23 
24  disable_cache();
25  /*
26  * AGESA sets the MTRRs main MTRRs. The shadow area needs to be set
27  * by coreboot.
28  */
29 
30  /* Enable access to AMD RdDram and WrDram extension bits */
31  msr = rdmsr(SYSCFG_MSR);
34  wrmsr(SYSCFG_MSR, msr);
35 
36  /* Set shadow WB, RdMEM, WrMEM */
37  msr.lo = msr.hi = 0;
39  msr.lo = msr.hi = 0x1e1e1e1e;
42  for (msrno = MTRR_FIX_4K_C0000; msrno <= MTRR_FIX_4K_F8000; msrno++)
43  wrmsr(msrno, msr);
44 
45  msr = rdmsr(SYSCFG_MSR);
48  wrmsr(SYSCFG_MSR, msr);
49 
50  if (acpi_is_wakeup_s3())
51  restore_mtrr();
52 
54  enable_cache();
55 
56  /* zero the machine check error status registers */
58 
59 #if CONFIG(LOGICAL_CPUS)
60  siblings = cpuid_ecx(0x80000008) & 0xff;
61 
62  if (siblings > 0) {
64  msr.lo |= 1 << 28;
66 
68  msr.hi |= 1 << (33 - 32);
70  }
71  printk(BIOS_DEBUG, "siblings = %02d, ", siblings);
72 #endif
73 
74  /* DisableCf8ExtCfg */
75  msr = rdmsr(NB_CFG_MSR);
76  msr.hi &= ~(1 << (46 - 32));
77  wrmsr(NB_CFG_MSR, msr);
78 
79  /* Write protect SMM space with SMMLOCK. */
80  msr = rdmsr(HWCR_MSR);
81  msr.lo |= (1 << 0);
82  wrmsr(HWCR_MSR, msr);
83 }
84 
85 static struct device_operations cpu_dev_ops = {
87 };
88 
89 static const struct cpu_device_id cpu_table[] = {
90  { X86_VENDOR_AMD, 0x500f00 }, /* ON-A0 */
91  { X86_VENDOR_AMD, 0x500f01 }, /* ON-A1 */
92  { X86_VENDOR_AMD, 0x500f10 }, /* ON-B0 */
93  { X86_VENDOR_AMD, 0x500f20 }, /* ON-C0 */
94  { 0, 0 },
95 };
96 
97 static const struct cpu_driver model_14 __cpu_driver = {
98  .ops = &cpu_dev_ops,
99  .id_table = cpu_table,
100 };
#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 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
#define CPU_ID_FEATURES_MSR
Definition: msr.h:65
#define NB_CFG_MSR
Definition: msr.h:19
#define CPU_ID_EXT_FEATURES_MSR
Definition: msr.h:66
#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 BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
static const struct cpu_driver model_14 __cpu_driver
Definition: model_14_init.c:97
static void model_14_init(struct device *dev)
Definition: model_14_init.c:15
static const struct cpu_device_id cpu_table[]
Definition: model_14_init.c:89
static struct device_operations cpu_dev_ops
Definition: model_14_init.c:85
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
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