blob: ff64ab18e415cea61be771b93aabc2470a43c5bd [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 Reinauer4da810b2009-07-21 21:41:42 +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);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000017 msr.lo |= (1 << 15); // config lock until next reset
18 msr.lo |= (1 << 14); // Deeper Sleep
Paul Menzel7129ccb2017-02-27 01:01:55 +010019 msr.lo |= (1 << 10); // Enable I/O MWAIT redirection for C-States
20 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
21 msr.lo |= (1 << 3); // dynamic L2
Stefan Reinauer45cc5502009-03-06 19:54:15 +000022
Elyes HAOUAS2765a892016-09-01 19:44:56 +020023 /* Number of supported C-States */
Stefan Reinauer4da810b2009-07-21 21:41:42 +000024 msr.lo &= ~7;
25 msr.lo |= HIGHEST_CLEVEL; // support at most C3
26
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020027 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000028
Paul Menzel7129ccb2017-02-27 01:01:55 +010029 /* Set Processor MWAIT IO BASE (P_BLK) */
Stefan Reinauer45cc5502009-03-06 19:54:15 +000030 msr.hi = 0;
Lee Leahycdc50482017-03-15 18:26:18 -070031 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff)
32 << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010033 wrmsr(MSR_PMG_IO_BASE_ADDR, msr);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000034
Stefan Reinauer4da810b2009-07-21 21:41:42 +000035 /* Set C_LVL controls and IO Capture Address */
Stefan Reinauer45cc5502009-03-06 19:54:15 +000036 msr.hi = 0;
Lee Leahycdc50482017-03-15 18:26:18 -070037 // -2 because LVL0+1 aren't counted
38 msr.lo = (PMB0_BASE + 4) | ((HIGHEST_CLEVEL - 2) << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010039 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000040}
41
Sven Schnelleedac28c2012-06-19 18:00:01 +020042#define IA32_PECI_CTL 0x5a0
43
Stefan Reinauer45cc5502009-03-06 19:54:15 +000044static void configure_misc(void)
45{
46 msr_t msr;
47
48 msr = rdmsr(IA32_MISC_ENABLE);
Lee Leahy7b5f12b92017-03-15 17:16:59 -070049 msr.lo |= (1 << 3); /* TM1 enable */
Stefan Reinauer45cc5502009-03-06 19:54:15 +000050 msr.lo |= (1 << 13); /* TM2 enable */
51 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
52
53 msr.lo |= (1 << 10); /* FERR# multiplexing */
54
55 // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
56 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
57
58 /* Enable C2E */
59 msr.lo |= (1 << 26);
60
61 /* Enable C4E */
62 /* TODO This should only be done on mobile CPUs, see cpuid 5 */
63 msr.hi |= (1 << (32 - 32)); // C4E
64 msr.hi |= (1 << (33 - 32)); // Hard C4E
65
66 /* Enable EMTTM. */
67 /* NOTE: We leave the EMTTM_CR_TABLE0-5 at their default values */
68 msr.hi |= (1 << (36 - 32));
69
70 wrmsr(IA32_MISC_ENABLE, msr);
71
72 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
73 wrmsr(IA32_MISC_ENABLE, msr);
Patrick Georgiac624a62011-08-09 08:52:14 +020074
75 // set maximum CPU speed
Elyes HAOUAS242ea842017-11-23 21:23:44 +010076 msr = rdmsr(IA32_PERF_STATUS);
Lee Leahy9d62e7e2017-03-15 17:40:50 -070077 int busratio_max = (msr.hi >> (40-32)) & 0x1f;
Patrick Georgiac624a62011-08-09 08:52:14 +020078
79 msr = rdmsr(IA32_PLATFORM_ID);
Lee Leahy9d62e7e2017-03-15 17:40:50 -070080 int vid_max = msr.lo & 0x3f;
Patrick Georgiac624a62011-08-09 08:52:14 +020081
82 msr.lo &= ~0xffff;
83 msr.lo |= busratio_max << 8;
84 msr.lo |= vid_max;
85
86 wrmsr(IA32_PERF_CTL, msr);
Sven Schnelleedac28c2012-06-19 18:00:01 +020087
88 /* Enable PECI */
89 msr = rdmsr(IA32_PECI_CTL);
90 msr.lo |= 1;
91 wrmsr(IA32_PECI_CTL, msr);
Stefan Reinauer45cc5502009-03-06 19:54:15 +000092}
93
94#define PIC_SENS_CFG 0x1aa
95static void configure_pic_thermal_sensors(void)
96{
97 msr_t msr;
98
99 msr = rdmsr(PIC_SENS_CFG);
100
101 msr.lo |= (1 << 21); // inter-core lock TM1
102 msr.lo |= (1 << 4); // Enable bypass filter
103
104 wrmsr(PIC_SENS_CFG, msr);
105}
106
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100107static void model_6fx_init(struct device *cpu)
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000108{
109 char processor_name[49];
110
111 /* Turn on caching if we haven't already */
Felix Held10796d82021-10-25 17:52:49 +0200112 enable_cache();
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000113
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000114 /* Print processor name */
115 fill_processor_name(processor_name);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000116 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000117
Stefan Reinauer4da810b2009-07-21 21:41:42 +0000118 /* Setup Page Attribute Tables (PAT) */
119 // TODO set up PAT
120
Stefan Reinauer45cc5502009-03-06 19:54:15 +0000121 /* Configure C States */
122 configure_c_states();
123
124 /* Configure Enhanced SpeedStep and Thermal Sensors */
125 configure_misc();
126
127 /* PIC thermal sensor control */
128 configure_pic_thermal_sensors();
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000129}
130
131static struct device_operations cpu_dev_ops = {
Stefan Reinauer45cc5502009-03-06 19:54:15 +0000132 .init = model_6fx_init,
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000133};
134
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100135static const struct cpu_device_id cpu_table[] = {
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000136 { X86_VENDOR_INTEL, 0x06f0 }, /* Intel Core 2 Solo/Core Duo */
Stefan Reinauerc7757f22009-04-30 10:14:22 +0000137 { X86_VENDOR_INTEL, 0x06f2 }, /* Intel Core 2 Solo/Core Duo */
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000138 { X86_VENDOR_INTEL, 0x06f6 }, /* Intel Core 2 Solo/Core Duo */
Stefan Reinauerc7757f22009-04-30 10:14:22 +0000139 { X86_VENDOR_INTEL, 0x06f7 }, /* Intel Core 2 Solo/Core Duo */
140 { X86_VENDOR_INTEL, 0x06fa }, /* Intel Core 2 Solo/Core Duo */
141 { X86_VENDOR_INTEL, 0x06fb }, /* Intel Core 2 Solo/Core Duo */
142 { X86_VENDOR_INTEL, 0x06fd }, /* Intel Core 2 Solo/Core Duo */
Arthur Heymans3f2d6c02017-01-08 21:14:46 +0100143 { X86_VENDOR_INTEL, 0x10661 }, /* Intel Core 2 Celeron Conroe-L */
Stefan Reinauer00a889c2008-10-29 04:48:44 +0000144 { 0, 0 },
145};
146
147static const struct cpu_driver driver __cpu_driver = {
148 .ops = &cpu_dev_ops,
149 .id_table = cpu_table,
150};