blob: 30519c025681f15b31aac7ec094e07345afd0a25 [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>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07006#include <acpi/acpi.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02007#include <cpu/cpu.h>
8#include <cpu/x86/mtrr.h>
9#include <cpu/x86/msr.h>
10#include <cpu/x86/lapic.h>
Arthur Heymansb66ee552018-05-15 16:35:45 +020011#include <cpu/x86/mp.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020012#include <cpu/intel/microcode.h>
13#include <cpu/intel/speedstep.h>
14#include <cpu/intel/turbo.h>
15#include <cpu/x86/cache.h>
16#include <cpu/x86/name.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020017#include "model_2065x.h"
18#include "chip.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030019#include <cpu/intel/smm_reloc.h>
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060020#include <cpu/intel/common/common.h>
Elyes HAOUASdda17fa2019-10-27 13:09:37 +010021#include <smp/node.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020022#include <types.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020023
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020024static void configure_thermal_target(void)
25{
26 struct cpu_intel_model_2065x_config *conf;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110027 struct device *lapic;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020028 msr_t msr;
29
30 /* Find pointer to CPU configuration */
31 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
32 if (!lapic || !lapic->chip_info)
33 return;
34 conf = lapic->chip_info;
35
Martin Roth4c3ab732013-07-08 16:23:54 -060036 /* Set TCC activation offset if supported */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020037 msr = rdmsr(MSR_PLATFORM_INFO);
38 if ((msr.lo & (1 << 30)) && conf->tcc_offset) {
39 msr = rdmsr(MSR_TEMPERATURE_TARGET);
40 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
41 msr.lo |= (conf->tcc_offset & 0xf) << 24;
42 wrmsr(MSR_TEMPERATURE_TARGET, msr);
43 }
44}
45
46static void configure_misc(void)
47{
48 msr_t msr;
49
50 msr = rdmsr(IA32_MISC_ENABLE);
51 msr.lo |= (1 << 0); /* Fast String enable */
Lee Leahy7b5f12b92017-03-15 17:16:59 -070052 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020053 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
54 wrmsr(IA32_MISC_ENABLE, msr);
55
56 /* Disable Thermal interrupts */
57 msr.lo = 0;
58 msr.hi = 0;
59 wrmsr(IA32_THERM_INTERRUPT, msr);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020060}
61
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020062static void set_max_ratio(void)
63{
64 msr_t msr, perf_ctl;
65
66 perf_ctl.hi = 0;
67
Angel Pons9f0093d2021-01-21 22:17:23 +010068 /* Platform Info bits 15:8 give max ratio */
69 msr = rdmsr(MSR_PLATFORM_INFO);
70 perf_ctl.lo = msr.lo & 0xff00;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020071 wrmsr(IA32_PERF_CTL, perf_ctl);
72
Angel Pons9f0093d2021-01-21 22:17:23 +010073 printk(BIOS_DEBUG, "model_x065x: frequency set to %d\n",
Angel Pons95de2312020-02-17 13:08:53 +010074 ((perf_ctl.lo >> 8) & 0xff) * IRONLAKE_BCLK);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020075}
76
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110077static void model_2065x_init(struct device *cpu)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020078{
79 char processor_name[49];
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020080
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020081 /* Clear out pending MCEs */
Felix Heldacbf1542021-07-13 16:44:18 +020082 /* This should only be done on a cold boot */
83 mca_clear_status();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020084
85 /* Print processor name */
86 fill_processor_name(processor_name);
87 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Patrick Rudolphfc57d6c2019-11-12 16:30:14 +010088 printk(BIOS_INFO, "CPU:lapic=%d, boot_cpu=%d\n", lapicid(),
Lee Leahy9d62e7e2017-03-15 17:40:50 -070089 boot_cpu());
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020090
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020091 /* Setup Page Attribute Tables (PAT) */
92 // TODO set up PAT
93
Elyes HAOUASd6e96862016-08-21 10:12:15 +020094 /* Enable the local CPU APICs */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020095 enable_lapic_tpr();
96 setup_lapic();
97
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060098 /* Set virtualization based on Kconfig option */
Matt DeVillierf9aed652018-12-15 15:57:33 -060099 set_vmx_and_lock();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200100
Michael Niewöhner63032432020-10-11 17:34:54 +0200101 set_aesni_lock();
Michael Niewöhner7f8767d2020-10-18 00:45:38 +0200102
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200103 /* Configure Enhanced SpeedStep and Thermal Sensors */
104 configure_misc();
105
106 /* Thermal throttle activation offset */
107 configure_thermal_target();
108
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200109 /* Set Max Ratio */
110 set_max_ratio();
111
112 /* Enable Turbo */
113 enable_turbo();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200114}
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200115
Arthur Heymansb66ee552018-05-15 16:35:45 +0200116/* MP initialization support. */
Arthur Heymansb66ee552018-05-15 16:35:45 +0200117static void pre_mp_init(void)
118{
119 /* Setup MTRRs based on physical address size. */
120 x86_setup_mtrrs_with_detect();
121 x86_mtrr_check();
122}
123
124static int get_cpu_count(void)
125{
126 msr_t msr;
127 int num_threads;
128 int num_cores;
129
Elyes HAOUASa6a396d2019-05-26 13:25:30 +0200130 msr = rdmsr(MSR_CORE_THREAD_COUNT);
Arthur Heymansb66ee552018-05-15 16:35:45 +0200131 num_threads = (msr.lo >> 0) & 0xffff;
132 num_cores = (msr.lo >> 16) & 0xffff;
133 printk(BIOS_DEBUG, "CPU has %u cores, %u threads enabled.\n",
134 num_cores, num_threads);
135
136 return num_threads;
137}
138
139static void get_microcode_info(const void **microcode, int *parallel)
140{
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100141 *microcode = intel_microcode_find();
Patrick Rudolphce51b342021-01-11 09:21:58 +0100142 *parallel = !intel_ht_supported();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200143}
144
145static void per_cpu_smm_trigger(void)
146{
147 /* Relocate the SMM handler. */
148 smm_relocate();
149
150 /* After SMM relocation a 2nd microcode load is required. */
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100151 const void *microcode_patch = intel_microcode_find();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200152 intel_microcode_load_unlocked(microcode_patch);
153}
154
155static void post_mp_init(void)
156{
157 /* Now that all APs have been relocated as well as the BSP let SMIs
158 * start flowing. */
Kyösti Mälkki0778c862020-06-10 12:44:03 +0300159 global_smi_enable();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200160
161 /* Lock down the SMRAM space. */
162 smm_lock();
163}
164
Arthur Heymansb66ee552018-05-15 16:35:45 +0200165static const struct mp_ops mp_ops = {
166 .pre_mp_init = pre_mp_init,
167 .get_cpu_count = get_cpu_count,
168 .get_smm_info = smm_info,
169 .get_microcode_info = get_microcode_info,
170 .pre_mp_smm_init = smm_initialize,
171 .per_cpu_smm_trigger = per_cpu_smm_trigger,
172 .relocation_handler = smm_relocation_handler,
173 .post_mp_init = post_mp_init,
174};
175
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300176void mp_init_cpus(struct bus *cpu_bus)
Arthur Heymansb66ee552018-05-15 16:35:45 +0200177{
Felix Held4dd7d112021-10-20 23:31:43 +0200178 /* TODO: Handle mp_init_with_smm failure? */
179 mp_init_with_smm(cpu_bus, &mp_ops);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200180}
181
182static struct device_operations cpu_dev_ops = {
183 .init = model_2065x_init,
184};
185
Angel Ponsa8305e72020-02-17 14:24:04 +0100186/* Arrandale / Clarkdale CPU IDs */
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100187static const struct cpu_device_id cpu_table[] = {
Angel Ponsa8305e72020-02-17 14:24:04 +0100188 { X86_VENDOR_INTEL, 0x20650 },
189 { X86_VENDOR_INTEL, 0x20651 },
190 { X86_VENDOR_INTEL, 0x20652 },
191 { X86_VENDOR_INTEL, 0x20654 },
192 { X86_VENDOR_INTEL, 0x20655 },
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200193 { 0, 0 },
194};
195
196static const struct cpu_driver driver __cpu_driver = {
197 .ops = &cpu_dev_ops,
198 .id_table = cpu_table,
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200199};