]> Git Repo - u-boot.git/blame - arch/x86/cpu/ivybridge/cpu.c
Init virtio before loading ENV from EXT4 or FAT
[u-boot.git] / arch / x86 / cpu / ivybridge / cpu.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0
8ef07571
SG
2/*
3 * Copyright (c) 2014 Google, Inc
4 * (C) Copyright 2008
5 * Graeme Russ, [email protected].
6 *
7 * Some portions from coreboot src/mainboard/google/link/romstage.c
8e0df066 8 * and src/cpu/intel/model_206ax/bootblock.c
8ef07571
SG
9 * Copyright (C) 2007-2010 coresystems GmbH
10 * Copyright (C) 2011 Google Inc.
8ef07571
SG
11 */
12
30c7c434 13#include <cpu_func.h>
aad78d27 14#include <dm.h>
2b605154 15#include <errno.h>
7fe32b34 16#include <event.h>
2b605154 17#include <fdtdec.h>
691d719d 18#include <init.h>
f7ae49fc 19#include <log.h>
858361b1 20#include <pch.h>
8ef07571 21#include <asm/cpu.h>
50dd3da0 22#include <asm/cpu_common.h>
401d1c4f 23#include <asm/global_data.h>
06d336cc 24#include <asm/intel_regs.h>
f5fbbe95 25#include <asm/io.h>
3eafce05 26#include <asm/lapic.h>
7e4a6ae6 27#include <asm/lpc_common.h>
9e66506d 28#include <asm/microcode.h>
f5fbbe95
SG
29#include <asm/msr.h>
30#include <asm/mtrr.h>
6e5b12b6 31#include <asm/pci.h>
70a09c6c 32#include <asm/post.h>
8ef07571 33#include <asm/processor.h>
f5fbbe95 34#include <asm/arch/model_206ax.h>
2b605154 35#include <asm/arch/pch.h>
8e0df066 36#include <asm/arch/sandybridge.h>
8ef07571
SG
37
38DECLARE_GLOBAL_DATA_PTR;
39
f5fbbe95
SG
40static int set_flex_ratio_to_tdp_nominal(void)
41{
f5fbbe95
SG
42 /* Minimum CPU revision for configurable TDP support */
43 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
44 return -EINVAL;
45
50dd3da0 46 return cpu_set_flex_ratio_to_tdp_nominal();
f5fbbe95
SG
47}
48
8ef07571 49int arch_cpu_init(void)
161d2e4e
SG
50{
51 post_code(POST_CPU_INIT);
161d2e4e
SG
52
53 return x86_cpu_init_f();
54}
55
f72d0d4a 56static int ivybridge_cpu_init(void)
8ef07571 57{
6e5b12b6 58 struct pci_controller *hose;
4acc83d4 59 struct udevice *bus, *dev;
8ef07571
SG
60 int ret;
61
aad78d27
SG
62 post_code(0x70);
63 ret = uclass_get_device(UCLASS_PCI, 0, &bus);
64 post_code(0x71);
8ef07571
SG
65 if (ret)
66 return ret;
aad78d27
SG
67 post_code(0x72);
68 hose = dev_get_uclass_priv(bus);
8ef07571 69
aad78d27
SG
70 /* TODO([email protected]): Get rid of gd->hose */
71 gd->hose = hose;
6e5b12b6 72
3f603cbb
SG
73 ret = uclass_first_device_err(UCLASS_LPC, &dev);
74 if (ret)
75 return ret;
4acc83d4 76
f5fbbe95
SG
77 /*
78 * We should do as little as possible before the serial console is
79 * up. Perhaps this should move to later. Our next lot of init
76d1d02f 80 * happens in checkcpu() when we have a console
f5fbbe95
SG
81 */
82 ret = set_flex_ratio_to_tdp_nominal();
83 if (ret)
84 return ret;
85
8ef07571
SG
86 return 0;
87}
f72d0d4a 88EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, ivybridge_cpu_init);
8ef07571 89
8e0df066
SG
90#define PCH_EHCI0_TEMP_BAR0 0xe8000000
91#define PCH_EHCI1_TEMP_BAR0 0xe8000400
92#define PCH_XHCI_TEMP_BAR0 0xe8001000
93
94/*
95 * Setup USB controller MMIO BAR to prevent the reference code from
96 * resetting the controller.
97 *
98 * The BAR will be re-assigned during device enumeration so these are only
99 * temporary.
100 *
101 * This is used to speed up the resume path.
102 */
5213f280 103static void enable_usb_bar(struct udevice *bus)
8e0df066
SG
104{
105 pci_dev_t usb0 = PCH_EHCI1_DEV;
106 pci_dev_t usb1 = PCH_EHCI2_DEV;
107 pci_dev_t usb3 = PCH_XHCI_DEV;
5213f280 108 ulong cmd;
8e0df066
SG
109
110 /* USB Controller 1 */
5213f280
SG
111 pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0,
112 PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32);
113 pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32);
8e0df066 114 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
5213f280 115 pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32);
8e0df066 116
5213f280
SG
117 /* USB Controller 2 */
118 pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0,
119 PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32);
120 pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32);
8e0df066 121 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
5213f280 122 pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32);
8e0df066 123
5213f280
SG
124 /* USB3 Controller 1 */
125 pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0,
126 PCH_XHCI_TEMP_BAR0, PCI_SIZE_32);
127 pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32);
8e0df066 128 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
5213f280 129 pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32);
8e0df066
SG
130}
131
76d1d02f 132int checkcpu(void)
8ef07571 133{
8e0df066 134 enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
f633efa3 135 struct udevice *dev, *lpc;
8e0df066
SG
136 uint32_t pm1_cnt;
137 uint16_t pm1_sts;
94060ff2
SG
138 int ret;
139
8e0df066
SG
140 /* TODO: cmos_post_init() */
141 if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
142 debug("soft reset detected\n");
143 boot_mode = PEI_BOOT_SOFT_RESET;
144
145 /* System is not happy after keyboard reset... */
146 debug("Issuing CF9 warm reset\n");
35b65dd8 147 reset_cpu();
8e0df066
SG
148 }
149
50dd3da0 150 ret = cpu_common_init();
4cc00f06
SG
151 if (ret) {
152 debug("%s: cpu_common_init() failed\n", __func__);
858361b1 153 return ret;
4cc00f06 154 }
8e0df066
SG
155
156 /* Check PM1_STS[15] to see if we are waking from Sx */
157 pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
158
159 /* Read PM1_CNT[12:10] to determine which Sx state */
160 pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
161
162 if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
8e0df066 163 debug("Resume from S3 detected, but disabled.\n");
8e0df066
SG
164 } else {
165 /*
166 * TODO: An indication of life might be possible here (e.g.
167 * keyboard light)
168 */
169 }
170 post_code(POST_EARLY_INIT);
171
172 /* Enable SPD ROMs and DDR-III DRAM */
3f603cbb 173 ret = uclass_first_device_err(UCLASS_I2C, &dev);
8d8f3acd
SG
174 if (ret) {
175 debug("%s: Failed to get I2C (ret=%d)\n", __func__, ret);
8e0df066 176 return ret;
8d8f3acd 177 }
8e0df066
SG
178
179 /* Prepare USB controller early in S3 resume */
50dd3da0
SG
180 if (boot_mode == PEI_BOOT_RESUME) {
181 uclass_first_device(UCLASS_LPC, &lpc);
5213f280 182 enable_usb_bar(pci_get_controller(lpc->parent));
50dd3da0 183 }
8e0df066
SG
184
185 gd->arch.pei_boot_mode = boot_mode;
186
76d1d02f
SG
187 return 0;
188}
189
190int print_cpuinfo(void)
191{
192 char processor_name[CPU_MAX_NAME_LEN];
193 const char *name;
194
8ef07571
SG
195 /* Print processor name */
196 name = cpu_get_name(processor_name);
197 printf("CPU: %s\n", name);
198
8e0df066
SG
199 post_code(POST_CPU_INFO);
200
8ef07571
SG
201 return 0;
202}
7b95252d
SG
203
204void board_debug_uart_init(void)
205{
206 /* This enables the debug UART */
a827ba91 207 pci_x86_write_config(PCH_LPC_DEV, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
7b95252d 208}
This page took 0.27056 seconds and 4 git commands to generate.