blob: ba3434b055c3f708d07f7f8fb1c696a4d5915fa0 [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 Glass7cf5fe02019-05-02 10:52:12 -060068#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070069 /*
70 * TODO(sjg@chromium.org): We use this area of RAM for the stack
71 * and global_data in SPL. Once U-Boot starts up and releocates it
72 * is not needed. We could make this a CONFIG option or perhaps
Simon Glass72cc5382022-10-20 18:22:39 -060073 * place it immediately below CONFIG_TEXT_BASE.
Simon Glass030777d2017-01-16 07:03:56 -070074 */
Simon Glassdae11532020-04-30 21:21:42 -060075 __maybe_unused char *ptr = (char *)0x110000;
Simon Glass0b3c5762019-10-20 21:37:49 -060076#else
77 struct udevice *punit;
Simon Glass7cf5fe02019-05-02 10:52:12 -060078#endif
Simon Glass030777d2017-01-16 07:03:56 -070079 int ret;
80
Simon Glass3a1d96f2023-07-15 21:39:11 -060081 log_debug("x86 spl starting\n");
Simon Glass81f14622019-10-20 21:37:55 -060082 if (IS_ENABLED(TPL))
83 ret = x86_cpu_reinit_f();
84 else
85 ret = x86_cpu_init_f();
Simon Glass030777d2017-01-16 07:03:56 -070086 ret = spl_init();
87 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -060088 log_debug("spl_init() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -070089 return ret;
90 }
Simon Glass030777d2017-01-16 07:03:56 -070091 ret = arch_cpu_init();
92 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -060093 log_debug("arch_cpu_init() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -070094 return ret;
95 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060096#ifndef CONFIG_TPL
Simon Glassfc557362022-03-04 08:43:05 -070097 ret = fsp_setup_pinctrl(NULL, NULL);
Simon Glass030777d2017-01-16 07:03:56 -070098 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -060099 log_debug("fsp_setup_pinctrl() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -0700100 return ret;
101 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600102#endif
Simon Glassfbfb4762023-07-15 21:39:00 -0600103 /*
104 * spl_board_init() below sets up the console if enabled. If it isn't,
105 * do it here. We cannot call this twice since it results in a double
106 * banner and CI tests fail.
107 */
108 if (!IS_ENABLED(CONFIG_SPL_BOARD_INIT))
109 preloader_console_init();
Simon Glass2f002162021-03-15 18:11:18 +1300110#if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
Simon Glass030777d2017-01-16 07:03:56 -0700111 ret = print_cpuinfo();
112 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -0600113 log_debug("print_cpuinfo() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -0700114 return ret;
115 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600116#endif
Simon Glass030777d2017-01-16 07:03:56 -0700117 ret = dram_init();
118 if (ret) {
Simon Glass3a1d96f2023-07-15 21:39:11 -0600119 log_debug("dram_init() failed (err=%d)\n", ret);
Simon Glass030777d2017-01-16 07:03:56 -0700120 return ret;
121 }
Simon Glass3a1d96f2023-07-15 21:39:11 -0600122 log_debug("mrc\n");
Simon Glass7cf5fe02019-05-02 10:52:12 -0600123 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
124 ret = mrccache_spl_save();
125 if (ret)
Simon Glass3a1d96f2023-07-15 21:39:11 -0600126 log_debug("Failed to write to mrccache (err=%d)\n",
127 ret);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600128 }
129
Simon Glassdae11532020-04-30 21:21:42 -0600130#ifndef CONFIG_SYS_COREBOOT
Simon Glass3a1d96f2023-07-15 21:39:11 -0600131 log_debug("bss\n");
Simon Glass05dc07b2023-05-04 16:50:54 -0600132 debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start,
133 (ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass030777d2017-01-16 07:03:56 -0700134 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass47717592021-01-24 10:06:10 -0700135# ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -0700136
137 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
138 ret = interrupt_init();
139 if (ret) {
140 debug("%s: interrupt_init() failed\n", __func__);
141 return ret;
142 }
143
144 /*
145 * The stack grows down from ptr. Put the global data at ptr. This
146 * will only be used for SPL. Once SPL loads U-Boot proper it will
147 * set up its own stack.
148 */
149 gd->new_gd = (struct global_data *)ptr;
150 memcpy(gd->new_gd, gd, sizeof(*gd));
Simon Glass23ae5c32023-07-15 21:39:05 -0600151
Simon Glass3a1d96f2023-07-15 21:39:11 -0600152 log_debug("logging\n");
Simon Glass23ae5c32023-07-15 21:39:05 -0600153 /*
154 * Make sure logging is disabled when we switch, since the log system
155 * list head will move
156 */
157 gd->new_gd->flags &= ~GD_FLG_LOG_READY;
Simon Glass030777d2017-01-16 07:03:56 -0700158 arch_setup_gd(gd->new_gd);
159 gd->start_addr_sp = (ulong)ptr;
160
Simon Glass23ae5c32023-07-15 21:39:05 -0600161 /* start up logging again, with the new list-head location */
162 ret = log_init();
163 if (ret) {
164 log_debug("Log setup failed (err=%d)\n", ret);
165 return ret;
166 }
167
Simon Glassfb842432023-07-15 21:38:36 -0600168 if (_LOG_DEBUG) {
169 ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP);
170 if (ret)
171 printf("mtrr_list failed\n");
172 }
173
Simon Glass030777d2017-01-16 07:03:56 -0700174 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
175 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
176 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
177 CONFIG_XIP_ROM_SIZE);
178 if (ret) {
Simon Glass7cf5fe02019-05-02 10:52:12 -0600179 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass030777d2017-01-16 07:03:56 -0700180 return ret;
181 }
Simon Glassdae11532020-04-30 21:21:42 -0600182# else
Simon Glass0b3c5762019-10-20 21:37:49 -0600183 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
184 if (ret)
185 debug("Could not find PUNIT (err=%d)\n", ret);
186
187 ret = set_max_freq();
188 if (ret)
189 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glassdae11532020-04-30 21:21:42 -0600190# endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600191#endif
Simon Glass3a1d96f2023-07-15 21:39:11 -0600192 log_debug("done\n");
Simon Glass030777d2017-01-16 07:03:56 -0700193
194 return 0;
195}
196
197void board_init_f(ulong flags)
198{
199 int ret;
200
201 ret = x86_spl_init();
202 if (ret) {
Simon Glassa0185fa2020-05-27 06:58:48 -0600203 printf("x86_spl_init: error %d\n", ret);
204 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700205 }
Simon Glassdae11532020-04-30 21:21:42 -0600206#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
Simon Glass7cf5fe02019-05-02 10:52:12 -0600207 gd->bd = malloc(sizeof(*gd->bd));
208 if (!gd->bd) {
209 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
210 hang();
211 }
212 board_init_r(gd, 0);
213#else
Simon Glass030777d2017-01-16 07:03:56 -0700214 /* Uninit CAR and jump to board_init_f_r() */
215 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600216#endif
Simon Glass030777d2017-01-16 07:03:56 -0700217}
218
219void board_init_f_r(void)
220{
Simon Glass6e7b1b52023-05-04 16:50:57 -0600221 mtrr_commit(false);
222 init_cache();
Simon Glass030777d2017-01-16 07:03:56 -0700223 gd->flags &= ~GD_FLG_SERIAL_READY;
224 debug("cache status %d\n", dcache_status());
225 board_init_r(gd, 0);
226}
227
228u32 spl_boot_device(void)
229{
Simon Glass19da9c42019-09-25 08:11:39 -0600230 return BOOT_DEVICE_SPI_MMAP;
Simon Glass030777d2017-01-16 07:03:56 -0700231}
232
233int spl_start_uboot(void)
234{
235 return 0;
236}
237
238void spl_board_announce_boot_device(void)
239{
240 printf("SPI flash");
241}
242
243static int spl_board_load_image(struct spl_image_info *spl_image,
244 struct spl_boot_device *bootdev)
245{
246 spl_image->size = CONFIG_SYS_MONITOR_LEN;
Simon Glass72cc5382022-10-20 18:22:39 -0600247 spl_image->entry_point = CONFIG_TEXT_BASE;
248 spl_image->load_addr = CONFIG_TEXT_BASE;
Simon Glass030777d2017-01-16 07:03:56 -0700249 spl_image->os = IH_OS_U_BOOT;
250 spl_image->name = "U-Boot";
251
Simon Glass91fcd1d2020-04-30 21:21:41 -0600252 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
Simon Glass53ea0f62023-05-04 16:50:55 -0600253 /* Copy U-Boot from ROM */
254 memcpy((void *)spl_image->load_addr,
255 (void *)spl_get_image_pos(), spl_get_image_size());
Simon Glass91fcd1d2020-04-30 21:21:41 -0600256 }
257
Simon Glass030777d2017-01-16 07:03:56 -0700258 debug("Loading to %lx\n", spl_image->load_addr);
259
260 return 0;
261}
Simon Glass19da9c42019-09-25 08:11:39 -0600262SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass030777d2017-01-16 07:03:56 -0700263
264int spl_spi_load_image(void)
265{
266 return -EPERM;
267}
268
Simon Glass7cf5fe02019-05-02 10:52:12 -0600269#ifdef CONFIG_X86_RUN_64BIT
Simon Glass030777d2017-01-16 07:03:56 -0700270void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
271{
272 int ret;
273
274 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
275 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
276 debug("ret=%d\n", ret);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600277 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700278}
Simon Glass7cf5fe02019-05-02 10:52:12 -0600279#endif
280
281void spl_board_init(void)
282{
283#ifndef CONFIG_TPL
284 preloader_console_init();
285#endif
Simon Glasse50c4552023-07-15 21:39:01 -0600286
287 if (CONFIG_IS_ENABLED(VIDEO)) {
288 struct udevice *dev;
289
290 /* Set up PCI video in SPL if required */
291 uclass_first_device_err(UCLASS_PCI, &dev);
292 uclass_first_device_err(UCLASS_VIDEO, &dev);
293 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600294}