blob: 55c0615708644855eff0dfc2d5c9073165f78f79 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass030777d2017-01-16 07:03:56 -07002/*
3 * Copyright (c) 2016 Google, Inc
Simon Glass030777d2017-01-16 07:03:56 -07004 */
5
Simon Glass3a1d96f2023-07-15 21:39:11 -06006#define LOG_CATEGORY LOGC_BOOT
7
Simon Glass030777d2017-01-16 07:03:56 -07008#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Simon Glass030777d2017-01-16 07:03:56 -070010#include <debug_uart.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060011#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -070012#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060013#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060014#include <init.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -070015#include <irq_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060016#include <log.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060017#include <malloc.h>
Simon Glass030777d2017-01-16 07:03:56 -070018#include <spl.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060019#include <syscon.h>
Simon Glasse50c4552023-07-15 21:39:01 -060020#include <vesa.h>
Simon Glass030777d2017-01-16 07:03:56 -070021#include <asm/cpu.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060022#include <asm/cpu_common.h>
Simon Glassfc557362022-03-04 08:43:05 -070023#include <asm/fsp2/fsp_api.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060024#include <asm/global_data.h>
Simon Glassfb842432023-07-15 21:38:36 -060025#include <asm/mp.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060026#include <asm/mrccache.h>
Simon Glass030777d2017-01-16 07:03:56 -070027#include <asm/mtrr.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060028#include <asm/pci.h>
Simon Glass030777d2017-01-16 07:03:56 -070029#include <asm/processor.h>
Simon Glass19da9c42019-09-25 08:11:39 -060030#include <asm/spl.h>
Simon Glass030777d2017-01-16 07:03:56 -070031#include <asm-generic/sections.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
Simon Glassfc557362022-03-04 08:43:05 -070035__weak int fsp_setup_pinctrl(void *ctx, struct event *event)
Bin Meng2240fde2017-01-18 03:32:53 -080036{
37 return 0;
38}
39
Simon Glass0b3c5762019-10-20 21:37:49 -060040#ifdef CONFIG_TPL
41
42static int set_max_freq(void)
43{
44 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
45 /*
46 * Burst Mode has been factory-configured as disabled and is not
47 * available in this physical processor package
48 */
49 debug("Burst Mode is factory-disabled\n");
50 return -ENOENT;
51 }
52
53 /* Enable burst mode */
54 cpu_set_burst_mode(true);
55
56 /* Enable speed step */
57 cpu_set_eist(true);
58
59 /* Set P-State ratio */
60 cpu_set_p_state_to_turbo_ratio();
61
62 return 0;
63}
64#endif
65
Simon Glass030777d2017-01-16 07:03:56 -070066static int x86_spl_init(void)
67{
Simon Glassb3f351f2023-07-15 21:39:13 -060068 struct udevice *dev;
69
Simon Glass7cf5fe02019-05-02 10:52:12 -060070#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070071 /*
72 * TODO(sjg@chromium.org): We use this area of RAM for the stack
73 * and global_data in SPL. Once U-Boot starts up and releocates it
74 * is not needed. We could make this a CONFIG option or perhaps
Simon Glass72cc5382022-10-20 18:22:39 -060075 * place it immediately below CONFIG_TEXT_BASE.
Simon Glass030777d2017-01-16 07:03:56 -070076 */
Simon Glassdae11532020-04-30 21:21:42 -060077 __maybe_unused char *ptr = (char *)0x110000;
Simon Glass0b3c5762019-10-20 21:37:49 -060078#else
79 struct udevice *punit;
Simon Glass7cf5fe02019-05-02 10:52:12 -060080#endif
Simon Glass030777d2017-01-16 07:03:56 -070081 int ret;
82
Simon Glass3a1d96f2023-07-15 21:39:11 -060083 log_debug("x86 spl starting\n");
Simon Glass81f14622019-10-20 21:37:55 -060084 if (IS_ENABLED(TPL))
85 ret = x86_cpu_reinit_f();
86 else
87 ret = x86_cpu_init_f();
Simon Glass030777d2017-01-16 07:03:56 -070088 ret = spl_init();
89 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -060090 log_debug("spl_init() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -070091 return ret;
92 }
Simon Glass030777d2017-01-16 07:03:56 -070093 ret = arch_cpu_init();
94 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -060095 log_debug("arch_cpu_init() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -070096 return ret;
97 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060098#ifndef CONFIG_TPL
Simon Glassfc557362022-03-04 08:43:05 -070099 ret = fsp_setup_pinctrl(NULL, NULL);
Simon Glass030777d2017-01-16 07:03:56 -0700100 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -0600101 log_debug("fsp_setup_pinctrl() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -0700102 return ret;
103 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600104#endif
Simon Glassfbfb4762023-07-15 21:39:00 -0600105 /*
106 * spl_board_init() below sets up the console if enabled. If it isn't,
107 * do it here. We cannot call this twice since it results in a double
108 * banner and CI tests fail.
109 */
110 if (!IS_ENABLED(CONFIG_SPL_BOARD_INIT))
111 preloader_console_init();
Simon Glass2f002162021-03-15 18:11:18 +1300112#if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
Simon Glass030777d2017-01-16 07:03:56 -0700113 ret = print_cpuinfo();
114 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -0600115 log_debug("print_cpuinfo() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -0700116 return ret;
117 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600118#endif
Simon Glassb3f351f2023-07-15 21:39:13 -0600119 /* probe the LPC so we get the GPIO_BASE set up correctly */
120 ret = uclass_first_device_err(UCLASS_LPC, &dev);
121 if (ret && ret != -ENODEV) {
122 log_debug("lpc probe failed\n");
123 return ret;
124 }
125
Simon Glass030777d2017-01-16 07:03:56 -0700126 ret = dram_init();
127 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -0600128 log_debug("dram_init() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -0700129 return ret;
130 }
Simon Glass3a1d96f2023-07-15 21:39:11 -0600131 log_debug("mrc\n");
Simon Glass7cf5fe02019-05-02 10:52:12 -0600132 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
133 ret = mrccache_spl_save();
134 if (ret)
Simon Glass3a1d96f2023-07-15 21:39:11 -0600135 log_debug("Failed to write to mrccache (err=%d)\n",
136 ret);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600137 }
138
Simon Glassdae11532020-04-30 21:21:42 -0600139#ifndef CONFIG_SYS_COREBOOT
Simon Glass05dc07b2023-05-04 16:50:54 -0600140 debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start,
141 (ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass030777d2017-01-16 07:03:56 -0700142 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass47717592021-01-24 10:06:10 -0700143# ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -0700144
145 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
146 ret = interrupt_init();
147 if (ret) {
148 debug("%s: interrupt_init() failed\n", __func__);
149 return ret;
150 }
151
152 /*
153 * The stack grows down from ptr. Put the global data at ptr. This
154 * will only be used for SPL. Once SPL loads U-Boot proper it will
155 * set up its own stack.
156 */
157 gd->new_gd = (struct global_data *)ptr;
158 memcpy(gd->new_gd, gd, sizeof(*gd));
Simon Glass23ae5c32023-07-15 21:39:05 -0600159
Simon Glass3a1d96f2023-07-15 21:39:11 -0600160 log_debug("logging\n");
Simon Glass23ae5c32023-07-15 21:39:05 -0600161 /*
162 * Make sure logging is disabled when we switch, since the log system
163 * list head will move
164 */
165 gd->new_gd->flags &= ~GD_FLG_LOG_READY;
Simon Glass030777d2017-01-16 07:03:56 -0700166 arch_setup_gd(gd->new_gd);
167 gd->start_addr_sp = (ulong)ptr;
168
Simon Glass23ae5c32023-07-15 21:39:05 -0600169 /* start up logging again, with the new list-head location */
170 ret = log_init();
171 if (ret) {
172 log_debug("Log setup failed (err=%d)\n", ret);
173 return ret;
174 }
175
Simon Glassfb842432023-07-15 21:38:36 -0600176 if (_LOG_DEBUG) {
177 ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP);
178 if (ret)
179 printf("mtrr_list failed\n");
180 }
181
Simon Glass030777d2017-01-16 07:03:56 -0700182 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
183 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
184 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
185 CONFIG_XIP_ROM_SIZE);
186 if (ret) {
Simon Glass7cf5fe02019-05-02 10:52:12 -0600187 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass030777d2017-01-16 07:03:56 -0700188 return ret;
189 }
Simon Glassdae11532020-04-30 21:21:42 -0600190# else
Simon Glass0b3c5762019-10-20 21:37:49 -0600191 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
192 if (ret)
193 debug("Could not find PUNIT (err=%d)\n", ret);
194
195 ret = set_max_freq();
196 if (ret)
197 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glassdae11532020-04-30 21:21:42 -0600198# endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600199#endif
Simon Glass3a1d96f2023-07-15 21:39:11 -0600200 log_debug("done\n");
Simon Glass030777d2017-01-16 07:03:56 -0700201
202 return 0;
203}
204
205void board_init_f(ulong flags)
206{
207 int ret;
208
209 ret = x86_spl_init();
210 if (ret) {
Simon Glassa0185fa2020-05-27 06:58:48 -0600211 printf("x86_spl_init: error %d\n", ret);
212 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700213 }
Simon Glassdae11532020-04-30 21:21:42 -0600214#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
Simon Glass7cf5fe02019-05-02 10:52:12 -0600215 gd->bd = malloc(sizeof(*gd->bd));
216 if (!gd->bd) {
217 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
218 hang();
219 }
220 board_init_r(gd, 0);
221#else
Simon Glass030777d2017-01-16 07:03:56 -0700222 /* Uninit CAR and jump to board_init_f_r() */
223 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600224#endif
Simon Glass030777d2017-01-16 07:03:56 -0700225}
226
227void board_init_f_r(void)
228{
Simon Glass6e7b1b52023-05-04 16:50:57 -0600229 mtrr_commit(false);
230 init_cache();
Simon Glass030777d2017-01-16 07:03:56 -0700231 gd->flags &= ~GD_FLG_SERIAL_READY;
232 debug("cache status %d\n", dcache_status());
233 board_init_r(gd, 0);
234}
235
236u32 spl_boot_device(void)
237{
Simon Glass19da9c42019-09-25 08:11:39 -0600238 return BOOT_DEVICE_SPI_MMAP;
Simon Glass030777d2017-01-16 07:03:56 -0700239}
240
241int spl_start_uboot(void)
242{
243 return 0;
244}
245
246void spl_board_announce_boot_device(void)
247{
248 printf("SPI flash");
249}
250
251static int spl_board_load_image(struct spl_image_info *spl_image,
252 struct spl_boot_device *bootdev)
253{
254 spl_image->size = CONFIG_SYS_MONITOR_LEN;
Simon Glass72cc5382022-10-20 18:22:39 -0600255 spl_image->entry_point = CONFIG_TEXT_BASE;
256 spl_image->load_addr = CONFIG_TEXT_BASE;
Simon Glass030777d2017-01-16 07:03:56 -0700257 spl_image->os = IH_OS_U_BOOT;
258 spl_image->name = "U-Boot";
259
Simon Glass91fcd1d2020-04-30 21:21:41 -0600260 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
Simon Glass53ea0f62023-05-04 16:50:55 -0600261 /* Copy U-Boot from ROM */
262 memcpy((void *)spl_image->load_addr,
263 (void *)spl_get_image_pos(), spl_get_image_size());
Simon Glass91fcd1d2020-04-30 21:21:41 -0600264 }
265
Simon Glass030777d2017-01-16 07:03:56 -0700266 debug("Loading to %lx\n", spl_image->load_addr);
267
268 return 0;
269}
Simon Glass19da9c42019-09-25 08:11:39 -0600270SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass030777d2017-01-16 07:03:56 -0700271
272int spl_spi_load_image(void)
273{
274 return -EPERM;
275}
276
Simon Glass7cf5fe02019-05-02 10:52:12 -0600277#ifdef CONFIG_X86_RUN_64BIT
Simon Glass030777d2017-01-16 07:03:56 -0700278void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
279{
280 int ret;
281
282 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
283 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
284 debug("ret=%d\n", ret);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600285 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700286}
Simon Glass7cf5fe02019-05-02 10:52:12 -0600287#endif
288
289void spl_board_init(void)
290{
291#ifndef CONFIG_TPL
292 preloader_console_init();
293#endif
Simon Glasse50c4552023-07-15 21:39:01 -0600294
295 if (CONFIG_IS_ENABLED(VIDEO)) {
296 struct udevice *dev;
297
298 /* Set up PCI video in SPL if required */
299 uclass_first_device_err(UCLASS_PCI, &dev);
300 uclass_first_device_err(UCLASS_VIDEO, &dev);
301 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600302}