blob: 5bd1c32815b22ee2a58dbf2c78513a0e6fe4cd24 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerc7757f22009-04-30 10:14:22 +00002
Stefan Reinauer00a889c2008-10-29 04:48:44 +00003#include <console/console.h>
4#include <device/device.h>
Stefan Reinauer00a889c2008-10-29 04:48:44 +00005#include <cpu/cpu.h>
Stefan Reinauer00a889c2008-10-29 04:48:44 +00006#include <cpu/x86/msr.h>
Stefan Reinauer2a27b202010-12-11 22:14:44 +00007#include <cpu/intel/speedstep.h>
Stefan Reinauer00a889c2008-10-29 04:48:44 +00008#include <cpu/x86/cache.h>
Uwe Hermannaac8f662010-09-29 09:54:16 +00009#include <cpu/x86/name.h>
Stefan Reinauer45cc5502009-03-06 19:54:15 +000010
Stefan Reinauerc7757f22009-04-30 10:14:22 +000011#define HIGHEST_CLEVEL 3
Stefan Reinauer45cc5502009-03-06 19:54:15 +000012static void configure_c_states(void)
13{
14 msr_t msr;
15
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020016 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Paul Menzel7129ccb2017-02-27 01:01:55 +010017 msr.lo |= (1 << 15); // config lock until next reset
Stefan Reinauer4da810b2009-07-21 21:41:42 +000018 msr.lo |= (1 << 10); // Enable I/O MWAIT redirection for C-States
Stefan Reinauerc7757f22009-04-30 10:14:22 +000019 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
Paul Menzel7129ccb2017-02-27 01:01:55 +010020 msr.lo |= (1 << 3); // dynamic L2
Stefan Reinauer4da810b2009-07-21 21:41:42 +000021
22 /* Number of supported C-States */
23 msr.lo &= ~7;
24 msr.lo |= HIGHEST_CLEVEL; // support at most C3
25
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020026 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Stefan Reinauerc7757f22009-04-30 10:14:22 +000027
Stefan Reinauer4da810b2009-07-21 21:41:42 +000028 /* Set Processor MWAIT IO BASE (P_BLK) */
29 msr.hi = 0;
Lee Leahycdc50482017-03-15 18:26:18 -070030 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff)
31 << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010032 wrmsr(MSR_PMG_IO_BASE_ADDR, msr);
Stefan Reinauerc7757f22009-04-30 10:14:22 +000033
Paul Menzel7129ccb2017-02-27 01:01:55 +010034 /* Set C_LVL controls and IO Capture Address */
Stefan Reinauer4da810b2009-07-21 21:41:42 +000035 msr.hi = 0;
Lee Leahycdc50482017-03-15 18:26:18 -070036 // -2 because LVL0+1 aren't counted
37 msr.lo = (PMB0_BASE + 4) | ((HIGHEST_CLEVEL - 2) << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010038 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000039}
40
Stefan Reinauer45cc5502009-03-06 19:54:15 +000041static void configure_misc(void)
42{
43 msr_t msr;
44
45 msr = rdmsr(IA32_MISC_ENABLE);
Lee Leahy7b5f12b92017-03-15 17:16:59 -070046 msr.lo |= (1 << 3); /* TM1 enable */
Stefan Reinauer45cc5502009-03-06 19:54:15 +000047 msr.lo |= (1 << 13); /* TM2 enable */
48 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
49
50 msr.lo |= (1 << 10); /* FERR# multiplexing */
51
52 // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
53 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
54
Arthur Heymansaacd5482016-10-06 12:14:14 +020055 /* Enable C2E */
56 msr.lo |= (1 << 26);
57
58 /* Enable C4E */
59 msr.hi |= (1 << (32 - 32)); // C4E
60 msr.hi |= (1 << (33 - 32)); // Hard C4E
61
Stefan Reinauer45cc5502009-03-06 19:54:15 +000062 wrmsr(IA32_MISC_ENABLE, msr);
63
64 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
65 wrmsr(IA32_MISC_ENABLE, msr);
Patrick Georgiac624a62011-08-09 08:52:14 +020066
67 // set maximum CPU speed
Elyes HAOUAS242ea842017-11-23 21:23:44 +010068 msr = rdmsr(IA32_PERF_STATUS);
Lee Leahy9d62e7e2017-03-15 17:40:50 -070069 int busratio_max = (msr.hi >> (40-32)) & 0x1f;
Patrick Georgiac624a62011-08-09 08:52:14 +020070
71 msr = rdmsr(IA32_PLATFORM_ID);
Lee Leahy9d62e7e2017-03-15 17:40:50 -070072 int vid_max = msr.lo & 0x3f;
Patrick Georgiac624a62011-08-09 08:52:14 +020073
74 msr.lo &= ~0xffff;
75 msr.lo |= busratio_max << 8;
76 msr.lo |= vid_max;
77
78 wrmsr(IA32_PERF_CTL, msr);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000079}
80
Stefan Reinauer4da810b2009-07-21 21:41:42 +000081#define PIC_SENS_CFG 0x1aa
82static void configure_pic_thermal_sensors(void)
83{
84 msr_t msr;
85
86 msr = rdmsr(PIC_SENS_CFG);
87
88 msr.lo |= (1 << 21); // inter-core lock TM1
89 msr.lo |= (1 << 4); // Enable bypass filter
90
91 wrmsr(PIC_SENS_CFG, msr);
92}
93
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110094static void model_6ex_init(struct device *cpu)
Stefan Reinauer00a889c2008-10-29 04:48:44 +000095{
96 char processor_name[49];
97
98 /* Turn on caching if we haven't already */
Felix Held10796d82021-10-25 17:52:49 +020099 enable_cache();
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000100
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000101 /* Print processor name */
102 fill_processor_name(processor_name);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000103 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000104
Paul Menzel7129ccb2017-02-27 01:01:55 +0100105 /* Setup Page Attribute Tables (PAT) */
106 // TODO set up PAT
107
Stefan Reinauer45cc5502009-03-06 19:54:15 +0000108 /* Configure C States */
109 configure_c_states();
110
111 /* Configure Enhanced SpeedStep and Thermal Sensors */
112 configure_misc();
113
Stefan Reinauer4da810b2009-07-21 21:41:42 +0000114 /* PIC thermal sensor control */
115 configure_pic_thermal_sensors();
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000116}
117
118static struct device_operations cpu_dev_ops = {
119 .init = model_6ex_init,
120};
121
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100122static const struct cpu_device_id cpu_table[] = {
Felix Held6a6ac1e2023-02-06 15:19:11 +0100123 { X86_VENDOR_INTEL, 0x06e0, CPUID_EXACT_MATCH_MASK }, /* Intel Core Solo/Core Duo */
124 { X86_VENDOR_INTEL, 0x06e8, CPUID_EXACT_MATCH_MASK }, /* Intel Core Solo/Core Duo */
125 { X86_VENDOR_INTEL, 0x06ec, CPUID_EXACT_MATCH_MASK }, /* Intel Core Solo/Core Duo */
Felix Held1e781652023-02-08 11:39:16 +0100126 CPU_TABLE_END
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000127};
128
129static const struct cpu_driver driver __cpu_driver = {
130 .ops = &cpu_dev_ops,
131 .id_table = cpu_table,
132};