1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Common code for Intel CPUs 4 * 5 * Copyright (c) 2016 Google, Inc 6 */ 7 8 #ifndef __ASM_CPU_COMMON_H 9 #define __ASM_CPU_COMMON_H 10 11 /* Standard Intel bus clock is fixed at 100MHz */ 12 enum { 13 INTEL_BCLK_MHZ = 100 14 }; 15 16 struct cpu_info; 17 struct udevice; 18 19 /** 20 * cpu_common_init() - Set up common CPU init 21 * 22 * This reports BIST failure, enables the LAPIC, updates microcode, enables 23 * the upper 128-bytes of CROM RAM, probes the northbridge, PCH, LPC and SATA. 24 * 25 * @return 0 if OK, -ve on error 26 */ 27 int cpu_common_init(void); 28 29 /** 30 * cpu_set_flex_ratio_to_tdp_nominal() - Set up the maximum non-turbo rate 31 * 32 * If a change is needed, this function will do a soft reset so it takes 33 * effect. 34 * 35 * Some details are available here: 36 * http://forum.hwbot.org/showthread.php?t=76092 37 * 38 * @return 0 if OK, -ve on error 39 */ 40 int cpu_set_flex_ratio_to_tdp_nominal(void); 41 42 /** 43 * cpu_intel_get_info() - Obtain CPU info for Intel CPUs 44 * 45 * Most Intel CPUs use the same MSR to obtain the clock speed, and use the same 46 * features. This function fills in these values, given the value of the base 47 * clock in MHz (typically this should be set to 100). 48 * 49 * @info: cpu_info struct to fill in 50 * @bclk_mz: the base clock in MHz 51 * 52 * @return 0 always 53 */ 54 int cpu_intel_get_info(struct cpu_info *info, int bclk_mz); 55 56 /** 57 * cpu_configure_thermal_target() - Set the thermal target for a CPU 58 * 59 * This looks up the tcc-offset property and uses it to set the 60 * MSR_TEMPERATURE_TARGET value. 61 * 62 * @dev: CPU device 63 * @return 0 if OK, -ENOENT if no target is given in device tree 64 */ 65 int cpu_configure_thermal_target(struct udevice *dev); 66 67 /** 68 * cpu_set_perf_control() - Set the nominal CPU clock speed 69 * 70 * This sets the clock speed as a multiplier of BCLK 71 * 72 * @clk_ratio: Ratio to use 73 */ 74 void cpu_set_perf_control(uint clk_ratio); 75 76 /** 77 * cpu_config_tdp_levels() - Check for configurable TDP option 78 * 79 * @return true if the CPU has configurable TDP (Thermal-design power) 80 */ 81 bool cpu_config_tdp_levels(void); 82 83 /** enum burst_mode_t - Burst-mode states */ 84 enum burst_mode_t { 85 BURST_MODE_UNKNOWN, 86 BURST_MODE_UNAVAILABLE, 87 BURST_MODE_DISABLED, 88 BURST_MODE_ENABLED 89 }; 90 91 /* 92 * cpu_get_burst_mode_state() - Get the Burst/Turbo Mode State 93 * 94 * This reads MSR IA32_MISC_ENABLE 0x1A0 95 * Bit 38 - TURBO_MODE_DISABLE Bit to get state ENABLED / DISABLED. 96 * Also checks cpuid 0x6 to see whether burst mode is supported. 97 * 98 * @return current burst mode status 99 */ 100 enum burst_mode_t cpu_get_burst_mode_state(void); 101 102 /** 103 * cpu_set_burst_mode() - Set CPU burst mode 104 * 105 * @burst_mode: true to enable burst mode, false to disable 106 */ 107 void cpu_set_burst_mode(bool burst_mode); 108 109 /** 110 * cpu_set_eist() - Enable Enhanced Intel Speed Step Technology 111 * 112 * @eist_status: true to enable EIST, false to disable 113 */ 114 void cpu_set_eist(bool eist_status); 115 116 /** 117 * cpu_set_p_state_to_turbo_ratio() - Set turbo ratio 118 * 119 * TURBO_RATIO_LIMIT MSR (0x1AD) Bits 31:0 indicates the 120 * factory configured values for of 1-core, 2-core, 3-core 121 * and 4-core turbo ratio limits for all processors. 122 * 123 * 7:0 - MAX_TURBO_1_CORE 124 * 15:8 - MAX_TURBO_2_CORES 125 * 23:16 - MAX_TURBO_3_CORES 126 * 31:24 - MAX_TURBO_4_CORES 127 * 128 * Set PERF_CTL MSR (0x199) P_Req with that value. 129 */ 130 void cpu_set_p_state_to_turbo_ratio(void); 131 132 /** 133 * cpu_get_coord_type() - Get the type of coordination for P-State transition 134 * 135 * See ACPI spec v6.3 section 8.4.6.5 _PSD (P-State Dependency) 136 * 137 * @return HW_ALL (always) 138 */ 139 int cpu_get_coord_type(void); 140 141 /** 142 * cpu_get_min_ratio() - get minimum support frequency ratio for CPU 143 * 144 * @return minimum ratio 145 */ 146 int cpu_get_min_ratio(void); 147 148 /** 149 * cpu_get_max_ratio() - get nominal TDP ration or max non-turbo ratio 150 * 151 * If a nominal TDP ratio is available, it is returned. Otherwise this returns 152 * the maximum non-turbo frequency ratio for this processor 153 * 154 * @return max ratio 155 */ 156 int cpu_get_max_ratio(void); 157 158 /** 159 * cpu_get_bus_clock_khz() - Get the bus clock frequency in KHz 160 * 161 * This is the value the clock ratio is multiplied with 162 * 163 * @return bus-block frequency in KHz 164 */ 165 int cpu_get_bus_clock_khz(void); 166 167 /** 168 * cpu_get_power_max() - Get maximum CPU TDP 169 * 170 * @return maximum CPU TDP (Thermal-design power) in mW 171 */ 172 int cpu_get_power_max(void); 173 174 /** 175 * cpu_get_max_turbo_ratio() - Get maximum turbo ratio 176 * 177 * @return maximum ratio 178 */ 179 int cpu_get_max_turbo_ratio(void); 180 181 /** 182 * cpu_get_cores_per_package() - Get the number of CPU cores in each package 183 * 184 * @return number of cores 185 */ 186 int cpu_get_cores_per_package(void); 187 188 /** 189 * cpu_mca_configure() - Set up machine-check exceptions ready for use 190 * 191 * These allow the SoC to report errors while running. See here for details: 192 * 193 * https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/machine-check-exceptions-debug-paper.pdf 194 */ 195 void cpu_mca_configure(void); 196 197 #endif 198