blob: 6c3aa56443aadf8b0948ff7e5fef0cc284582a03 [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Barnali Sarkar19b546f2017-05-03 18:00:48 +05302
3#ifndef SOC_INTEL_COMMON_BLOCK_CPULIB_H
4#define SOC_INTEL_COMMON_BLOCK_CPULIB_H
5
Julius Wernera2148372019-11-13 19:50:33 -08006#include <types.h>
Barnali Sarkar19b546f2017-05-03 18:00:48 +05307
8/*
Werner Zeh6b522c32018-11-22 15:10:18 +01009 * Set PERF_CTL MSR (0x199) P_Req with
Barnali Sarkar19b546f2017-05-03 18:00:48 +053010 * Turbo Ratio which is the Maximum Ratio.
11 */
12void cpu_set_max_ratio(void);
13
Sridahr Siricilla74245762021-11-11 01:42:30 +053014/* Get CPU bus frequency in MHz */
15u32 cpu_get_bus_frequency(void);
16
17/* Get CPU's max non-turbo ratio */
18u8 cpu_get_max_non_turbo_ratio(void);
19
20/* Check if CPU is hybrid CPU or not */
21bool cpu_is_hybrid_supported(void);
22
23/*
24 * Returns type of CPU that executing the function. It returns 0x20
25 * if CPU is atom, otherwise 0x40 if CPU is CORE. The API must be called
26 * if CPU is hybrid.
27 */
28uint8_t cpu_get_cpu_type(void);
Barnali Sarkar19b546f2017-05-03 18:00:48 +053029/*
30 * Get the TDP Nominal Ratio from MSR 0x648 Bits 7:0.
31 */
32u8 cpu_get_tdp_nominal_ratio(void);
33
34/*
35 * Read PLATFORM_INFO MSR (0xCE).
36 * Return Value of Bit 34:33 (CONFIG_TDP_LEVELS).
37 *
38 * Possible values of Bit 34:33 are -
39 * 00 : Config TDP not supported
40 * 01 : One Additional TDP level supported
41 * 10 : Two Additional TDP level supported
42 * 11 : Reserved
43 */
44int cpu_config_tdp_levels(void);
45
46/*
47 * TURBO_RATIO_LIMIT MSR (0x1AD) Bits 31:0 indicates the
48 * factory configured values for of 1-core, 2-core, 3-core
49 * and 4-core turbo ratio limits for all processors.
50 *
51 * 7:0 - MAX_TURBO_1_CORE
52 * 15:8 - MAX_TURBO_2_CORES
53 * 23:16 - MAX_TURBO_3_CORES
54 * 31:24 - MAX_TURBO_4_CORES
55 *
Werner Zeh6b522c32018-11-22 15:10:18 +010056 * Set PERF_CTL MSR (0x199) P_Req with that value.
Barnali Sarkar19b546f2017-05-03 18:00:48 +053057 */
58void cpu_set_p_state_to_turbo_ratio(void);
59
60/*
61 * CONFIG_TDP_NOMINAL MSR (0x648) Bits 7:0 tells Nominal
62 * TDP level ratio to be used for specific processor (in units
63 * of 100MHz).
64 *
Werner Zeh6b522c32018-11-22 15:10:18 +010065 * Set PERF_CTL MSR (0x199) P_Req with that value.
Barnali Sarkar19b546f2017-05-03 18:00:48 +053066 */
67void cpu_set_p_state_to_nominal_tdp_ratio(void);
68
69/*
70 * PLATFORM_INFO MSR (0xCE) Bits 15:8 tells
71 * MAX_NON_TURBO_LIM_RATIO.
72 *
Werner Zeh6b522c32018-11-22 15:10:18 +010073 * Set PERF_CTL MSR (0x199) P_Req with that value.
Barnali Sarkar19b546f2017-05-03 18:00:48 +053074 */
75void cpu_set_p_state_to_max_non_turbo_ratio(void);
76
77/*
Werner Zeh6b522c32018-11-22 15:10:18 +010078 * Set PERF_CTL MSR (0x199) P_Req with the value
Werner Zeh52c58922018-11-21 10:38:12 +010079 * for maximum efficiency. This value is reported in PLATFORM_INFO MSR (0xCE)
80 * in Bits 47:40 and is extracted with cpu_get_min_ratio().
81 */
82void cpu_set_p_state_to_min_clock_ratio(void);
83
84/*
Barnali Sarkar19b546f2017-05-03 18:00:48 +053085 * Get the Burst/Turbo Mode State from MSR IA32_MISC_ENABLE 0x1A0
86 * Bit 38 - TURBO_MODE_DISABLE Bit to get state ENABLED / DISABLED.
87 * Also check for the cpuid 0x6 to check whether Burst mode unsupported.
88 * Below are the possible cpu_get_burst_mode_state() return values-
89 * These states are exposed to the User since user
90 * need to know which is the current Burst Mode State.
91 */
92enum {
93 BURST_MODE_UNKNOWN,
94 BURST_MODE_UNAVAILABLE,
95 BURST_MODE_DISABLED,
96 BURST_MODE_ENABLED
97};
98int cpu_get_burst_mode_state(void);
99
100/*
Subrata Banik6d569162019-04-10 12:19:27 +0530101 * Program CPU Burst mode
102 * true = Enable Burst mode.
103 * false = Disable Burst mode.
Barnali Sarkar19b546f2017-05-03 18:00:48 +0530104 */
Subrata Banik6d569162019-04-10 12:19:27 +0530105void cpu_burst_mode(bool burst_mode_status);
Barnali Sarkar19b546f2017-05-03 18:00:48 +0530106
107/*
Subrata Banik6d569162019-04-10 12:19:27 +0530108 * Program Enhanced Intel Speed Step Technology
109 * true = Enable EIST.
110 * false = Disable EIST.
Barnali Sarkar19b546f2017-05-03 18:00:48 +0530111 */
Subrata Banik6d569162019-04-10 12:19:27 +0530112void cpu_set_eist(bool eist_status);
Barnali Sarkar19b546f2017-05-03 18:00:48 +0530113
114/*
Subrata Banik56ab8e22022-01-07 13:40:19 +0000115 * SoC specific implementation:
116 *
117 * Check CPU security level using ENABLE_IA_UNTRUSTED_MODE of CPU MSR.
118 * If bit is set, meaning CPU has dropped its security level by entering
119 * into `untrusted mode`. Otherwise, it's in `trusted mode`.
120 */
121bool cpu_soc_is_in_untrusted_mode(void);
122
Subrata Banik37a55d12022-05-30 18:11:12 +0000123/* SoC function to set the BIOS DONE MSR. */
124void cpu_soc_bios_done(void);
125
Subrata Banik56ab8e22022-01-07 13:40:19 +0000126/*
Barnali Sarkar91d38a5b2017-06-13 19:17:35 +0530127 * This function fills in the number of Cores(physical) and Threads(virtual)
128 * of the CPU in the function arguments. It also returns if the number of cores
129 * and number of threads are equal.
130 */
131int cpu_read_topology(unsigned int *num_phys, unsigned int *num_virt);
132
Shaunak Saha5f843102017-08-16 09:54:00 -0700133/*
134 * cpu_get_bus_clock returns the bus clock frequency in KHz.
135 * This is the value the clock ratio is multiplied with.
136 */
137uint32_t cpu_get_bus_clock(void);
138
139/*
140 * cpu_get_coord_type returns coordination type (SW_ANY or SW_ALL or HW_ALL)
141 * which is used to populate _PSD object.
142 */
143int cpu_get_coord_type(void);
144
145/*
146 * cpu_get_min_ratio returns the minimum frequency ratio that is supported
147 * by this processor
148 */
149uint32_t cpu_get_min_ratio(void);
150
151/*
152 * cpu_get_max_ratio returns the nominal TDP ratio if available or the
153 * maximum non turbo frequency ratio for this processor
154 */
155uint32_t cpu_get_max_ratio(void);
156
Sumeet R Pawnikar360684b2020-06-18 15:56:11 +0530157/* Thermal throttle activation offset */
158void configure_tcc_thermal_target(void);
159
Shaunak Saha5f843102017-08-16 09:54:00 -0700160/*
161 * cpu_get_power_max calculates CPU TDP in mW
162 */
163uint32_t cpu_get_power_max(void);
164
165/*
166 * cpu_get_max_turbo_ratio returns the maximum turbo ratio limit for the
167 * processor
168 */
169uint32_t cpu_get_max_turbo_ratio(void);
170
Pratik Prajapati4e203072017-08-28 12:16:23 -0700171/* Configure Machine Check Architecture support */
Subrata Banikf91344c2019-05-06 19:23:26 +0530172void mca_configure(void);
Pratik Prajapati4e203072017-08-28 12:16:23 -0700173
Michael Niewöhner5ce66da2019-09-22 21:56:17 +0200174/* Lock chipset memory registers to protect SMM */
Michael Niewöhner6e64c1a2020-08-05 21:36:11 +0200175void cpu_lt_lock_memory(void);
Michael Niewöhner5ce66da2019-09-22 21:56:17 +0200176
Michael Niewöhner490546f2020-09-15 12:20:08 +0200177/* Get a supported PRMRR size in bytes with respect to users choice */
178int get_valid_prmrr_size(void);
Michael Niewöhner7736bfc2019-10-22 23:05:06 +0200179
Michael Niewöhner310c7632020-10-01 22:28:03 +0200180/*
181 * Enable the emulated ACPI timer in case it's not available or to allow
182 * disabling the PM ACPI timer (PM1_TMR) for power saving.
183 */
184void enable_pm_timer_emulation(void);
185
Aamir Bohrad1925902021-02-19 16:18:07 +0530186/* Derive core, package and thread information from lapic ID */
187void get_cpu_topology_from_apicid(uint32_t apicid, uint8_t *package,
188 uint8_t *core, uint8_t *thread);
189
Subrata Banik13fd3c82022-06-05 18:57:36 +0530190/*
191 * Initialize core PRMRR
192 *
193 * Read the BSP PRMRR snapshot and apply on the rest of the core threads
194 */
195void init_core_prmrr(void);
196
Subrata Banik29a92e82022-08-15 15:16:43 +0530197/*
198 * Check if TME is supported by the CPU
199 *
200 * coreboot shall detect the existence of TME feature by running CPUID instruction:
201 * CPUID leaf 7/sub-leaf 0: Return Value in ECX [bit 13] = 1
202 */
203bool is_tme_supported(void);
204
Subrata Banik66cd1842022-08-15 16:29:31 +0530205/*
206 * Set TME core activate MSR
207 *
208 * Write zero to TME core activate MSR will translate the TME_ACTIVATE[MK_TME_KEYID_BITS]
209 * value into PMH mask register.
210 * TME_ACTIVATE[MK_TME_KEYID_BITS] = MSR 0x982 Bits[32-35]
211 */
212void set_tme_core_activate(void);
213
Pratikkumar Prajapatie51978f2022-12-19 10:13:09 -0800214/*
215 * This function checks if the CPU supports SGX feature.
216 * Returns true if SGX feature is supported otherwise false.
217 */
218bool is_sgx_supported(void);
219
Barnali Sarkar19b546f2017-05-03 18:00:48 +0530220#endif /* SOC_INTEL_COMMON_BLOCK_CPULIB_H */