blob: f70d7b2f5f41f0c1d88e83f1b7ea7b7ad8019ca2 [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>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020022
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020023static void configure_thermal_target(void)
24{
25 struct cpu_intel_model_2065x_config *conf;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110026 struct device *lapic;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020027 msr_t msr;
28
29 /* Find pointer to CPU configuration */
30 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
31 if (!lapic || !lapic->chip_info)
32 return;
33 conf = lapic->chip_info;
34
Martin Roth4c3ab732013-07-08 16:23:54 -060035 /* Set TCC activation offset if supported */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020036 msr = rdmsr(MSR_PLATFORM_INFO);
37 if ((msr.lo & (1 << 30)) && conf->tcc_offset) {
38 msr = rdmsr(MSR_TEMPERATURE_TARGET);
39 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
40 msr.lo |= (conf->tcc_offset & 0xf) << 24;
41 wrmsr(MSR_TEMPERATURE_TARGET, msr);
42 }
43}
44
45static void configure_misc(void)
46{
47 msr_t msr;
48
49 msr = rdmsr(IA32_MISC_ENABLE);
50 msr.lo |= (1 << 0); /* Fast String enable */
Lee Leahy7b5f12b92017-03-15 17:16:59 -070051 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020052 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
53 wrmsr(IA32_MISC_ENABLE, msr);
54
55 /* Disable Thermal interrupts */
56 msr.lo = 0;
57 msr.hi = 0;
58 wrmsr(IA32_THERM_INTERRUPT, msr);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020059}
60
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020061static void set_max_ratio(void)
62{
63 msr_t msr, perf_ctl;
64
65 perf_ctl.hi = 0;
66
Angel Pons9f0093d2021-01-21 22:17:23 +010067 /* Platform Info bits 15:8 give max ratio */
68 msr = rdmsr(MSR_PLATFORM_INFO);
69 perf_ctl.lo = msr.lo & 0xff00;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020070 wrmsr(IA32_PERF_CTL, perf_ctl);
71
Angel Pons9f0093d2021-01-21 22:17:23 +010072 printk(BIOS_DEBUG, "model_x065x: frequency set to %d\n",
Angel Pons95de2312020-02-17 13:08:53 +010073 ((perf_ctl.lo >> 8) & 0xff) * IRONLAKE_BCLK);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020074}
75
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110076static void model_2065x_init(struct device *cpu)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020077{
78 char processor_name[49];
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020079
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020080 /* Clear out pending MCEs */
Felix Heldacbf1542021-07-13 16:44:18 +020081 /* This should only be done on a cold boot */
82 mca_clear_status();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020083
84 /* Print processor name */
85 fill_processor_name(processor_name);
86 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Patrick Rudolphfc57d6c2019-11-12 16:30:14 +010087 printk(BIOS_INFO, "CPU:lapic=%d, boot_cpu=%d\n", lapicid(),
Lee Leahy9d62e7e2017-03-15 17:40:50 -070088 boot_cpu());
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020089
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020090 /* Setup Page Attribute Tables (PAT) */
91 // TODO set up PAT
92
Elyes HAOUASd6e96862016-08-21 10:12:15 +020093 /* Enable the local CPU APICs */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020094 enable_lapic_tpr();
95 setup_lapic();
96
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060097 /* Set virtualization based on Kconfig option */
Matt DeVillierf9aed652018-12-15 15:57:33 -060098 set_vmx_and_lock();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020099
Michael Niewöhner63032432020-10-11 17:34:54 +0200100 set_aesni_lock();
Michael Niewöhner7f8767d2020-10-18 00:45:38 +0200101
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200102 /* Configure Enhanced SpeedStep and Thermal Sensors */
103 configure_misc();
104
105 /* Thermal throttle activation offset */
106 configure_thermal_target();
107
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200108 /* Set Max Ratio */
109 set_max_ratio();
110
111 /* Enable Turbo */
112 enable_turbo();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200113}
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200114
Arthur Heymansb66ee552018-05-15 16:35:45 +0200115/* MP initialization support. */
Arthur Heymansb66ee552018-05-15 16:35:45 +0200116static void pre_mp_init(void)
117{
118 /* Setup MTRRs based on physical address size. */
119 x86_setup_mtrrs_with_detect();
120 x86_mtrr_check();
121}
122
123static int get_cpu_count(void)
124{
125 msr_t msr;
126 int num_threads;
127 int num_cores;
128
Elyes HAOUASa6a396d2019-05-26 13:25:30 +0200129 msr = rdmsr(MSR_CORE_THREAD_COUNT);
Arthur Heymansb66ee552018-05-15 16:35:45 +0200130 num_threads = (msr.lo >> 0) & 0xffff;
131 num_cores = (msr.lo >> 16) & 0xffff;
132 printk(BIOS_DEBUG, "CPU has %u cores, %u threads enabled.\n",
133 num_cores, num_threads);
134
135 return num_threads;
136}
137
138static void get_microcode_info(const void **microcode, int *parallel)
139{
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100140 *microcode = intel_microcode_find();
Patrick Rudolphce51b342021-01-11 09:21:58 +0100141 *parallel = !intel_ht_supported();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200142}
143
144static void per_cpu_smm_trigger(void)
145{
146 /* Relocate the SMM handler. */
147 smm_relocate();
148
149 /* After SMM relocation a 2nd microcode load is required. */
Patrick Rudolph3fa23b82021-01-25 09:42:08 +0100150 const void *microcode_patch = intel_microcode_find();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200151 intel_microcode_load_unlocked(microcode_patch);
152}
153
154static void post_mp_init(void)
155{
156 /* Now that all APs have been relocated as well as the BSP let SMIs
157 * start flowing. */
Kyösti Mälkki0778c862020-06-10 12:44:03 +0300158 global_smi_enable();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200159
160 /* Lock down the SMRAM space. */
161 smm_lock();
162}
163
Arthur Heymansb66ee552018-05-15 16:35:45 +0200164static const struct mp_ops mp_ops = {
165 .pre_mp_init = pre_mp_init,
166 .get_cpu_count = get_cpu_count,
167 .get_smm_info = smm_info,
168 .get_microcode_info = get_microcode_info,
169 .pre_mp_smm_init = smm_initialize,
170 .per_cpu_smm_trigger = per_cpu_smm_trigger,
171 .relocation_handler = smm_relocation_handler,
172 .post_mp_init = post_mp_init,
173};
174
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300175void mp_init_cpus(struct bus *cpu_bus)
Arthur Heymansb66ee552018-05-15 16:35:45 +0200176{
177 if (mp_init_with_smm(cpu_bus, &mp_ops))
178 printk(BIOS_ERR, "MP initialization failure.\n");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200179}
180
181static struct device_operations cpu_dev_ops = {
182 .init = model_2065x_init,
183};
184
Angel Ponsa8305e72020-02-17 14:24:04 +0100185/* Arrandale / Clarkdale CPU IDs */
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100186static const struct cpu_device_id cpu_table[] = {
Angel Ponsa8305e72020-02-17 14:24:04 +0100187 { X86_VENDOR_INTEL, 0x20650 },
188 { X86_VENDOR_INTEL, 0x20651 },
189 { X86_VENDOR_INTEL, 0x20652 },
190 { X86_VENDOR_INTEL, 0x20654 },
191 { X86_VENDOR_INTEL, 0x20655 },
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200192 { 0, 0 },
193};
194
195static const struct cpu_driver driver __cpu_driver = {
196 .ops = &cpu_dev_ops,
197 .id_table = cpu_table,
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200198};