blob: 0fdef6f3690b50ef1c472fa07fd4b7d8de771634 [file] [log] [blame]
Simon Glass780ba482016-03-11 22:06:58 -07001/*
2 * Copyright (c) 2016 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
10#include <asm/cpu_common.h>
11#include <asm/intel_regs.h>
12#include <asm/lapic.h>
13#include <asm/lpc_common.h>
14#include <asm/msr.h>
15#include <asm/mtrr.h>
16#include <asm/post.h>
17#include <asm/microcode.h>
18
19DECLARE_GLOBAL_DATA_PTR;
20
21static int report_bist_failure(void)
22{
23 if (gd->arch.bist != 0) {
24 post_code(POST_BIST_FAILURE);
25 printf("BIST failed: %08x\n", gd->arch.bist);
26 return -EFAULT;
27 }
28
29 return 0;
30}
31
32int cpu_common_init(void)
33{
34 struct udevice *dev, *lpc;
35 int ret;
36
37 /* Halt if there was a built in self test failure */
38 ret = report_bist_failure();
39 if (ret)
40 return ret;
41
42 enable_lapic();
43
44 ret = microcode_update_intel();
45 if (ret && ret != -EEXIST)
46 return ret;
47
48 /* Enable upper 128bytes of CMOS */
49 writel(1 << 2, RCB_REG(RC));
50
51 /* Early chipset init required before RAM init can work */
52 uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
53
54 ret = uclass_first_device(UCLASS_LPC, &lpc);
55 if (ret)
56 return ret;
57 if (!lpc)
58 return -ENODEV;
59
60 /* Cause the SATA device to do its early init */
Simon Glass85ee1652016-05-01 11:35:52 -060061 uclass_first_device(UCLASS_AHCI, &dev);
Simon Glass780ba482016-03-11 22:06:58 -070062
63 return 0;
64}
65
66int cpu_set_flex_ratio_to_tdp_nominal(void)
67{
68 msr_t flex_ratio, msr;
69 u8 nominal_ratio;
70
71 /* Check for Flex Ratio support */
72 flex_ratio = msr_read(MSR_FLEX_RATIO);
73 if (!(flex_ratio.lo & FLEX_RATIO_EN))
74 return -EINVAL;
75
76 /* Check for >0 configurable TDPs */
77 msr = msr_read(MSR_PLATFORM_INFO);
78 if (((msr.hi >> 1) & 3) == 0)
79 return -EINVAL;
80
81 /* Use nominal TDP ratio for flex ratio */
82 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
83 nominal_ratio = msr.lo & 0xff;
84
85 /* See if flex ratio is already set to nominal TDP ratio */
86 if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
87 return 0;
88
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);
94
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);
98
99 debug("CPU: Soft reset to set up flex ratio\n");
100
101 /* Set soft reset control to use register value */
102 setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
103
104 /* Issue warm reset, will be "CPU only" due to soft reset data */
Simon Glass8b73e9f2016-03-11 22:06:59 -0700105 outb(0x0, IO_PORT_RESET);
106 outb(SYS_RST | RST_CPU, IO_PORT_RESET);
Simon Glass780ba482016-03-11 22:06:58 -0700107 cpu_hlt();
108
109 /* Not reached */
110 return -EINVAL;
111}