Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 6 | #include <cpu/cpu.h> |
| 7 | #include <cpu/x86/mtrr.h> |
| 8 | #include <cpu/x86/msr.h> |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 9 | #include <cpu/x86/mp.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 10 | #include <cpu/x86/lapic.h> |
| 11 | #include <cpu/intel/microcode.h> |
Kyösti Mälkki | faf20d3 | 2019-08-14 05:41:41 +0300 | [diff] [blame] | 12 | #include <cpu/intel/smm_reloc.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 13 | #include <cpu/intel/speedstep.h> |
| 14 | #include <cpu/intel/turbo.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | #include <cpu/x86/name.h> |
Aaron Durbin | f24262d | 2013-04-10 14:59:21 -0500 | [diff] [blame] | 16 | #include <delay.h> |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 17 | #include <northbridge/intel/haswell/haswell.h> |
| 18 | #include <southbridge/intel/lynxpoint/pch.h> |
Matt DeVillier | ed6fe2f | 2016-12-14 16:12:43 -0600 | [diff] [blame] | 19 | #include <cpu/intel/common/common.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 20 | #include "haswell.h" |
| 21 | #include "chip.h" |
| 22 | |
| 23 | /* |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 24 | * List of supported C-states in this processor. Only the ULT parts support C8, |
| 25 | * C9, and C10. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 26 | */ |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 27 | enum { |
| 28 | C_STATE_C0, /* 0 */ |
| 29 | C_STATE_C1, /* 1 */ |
| 30 | C_STATE_C1E, /* 2 */ |
| 31 | C_STATE_C3, /* 3 */ |
| 32 | C_STATE_C6_SHORT_LAT, /* 4 */ |
| 33 | C_STATE_C6_LONG_LAT, /* 5 */ |
| 34 | C_STATE_C7_SHORT_LAT, /* 6 */ |
| 35 | C_STATE_C7_LONG_LAT, /* 7 */ |
| 36 | C_STATE_C7S_SHORT_LAT, /* 8 */ |
| 37 | C_STATE_C7S_LONG_LAT, /* 9 */ |
| 38 | C_STATE_C8, /* 10 */ |
| 39 | C_STATE_C9, /* 11 */ |
| 40 | C_STATE_C10, /* 12 */ |
| 41 | NUM_C_STATES |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 42 | }; |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 43 | |
| 44 | #define MWAIT_RES(state, sub_state) \ |
| 45 | { \ |
| 46 | .addrl = (((state) << 4) | (sub_state)), \ |
| 47 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 48 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 49 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 50 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
| 51 | } |
| 52 | |
| 53 | static acpi_cstate_t cstate_map[NUM_C_STATES] = { |
| 54 | [C_STATE_C0] = { }, |
| 55 | [C_STATE_C1] = { |
| 56 | .latency = 0, |
| 57 | .power = 1000, |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 58 | .resource = MWAIT_RES(0, 0), |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 59 | }, |
| 60 | [C_STATE_C1E] = { |
| 61 | .latency = 0, |
| 62 | .power = 1000, |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 63 | .resource = MWAIT_RES(0, 1), |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 64 | }, |
| 65 | [C_STATE_C3] = { |
| 66 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 67 | .power = 900, |
| 68 | .resource = MWAIT_RES(1, 0), |
| 69 | }, |
| 70 | [C_STATE_C6_SHORT_LAT] = { |
| 71 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
| 72 | .power = 800, |
| 73 | .resource = MWAIT_RES(2, 0), |
| 74 | }, |
| 75 | [C_STATE_C6_LONG_LAT] = { |
| 76 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
| 77 | .power = 800, |
| 78 | .resource = MWAIT_RES(2, 1), |
| 79 | }, |
| 80 | [C_STATE_C7_SHORT_LAT] = { |
| 81 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
| 82 | .power = 700, |
| 83 | .resource = MWAIT_RES(3, 0), |
| 84 | }, |
| 85 | [C_STATE_C7_LONG_LAT] = { |
| 86 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
| 87 | .power = 700, |
| 88 | .resource = MWAIT_RES(3, 1), |
| 89 | }, |
| 90 | [C_STATE_C7S_SHORT_LAT] = { |
| 91 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
| 92 | .power = 700, |
| 93 | .resource = MWAIT_RES(3, 2), |
| 94 | }, |
| 95 | [C_STATE_C7S_LONG_LAT] = { |
| 96 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
| 97 | .power = 700, |
| 98 | .resource = MWAIT_RES(3, 3), |
| 99 | }, |
| 100 | [C_STATE_C8] = { |
| 101 | .latency = C_STATE_LATENCY_FROM_LAT_REG(3), |
| 102 | .power = 600, |
| 103 | .resource = MWAIT_RES(4, 0), |
| 104 | }, |
| 105 | [C_STATE_C9] = { |
| 106 | .latency = C_STATE_LATENCY_FROM_LAT_REG(4), |
| 107 | .power = 500, |
| 108 | .resource = MWAIT_RES(5, 0), |
| 109 | }, |
| 110 | [C_STATE_C10] = { |
| 111 | .latency = C_STATE_LATENCY_FROM_LAT_REG(5), |
| 112 | .power = 400, |
| 113 | .resource = MWAIT_RES(6, 0), |
| 114 | }, |
| 115 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 116 | |
| 117 | /* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */ |
| 118 | static const u8 power_limit_time_sec_to_msr[] = { |
| 119 | [0] = 0x00, |
| 120 | [1] = 0x0a, |
| 121 | [2] = 0x0b, |
| 122 | [3] = 0x4b, |
| 123 | [4] = 0x0c, |
| 124 | [5] = 0x2c, |
| 125 | [6] = 0x4c, |
| 126 | [7] = 0x6c, |
| 127 | [8] = 0x0d, |
| 128 | [10] = 0x2d, |
| 129 | [12] = 0x4d, |
| 130 | [14] = 0x6d, |
| 131 | [16] = 0x0e, |
| 132 | [20] = 0x2e, |
| 133 | [24] = 0x4e, |
| 134 | [28] = 0x6e, |
| 135 | [32] = 0x0f, |
| 136 | [40] = 0x2f, |
| 137 | [48] = 0x4f, |
| 138 | [56] = 0x6f, |
| 139 | [64] = 0x10, |
| 140 | [80] = 0x30, |
| 141 | [96] = 0x50, |
| 142 | [112] = 0x70, |
| 143 | [128] = 0x11, |
| 144 | }; |
| 145 | |
| 146 | /* Convert POWER_LIMIT_1_TIME MSR value to seconds */ |
| 147 | static const u8 power_limit_time_msr_to_sec[] = { |
| 148 | [0x00] = 0, |
| 149 | [0x0a] = 1, |
| 150 | [0x0b] = 2, |
| 151 | [0x4b] = 3, |
| 152 | [0x0c] = 4, |
| 153 | [0x2c] = 5, |
| 154 | [0x4c] = 6, |
| 155 | [0x6c] = 7, |
| 156 | [0x0d] = 8, |
| 157 | [0x2d] = 10, |
| 158 | [0x4d] = 12, |
| 159 | [0x6d] = 14, |
| 160 | [0x0e] = 16, |
| 161 | [0x2e] = 20, |
| 162 | [0x4e] = 24, |
| 163 | [0x6e] = 28, |
| 164 | [0x0f] = 32, |
| 165 | [0x2f] = 40, |
| 166 | [0x4f] = 48, |
| 167 | [0x6f] = 56, |
| 168 | [0x10] = 64, |
| 169 | [0x30] = 80, |
| 170 | [0x50] = 96, |
| 171 | [0x70] = 112, |
| 172 | [0x11] = 128, |
| 173 | }; |
| 174 | |
Angel Pons | 5d92aa5 | 2020-10-14 00:02:37 +0200 | [diff] [blame] | 175 | /* The core 100MHz BCLK is disabled in deeper c-states. One needs to calibrate |
| 176 | * the 100MHz BCLK against the 24MHz BCLK to restore the clocks properly |
Aaron Durbin | f24262d | 2013-04-10 14:59:21 -0500 | [diff] [blame] | 177 | * when a core is woken up. */ |
| 178 | static int pcode_ready(void) |
| 179 | { |
| 180 | int wait_count; |
| 181 | const int delay_step = 10; |
| 182 | |
| 183 | wait_count = 0; |
| 184 | do { |
| 185 | if (!(MCHBAR32(BIOS_MAILBOX_INTERFACE) & MAILBOX_RUN_BUSY)) |
| 186 | return 0; |
| 187 | wait_count += delay_step; |
| 188 | udelay(delay_step); |
| 189 | } while (wait_count < 1000); |
| 190 | |
| 191 | return -1; |
| 192 | } |
| 193 | |
| 194 | static void calibrate_24mhz_bclk(void) |
| 195 | { |
| 196 | int err_code; |
| 197 | |
| 198 | if (pcode_ready() < 0) { |
| 199 | printk(BIOS_ERR, "PCODE: mailbox timeout on wait ready.\n"); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | /* A non-zero value initiates the PCODE calibration. */ |
| 204 | MCHBAR32(BIOS_MAILBOX_DATA) = ~0; |
| 205 | MCHBAR32(BIOS_MAILBOX_INTERFACE) = |
| 206 | MAILBOX_RUN_BUSY | MAILBOX_BIOS_CMD_FSM_MEASURE_INTVL; |
| 207 | |
| 208 | if (pcode_ready() < 0) { |
| 209 | printk(BIOS_ERR, "PCODE: mailbox timeout on completion.\n"); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | err_code = MCHBAR32(BIOS_MAILBOX_INTERFACE) & 0xff; |
| 214 | |
Angel Pons | 5d92aa5 | 2020-10-14 00:02:37 +0200 | [diff] [blame] | 215 | printk(BIOS_DEBUG, "PCODE: 24MHz BCLK calibration response: %d\n", |
Aaron Durbin | f24262d | 2013-04-10 14:59:21 -0500 | [diff] [blame] | 216 | err_code); |
| 217 | |
| 218 | /* Read the calibrated value. */ |
| 219 | MCHBAR32(BIOS_MAILBOX_INTERFACE) = |
| 220 | MAILBOX_RUN_BUSY | MAILBOX_BIOS_CMD_READ_CALIBRATION; |
| 221 | |
| 222 | if (pcode_ready() < 0) { |
| 223 | printk(BIOS_ERR, "PCODE: mailbox timeout on read.\n"); |
| 224 | return; |
| 225 | } |
| 226 | |
Angel Pons | 5d92aa5 | 2020-10-14 00:02:37 +0200 | [diff] [blame] | 227 | printk(BIOS_DEBUG, "PCODE: 24MHz BCLK calibration value: 0x%08x\n", |
Aaron Durbin | f24262d | 2013-04-10 14:59:21 -0500 | [diff] [blame] | 228 | MCHBAR32(BIOS_MAILBOX_DATA)); |
| 229 | } |
| 230 | |
Duncan Laurie | e1e87e0 | 2013-04-26 10:35:19 -0700 | [diff] [blame] | 231 | static u32 pcode_mailbox_read(u32 command) |
| 232 | { |
| 233 | if (pcode_ready() < 0) { |
| 234 | printk(BIOS_ERR, "PCODE: mailbox timeout on wait ready.\n"); |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | /* Send command and start transaction */ |
| 239 | MCHBAR32(BIOS_MAILBOX_INTERFACE) = command | MAILBOX_RUN_BUSY; |
| 240 | |
| 241 | if (pcode_ready() < 0) { |
| 242 | printk(BIOS_ERR, "PCODE: mailbox timeout on completion.\n"); |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | /* Read mailbox */ |
| 247 | return MCHBAR32(BIOS_MAILBOX_DATA); |
| 248 | } |
| 249 | |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 250 | static void initialize_vr_config(void) |
| 251 | { |
Angel Pons | 242fd28 | 2020-10-28 23:48:56 +0100 | [diff] [blame^] | 252 | struct cpu_vr_config vr_config = { 0 }; |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 253 | msr_t msr; |
| 254 | |
Angel Pons | 242fd28 | 2020-10-28 23:48:56 +0100 | [diff] [blame^] | 255 | const struct device *lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC); |
| 256 | |
| 257 | if (lapic && lapic->chip_info) { |
| 258 | const struct cpu_intel_haswell_config *conf = lapic->chip_info; |
| 259 | |
| 260 | vr_config = conf->vr_config; |
| 261 | } |
| 262 | |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 263 | printk(BIOS_DEBUG, "Initializing VR config.\n"); |
| 264 | |
| 265 | /* Configure VR_CURRENT_CONFIG. */ |
| 266 | msr = rdmsr(MSR_VR_CURRENT_CONFIG); |
| 267 | /* Preserve bits 63 and 62. Bit 62 is PSI4 enable, but it is only valid |
| 268 | * on ULT systems. */ |
| 269 | msr.hi &= 0xc0000000; |
| 270 | msr.hi |= (0x01 << (52 - 32)); /* PSI3 threshold - 1A. */ |
| 271 | msr.hi |= (0x05 << (42 - 32)); /* PSI2 threshold - 5A. */ |
Angel Pons | 9dcd1c1 | 2020-10-28 22:41:26 +0100 | [diff] [blame] | 272 | msr.hi |= (0x14 << (32 - 32)); /* PSI1 threshold - 20A. */ |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 273 | |
Duncan Laurie | 118d105 | 2013-07-09 15:34:25 -0700 | [diff] [blame] | 274 | if (haswell_is_ult()) |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 275 | msr.hi |= (1 << (62 - 32)); /* Enable PSI4 */ |
| 276 | /* Leave the max instantaneous current limit (12:0) to default. */ |
| 277 | wrmsr(MSR_VR_CURRENT_CONFIG, msr); |
| 278 | |
| 279 | /* Configure VR_MISC_CONFIG MSR. */ |
| 280 | msr = rdmsr(MSR_VR_MISC_CONFIG); |
| 281 | /* Set the IOUT_SLOPE scalar applied to dIout in U10.1.9 format. */ |
| 282 | msr.hi &= ~(0x3ff << (40 - 32)); |
| 283 | msr.hi |= (0x200 << (40 - 32)); /* 1.0 */ |
| 284 | /* Set IOUT_OFFSET to 0. */ |
| 285 | msr.hi &= ~0xff; |
| 286 | /* Set exit ramp rate to fast. */ |
| 287 | msr.hi |= (1 << (50 - 32)); |
| 288 | /* Set entry ramp rate to slow. */ |
| 289 | msr.hi &= ~(1 << (51 - 32)); |
| 290 | /* Enable decay mode on C-state entry. */ |
| 291 | msr.hi |= (1 << (52 - 32)); |
Angel Pons | 242fd28 | 2020-10-28 23:48:56 +0100 | [diff] [blame^] | 292 | /* Set the slow ramp rate */ |
Tristan Corrick | fdf907e | 2018-10-31 02:27:12 +1300 | [diff] [blame] | 293 | if (haswell_is_ult()) { |
Tristan Corrick | fdf907e | 2018-10-31 02:27:12 +1300 | [diff] [blame] | 294 | msr.hi &= ~(0x3 << (53 - 32)); |
Angel Pons | 242fd28 | 2020-10-28 23:48:56 +0100 | [diff] [blame^] | 295 | /* Configure the C-state exit ramp rate. */ |
| 296 | if (vr_config.slow_ramp_rate_enable) { |
| 297 | /* Configured slow ramp rate. */ |
| 298 | msr.hi |= ((vr_config.slow_ramp_rate_set & 0x3) << (53 - 32)); |
| 299 | /* Set exit ramp rate to slow. */ |
| 300 | msr.hi &= ~(1 << (50 - 32)); |
| 301 | } else { |
| 302 | /* Fast ramp rate / 4. */ |
| 303 | msr.hi |= (1 << (53 - 32)); |
| 304 | } |
Tristan Corrick | fdf907e | 2018-10-31 02:27:12 +1300 | [diff] [blame] | 305 | } |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 306 | /* Set MIN_VID (31:24) to allow CPU to have full control. */ |
| 307 | msr.lo &= ~0xff000000; |
Angel Pons | 242fd28 | 2020-10-28 23:48:56 +0100 | [diff] [blame^] | 308 | msr.lo |= (vr_config.cpu_min_vid & 0xff) << 24; |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 309 | wrmsr(MSR_VR_MISC_CONFIG, msr); |
| 310 | |
| 311 | /* Configure VR_MISC_CONFIG2 MSR. */ |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 312 | if (!haswell_is_ult()) |
| 313 | return; |
| 314 | |
| 315 | msr = rdmsr(MSR_VR_MISC_CONFIG2); |
| 316 | msr.lo &= ~0xffff; |
| 317 | /* Allow CPU to control minimum voltage completely (15:8) and |
| 318 | * set the fast ramp voltage to 1110mV (0x6f in 10mV steps). */ |
| 319 | msr.lo |= 0x006f; |
| 320 | wrmsr(MSR_VR_MISC_CONFIG2, msr); |
Aaron Durbin | 16cbf89 | 2013-07-03 16:21:28 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Duncan Laurie | e1e87e0 | 2013-04-26 10:35:19 -0700 | [diff] [blame] | 323 | static void configure_pch_power_sharing(void) |
| 324 | { |
| 325 | u32 pch_power, pch_power_ext, pmsync, pmsync2; |
| 326 | int i; |
| 327 | |
| 328 | /* Read PCH Power levels from PCODE */ |
| 329 | pch_power = pcode_mailbox_read(MAILBOX_BIOS_CMD_READ_PCH_POWER); |
| 330 | pch_power_ext = pcode_mailbox_read(MAILBOX_BIOS_CMD_READ_PCH_POWER_EXT); |
| 331 | |
| 332 | printk(BIOS_INFO, "PCH Power: PCODE Levels 0x%08x 0x%08x\n", |
Lee Leahy | 7b5f12b9 | 2017-03-15 17:16:59 -0700 | [diff] [blame] | 333 | pch_power, pch_power_ext); |
Duncan Laurie | e1e87e0 | 2013-04-26 10:35:19 -0700 | [diff] [blame] | 334 | |
| 335 | pmsync = RCBA32(PMSYNC_CONFIG); |
| 336 | pmsync2 = RCBA32(PMSYNC_CONFIG2); |
| 337 | |
| 338 | /* Program PMSYNC_TPR_CONFIG PCH power limit values |
| 339 | * pmsync[0:4] = mailbox[0:5] |
| 340 | * pmsync[8:12] = mailbox[6:11] |
| 341 | * pmsync[16:20] = mailbox[12:17] |
| 342 | */ |
| 343 | for (i = 0; i < 3; i++) { |
| 344 | u32 level = pch_power & 0x3f; |
| 345 | pch_power >>= 6; |
| 346 | pmsync &= ~(0x1f << (i * 8)); |
| 347 | pmsync |= (level & 0x1f) << (i * 8); |
| 348 | } |
| 349 | RCBA32(PMSYNC_CONFIG) = pmsync; |
| 350 | |
| 351 | /* Program PMSYNC_TPR_CONFIG2 Extended PCH power limit values |
| 352 | * pmsync2[0:4] = mailbox[23:18] |
| 353 | * pmsync2[8:12] = mailbox_ext[6:11] |
| 354 | * pmsync2[16:20] = mailbox_ext[12:17] |
| 355 | * pmsync2[24:28] = mailbox_ext[18:22] |
| 356 | */ |
| 357 | pmsync2 &= ~0x1f; |
| 358 | pmsync2 |= pch_power & 0x1f; |
| 359 | |
| 360 | for (i = 1; i < 4; i++) { |
| 361 | u32 level = pch_power_ext & 0x3f; |
| 362 | pch_power_ext >>= 6; |
| 363 | pmsync2 &= ~(0x1f << (i * 8)); |
| 364 | pmsync2 |= (level & 0x1f) << (i * 8); |
| 365 | } |
| 366 | RCBA32(PMSYNC_CONFIG2) = pmsync2; |
| 367 | } |
| 368 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 369 | int cpu_config_tdp_levels(void) |
| 370 | { |
| 371 | msr_t platform_info; |
| 372 | |
| 373 | /* Bits 34:33 indicate how many levels supported */ |
| 374 | platform_info = rdmsr(MSR_PLATFORM_INFO); |
| 375 | return (platform_info.hi >> 1) & 3; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Configure processor power limits if possible |
| 380 | * This must be done AFTER set of BIOS_RESET_CPL |
| 381 | */ |
| 382 | void set_power_limits(u8 power_limit_1_time) |
| 383 | { |
| 384 | msr_t msr = rdmsr(MSR_PLATFORM_INFO); |
| 385 | msr_t limit; |
Lee Leahy | 73a2894 | 2017-03-15 17:52:06 -0700 | [diff] [blame] | 386 | unsigned int power_unit; |
| 387 | unsigned int tdp, min_power, max_power, max_time; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 388 | u8 power_limit_1_val; |
| 389 | |
Edward O'Callaghan | 5cfef13 | 2014-08-03 20:00:47 +1000 | [diff] [blame] | 390 | if (power_limit_1_time >= ARRAY_SIZE(power_limit_time_sec_to_msr)) |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 391 | power_limit_1_time = ARRAY_SIZE(power_limit_time_sec_to_msr) - 1; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 392 | |
| 393 | if (!(msr.lo & PLATFORM_INFO_SET_TDP)) |
| 394 | return; |
| 395 | |
| 396 | /* Get units */ |
| 397 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 398 | power_unit = 2 << ((msr.lo & 0xf) - 1); |
| 399 | |
| 400 | /* Get power defaults for this SKU */ |
| 401 | msr = rdmsr(MSR_PKG_POWER_SKU); |
| 402 | tdp = msr.lo & 0x7fff; |
| 403 | min_power = (msr.lo >> 16) & 0x7fff; |
| 404 | max_power = msr.hi & 0x7fff; |
| 405 | max_time = (msr.hi >> 16) & 0x7f; |
| 406 | |
| 407 | printk(BIOS_DEBUG, "CPU TDP: %u Watts\n", tdp / power_unit); |
| 408 | |
| 409 | if (power_limit_time_msr_to_sec[max_time] > power_limit_1_time) |
| 410 | power_limit_1_time = power_limit_time_msr_to_sec[max_time]; |
| 411 | |
| 412 | if (min_power > 0 && tdp < min_power) |
| 413 | tdp = min_power; |
| 414 | |
| 415 | if (max_power > 0 && tdp > max_power) |
| 416 | tdp = max_power; |
| 417 | |
| 418 | power_limit_1_val = power_limit_time_sec_to_msr[power_limit_1_time]; |
| 419 | |
| 420 | /* Set long term power limit to TDP */ |
| 421 | limit.lo = 0; |
| 422 | limit.lo |= tdp & PKG_POWER_LIMIT_MASK; |
| 423 | limit.lo |= PKG_POWER_LIMIT_EN; |
| 424 | limit.lo |= (power_limit_1_val & PKG_POWER_LIMIT_TIME_MASK) << |
| 425 | PKG_POWER_LIMIT_TIME_SHIFT; |
| 426 | |
| 427 | /* Set short term power limit to 1.25 * TDP */ |
| 428 | limit.hi = 0; |
| 429 | limit.hi |= ((tdp * 125) / 100) & PKG_POWER_LIMIT_MASK; |
| 430 | limit.hi |= PKG_POWER_LIMIT_EN; |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 431 | /* Power limit 2 time is only programmable on server SKU */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 432 | |
| 433 | wrmsr(MSR_PKG_POWER_LIMIT, limit); |
| 434 | |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 435 | /* Set power limit values in MCHBAR as well */ |
| 436 | MCHBAR32(MCH_PKG_POWER_LIMIT_LO) = limit.lo; |
| 437 | MCHBAR32(MCH_PKG_POWER_LIMIT_HI) = limit.hi; |
| 438 | |
| 439 | /* Set DDR RAPL power limit by copying from MMIO to MSR */ |
| 440 | msr.lo = MCHBAR32(MCH_DDR_POWER_LIMIT_LO); |
| 441 | msr.hi = MCHBAR32(MCH_DDR_POWER_LIMIT_HI); |
| 442 | wrmsr(MSR_DDR_RAPL_LIMIT, msr); |
| 443 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 444 | /* Use nominal TDP values for CPUs with configurable TDP */ |
| 445 | if (cpu_config_tdp_levels()) { |
| 446 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 447 | limit.hi = 0; |
| 448 | limit.lo = msr.lo & 0xff; |
| 449 | wrmsr(MSR_TURBO_ACTIVATION_RATIO, limit); |
| 450 | } |
| 451 | } |
| 452 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 453 | static void configure_c_states(void) |
| 454 | { |
| 455 | msr_t msr; |
| 456 | |
Elyes HAOUAS | 4e6b790 | 2018-10-02 08:44:47 +0200 | [diff] [blame] | 457 | msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL); |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 458 | msr.lo |= (1 << 30); // Package c-state Undemotion Enable |
| 459 | msr.lo |= (1 << 29); // Package c-state Demotion Enable |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 460 | msr.lo |= (1 << 28); // C1 Auto Undemotion Enable |
| 461 | msr.lo |= (1 << 27); // C3 Auto Undemotion Enable |
| 462 | msr.lo |= (1 << 26); // C1 Auto Demotion Enable |
| 463 | msr.lo |= (1 << 25); // C3 Auto Demotion Enable |
| 464 | msr.lo &= ~(1 << 10); // Disable IO MWAIT redirection |
Duncan Laurie | 1c09710 | 2013-05-07 13:19:56 -0700 | [diff] [blame] | 465 | /* The deepest package c-state defaults to factory-configured value. */ |
Elyes HAOUAS | 4e6b790 | 2018-10-02 08:44:47 +0200 | [diff] [blame] | 466 | wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 467 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 468 | msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 469 | msr.lo &= ~(1 << 0); // Enable P-state HW_ALL coordination |
| 470 | wrmsr(MSR_MISC_PWR_MGMT, msr); |
| 471 | |
| 472 | msr = rdmsr(MSR_POWER_CTL); |
| 473 | msr.lo |= (1 << 18); // Enable Energy Perf Bias MSR 0x1b0 |
| 474 | msr.lo |= (1 << 1); // C1E Enable |
| 475 | msr.lo |= (1 << 0); // Bi-directional PROCHOT# |
| 476 | wrmsr(MSR_POWER_CTL, msr); |
| 477 | |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 478 | /* C-state Interrupt Response Latency Control 0 - package C3 latency */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 479 | msr.hi = 0; |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 480 | msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_0_LIMIT; |
| 481 | wrmsr(MSR_C_STATE_LATENCY_CONTROL_0, msr); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 482 | |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 483 | /* C-state Interrupt Response Latency Control 1 */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 484 | msr.hi = 0; |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 485 | msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_1_LIMIT; |
| 486 | wrmsr(MSR_C_STATE_LATENCY_CONTROL_1, msr); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 487 | |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 488 | /* C-state Interrupt Response Latency Control 2 - package C6/C7 short */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 489 | msr.hi = 0; |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 490 | msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_2_LIMIT; |
| 491 | wrmsr(MSR_C_STATE_LATENCY_CONTROL_2, msr); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 492 | |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 493 | /* Only Haswell ULT supports the 3-5 latency response registers */ |
| 494 | if (!haswell_is_ult()) |
| 495 | return; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 496 | |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 497 | /* C-state Interrupt Response Latency Control 3 - package C8 */ |
| 498 | msr.hi = 0; |
| 499 | msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_3_LIMIT; |
| 500 | wrmsr(MSR_C_STATE_LATENCY_CONTROL_3, msr); |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 501 | |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 502 | /* C-state Interrupt Response Latency Control 4 - package C9 */ |
| 503 | msr.hi = 0; |
| 504 | msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_4_LIMIT; |
| 505 | wrmsr(MSR_C_STATE_LATENCY_CONTROL_4, msr); |
| 506 | |
| 507 | /* C-state Interrupt Response Latency Control 5 - package C10 */ |
| 508 | msr.hi = 0; |
| 509 | msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_5_LIMIT; |
| 510 | wrmsr(MSR_C_STATE_LATENCY_CONTROL_5, msr); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 511 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 512 | |
| 513 | static void configure_thermal_target(void) |
| 514 | { |
| 515 | struct cpu_intel_haswell_config *conf; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 516 | struct device *lapic; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 517 | msr_t msr; |
| 518 | |
| 519 | /* Find pointer to CPU configuration */ |
| 520 | lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC); |
| 521 | if (!lapic || !lapic->chip_info) |
| 522 | return; |
| 523 | conf = lapic->chip_info; |
| 524 | |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 525 | /* Set TCC activation offset if supported */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 526 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 527 | if ((msr.lo & (1 << 30)) && conf->tcc_offset) { |
| 528 | msr = rdmsr(MSR_TEMPERATURE_TARGET); |
| 529 | msr.lo &= ~(0xf << 24); /* Bits 27:24 */ |
| 530 | msr.lo |= (conf->tcc_offset & 0xf) << 24; |
| 531 | wrmsr(MSR_TEMPERATURE_TARGET, msr); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static void configure_misc(void) |
| 536 | { |
| 537 | msr_t msr; |
| 538 | |
| 539 | msr = rdmsr(IA32_MISC_ENABLE); |
| 540 | msr.lo |= (1 << 0); /* Fast String enable */ |
Lee Leahy | 7b5f12b9 | 2017-03-15 17:16:59 -0700 | [diff] [blame] | 541 | msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 542 | msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */ |
| 543 | wrmsr(IA32_MISC_ENABLE, msr); |
| 544 | |
| 545 | /* Disable Thermal interrupts */ |
| 546 | msr.lo = 0; |
| 547 | msr.hi = 0; |
| 548 | wrmsr(IA32_THERM_INTERRUPT, msr); |
| 549 | |
| 550 | /* Enable package critical interrupt only */ |
| 551 | msr.lo = 1 << 4; |
| 552 | msr.hi = 0; |
| 553 | wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr); |
| 554 | } |
| 555 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 556 | static void set_max_ratio(void) |
| 557 | { |
| 558 | msr_t msr, perf_ctl; |
| 559 | |
| 560 | perf_ctl.hi = 0; |
| 561 | |
| 562 | /* Check for configurable TDP option */ |
Angel Pons | 053deb8 | 2020-10-28 22:40:02 +0100 | [diff] [blame] | 563 | if (get_turbo_state() == TURBO_ENABLED) { |
| 564 | msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 565 | perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 566 | } else if (cpu_config_tdp_levels()) { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 567 | /* Set to nominal TDP ratio */ |
| 568 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 569 | perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 570 | } else { |
| 571 | /* Platform Info bits 15:8 give max ratio */ |
| 572 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 573 | perf_ctl.lo = msr.lo & 0xff00; |
| 574 | } |
| 575 | wrmsr(IA32_PERF_CTL, perf_ctl); |
| 576 | |
Angel Pons | f6cf4927 | 2020-09-25 01:14:24 +0200 | [diff] [blame] | 577 | printk(BIOS_DEBUG, "CPU: frequency set to %d\n", |
Angel Pons | ca96549 | 2020-10-28 19:15:36 +0100 | [diff] [blame] | 578 | ((perf_ctl.lo >> 8) & 0xff) * CPU_BCLK); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 579 | } |
| 580 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 581 | static void configure_mca(void) |
| 582 | { |
| 583 | msr_t msr; |
| 584 | int i; |
Aaron Durbin | 24614af | 2013-01-12 01:07:28 -0600 | [diff] [blame] | 585 | int num_banks; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 586 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 587 | msr = rdmsr(IA32_MCG_CAP); |
Aaron Durbin | 24614af | 2013-01-12 01:07:28 -0600 | [diff] [blame] | 588 | num_banks = msr.lo & 0xff; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 589 | msr.lo = msr.hi = 0; |
Aaron Durbin | 24614af | 2013-01-12 01:07:28 -0600 | [diff] [blame] | 590 | /* TODO(adurbin): This should only be done on a cold boot. Also, some |
| 591 | * of these banks are core vs package scope. For now every CPU clears |
| 592 | * every bank. */ |
| 593 | for (i = 0; i < num_banks; i++) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 594 | wrmsr(IA32_MC0_STATUS + (i * 4), msr); |
| 595 | } |
| 596 | |
Aaron Durbin | 305b1f0 | 2013-01-15 08:27:05 -0600 | [diff] [blame] | 597 | /* All CPUs including BSP will run the following function. */ |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 598 | static void cpu_core_init(struct device *cpu) |
Aaron Durbin | 7af2069 | 2013-01-14 14:54:41 -0600 | [diff] [blame] | 599 | { |
| 600 | /* Clear out pending MCEs */ |
| 601 | configure_mca(); |
| 602 | |
Elyes HAOUAS | d6e9686 | 2016-08-21 10:12:15 +0200 | [diff] [blame] | 603 | /* Enable the local CPU APICs */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 604 | enable_lapic_tpr(); |
| 605 | setup_lapic(); |
| 606 | |
Matt DeVillier | ed6fe2f | 2016-12-14 16:12:43 -0600 | [diff] [blame] | 607 | /* Set virtualization based on Kconfig option */ |
Matt DeVillier | f9aed65 | 2018-12-15 15:57:33 -0600 | [diff] [blame] | 608 | set_vmx_and_lock(); |
Matt DeVillier | b2a14fb | 2014-07-07 18:48:16 -0500 | [diff] [blame] | 609 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 610 | /* Configure C States */ |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 611 | configure_c_states(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 612 | |
| 613 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 614 | configure_misc(); |
| 615 | |
| 616 | /* Thermal throttle activation offset */ |
| 617 | configure_thermal_target(); |
| 618 | |
| 619 | /* Enable Direct Cache Access */ |
| 620 | configure_dca_cap(); |
| 621 | |
| 622 | /* Set energy policy */ |
| 623 | set_energy_perf_bias(ENERGY_POLICY_NORMAL); |
| 624 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 625 | /* Enable Turbo */ |
| 626 | enable_turbo(); |
Aaron Durbin | 7af2069 | 2013-01-14 14:54:41 -0600 | [diff] [blame] | 627 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 628 | |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 629 | /* MP initialization support. */ |
| 630 | static const void *microcode_patch; |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 631 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 632 | static void pre_mp_init(void) |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 633 | { |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 634 | /* Setup MTRRs based on physical address size. */ |
| 635 | x86_setup_mtrrs_with_detect(); |
| 636 | x86_mtrr_check(); |
| 637 | |
| 638 | initialize_vr_config(); |
| 639 | |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 640 | if (!haswell_is_ult()) |
| 641 | return; |
| 642 | |
| 643 | calibrate_24mhz_bclk(); |
| 644 | configure_pch_power_sharing(); |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 645 | } |
| 646 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 647 | static int get_cpu_count(void) |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 648 | { |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 649 | msr_t msr; |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 650 | int num_threads; |
| 651 | int num_cores; |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 652 | |
Elyes HAOUAS | a6a396d | 2019-05-26 13:25:30 +0200 | [diff] [blame] | 653 | msr = rdmsr(MSR_CORE_THREAD_COUNT); |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 654 | num_threads = (msr.lo >> 0) & 0xffff; |
| 655 | num_cores = (msr.lo >> 16) & 0xffff; |
| 656 | printk(BIOS_DEBUG, "CPU has %u cores, %u threads enabled.\n", |
| 657 | num_cores, num_threads); |
| 658 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 659 | return num_threads; |
| 660 | } |
Aaron Durbin | 7af2069 | 2013-01-14 14:54:41 -0600 | [diff] [blame] | 661 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 662 | static void get_microcode_info(const void **microcode, int *parallel) |
| 663 | { |
Aaron Durbin | 305b1f0 | 2013-01-15 08:27:05 -0600 | [diff] [blame] | 664 | microcode_patch = intel_microcode_find(); |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 665 | *microcode = microcode_patch; |
| 666 | *parallel = 1; |
| 667 | } |
Aaron Durbin | 7af2069 | 2013-01-14 14:54:41 -0600 | [diff] [blame] | 668 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 669 | static void per_cpu_smm_trigger(void) |
| 670 | { |
| 671 | /* Relocate the SMM handler. */ |
| 672 | smm_relocate(); |
Aaron Durbin | 305b1f0 | 2013-01-15 08:27:05 -0600 | [diff] [blame] | 673 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 674 | /* After SMM relocation a 2nd microcode load is required. */ |
| 675 | intel_microcode_load_unlocked(microcode_patch); |
| 676 | } |
| 677 | |
| 678 | static void post_mp_init(void) |
| 679 | { |
Angel Pons | 053deb8 | 2020-10-28 22:40:02 +0100 | [diff] [blame] | 680 | /* Set Max Ratio */ |
| 681 | set_max_ratio(); |
| 682 | |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 683 | /* Now that all APs have been relocated as well as the BSP let SMIs |
| 684 | * start flowing. */ |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 685 | global_smi_enable(); |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 686 | |
| 687 | /* Lock down the SMRAM space. */ |
| 688 | smm_lock(); |
| 689 | } |
| 690 | |
| 691 | static const struct mp_ops mp_ops = { |
| 692 | .pre_mp_init = pre_mp_init, |
| 693 | .get_cpu_count = get_cpu_count, |
| 694 | .get_smm_info = smm_info, |
| 695 | .get_microcode_info = get_microcode_info, |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 696 | .pre_mp_smm_init = smm_initialize, |
| 697 | .per_cpu_smm_trigger = per_cpu_smm_trigger, |
| 698 | .relocation_handler = smm_relocation_handler, |
| 699 | .post_mp_init = post_mp_init, |
| 700 | }; |
| 701 | |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 702 | void mp_init_cpus(struct bus *cpu_bus) |
Aaron Durbin | 463af33 | 2016-05-03 17:26:35 -0500 | [diff] [blame] | 703 | { |
Lee Leahy | 26eeb0f | 2017-03-15 18:08:50 -0700 | [diff] [blame] | 704 | if (mp_init_with_smm(cpu_bus, &mp_ops)) |
Aaron Durbin | 014baea | 2014-03-28 22:01:05 -0500 | [diff] [blame] | 705 | printk(BIOS_ERR, "MP initialization failure.\n"); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static struct device_operations cpu_dev_ops = { |
Angel Pons | 4c95f10 | 2020-10-28 19:38:12 +0100 | [diff] [blame] | 709 | .init = cpu_core_init, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 710 | }; |
| 711 | |
Jonathan Neuschäfer | 8f06ce3 | 2017-11-20 01:56:44 +0100 | [diff] [blame] | 712 | static const struct cpu_device_id cpu_table[] = { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 713 | { X86_VENDOR_INTEL, 0x306c1 }, /* Intel Haswell 4+2 A0 */ |
| 714 | { X86_VENDOR_INTEL, 0x306c2 }, /* Intel Haswell 4+2 B0 */ |
Tristan Corrick | 22f9700 | 2018-10-31 02:22:39 +1300 | [diff] [blame] | 715 | { X86_VENDOR_INTEL, 0x306c3 }, /* Intel Haswell C0 */ |
Duncan Laurie | 51254049 | 2012-12-17 11:24:45 -0800 | [diff] [blame] | 716 | { X86_VENDOR_INTEL, 0x40650 }, /* Intel Haswell ULT B0 */ |
| 717 | { X86_VENDOR_INTEL, 0x40651 }, /* Intel Haswell ULT B1 */ |
Iru Cai | 27126f1 | 2020-07-30 23:04:03 +0800 | [diff] [blame] | 718 | { X86_VENDOR_INTEL, 0x40660 }, /* Intel Crystal Well C0 */ |
| 719 | { X86_VENDOR_INTEL, 0x40661 }, /* Intel Crystal Well C1 */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 720 | { 0, 0 }, |
| 721 | }; |
| 722 | |
| 723 | static const struct cpu_driver driver __cpu_driver = { |
| 724 | .ops = &cpu_dev_ops, |
| 725 | .id_table = cpu_table, |
Aaron Durbin | 7c35131 | 2013-04-10 14:46:25 -0500 | [diff] [blame] | 726 | .cstates = cstate_map, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 727 | }; |