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