1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016 Google, Inc
8 #include <debug_uart.h>
15 #include <asm/cpu_common.h>
16 #include <asm/mrccache.h>
19 #include <asm/processor.h>
21 #include <asm-generic/sections.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 __weak int arch_cpu_init_dm(void)
32 static int set_max_freq(void)
34 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
36 * Burst Mode has been factory-configured as disabled and is not
37 * available in this physical processor package
39 debug("Burst Mode is factory-disabled\n");
43 /* Enable burst mode */
44 cpu_set_burst_mode(true);
46 /* Enable speed step */
49 /* Set P-State ratio */
50 cpu_set_p_state_to_turbo_ratio();
56 static int x86_spl_init(void)
60 * TODO(sjg@chromium.org): We use this area of RAM for the stack
61 * and global_data in SPL. Once U-Boot starts up and releocates it
62 * is not needed. We could make this a CONFIG option or perhaps
63 * place it immediately below CONFIG_SYS_TEXT_BASE.
65 char *ptr = (char *)0x110000;
67 struct udevice *punit;
71 debug("%s starting\n", __func__);
73 ret = x86_cpu_reinit_f();
75 ret = x86_cpu_init_f();
78 debug("%s: spl_init() failed\n", __func__);
81 ret = arch_cpu_init();
83 debug("%s: arch_cpu_init() failed\n", __func__);
87 ret = arch_cpu_init_dm();
89 debug("%s: arch_cpu_init_dm() failed\n", __func__);
93 preloader_console_init();
95 ret = print_cpuinfo();
97 debug("%s: print_cpuinfo() failed\n", __func__);
103 debug("%s: dram_init() failed\n", __func__);
106 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
107 ret = mrccache_spl_save();
109 debug("%s: Failed to write to mrccache (err=%d)\n",
114 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
116 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
117 ret = interrupt_init();
119 debug("%s: interrupt_init() failed\n", __func__);
124 * The stack grows down from ptr. Put the global data at ptr. This
125 * will only be used for SPL. Once SPL loads U-Boot proper it will
126 * set up its own stack.
128 gd->new_gd = (struct global_data *)ptr;
129 memcpy(gd->new_gd, gd, sizeof(*gd));
130 arch_setup_gd(gd->new_gd);
131 gd->start_addr_sp = (ulong)ptr;
133 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
134 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
135 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
136 CONFIG_XIP_ROM_SIZE);
138 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
143 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
145 debug("Could not find PUNIT (err=%d)\n", ret);
147 ret = set_max_freq();
149 debug("Failed to set CPU frequency (err=%d)\n", ret);
155 void board_init_f(ulong flags)
159 ret = x86_spl_init();
161 debug("Error %d\n", ret);
162 panic("x86_spl_init fail");
165 gd->bd = malloc(sizeof(*gd->bd));
167 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
172 /* Uninit CAR and jump to board_init_f_r() */
173 board_init_f_r_trampoline(gd->start_addr_sp);
177 void board_init_f_r(void)
180 gd->flags &= ~GD_FLG_SERIAL_READY;
181 debug("cache status %d\n", dcache_status());
185 u32 spl_boot_device(void)
187 return BOOT_DEVICE_SPI_MMAP;
190 int spl_start_uboot(void)
195 void spl_board_announce_boot_device(void)
200 static int spl_board_load_image(struct spl_image_info *spl_image,
201 struct spl_boot_device *bootdev)
203 spl_image->size = CONFIG_SYS_MONITOR_LEN;
204 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
205 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
206 spl_image->os = IH_OS_U_BOOT;
207 spl_image->name = "U-Boot";
209 debug("Loading to %lx\n", spl_image->load_addr);
213 SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
215 int spl_spi_load_image(void)
220 #ifdef CONFIG_X86_RUN_64BIT
221 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
225 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
226 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
227 debug("ret=%d\n", ret);
232 void spl_board_init(void)
235 preloader_console_init();