blob: 94c3f2b39e318780d15d05a06a12355a8be7ade5 [file] [log] [blame]
Aaron Durbin302cbd62013-10-21 12:36:17 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google 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.
Aaron Durbin302cbd62013-10-21 12:36:17 -050014 */
15
16#include <stdlib.h>
17#include <console/console.h>
18#include <cpu/cpu.h>
19#include <cpu/intel/microcode.h>
Duncan Laurie05a33932013-11-05 12:59:50 -080020#include <cpu/intel/turbo.h>
Aaron Durbin7837be62013-10-21 22:32:00 -050021#include <cpu/x86/cache.h>
22#include <cpu/x86/lapic.h>
Aaron Durbin302cbd62013-10-21 12:36:17 -050023#include <cpu/x86/mp.h>
Aaron Durbin7837be62013-10-21 22:32:00 -050024#include <cpu/x86/msr.h>
25#include <cpu/x86/mtrr.h>
26#include <cpu/x86/smm.h>
Duncan Laurie05a33932013-11-05 12:59:50 -080027#include <reg_script.h>
Aaron Durbin302cbd62013-10-21 12:36:17 -050028
Julius Werner18ea2d32014-10-07 16:42:17 -070029#include <soc/iosf.h>
30#include <soc/msr.h>
31#include <soc/pattrs.h>
32#include <soc/ramstage.h>
33#include <soc/smm.h>
Aaron Durbin7837be62013-10-21 22:32:00 -050034
Duncan Laurie05a33932013-11-05 12:59:50 -080035/* Core level MSRs */
36const struct reg_script core_msr_script[] = {
Duncan Laurie31ac9e32014-03-28 10:52:13 -070037 /* Dynamic L2 shrink enable and threshold, clear SINGLE_PCTL bit 11 */
38 REG_MSR_RMW(MSR_PMG_CST_CONFIG_CONTROL, ~0x3f080f, 0xe0008),
39 REG_MSR_RMW(MSR_POWER_MISC,
40 ~(ENABLE_ULFM_AUTOCM_MASK | ENABLE_INDP_AUTOCM_MASK), 0),
Duncan Laurie05a33932013-11-05 12:59:50 -080041 /* Disable C1E */
42 REG_MSR_RMW(MSR_POWER_CTL, ~0x2, 0),
43 REG_MSR_OR(MSR_POWER_MISC, 0x44),
44 REG_SCRIPT_END
45};
46
Aaron Durbin302cbd62013-10-21 12:36:17 -050047static void baytrail_core_init(device_t cpu)
48{
49 printk(BIOS_DEBUG, "Init BayTrail core.\n");
Duncan Laurie05a33932013-11-05 12:59:50 -080050
Aaron Durbin59d1d872014-01-14 17:34:10 -060051 /* On bay trail the turbo disable bit is actually scoped at building
52 * block level -- not package. For non-bsp cores that are within a
53 * building block enable turbo. The cores within the BSP's building
54 * block will just see it already enabled and move on. */
55 if (lapicid())
56 enable_turbo();
57
Duncan Laurie05a33932013-11-05 12:59:50 -080058 /* Set core MSRs */
59 reg_script_run(core_msr_script);
60
61 /* Set this core to max frequency ratio */
62 set_max_freq();
Aaron Durbin302cbd62013-10-21 12:36:17 -050063}
64
65static struct device_operations cpu_dev_ops = {
66 .init = baytrail_core_init,
67};
68
69static struct cpu_device_id cpu_table[] = {
70 { X86_VENDOR_INTEL, 0x30673 },
Aaron Durbin1ea9bde2014-01-08 17:33:05 -060071 { X86_VENDOR_INTEL, 0x30678 },
Aaron Durbin302cbd62013-10-21 12:36:17 -050072 { 0, 0 },
73};
74
75static const struct cpu_driver driver __cpu_driver = {
76 .ops = &cpu_dev_ops,
77 .id_table = cpu_table,
78};
79
Aaron Durbin7837be62013-10-21 22:32:00 -050080
81/*
Aaron Durbinb04bb652016-05-03 11:12:52 -050082 * MP and SMM loading initialization.
Aaron Durbin7837be62013-10-21 22:32:00 -050083 */
84
85struct smm_relocation_attrs {
86 uint32_t smbase;
87 uint32_t smrr_base;
88 uint32_t smrr_mask;
89};
90
91static struct smm_relocation_attrs relo_attrs;
92
Aaron Durbinb04bb652016-05-03 11:12:52 -050093/* Package level MSRs */
94static const struct reg_script package_msr_script[] = {
95 /* Set Package TDP to ~7W */
96 REG_MSR_WRITE(MSR_PKG_POWER_LIMIT, 0x3880fa),
97 REG_MSR_RMW(MSR_PP1_POWER_LIMIT, ~(0x7f << 17), 0),
98 REG_MSR_WRITE(MSR_PKG_TURBO_CFG1, 0x702),
99 REG_MSR_WRITE(MSR_CPU_TURBO_WKLD_CFG1, 0x200b),
100 REG_MSR_WRITE(MSR_CPU_TURBO_WKLD_CFG2, 0),
101 REG_MSR_WRITE(MSR_CPU_THERM_CFG1, 0x00000305),
102 REG_MSR_WRITE(MSR_CPU_THERM_CFG2, 0x0405500d),
103 REG_MSR_WRITE(MSR_CPU_THERM_SENS_CFG, 0x27),
104 REG_SCRIPT_END
105};
Aaron Durbin7837be62013-10-21 22:32:00 -0500106
Aaron Durbinb04bb652016-05-03 11:12:52 -0500107static void pre_mp_init(void)
108{
109 uint32_t bsmrwac;
110
111 /* Set up MTRRs based on physical address size. */
112 x86_setup_mtrrs_with_detect();
113 x86_mtrr_check();
114
115 /*
116 * Configure the BUNIT to allow dirty cache line evictions in non-SMM
117 * mode for the lines that were dirtied while in SMM mode. Otherwise
118 * the writes would be silently dropped.
119 */
120 bsmrwac = iosf_bunit_read(BUNIT_SMRWAC) | SAI_IA_UNTRUSTED;
121 iosf_bunit_write(BUNIT_SMRWAC, bsmrwac);
122
123 /* Set package MSRs */
124 reg_script_run(package_msr_script);
125
126 /* Enable Turbo Mode on BSP and siblings of the BSP's building block. */
127 enable_turbo();
Aaron Durbin7837be62013-10-21 22:32:00 -0500128}
129
Aaron Durbinb04bb652016-05-03 11:12:52 -0500130static int get_cpu_count(void)
131{
132 const struct pattrs *pattrs = pattrs_get();
133
134 return pattrs->num_cpus;
135}
136
137static void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize,
138 size_t *smm_save_state_size)
139{
140 /* All range registers are aligned to 4KiB */
141 const uint32_t rmask = ~((1 << 12) - 1);
142
143 /* Initialize global tracking state. */
144 relo_attrs.smbase = (uint32_t)smm_region_start();
145 relo_attrs.smrr_base = relo_attrs.smbase | MTRR_TYPE_WRBACK;
146 relo_attrs.smrr_mask = ~(smm_region_size() - 1) & rmask;
147 relo_attrs.smrr_mask |= MTRR_PHYS_MASK_VALID;
148
149 *perm_smbase = relo_attrs.smbase;
150 *perm_smsize = smm_region_size() - CONFIG_SMM_RESERVED_SIZE;
151 *smm_save_state_size = sizeof(em64t100_smm_state_save_area_t);
152}
153
154/* The APIC id space on Bay Trail is sparse. Each id is separated by 2. */
155static int adjust_apic_id(int index, int apic_id)
156{
157 return 2 * index;
158}
159
160static void get_microcode_info(const void **microcode, int *parallel)
161{
162 const struct pattrs *pattrs = pattrs_get();
163
164 *microcode = pattrs->microcode_patch;
165 *parallel = 1;
166}
167
168static void per_cpu_smm_trigger(void)
169{
170 const struct pattrs *pattrs = pattrs_get();
171
172 /* Relocate SMM space. */
173 smm_initiate_relocation();
174
175 /* Load microcode after SMM relocation. */
176 intel_microcode_load_unlocked(pattrs->microcode_patch);
177}
178
179static void relocation_handler(int cpu, uintptr_t curr_smbase,
180 uintptr_t staggered_smbase)
Aaron Durbin7837be62013-10-21 22:32:00 -0500181{
182 msr_t smrr;
183 em64t100_smm_state_save_area_t *smm_state;
Aaron Durbin7837be62013-10-21 22:32:00 -0500184
185 /* Set up SMRR. */
186 smrr.lo = relo_attrs.smrr_base;
187 smrr.hi = 0;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700188 wrmsr(SMRR_PHYS_BASE, smrr);
Aaron Durbin7837be62013-10-21 22:32:00 -0500189 smrr.lo = relo_attrs.smrr_mask;
190 smrr.hi = 0;
Alexandru Gagniuc86091f92015-09-30 20:23:09 -0700191 wrmsr(SMRR_PHYS_MASK, smrr);
Aaron Durbin7837be62013-10-21 22:32:00 -0500192
Aaron Durbinb04bb652016-05-03 11:12:52 -0500193 smm_state = (void *)(SMM_EM64T100_SAVE_STATE_OFFSET + curr_smbase);
194 smm_state->smbase = staggered_smbase;
Aaron Durbin7837be62013-10-21 22:32:00 -0500195}
196
Aaron Durbinb04bb652016-05-03 11:12:52 -0500197static const struct mp_ops mp_ops = {
198 .pre_mp_init = pre_mp_init,
199 .get_cpu_count = get_cpu_count,
200 .get_smm_info = get_smm_info,
201 .get_microcode_info = get_microcode_info,
202 .adjust_cpu_apic_entry = adjust_apic_id,
203 .pre_mp_smm_init = southcluster_smm_clear_state,
204 .per_cpu_smm_trigger = per_cpu_smm_trigger,
205 .relocation_handler = relocation_handler,
206 .post_mp_init = southcluster_smm_enable_smi,
207};
208
209void baytrail_init_cpus(device_t dev)
Aaron Durbin7837be62013-10-21 22:32:00 -0500210{
Aaron Durbinb04bb652016-05-03 11:12:52 -0500211 struct bus *cpu_bus = dev->link_list;
Aaron Durbin7837be62013-10-21 22:32:00 -0500212
Aaron Durbinb04bb652016-05-03 11:12:52 -0500213 if (mp_init_with_smm(cpu_bus, &mp_ops)) {
214 printk(BIOS_ERR, "MP initialization failure.\n");
Aaron Durbin7837be62013-10-21 22:32:00 -0500215 }
Aaron Durbin7837be62013-10-21 22:32:00 -0500216}