blob: 188f95cf0839b7ffee314ef7541089930e2a797b [file] [log] [blame]
Siyuan Wang5d7d09c2013-07-09 17:08:41 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080014 */
15
16#include <console/console.h>
17#include <cpu/x86/msr.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020018#include <cpu/amd/msr.h>
19#include <cpu/x86/mtrr.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080020#include <cpu/amd/mtrr.h>
21#include <device/device.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080022#include <string.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080023#include <cpu/x86/pae.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080024#include <cpu/x86/lapic.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080025#include <cpu/cpu.h>
26#include <cpu/x86/cache.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080027#include <arch/acpi.h>
Kyösti Mälkkid4955f02017-09-08 07:14:17 +030028#include <northbridge/amd/agesa/agesa_helper.h>
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080029
Elyes HAOUASd2d8a312018-02-08 13:38:21 +010030static void model_16_init(struct device *dev)
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080031{
32 printk(BIOS_DEBUG, "Model 16 Init.\n");
33
34 u8 i;
35 msr_t msr;
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -060036 int num_banks;
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080037 int msrno;
Edward O'Callaghan3b8bfeb2014-11-21 12:34:00 +110038#if IS_ENABLED(CONFIG_LOGICAL_CPUS)
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080039 u32 siblings;
40#endif
41
42 //x86_enable_cache();
43 //amd_setup_mtrrs();
44 //x86_mtrr_check();
Elyes HAOUAS12d65f82018-01-28 22:35:47 +010045 disable_cache();
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080046 /* Enable access to AMD RdDram and WrDram extension bits */
47 msr = rdmsr(SYSCFG_MSR);
48 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
49 msr.lo &= ~SYSCFG_MSR_MtrrFixDramEn;
50 wrmsr(SYSCFG_MSR, msr);
51
52 // BSP: make a0000-bffff UC, c0000-fffff WB, same as OntarioApMtrrSettingsList for APs
53 msr.lo = msr.hi = 0;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020054 wrmsr(MTRR_FIX_16K_A0000, msr);
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080055 msr.lo = msr.hi = 0x1e1e1e1e;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020056 wrmsr(MTRR_FIX_64K_00000, msr);
57 wrmsr(MTRR_FIX_16K_80000, msr);
58 for (msrno = MTRR_FIX_4K_C0000; msrno <= MTRR_FIX_4K_F8000; msrno++)
59 wrmsr(msrno, msr);
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080060
61 msr = rdmsr(SYSCFG_MSR);
62 msr.lo &= ~SYSCFG_MSR_MtrrFixDramModEn;
63 msr.lo |= SYSCFG_MSR_MtrrFixDramEn;
64 wrmsr(SYSCFG_MSR, msr);
65
Kyösti Mälkki9107e532014-06-19 20:52:39 +030066 if (acpi_is_wakeup())
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080067 restore_mtrr();
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080068
69 x86_mtrr_check();
70 x86_enable_cache();
71
72 /* zero the machine check error status registers */
Elyes HAOUAS400ce552018-10-12 10:54:30 +020073 msr = rdmsr(IA32_MCG_CAP);
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -060074 num_banks = msr.lo & MCA_BANKS_MASK;
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080075 msr.lo = 0;
76 msr.hi = 0;
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -060077 for (i = 0; i < num_banks; i++)
Elyes HAOUAS400ce552018-10-12 10:54:30 +020078 wrmsr(IA32_MC0_STATUS + (i * 4), msr);
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080079
Elyes HAOUASd6e96862016-08-21 10:12:15 +020080 /* Enable the local CPU APICs */
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080081 setup_lapic();
82
Edward O'Callaghan3b8bfeb2014-11-21 12:34:00 +110083#if IS_ENABLED(CONFIG_LOGICAL_CPUS)
Siyuan Wang5d7d09c2013-07-09 17:08:41 +080084 siblings = cpuid_ecx(0x80000008) & 0xff;
85
86 if (siblings > 0) {
87 msr = rdmsr_amd(CPU_ID_FEATURES_MSR);
88 msr.lo |= 1 << 28;
89 wrmsr_amd(CPU_ID_FEATURES_MSR, msr);
90
91 msr = rdmsr_amd(CPU_ID_EXT_FEATURES_MSR);
92 msr.hi |= 1 << (33 - 32);
93 wrmsr_amd(CPU_ID_EXT_FEATURES_MSR, msr);
94 }
95 printk(BIOS_DEBUG, "siblings = %02d, ", siblings);
96#endif
97
98 /* DisableCf8ExtCfg */
99 msr = rdmsr(NB_CFG_MSR);
100 msr.hi &= ~(1 << (46 - 32));
101 wrmsr(NB_CFG_MSR, msr);
102
Siyuan Wang5d7d09c2013-07-09 17:08:41 +0800103 /* Write protect SMM space with SMMLOCK. */
104 msr = rdmsr(HWCR_MSR);
105 msr.lo |= (1 << 0);
106 wrmsr(HWCR_MSR, msr);
107}
108
109static struct device_operations cpu_dev_ops = {
110 .init = model_16_init,
111};
112
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100113static const struct cpu_device_id cpu_table[] = {
Paul Menzel22f32c72017-02-27 01:26:42 +0100114 { X86_VENDOR_AMD, 0x700f00 }, /* KB-A0 */
Siyuan Wang5d7d09c2013-07-09 17:08:41 +0800115 { 0, 0 },
116};
117
118static const struct cpu_driver model_15 __cpu_driver = {
119 .ops = &cpu_dev_ops,
120 .id_table = cpu_table,
121};