1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2014 Google Inc.
4 * Copyright (c) 2016 Google, Inc
5 * Copyright (C) 2015-2018 Intel Corporation.
6 * Copyright (C) 2018 Siemens AG
7 * Some code taken from coreboot cpulib.c
16 #include <asm/cpu_common.h>
17 #include <asm/intel_regs.h>
18 #include <asm/lapic.h>
19 #include <asm/lpc_common.h>
23 #include <asm/microcode.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 static int report_bist_failure(void)
29 if (gd->arch.bist != 0) {
30 post_code(POST_BIST_FAILURE);
31 printf("BIST failed: %08x\n", gd->arch.bist);
38 int cpu_common_init(void)
40 struct udevice *dev, *lpc;
43 /* Halt if there was a built in self test failure */
44 ret = report_bist_failure();
50 ret = microcode_update_intel();
51 if (ret && ret != -EEXIST) {
52 debug("%s: Microcode update failure (err=%d)\n", __func__, ret);
56 /* Enable upper 128bytes of CMOS */
57 writel(1 << 2, RCB_REG(RC));
59 /* Early chipset init required before RAM init can work */
60 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
62 ret = uclass_first_device(UCLASS_LPC, &lpc);
68 /* Cause the SATA device to do its early init */
69 uclass_first_device(UCLASS_AHCI, &dev);
74 int cpu_set_flex_ratio_to_tdp_nominal(void)
76 msr_t flex_ratio, msr;
79 /* Check for Flex Ratio support */
80 flex_ratio = msr_read(MSR_FLEX_RATIO);
81 if (!(flex_ratio.lo & FLEX_RATIO_EN))
84 /* Check for >0 configurable TDPs */
85 msr = msr_read(MSR_PLATFORM_INFO);
86 if (((msr.hi >> 1) & 3) == 0)
89 /* Use nominal TDP ratio for flex ratio */
90 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
91 nominal_ratio = msr.lo & 0xff;
93 /* See if flex ratio is already set to nominal TDP ratio */
94 if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
97 /* Set flex ratio to nominal TDP ratio */
98 flex_ratio.lo &= ~0xff00;
99 flex_ratio.lo |= nominal_ratio << 8;
100 flex_ratio.lo |= FLEX_RATIO_LOCK;
101 msr_write(MSR_FLEX_RATIO, flex_ratio);
103 /* Set flex ratio in soft reset data register bits 11:6 */
104 clrsetbits_le32(RCB_REG(SOFT_RESET_DATA), 0x3f << 6,
105 (nominal_ratio & 0x3f) << 6);
107 debug("CPU: Soft reset to set up flex ratio\n");
109 /* Set soft reset control to use register value */
110 setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
112 /* Issue warm reset, will be "CPU only" due to soft reset data */
113 outb(0x0, IO_PORT_RESET);
114 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
121 int cpu_intel_get_info(struct cpu_info *info, int bclk)
125 msr = msr_read(MSR_IA32_PERF_CTL);
126 info->cpu_freq = ((msr.lo >> 8) & 0xff) * bclk * 1000000;
127 info->features = 1 << CPU_FEAT_L1_CACHE | 1 << CPU_FEAT_MMU |
128 1 << CPU_FEAT_UCODE | 1 << CPU_FEAT_DEVICE_ID;
133 int cpu_configure_thermal_target(struct udevice *dev)
139 ret = dev_read_u32(dev, "tcc-offset", &tcc_offset);
143 /* Set TCC activaiton offset if supported */
144 msr = msr_read(MSR_PLATFORM_INFO);
145 if (msr.lo & (1 << 30)) {
146 msr = msr_read(MSR_TEMPERATURE_TARGET);
147 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
148 msr.lo |= (tcc_offset & 0xf) << 24;
149 msr_write(MSR_TEMPERATURE_TARGET, msr);
155 void cpu_set_perf_control(uint clk_ratio)
159 perf_ctl.lo = (clk_ratio & 0xff) << 8;
161 msr_write(MSR_IA32_PERF_CTL, perf_ctl);
162 debug("CPU: frequency set to %d MHz\n", clk_ratio * INTEL_BCLK_MHZ);
165 bool cpu_config_tdp_levels(void)
169 /* Bits 34:33 indicate how many levels supported */
170 platform_info = msr_read(MSR_PLATFORM_INFO);
172 return ((platform_info.hi >> 1) & 3) != 0;
175 void cpu_set_p_state_to_turbo_ratio(void)
179 msr = msr_read(MSR_TURBO_RATIO_LIMIT);
180 cpu_set_perf_control(msr.lo);
183 enum burst_mode_t cpu_get_burst_mode_state(void)
185 enum burst_mode_t state;
186 int burst_en, burst_cap;
190 eax = cpuid_eax(0x6);
191 burst_cap = eax & 0x2;
192 msr = msr_read(MSR_IA32_MISC_ENABLE);
193 burst_en = !(msr.hi & BURST_MODE_DISABLE);
195 if (!burst_cap && burst_en)
196 state = BURST_MODE_UNAVAILABLE;
197 else if (burst_cap && !burst_en)
198 state = BURST_MODE_DISABLED;
199 else if (burst_cap && burst_en)
200 state = BURST_MODE_ENABLED;
202 state = BURST_MODE_UNKNOWN;
207 void cpu_set_burst_mode(bool burst_mode)
211 msr = msr_read(MSR_IA32_MISC_ENABLE);
213 msr.hi &= ~BURST_MODE_DISABLE;
215 msr.hi |= BURST_MODE_DISABLE;
216 msr_write(MSR_IA32_MISC_ENABLE, msr);
219 void cpu_set_eist(bool eist_status)
223 msr = msr_read(MSR_IA32_MISC_ENABLE);
225 msr.lo |= MISC_ENABLE_ENHANCED_SPEEDSTEP;
227 msr.lo &= ~MISC_ENABLE_ENHANCED_SPEEDSTEP;
228 msr_write(MSR_IA32_MISC_ENABLE, msr);