blob: 3086f158dfb747c26b7243e1158765dd1203fd09 [file] [log] [blame]
Frank Vibrans420faca2011-02-14 18:42:12 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 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.
Frank Vibrans420faca2011-02-14 18:42:12 +000014 */
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>
Frank Vibrans420faca2011-02-14 18:42:12 +000020#include <cpu/amd/mtrr.h>
21#include <device/device.h>
Frank Vibrans420faca2011-02-14 18:42:12 +000022#include <string.h>
Frank Vibrans420faca2011-02-14 18:42:12 +000023#include <cpu/x86/pae.h>
Frank Vibrans420faca2011-02-14 18:42:12 +000024#include <cpu/x86/lapic.h>
Frank Vibrans420faca2011-02-14 18:42:12 +000025#include <cpu/cpu.h>
26#include <cpu/x86/cache.h>
zbaof7223732012-04-13 13:42:15 +080027#include <arch/acpi.h>
Kyösti Mälkkid4955f02017-09-08 07:14:17 +030028#include <northbridge/amd/agesa/agesa_helper.h>
Frank Vibrans420faca2011-02-14 18:42:12 +000029
Elyes HAOUASd2d8a312018-02-08 13:38:21 +010030static void model_14_init(struct device *dev)
Frank Vibrans420faca2011-02-14 18:42:12 +000031{
Paul Menzel22f32c72017-02-27 01:26:42 +010032 u8 i;
zbaof7223732012-04-13 13:42:15 +080033 msr_t msr;
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -060034 int num_banks;
Paul Menzel22f32c72017-02-27 01:26:42 +010035 int msrno;
Edward O'Callaghan3b8bfeb2014-11-21 12:34:00 +110036#if IS_ENABLED(CONFIG_LOGICAL_CPUS)
zbaof7223732012-04-13 13:42:15 +080037 u32 siblings;
38#endif
39 printk(BIOS_DEBUG, "Model 14 Init.\n");
40
Elyes HAOUAS12d65f82018-01-28 22:35:47 +010041 disable_cache();
zbaof7223732012-04-13 13:42:15 +080042 /*
43 * AGESA sets the MTRRs main MTRRs. The shadow area needs to be set
44 * by coreboot. The amd_setup_mtrrs should work, but needs debug on fam14.
45 * TODO:
46 * amd_setup_mtrrs();
47 */
48
49 /* Enable access to AMD RdDram and WrDram extension bits */
50 msr = rdmsr(SYSCFG_MSR);
51 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
52 msr.lo &= ~SYSCFG_MSR_MtrrFixDramEn;
53 wrmsr(SYSCFG_MSR, msr);
54
55 /* Set shadow WB, RdMEM, WrMEM */
56 msr.lo = msr.hi = 0;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020057 wrmsr(MTRR_FIX_16K_A0000, msr);
Paul Menzel22f32c72017-02-27 01:26:42 +010058 msr.lo = msr.hi = 0x1e1e1e1e;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020059 wrmsr(MTRR_FIX_64K_00000, msr);
60 wrmsr(MTRR_FIX_16K_80000, msr);
61 for (msrno = MTRR_FIX_4K_C0000; msrno <= MTRR_FIX_4K_F8000; msrno++)
Paul Menzel22f32c72017-02-27 01:26:42 +010062 wrmsr(msrno, msr);
zbaof7223732012-04-13 13:42:15 +080063
64 msr = rdmsr(SYSCFG_MSR);
65 msr.lo &= ~SYSCFG_MSR_MtrrFixDramModEn;
66 msr.lo |= SYSCFG_MSR_MtrrFixDramEn;
67 wrmsr(SYSCFG_MSR, msr);
68
Kyösti Mälkki9107e532014-06-19 20:52:39 +030069 if (acpi_is_wakeup())
zbaof7223732012-04-13 13:42:15 +080070 restore_mtrr();
Frank Vibrans420faca2011-02-14 18:42:12 +000071
zbaof7223732012-04-13 13:42:15 +080072 x86_mtrr_check();
73 x86_enable_cache();
Frank Vibrans420faca2011-02-14 18:42:12 +000074
zbaof7223732012-04-13 13:42:15 +080075 /* zero the machine check error status registers */
Elyes HAOUAS400ce552018-10-12 10:54:30 +020076 msr = rdmsr(IA32_MCG_CAP);
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -060077 num_banks = msr.lo & MCA_BANKS_MASK;
zbaof7223732012-04-13 13:42:15 +080078 msr.lo = 0;
79 msr.hi = 0;
Marshall Dawsonbd4a3f82018-08-07 07:27:57 -060080 for (i = 0; i < num_banks; i++)
Elyes HAOUAS400ce552018-10-12 10:54:30 +020081 wrmsr(IA32_MC0_STATUS + (i * 4), msr);
Scott Duplichana72425a2011-05-15 21:01:42 +000082
Elyes HAOUASd6e96862016-08-21 10:12:15 +020083 /* Enable the local CPU APICs */
zbaof7223732012-04-13 13:42:15 +080084 setup_lapic();
Frank Vibrans420faca2011-02-14 18:42:12 +000085
Edward O'Callaghan3b8bfeb2014-11-21 12:34:00 +110086#if IS_ENABLED(CONFIG_LOGICAL_CPUS)
zbaof7223732012-04-13 13:42:15 +080087 siblings = cpuid_ecx(0x80000008) & 0xff;
Frank Vibrans420faca2011-02-14 18:42:12 +000088
zbaof7223732012-04-13 13:42:15 +080089 if (siblings > 0) {
90 msr = rdmsr_amd(CPU_ID_FEATURES_MSR);
91 msr.lo |= 1 << 28;
92 wrmsr_amd(CPU_ID_FEATURES_MSR, msr);
Frank Vibrans420faca2011-02-14 18:42:12 +000093
zbaof7223732012-04-13 13:42:15 +080094 msr = rdmsr_amd(CPU_ID_EXT_FEATURES_MSR);
95 msr.hi |= 1 << (33 - 32);
96 wrmsr_amd(CPU_ID_EXT_FEATURES_MSR, msr);
97 }
Paul Menzel22f32c72017-02-27 01:26:42 +010098 printk(BIOS_DEBUG, "siblings = %02d, ", siblings);
Frank Vibrans420faca2011-02-14 18:42:12 +000099#endif
100
zbaof7223732012-04-13 13:42:15 +0800101 /* DisableCf8ExtCfg */
102 msr = rdmsr(NB_CFG_MSR);
103 msr.hi &= ~(1 << (46 - 32));
104 wrmsr(NB_CFG_MSR, msr);
Frank Vibrans420faca2011-02-14 18:42:12 +0000105
zbaof7223732012-04-13 13:42:15 +0800106 /* Write protect SMM space with SMMLOCK. */
107 msr = rdmsr(HWCR_MSR);
108 msr.lo |= (1 << 0);
109 wrmsr(HWCR_MSR, msr);
Frank Vibrans420faca2011-02-14 18:42:12 +0000110}
111
112static struct device_operations cpu_dev_ops = {
zbaoafd141d2012-03-30 15:32:07 +0800113 .init = model_14_init,
Frank Vibrans420faca2011-02-14 18:42:12 +0000114};
115
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100116static const struct cpu_device_id cpu_table[] = {
zbaoafd141d2012-03-30 15:32:07 +0800117 { X86_VENDOR_AMD, 0x500f00 }, /* ON-A0 */
118 { X86_VENDOR_AMD, 0x500f01 }, /* ON-A1 */
119 { X86_VENDOR_AMD, 0x500f10 }, /* ON-B0 */
120 { X86_VENDOR_AMD, 0x500f20 }, /* ON-C0 */
121 { 0, 0 },
Frank Vibrans420faca2011-02-14 18:42:12 +0000122};
123
124static const struct cpu_driver model_14 __cpu_driver = {
zbaoafd141d2012-03-30 15:32:07 +0800125 .ops = &cpu_dev_ops,
126 .id_table = cpu_table,
Frank Vibrans420faca2011-02-14 18:42:12 +0000127};