blob: 09543b6b157e9998f28045d02b666b05bd3a0a58 [file] [log] [blame]
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015-2016 Intel Corp.
5 * Copyright (C) 2017 Advanced Micro Devices, Inc.
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.
15 */
16
Marshall Dawsonb6172112017-09-13 17:47:31 -060017#include <cpu/cpu.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060018#include <cpu/x86/mp.h>
19#include <cpu/x86/mtrr.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060020#include <cpu/x86/msr.h>
Marshall Dawson178e65d2017-10-20 13:20:25 -060021#include <cpu/x86/lapic.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060022#include <cpu/amd/amdfam15.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060023#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020024#include <device/pci_ops.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060025#include <soc/pci_devs.h>
26#include <soc/cpu.h>
27#include <soc/northbridge.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060028#include <soc/smi.h>
Marshall Dawson0814b122018-01-10 11:35:24 -070029#include <soc/iomap.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060030#include <console/console.h>
31
32/*
Marshall Dawsonb6172112017-09-13 17:47:31 -060033 * MP and SMM loading initialization.
34 */
35struct smm_relocation_attrs {
36 uint32_t smbase;
37 uint32_t tseg_base;
38 uint32_t tseg_mask;
39};
40
41static struct smm_relocation_attrs relo_attrs;
42
43/*
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060044 * Do essential initialization tasks before APs can be fired up -
45 *
46 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
47 * creates the MTRR solution that the APs will use. Otherwise APs will try to
48 * apply the incomplete solution as the BSP is calculating it.
49 */
50static void pre_mp_init(void)
51{
52 x86_setup_mtrrs_with_detect();
53 x86_mtrr_check();
54}
55
56static int get_cpu_count(void)
57{
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020058 struct device *nb = dev_find_slot(0, HT_DEVFN);
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060059 return (pci_read_config16(nb, D18F0_CPU_CNT) & CPU_CNT_MASK) + 1;
60}
61
Marshall Dawsonb6172112017-09-13 17:47:31 -060062static void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize,
63 size_t *smm_save_state_size)
64{
65 void *smm_base;
66 size_t smm_size;
67 void *handler_base;
68 size_t handler_size;
69
70 /* Initialize global tracking state. */
71 smm_region_info(&smm_base, &smm_size);
72 smm_subregion(SMM_SUBREGION_HANDLER, &handler_base, &handler_size);
73
74 relo_attrs.smbase = (uint32_t)smm_base;
75 relo_attrs.tseg_base = relo_attrs.smbase;
76 relo_attrs.tseg_mask = ALIGN_DOWN(~(smm_size - 1), 128 * KiB);
Marshall Dawson2a5e15c2018-01-24 12:07:11 -070077 relo_attrs.tseg_mask |= SMM_TSEG_WB;
Marshall Dawsonb6172112017-09-13 17:47:31 -060078
79 *perm_smbase = (uintptr_t)handler_base;
80 *perm_smsize = handler_size;
81 *smm_save_state_size = sizeof(amd64_smm_state_save_area_t);
82}
83
84static void relocation_handler(int cpu, uintptr_t curr_smbase,
85 uintptr_t staggered_smbase)
86{
87 msr_t tseg_base, tseg_mask;
88 amd64_smm_state_save_area_t *smm_state;
89
90 tseg_base.lo = relo_attrs.tseg_base;
91 tseg_base.hi = 0;
92 wrmsr(MSR_TSEG_BASE, tseg_base);
93 tseg_mask.lo = relo_attrs.tseg_mask;
94 tseg_mask.hi = ((1 << (cpu_phys_address_size() - 32)) - 1);
95 wrmsr(MSR_SMM_MASK, tseg_mask);
96 smm_state = (void *)(SMM_AMD64_SAVE_STATE_OFFSET + curr_smbase);
97 smm_state->smbase = staggered_smbase;
98}
99
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -0600100static const struct mp_ops mp_ops = {
101 .pre_mp_init = pre_mp_init,
102 .get_cpu_count = get_cpu_count,
Marshall Dawsonb6172112017-09-13 17:47:31 -0600103 .get_smm_info = get_smm_info,
104 .relocation_handler = relocation_handler,
105 .post_mp_init = enable_smi_generation,
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -0600106};
107
108void stoney_init_cpus(struct device *dev)
109{
110 /* Clear for take-off */
111 if (mp_init_with_smm(dev->link_list, &mp_ops) < 0)
112 printk(BIOS_ERR, "MP initialization failure.\n");
Marshall Dawson8f031d82018-04-09 22:15:06 -0600113
114 /* The flash is now no longer cacheable. Reset to WP for performance. */
115 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Marshall Dawson2e49cf122018-08-03 17:05:22 -0600116
117 set_warm_reset_flag();
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -0600118}
Marshall Dawson178e65d2017-10-20 13:20:25 -0600119
Marshall Dawson74473ec2018-08-05 10:42:17 -0600120static const char *const mca_bank_name[] = {
121 "Load-store unit",
122 "Instruction fetch unit",
123 "Combined unit",
124 "Reserved",
125 "Northbridge",
126 "Execution unit",
127 "Floating point unit"
128};
Marshall Dawson178e65d2017-10-20 13:20:25 -0600129
Marshall Dawson74473ec2018-08-05 10:42:17 -0600130static void check_mca(void)
131{
Marshall Dawson178e65d2017-10-20 13:20:25 -0600132 int i;
133 msr_t msr;
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -0600134 int num_banks;
Marshall Dawson178e65d2017-10-20 13:20:25 -0600135
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -0600136 msr = rdmsr(MCG_CAP);
137 num_banks = msr.lo & MCA_BANKS_MASK;
Marshall Dawson74473ec2018-08-05 10:42:17 -0600138
139 if (is_warm_reset()) {
140 for (i = 0 ; i < num_banks ; i++) {
141 if (i == 3) /* Reserved in Family 15h */
142 continue;
143
144 msr = rdmsr(MC0_STATUS + (i * 4));
145 if (msr.hi || msr.lo) {
146 int core = cpuid_ebx(1) >> 24;
147
148 printk(BIOS_WARNING, "#MC Error: core %d, bank %d %s\n",
149 core, i, mca_bank_name[i]);
150
151 printk(BIOS_WARNING, " MC%d_STATUS = %08x_%08x\n",
152 i, msr.hi, msr.lo);
153 msr = rdmsr(MC0_ADDR + (i * 4));
154 printk(BIOS_WARNING, " MC%d_ADDR = %08x_%08x\n",
155 i, msr.hi, msr.lo);
156 msr = rdmsr(MC0_MISC + (i * 4));
157 printk(BIOS_WARNING, " MC%d_MISC = %08x_%08x\n",
158 i, msr.hi, msr.lo);
159 msr = rdmsr(MC0_CTL + (i * 4));
160 printk(BIOS_WARNING, " MC%d_CTL = %08x_%08x\n",
161 i, msr.hi, msr.lo);
162 msr = rdmsr(MC0_CTL_MASK + i);
163 printk(BIOS_WARNING, " MC%d_CTL_MASK = %08x_%08x\n",
164 i, msr.hi, msr.lo);
165 }
166 }
167 }
168
169 /* zero the machine check error status registers */
Marshall Dawson178e65d2017-10-20 13:20:25 -0600170 msr.lo = 0;
171 msr.hi = 0;
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -0600172 for (i = 0 ; i < num_banks ; i++)
Marshall Dawsonbddd1572018-08-07 07:17:41 -0600173 wrmsr(MC0_STATUS + (i * 4), msr);
Marshall Dawson74473ec2018-08-05 10:42:17 -0600174}
Marshall Dawson178e65d2017-10-20 13:20:25 -0600175
Marshall Dawson74473ec2018-08-05 10:42:17 -0600176static void model_15_init(struct device *dev)
177{
178 check_mca();
Marshall Dawson178e65d2017-10-20 13:20:25 -0600179 setup_lapic();
180}
181
182static struct device_operations cpu_dev_ops = {
183 .init = model_15_init,
184};
185
186static struct cpu_device_id cpu_table[] = {
187 { X86_VENDOR_AMD, 0x670f00 },
188 { 0, 0 },
189};
190
191static const struct cpu_driver model_15 __cpu_driver = {
192 .ops = &cpu_dev_ops,
193 .id_table = cpu_table,
194};