coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
cpu.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <amdblocks/mca.h>
4 #include <amdblocks/reset.h>
5 #include <amdblocks/smm.h>
6 #include <cpu/amd/msr.h>
7 #include <cpu/cpu.h>
8 #include <cpu/x86/mp.h>
9 #include <cpu/x86/mtrr.h>
10 #include <cpu/x86/msr.h>
11 #include <cpu/x86/smm.h>
12 #include <device/device.h>
13 #include <device/pci_ops.h>
14 #include <soc/pci_devs.h>
15 #include <soc/cpu.h>
16 #include <soc/northbridge.h>
17 #include <soc/smi.h>
18 #include <soc/iomap.h>
19 #include <console/console.h>
20 #include <types.h>
21 
22 /*
23  * MP and SMM loading initialization.
24  */
25 
26 /*
27  * Do essential initialization tasks before APs can be fired up -
28  *
29  * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
30  * creates the MTRR solution that the APs will use. Otherwise APs will try to
31  * apply the incomplete solution as the BSP is calculating it.
32  */
33 static void pre_mp_init(void)
34 {
37 }
38 
39 static int get_cpu_count(void)
40 {
42 }
43 
44 static const struct mp_ops mp_ops = {
46  .get_cpu_count = get_cpu_count,
47  .get_smm_info = get_smm_info,
48  .relocation_handler = smm_relocation_handler,
49  .post_mp_init = global_smi_enable,
50 };
51 
52 void mp_init_cpus(struct bus *cpu_bus)
53 {
54  if (mp_init_with_smm(cpu_bus, &mp_ops) != CB_SUCCESS)
56  "mp_init_with_smm failed. Halting.\n");
57 
58  /* The flash is now no longer cacheable. Reset to WP for performance. */
60 
62 }
63 
64 static void model_15_init(struct device *dev)
65 {
66  check_mca();
67 
68  /*
69  * Per AMD, sync an undocumented MSR with the PSP base address.
70  * Experiments showed that if you write to the MSR after it has
71  * been previously programmed, it causes a general protection fault.
72  * Also, the MSR survives warm reset and S3 cycles, so we need to
73  * test if it was previously written before writing to it.
74  */
75  msr_t psp_msr;
76  uint32_t psp_bar; /* Note: NDA BKDG names this 32-bit register BAR3 */
79  psp_msr = rdmsr(PSP_ADDR_MSR);
80  if (psp_msr.lo == 0) {
81  psp_msr.lo = psp_bar;
82  wrmsr(PSP_ADDR_MSR, psp_msr);
83  }
84 }
85 
86 static struct device_operations cpu_dev_ops = {
88 };
89 
90 static struct cpu_device_id cpu_table[] = {
91  { X86_VENDOR_AMD, 0x660f01 },
92  { X86_VENDOR_AMD, 0x670f00 },
93  { 0, 0 },
94 };
95 
96 static const struct cpu_driver model_15 __cpu_driver = {
97  .ops = &cpu_dev_ops,
98  .id_table = cpu_table,
99 };
#define FLASH_BASE_ADDR
Definition: io.h:13
#define X86_VENDOR_AMD
Definition: cpu.h:140
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
#define die_with_post_code(value, fmt,...)
Definition: console.h:21
void smm_relocation_handler(int cpu, uintptr_t curr_smbase, uintptr_t staggered_smbase)
Definition: smmrelocate.c:90
enum cb_err mp_init_with_smm(struct bus *cpu_bus, const struct mp_ops *mp_ops)
Definition: mp_init.c:1145
void x86_mtrr_check(void)
Definition: mtrr.c:836
void mtrr_use_temp_range(uintptr_t begin, size_t size, int type)
Definition: mtrr.c:868
void x86_setup_mtrrs_with_detect(void)
Definition: mtrr.c:823
#define PSP_ADDR_MSR
Definition: msr.h:81
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
void global_smi_enable(void)
Set the EOS bit and enable SMI generation from southbridge.
Definition: smi_util.c:60
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
void check_mca(void)
Definition: mca_common.c:36
#define CPU_CNT_MASK
Definition: northbridge.h:36
#define D18F0_CPU_CNT
Definition: northbridge.h:35
#define PCI_BASE_ADDRESS_MEM_ATTR_MASK
Definition: pci_def.h:77
#define PCI_BASE_ADDRESS_4
Definition: pci_def.h:67
#define POST_HW_INIT_FAILURE
Hardware initialization failure.
Definition: post_codes.h:353
void mp_init_cpus(struct bus *cpu_bus)
Definition: cpu.c:55
int get_cpu_count(void)
Definition: cpu.c:10
void set_warm_reset_flag(void)
Definition: reset.c:13
static void pre_mp_init(void)
Definition: cpu.c:33
static const struct cpu_driver model_15 __cpu_driver
Definition: cpu.c:96
static struct cpu_device_id cpu_table[]
Definition: cpu.c:90
static struct device_operations cpu_dev_ops
Definition: cpu.c:86
static void model_15_init(struct device *dev)
Definition: cpu.c:64
#define SOC_PSP_DEV
Definition: pci_devs.h:82
#define SOC_HT_DEV
Definition: pci_devs.h:98
static void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize, size_t *smm_save_state_size)
Definition: cpu.c:149
unsigned int uint32_t
Definition: stdint.h:14
Definition: device.h:76
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
Definition: mp.h:20
void(* pre_mp_init)(void)
Definition: mp.h:27
unsigned int lo
Definition: msr.h:111
#define MTRR_TYPE_WRPROT
Definition: mtrr.h:13