1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 Google, Inc
8 #include <debug_uart.h>
19 #include <asm/cpu_common.h>
20 #include <asm/mrccache.h>
23 #include <asm/processor.h>
25 #include <asm-generic/sections.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 __weak int arch_cpu_init_dm(void)
36 static int set_max_freq(void)
38 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
40 * Burst Mode has been factory-configured as disabled and is not
41 * available in this physical processor package
43 debug("Burst Mode is factory-disabled\n");
47 /* Enable burst mode */
48 cpu_set_burst_mode(true);
50 /* Enable speed step */
53 /* Set P-State ratio */
54 cpu_set_p_state_to_turbo_ratio();
60 static int x86_spl_init(void)
65 * and global_data in SPL. Once U-Boot starts up and releocates it
66 * is not needed. We could make this a CONFIG option or perhaps
67 * place it immediately below CONFIG_SYS_TEXT_BASE.
69 __maybe_unused char *ptr = (char *)0x110000;
71 struct udevice *punit;
75 debug("%s starting\n", __func__);
77 ret = x86_cpu_reinit_f();
79 ret = x86_cpu_init_f();
82 debug("%s: spl_init() failed\n", __func__);
85 ret = arch_cpu_init();
87 debug("%s: arch_cpu_init() failed\n", __func__);
91 ret = arch_cpu_init_dm();
93 debug("%s: arch_cpu_init_dm() failed\n", __func__);
97 preloader_console_init();
99 ret = print_cpuinfo();
101 debug("%s: print_cpuinfo() failed\n", __func__);
107 debug("%s: dram_init() failed\n", __func__);
110 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
111 ret = mrccache_spl_save();
113 debug("%s: Failed to write to mrccache (err=%d)\n",
117 #ifndef CONFIG_SYS_COREBOOT
119 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
122 ret = interrupt_init();
124 debug("%s: interrupt_init() failed\n", __func__);
129 * The stack grows down from ptr. Put the global data at ptr. This
130 * will only be used for SPL. Once SPL loads U-Boot proper it will
131 * set up its own stack.
133 gd->new_gd = (struct global_data *)ptr;
134 memcpy(gd->new_gd, gd, sizeof(*gd));
135 arch_setup_gd(gd->new_gd);
136 gd->start_addr_sp = (ulong)ptr;
138 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
139 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
140 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
141 CONFIG_XIP_ROM_SIZE);
143 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
148 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
150 debug("Could not find PUNIT (err=%d)\n", ret);
152 ret = set_max_freq();
154 debug("Failed to set CPU frequency (err=%d)\n", ret);
161 void board_init_f(ulong flags)
165 ret = x86_spl_init();
167 debug("Error %d\n", ret);
168 panic("x86_spl_init fail");
170 #if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
171 gd->bd = malloc(sizeof(*gd->bd));
173 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
178 /* Uninit CAR and jump to board_init_f_r() */
179 board_init_f_r_trampoline(gd->start_addr_sp);
183 void board_init_f_r(void)
186 gd->flags &= ~GD_FLG_SERIAL_READY;
187 debug("cache status %d\n", dcache_status());
191 u32 spl_boot_device(void)
193 return BOOT_DEVICE_SPI_MMAP;
196 int spl_start_uboot(void)
201 void spl_board_announce_boot_device(void)
206 static int spl_board_load_image(struct spl_image_info *spl_image,
207 struct spl_boot_device *bootdev)
209 spl_image->size = CONFIG_SYS_MONITOR_LEN;
210 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
211 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
212 spl_image->os = IH_OS_U_BOOT;
213 spl_image->name = "U-Boot";
215 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
217 * Copy U-Boot from ROM
219 * correctly here, and in the device-tree binman definition.
221 * Also consider using FIT so we get the correct image length
224 memcpy((char *)spl_image->load_addr, (char *)0xfff00000,
228 debug("Loading to %lx\n", spl_image->load_addr);
232 SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
234 int spl_spi_load_image(void)
239 #ifdef CONFIG_X86_RUN_64BIT
240 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
244 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
245 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
246 debug("ret=%d\n", ret);
251 void spl_board_init(void)
254 preloader_console_init();