blob: cb748543468362e05e98a197f6fd6c86ce1bccda [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02002
Arthur Heymansb66ee552018-05-15 16:35:45 +02003#include <assert.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02004#include <console/console.h>
5#include <device/device.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02006#include <cpu/cpu.h>
7#include <cpu/x86/mtrr.h>
8#include <cpu/x86/msr.h>
9#include <cpu/x86/lapic.h>
Arthur Heymansb66ee552018-05-15 16:35:45 +020010#include <cpu/x86/mp.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020011#include <cpu/intel/microcode.h>
12#include <cpu/intel/speedstep.h>
13#include <cpu/intel/turbo.h>
14#include <cpu/x86/cache.h>
15#include <cpu/x86/name.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020016#include "model_2065x.h"
17#include "chip.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030018#include <cpu/intel/smm_reloc.h>
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060019#include <cpu/intel/common/common.h>
Elyes HAOUASdda17fa2019-10-27 13:09:37 +010020#include <smp/node.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020021#include <types.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020022
Arthur Heymans3627f292021-11-15 20:11:45 +010023static void configure_thermal_target(struct device *dev)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020024{
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020025 struct cpu_intel_model_2065x_config *conf = dev->upstream->dev->chip_info;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020026 msr_t msr;
27
Martin Roth4c3ab732013-07-08 16:23:54 -060028 /* Set TCC activation offset if supported */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020029 msr = rdmsr(MSR_PLATFORM_INFO);
30 if ((msr.lo & (1 << 30)) && conf->tcc_offset) {
31 msr = rdmsr(MSR_TEMPERATURE_TARGET);
32 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
33 msr.lo |= (conf->tcc_offset & 0xf) << 24;
34 wrmsr(MSR_TEMPERATURE_TARGET, msr);
35 }
36}
37
38static void configure_misc(void)
39{
40 msr_t msr;
41
42 msr = rdmsr(IA32_MISC_ENABLE);
43 msr.lo |= (1 << 0); /* Fast String enable */
Lee Leahy7b5f12b92017-03-15 17:16:59 -070044 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020045 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
46 wrmsr(IA32_MISC_ENABLE, msr);
47
48 /* Disable Thermal interrupts */
49 msr.lo = 0;
50 msr.hi = 0;
51 wrmsr(IA32_THERM_INTERRUPT, msr);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020052}
53
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020054static void set_max_ratio(void)
55{
56 msr_t msr, perf_ctl;
57
58 perf_ctl.hi = 0;
59
Angel Pons9f0093d2021-01-21 22:17:23 +010060 /* Platform Info bits 15:8 give max ratio */
61 msr = rdmsr(MSR_PLATFORM_INFO);
62 perf_ctl.lo = msr.lo & 0xff00;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020063 wrmsr(IA32_PERF_CTL, perf_ctl);
64
Angel Pons9f0093d2021-01-21 22:17:23 +010065 printk(BIOS_DEBUG, "model_x065x: frequency set to %d\n",
Angel Pons95de2312020-02-17 13:08:53 +010066 ((perf_ctl.lo >> 8) & 0xff) * IRONLAKE_BCLK);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020067}
68
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110069static void model_2065x_init(struct device *cpu)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020070{
71 char processor_name[49];
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020072
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020073 /* Clear out pending MCEs */
Felix Heldacbf1542021-07-13 16:44:18 +020074 /* This should only be done on a cold boot */
75 mca_clear_status();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020076
77 /* Print processor name */
78 fill_processor_name(processor_name);
79 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Patrick Rudolphfc57d6c2019-11-12 16:30:14 +010080 printk(BIOS_INFO, "CPU:lapic=%d, boot_cpu=%d\n", lapicid(),
Lee Leahy9d62e7e2017-03-15 17:40:50 -070081 boot_cpu());
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020082
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020083 /* Setup Page Attribute Tables (PAT) */
84 // TODO set up PAT
85
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020086 enable_lapic_tpr();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020087
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060088 /* Set virtualization based on Kconfig option */
Matt DeVillierf9aed652018-12-15 15:57:33 -060089 set_vmx_and_lock();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020090
Michael Niewöhner63032432020-10-11 17:34:54 +020091 set_aesni_lock();
Michael Niewöhner7f8767d2020-10-18 00:45:38 +020092
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020093 /* Configure Enhanced SpeedStep and Thermal Sensors */
94 configure_misc();
95
96 /* Thermal throttle activation offset */
Arthur Heymans3627f292021-11-15 20:11:45 +010097 configure_thermal_target(cpu);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020098
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020099 /* Set Max Ratio */
100 set_max_ratio();
101
102 /* Enable Turbo */
103 enable_turbo();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200104}
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200105
Arthur Heymansb66ee552018-05-15 16:35:45 +0200106/* MP initialization support. */
Arthur Heymansb66ee552018-05-15 16:35:45 +0200107static void pre_mp_init(void)
108{
109 /* Setup MTRRs based on physical address size. */
110 x86_setup_mtrrs_with_detect();
111 x86_mtrr_check();
112}
113
114static int get_cpu_count(void)
115{
116 msr_t msr;
Angel Pons04c497a2021-11-03 16:30:10 +0100117 unsigned int num_threads;
118 unsigned int num_cores;
Arthur Heymansb66ee552018-05-15 16:35:45 +0200119
Elyes HAOUASa6a396d2019-05-26 13:25:30 +0200120 msr = rdmsr(MSR_CORE_THREAD_COUNT);
Arthur Heymansb66ee552018-05-15 16:35:45 +0200121 num_threads = (msr.lo >> 0) & 0xffff;
122 num_cores = (msr.lo >> 16) & 0xffff;
123 printk(BIOS_DEBUG, "CPU has %u cores, %u threads enabled.\n",
124 num_cores, num_threads);
125
126 return num_threads;
127}
128
129static void get_microcode_info(const void **microcode, int *parallel)
130{
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100131 *microcode = intel_microcode_find();
Patrick Rudolphce51b342021-01-11 09:21:58 +0100132 *parallel = !intel_ht_supported();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200133}
134
135static void per_cpu_smm_trigger(void)
136{
137 /* Relocate the SMM handler. */
138 smm_relocate();
139
140 /* After SMM relocation a 2nd microcode load is required. */
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100141 const void *microcode_patch = intel_microcode_find();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200142 intel_microcode_load_unlocked(microcode_patch);
143}
144
145static void post_mp_init(void)
146{
147 /* Now that all APs have been relocated as well as the BSP let SMIs
148 * start flowing. */
Kyösti Mälkki0778c862020-06-10 12:44:03 +0300149 global_smi_enable();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200150
151 /* Lock down the SMRAM space. */
152 smm_lock();
153}
154
Arthur Heymansb66ee552018-05-15 16:35:45 +0200155static const struct mp_ops mp_ops = {
156 .pre_mp_init = pre_mp_init,
157 .get_cpu_count = get_cpu_count,
158 .get_smm_info = smm_info,
159 .get_microcode_info = get_microcode_info,
160 .pre_mp_smm_init = smm_initialize,
161 .per_cpu_smm_trigger = per_cpu_smm_trigger,
162 .relocation_handler = smm_relocation_handler,
163 .post_mp_init = post_mp_init,
164};
165
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300166void mp_init_cpus(struct bus *cpu_bus)
Arthur Heymansb66ee552018-05-15 16:35:45 +0200167{
Felix Held4dd7d112021-10-20 23:31:43 +0200168 /* TODO: Handle mp_init_with_smm failure? */
169 mp_init_with_smm(cpu_bus, &mp_ops);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200170}
171
172static struct device_operations cpu_dev_ops = {
173 .init = model_2065x_init,
174};
175
Angel Ponsa8305e72020-02-17 14:24:04 +0100176/* Arrandale / Clarkdale CPU IDs */
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100177static const struct cpu_device_id cpu_table[] = {
Felix Held6a6ac1e2023-02-06 15:19:11 +0100178 { X86_VENDOR_INTEL, 0x20650, CPUID_EXACT_MATCH_MASK },
179 { X86_VENDOR_INTEL, 0x20651, CPUID_EXACT_MATCH_MASK },
180 { X86_VENDOR_INTEL, 0x20652, CPUID_EXACT_MATCH_MASK },
181 { X86_VENDOR_INTEL, 0x20654, CPUID_EXACT_MATCH_MASK },
182 { X86_VENDOR_INTEL, 0x20655, CPUID_EXACT_MATCH_MASK },
Felix Held1e781652023-02-08 11:39:16 +0100183 CPU_TABLE_END
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200184};
185
186static const struct cpu_driver driver __cpu_driver = {
187 .ops = &cpu_dev_ops,
188 .id_table = cpu_table,
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200189};