1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 Google, Inc
6 #define LOG_CATEGORY LOGC_BOOT
9 #include <debug_uart.h>
21 #include <asm/cpu_common.h>
22 #include <asm/fsp2/fsp_api.h>
23 #include <asm/global_data.h>
25 #include <asm/mrccache.h>
28 #include <asm/processor.h>
31 #include <asm/u-boot-x86.h>
32 #include <asm-generic/sections.h>
34 DECLARE_GLOBAL_DATA_PTR;
36 __weak int fsp_setup_pinctrl(void *ctx, struct event *event)
43 static int set_max_freq(void)
45 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
47 * Burst Mode has been factory-configured as disabled and is not
48 * available in this physical processor package
50 debug("Burst Mode is factory-disabled\n");
54 /* Enable burst mode */
55 cpu_set_burst_mode(true);
57 /* Enable speed step */
60 /* Set P-State ratio */
61 cpu_set_p_state_to_turbo_ratio();
67 static int x86_spl_init(void)
74 * and global_data in SPL. Once U-Boot starts up and releocates it
75 * is not needed. We could make this a CONFIG option or perhaps
76 * place it immediately below CONFIG_TEXT_BASE.
78 __maybe_unused char *ptr = (char *)0x110000;
80 struct udevice *punit;
84 log_debug("x86 spl starting\n");
86 ret = x86_cpu_reinit_f();
88 ret = x86_cpu_init_f();
91 log_debug("spl_init() failed (err=%d)\n", ret);
94 ret = arch_cpu_init();
96 log_debug("arch_cpu_init() failed (err=%d)\n", ret);
100 ret = fsp_setup_pinctrl(NULL, NULL);
102 log_debug("fsp_setup_pinctrl() failed (err=%d)\n", ret);
107 * spl_board_init() below sets up the console if enabled. If it isn't,
108 * do it here. We cannot call this twice since it results in a double
109 * banner and CI tests fail.
111 if (!IS_ENABLED(CONFIG_SPL_BOARD_INIT))
112 preloader_console_init();
113 #if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
114 ret = print_cpuinfo();
116 log_debug("print_cpuinfo() failed (err=%d)\n", ret);
120 /* probe the LPC so we get the GPIO_BASE set up correctly */
121 ret = uclass_first_device_err(UCLASS_LPC, &dev);
122 if (ret && ret != -ENODEV) {
123 log_debug("lpc probe failed\n");
129 log_debug("dram_init() failed (err=%d)\n", ret);
133 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
134 ret = mrccache_spl_save();
136 log_debug("Failed to write to mrccache (err=%d)\n",
140 #ifndef CONFIG_SYS_COREBOOT
141 debug("BSS clear from %lx to %lx len %lx\n", (ulong)__bss_start,
142 (ulong)__bss_end, (ulong)__bss_end - (ulong)__bss_start);
143 memset(__bss_start, 0, (ulong)__bss_end - (ulong)__bss_start);
147 ret = interrupt_init();
149 debug("%s: interrupt_init() failed\n", __func__);
154 * The stack grows down from ptr. Put the global data at ptr. This
155 * will only be used for SPL. Once SPL loads U-Boot proper it will
156 * set up its own stack.
158 gd->new_gd = (struct global_data *)ptr;
159 memcpy(gd->new_gd, gd, sizeof(*gd));
161 log_debug("logging\n");
163 * Make sure logging is disabled when we switch, since the log system
164 * list head will move
166 gd->new_gd->flags &= ~GD_FLG_LOG_READY;
167 arch_setup_gd(gd->new_gd);
168 gd->start_addr_sp = (ulong)ptr;
170 /* start up logging again, with the new list-head location */
173 log_debug("Log setup failed (err=%d)\n", ret);
178 ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP);
180 printf("mtrr_list failed\n");
183 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
184 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
185 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
186 CONFIG_XIP_ROM_SIZE);
188 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
192 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
194 debug("Could not find PUNIT (err=%d)\n", ret);
196 ret = set_max_freq();
198 debug("Failed to set CPU frequency (err=%d)\n", ret);
206 void board_init_f(ulong flags)
210 ret = x86_spl_init();
212 printf("x86_spl_init: error %d\n", ret);
215 #if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
216 gd->bd = malloc(sizeof(*gd->bd));
218 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
223 /* Uninit CAR and jump to board_init_f_r() */
224 board_init_f_r_trampoline(gd->start_addr_sp);
228 void board_init_f_r(void)
232 gd->flags &= ~GD_FLG_SERIAL_READY;
234 /* make sure driver model is not accessed from now on */
235 gd->flags |= GD_FLG_DM_DEAD;
236 debug("cache status %d\n", dcache_status());
240 u32 spl_boot_device(void)
242 return BOOT_DEVICE_SPI_MMAP;
245 int spl_start_uboot(void)
250 void spl_board_announce_boot_device(void)
255 static int spl_board_load_image(struct spl_image_info *spl_image,
256 struct spl_boot_device *bootdev)
258 spl_image->size = CONFIG_SYS_MONITOR_LEN;
259 spl_image->entry_point = CONFIG_TEXT_BASE;
260 spl_image->load_addr = CONFIG_TEXT_BASE;
261 spl_image->os = IH_OS_U_BOOT;
262 spl_image->name = "U-Boot";
264 if (spl_image->load_addr != spl_get_image_pos()) {
265 /* Copy U-Boot from ROM */
266 memcpy((void *)spl_image->load_addr,
267 (void *)spl_get_image_pos(), spl_get_image_size());
270 debug("Loading to %lx\n", spl_image->load_addr);
274 SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
276 int spl_spi_load_image(void)
281 #ifdef CONFIG_X86_RUN_64BIT
282 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
286 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
287 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
288 debug("ret=%d\n", ret);
293 void spl_board_init(void)
296 preloader_console_init();
298 if (IS_ENABLED(CONFIG_QEMU))
301 if (CONFIG_IS_ENABLED(UPL_OUT))
302 gd->flags |= GD_FLG_UPL;
304 if (CONFIG_IS_ENABLED(VIDEO)) {
308 /* Set up PCI video in SPL if required */
309 ret = uclass_first_device_err(UCLASS_PCI, &dev);
311 panic("Failed to set up PCI");
312 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
314 panic("Failed to set up video");