2 * Copyright (c) 2016 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0
10 #include <asm/cpu_common.h>
11 #include <asm/intel_regs.h>
12 #include <asm/lapic.h>
13 #include <asm/lpc_common.h>
17 #include <asm/microcode.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 static int report_bist_failure(void)
23 if (gd->arch.bist != 0) {
24 post_code(POST_BIST_FAILURE);
25 printf("BIST failed: %08x\n", gd->arch.bist);
32 int cpu_common_init(void)
34 struct udevice *dev, *lpc;
37 /* Halt if there was a built in self test failure */
38 ret = report_bist_failure();
44 ret = microcode_update_intel();
45 if (ret && ret != -EEXIST)
48 /* Enable upper 128bytes of CMOS */
49 writel(1 << 2, RCB_REG(RC));
51 /* Early chipset init required before RAM init can work */
52 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
54 ret = uclass_first_device(UCLASS_LPC, &lpc);
60 /* Cause the SATA device to do its early init */
61 uclass_first_device(UCLASS_DISK, &dev);
66 int cpu_set_flex_ratio_to_tdp_nominal(void)
68 msr_t flex_ratio, msr;
71 /* Check for Flex Ratio support */
72 flex_ratio = msr_read(MSR_FLEX_RATIO);
73 if (!(flex_ratio.lo & FLEX_RATIO_EN))
76 /* Check for >0 configurable TDPs */
77 msr = msr_read(MSR_PLATFORM_INFO);
78 if (((msr.hi >> 1) & 3) == 0)
81 /* Use nominal TDP ratio for flex ratio */
82 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
83 nominal_ratio = msr.lo & 0xff;
85 /* See if flex ratio is already set to nominal TDP ratio */
86 if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
89 /* Set flex ratio to nominal TDP ratio */
90 flex_ratio.lo &= ~0xff00;
91 flex_ratio.lo |= nominal_ratio << 8;
92 flex_ratio.lo |= FLEX_RATIO_LOCK;
93 msr_write(MSR_FLEX_RATIO, flex_ratio);
95 /* Set flex ratio in soft reset data register bits 11:6 */
96 clrsetbits_le32(RCB_REG(SOFT_RESET_DATA), 0x3f << 6,
97 (nominal_ratio & 0x3f) << 6);
99 debug("CPU: Soft reset to set up flex ratio\n");
101 /* Set soft reset control to use register value */
102 setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
104 /* Issue warm reset, will be "CPU only" due to soft reset data */
105 outb(0x0, PORT_RESET);
106 outb(SYS_RST | RST_CPU, PORT_RESET);