Debian Codegraph @

src/cpu/intel/haswell/haswell.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef _CPU_INTEL_HASWELL_H
4 #define _CPU_INTEL_HASWELL_H
5
6 #include <cpu/cpu.h>
7 #include <stdbool.h>
8 #include <stdint.h>
9
10 /* CPU types without stepping */
11 #define HASWELL_FAMILY_TRAD 0x306c0
12 #define HASWELL_FAMILY_ULT 0x40650
13 #define CRYSTALWELL_FAMILY 0x306c0
14 #define BROADWELL_FAMILY_ULT 0x306d0
15
16 /* Haswell CPUIDs */
17 #define CPUID_HASWELL_A0 0x306c1
18 #define CPUID_HASWELL_B0 0x306c2
19 #define CPUID_HASWELL_C0 0x306c3
20
21 #define CPUID_HASWELL_ULT_B0 0x40650
22 #define CPUID_HASWELL_ULT_C0 0x40651
23
24 /* Crystalwell CPUIDs */
25 #define CPUID_CRYSTALWELL_B0 0x40660
26 #define CPUID_CRYSTALWELL_C0 0x40661
27
28 /* Broadwell CPUIDs */
29 #define CPUID_BROADWELL_C0 0x40671
30
31 #define CPUID_BROADWELL_ULT_C0 0x306d2
32 #define CPUID_BROADWELL_ULT_D0 0x306d3
33 #define CPUID_BROADWELL_ULT_E0 0x306d4
34
35 /* Haswell and Broadwell bus clock is fixed at 100MHz */
36 #define CPU_BCLK 100
37
38 #define MSR_CORE_THREAD_COUNT 0x35
39 #define MSR_PLATFORM_INFO 0xce
40 #define PLATFORM_INFO_SET_TDP (1 << 29)
41 #define TIMED_MWAIT_SUPPORTED (1 << (37 - 32))
42 #define MSR_PKG_CST_CONFIG_CONTROL 0xe2
43 #define MSR_PMG_IO_CAPTURE_BASE 0xe4
44 #define MSR_FEATURE_CONFIG 0x13c
45 #define SMM_MCA_CAP_MSR 0x17d
46 #define SMM_CPU_SVRSTR_BIT 57
47 #define SMM_CPU_SVRSTR_MASK (1 << (SMM_CPU_SVRSTR_BIT - 32))
48 #define MSR_FLEX_RATIO 0x194
49 #define FLEX_RATIO_LOCK (1 << 20)
50 #define FLEX_RATIO_EN (1 << 16)
51 #define MSR_TEMPERATURE_TARGET 0x1a2
52 #define MSR_MISC_PWR_MGMT 0x1aa
53 #define MISC_PWR_MGMT_EIST_HW_DIS (1 << 0)
54 #define MSR_TURBO_RATIO_LIMIT 0x1ad
55 #define MSR_PRMRR_PHYS_BASE 0x1f4
56 #define MSR_PRMRR_PHYS_MASK 0x1f5
57 #define MSR_POWER_CTL 0x1fc
58 #define MSR_LT_LOCK_MEMORY 0x2e7
59 #define MSR_UNCORE_PRMRR_PHYS_BASE 0x2f4
60 #define MSR_UNCORE_PRMRR_PHYS_MASK 0x2f5
61 #define SMM_FEATURE_CONTROL_MSR 0x4e0
62 #define SMM_CPU_SAVE_EN (1 << 1)
63
64 #define MSR_C_STATE_LATENCY_CONTROL_0 0x60a
65 #define MSR_C_STATE_LATENCY_CONTROL_1 0x60b
66 #define MSR_C_STATE_LATENCY_CONTROL_2 0x60c
67 #define MSR_C_STATE_LATENCY_CONTROL_3 0x633
68 #define MSR_C_STATE_LATENCY_CONTROL_4 0x634
69 #define MSR_C_STATE_LATENCY_CONTROL_5 0x635
70 #define IRTL_VALID (1 << 15)
71 #define IRTL_1_NS (0 << 10)
72 #define IRTL_32_NS (1 << 10)
73 #define IRTL_1024_NS (2 << 10)
74 #define IRTL_32768_NS (3 << 10)
75 #define IRTL_1048576_NS (4 << 10)
76 #define IRTL_33554432_NS (5 << 10)
77 #define IRTL_RESPONSE_MASK (0x3ff)
78
79 /* Long duration in low dword, short duration in high dword */
80 #define MSR_PKG_POWER_LIMIT 0x610
81 #define PKG_POWER_LIMIT_MASK 0x7fff
82 #define PKG_POWER_LIMIT_EN (1 << 15)
83 #define PKG_POWER_LIMIT_CLAMP (1 << 16)
84 #define PKG_POWER_LIMIT_TIME_SHIFT 17
85 #define PKG_POWER_LIMIT_TIME_MASK 0x7f
86
87 #define MSR_VR_CURRENT_CONFIG 0x601
88 #define MSR_VR_MISC_CONFIG 0x603
89 #define MSR_PKG_POWER_SKU_UNIT 0x606
90 #define MSR_PKG_POWER_SKU 0x614
91 #define MSR_DDR_RAPL_LIMIT 0x618
92 #define MSR_VR_MISC_CONFIG2 0x636
93 #define MSR_PP0_POWER_LIMIT 0x638
94 #define MSR_PP1_POWER_LIMIT 0x640
95
96 #define MSR_CONFIG_TDP_NOMINAL 0x648
97 #define MSR_CONFIG_TDP_LEVEL1 0x649
98 #define MSR_CONFIG_TDP_LEVEL2 0x64a
99 #define MSR_CONFIG_TDP_CONTROL 0x64b
100 #define MSR_TURBO_ACTIVATION_RATIO 0x64c
101
102 /* SMM save state MSRs */
103 #define SMBASE_MSR 0xc20
104 #define IEDBASE_MSR 0xc22
105
106 /* MTRR_CAP_MSR bit definitions */
107 #define SMRR_SUPPORTED (1 << 11)
108 #define PRMRR_SUPPORTED (1 << 12)
109
110 /* Intel suggested latency times in units of 1024ns. */
111 #define C_STATE_LATENCY_CONTROL_0_LIMIT 0x42
112 #define C_STATE_LATENCY_CONTROL_1_LIMIT 0x73
113 #define C_STATE_LATENCY_CONTROL_2_LIMIT 0x91
114 #define C_STATE_LATENCY_CONTROL_3_LIMIT 0xe4
115 #define C_STATE_LATENCY_CONTROL_4_LIMIT 0x145
116 #define C_STATE_LATENCY_CONTROL_5_LIMIT 0x1ef
117
118 #define C_STATE_LATENCY_MICRO_SECONDS(limit, base) \
119 (((1 << ((base) * 5)) * (limit)) / 1000)
120 #define C_STATE_LATENCY_FROM_LAT_REG(reg) \
121 C_STATE_LATENCY_MICRO_SECONDS(C_STATE_LATENCY_CONTROL_ ##reg## _LIMIT, \
122 (IRTL_1024_NS >> 10))
123
124 /* P-state configuration */
125 #define PSS_MAX_ENTRIES 8
126 #define PSS_RATIO_STEP 2
127 #define PSS_LATENCY_TRANSITION 10
128 #define PSS_LATENCY_BUSMASTER 10
129
130 /* Sanity check config options. */
131 #if (CONFIG_SMM_TSEG_SIZE <= (CONFIG_IED_REGION_SIZE + CONFIG_SMM_RESERVED_SIZE))
132 # error "CONFIG_SMM_TSEG_SIZE <= (CONFIG_IED_REGION_SIZE + CONFIG_SMM_RESERVED_SIZE)"
133 #endif
134 #if (CONFIG_SMM_TSEG_SIZE < 0x800000)
135 # error "CONFIG_SMM_TSEG_SIZE must at least be 8MiB"
136 #endif
137 #if ((CONFIG_SMM_TSEG_SIZE & (CONFIG_SMM_TSEG_SIZE - 1)) != 0)
138 # error "CONFIG_SMM_TSEG_SIZE is not a power of 2"
139 #endif
140 #if ((CONFIG_IED_REGION_SIZE & (CONFIG_IED_REGION_SIZE - 1)) != 0)
141 # error "CONFIG_IED_REGION_SIZE is not a power of 2"
142 #endif
143
144 /*
145 * List of supported C-states for Haswell and Broadwell.
146 * Only the ULT parts support C8, C9, and C10.
147 */
148 enum {
149 C_STATE_C0 = 0,
150 C_STATE_C1 = 1,
151 C_STATE_C1E = 2,
152 C_STATE_C3 = 3,
153 C_STATE_C6_SHORT_LAT = 4,
154 C_STATE_C6_LONG_LAT = 5,
155 C_STATE_C7_SHORT_LAT = 6,
156 C_STATE_C7_LONG_LAT = 7,
157 C_STATE_C7S_SHORT_LAT = 8,
158 C_STATE_C7S_LONG_LAT = 9,
159 C_STATE_C8 = 10,
160 C_STATE_C9 = 11,
161 C_STATE_C10 = 12,
162 NUM_C_STATES,
163 };
164
165 /* Lock MSRs */
166 void intel_cpu_haswell_finalize_smm(void);
167
168 /* Configure power limits for turbo mode */
169 void set_power_limits(u8 power_limit_1_time);
170 int cpu_config_tdp_levels(void);
171
172 void set_max_freq(void);
173
174 /* pcode_mailbox.c */
175 int pcode_ready(void);
176 u32 pcode_mailbox_read(u32 command);
177 int pcode_mailbox_write(u32 command, u32 data);
178
179 /* CPU identification */
180 static inline u32 cpu_family_model(void)
181 {
182 return cpuid_eax(1) & 0x0fff0ff0;
183 }
184
185 static inline u32 cpu_stepping(void)
186 {
187 return cpuid_eax(1) & 0xf;
188 }
189
190 static inline bool haswell_is_ult(void)
191 {
192 return CONFIG(INTEL_LYNXPOINT_LP);
193 }
194
195 #endif