blob: 92a5e6aec7112e9ac21a1294dfd42d02a83e4788 [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
6#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glass030777d2017-01-16 07:03:56 -07008#include <debug_uart.h>
Simon Glass0b3c5762019-10-20 21:37:49 -06009#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -070010#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -070013#include <irq_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060015#include <malloc.h>
Simon Glass030777d2017-01-16 07:03:56 -070016#include <spl.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060017#include <syscon.h>
Simon Glasse50c4552023-07-15 21:39:01 -060018#include <vesa.h>
Simon Glass030777d2017-01-16 07:03:56 -070019#include <asm/cpu.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060020#include <asm/cpu_common.h>
Simon Glassfc557362022-03-04 08:43:05 -070021#include <asm/fsp2/fsp_api.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060022#include <asm/global_data.h>
Simon Glassfb842432023-07-15 21:38:36 -060023#include <asm/mp.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060024#include <asm/mrccache.h>
Simon Glass030777d2017-01-16 07:03:56 -070025#include <asm/mtrr.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060026#include <asm/pci.h>
Simon Glass030777d2017-01-16 07:03:56 -070027#include <asm/processor.h>
Simon Glass19da9c42019-09-25 08:11:39 -060028#include <asm/spl.h>
Simon Glass030777d2017-01-16 07:03:56 -070029#include <asm-generic/sections.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
Simon Glassfc557362022-03-04 08:43:05 -070033__weak int fsp_setup_pinctrl(void *ctx, struct event *event)
Bin Meng2240fde2017-01-18 03:32:53 -080034{
35 return 0;
36}
37
Simon Glass0b3c5762019-10-20 21:37:49 -060038#ifdef CONFIG_TPL
39
40static int set_max_freq(void)
41{
42 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
43 /*
44 * Burst Mode has been factory-configured as disabled and is not
45 * available in this physical processor package
46 */
47 debug("Burst Mode is factory-disabled\n");
48 return -ENOENT;
49 }
50
51 /* Enable burst mode */
52 cpu_set_burst_mode(true);
53
54 /* Enable speed step */
55 cpu_set_eist(true);
56
57 /* Set P-State ratio */
58 cpu_set_p_state_to_turbo_ratio();
59
60 return 0;
61}
62#endif
63
Simon Glass030777d2017-01-16 07:03:56 -070064static int x86_spl_init(void)
65{
Simon Glass7cf5fe02019-05-02 10:52:12 -060066#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070067 /*
68 * TODO(sjg@chromium.org): We use this area of RAM for the stack
69 * and global_data in SPL. Once U-Boot starts up and releocates it
70 * is not needed. We could make this a CONFIG option or perhaps
Simon Glass72cc5382022-10-20 18:22:39 -060071 * place it immediately below CONFIG_TEXT_BASE.
Simon Glass030777d2017-01-16 07:03:56 -070072 */
Simon Glassdae11532020-04-30 21:21:42 -060073 __maybe_unused char *ptr = (char *)0x110000;
Simon Glass0b3c5762019-10-20 21:37:49 -060074#else
75 struct udevice *punit;
Simon Glass7cf5fe02019-05-02 10:52:12 -060076#endif
Simon Glass030777d2017-01-16 07:03:56 -070077 int ret;
78
79 debug("%s starting\n", __func__);
Simon Glass81f14622019-10-20 21:37:55 -060080 if (IS_ENABLED(TPL))
81 ret = x86_cpu_reinit_f();
82 else
83 ret = x86_cpu_init_f();
Simon Glass030777d2017-01-16 07:03:56 -070084 ret = spl_init();
85 if (ret) {
86 debug("%s: spl_init() failed\n", __func__);
87 return ret;
88 }
Simon Glass030777d2017-01-16 07:03:56 -070089 ret = arch_cpu_init();
90 if (ret) {
91 debug("%s: arch_cpu_init() failed\n", __func__);
92 return ret;
93 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060094#ifndef CONFIG_TPL
Simon Glassfc557362022-03-04 08:43:05 -070095 ret = fsp_setup_pinctrl(NULL, NULL);
Simon Glass030777d2017-01-16 07:03:56 -070096 if (ret) {
Tom Rinif5af9512023-01-14 15:49:35 -050097 debug("%s: fsp_setup_pinctrl() failed\n", __func__);
Simon Glass030777d2017-01-16 07:03:56 -070098 return ret;
99 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600100#endif
Simon Glassfbfb4762023-07-15 21:39:00 -0600101 /*
102 * spl_board_init() below sets up the console if enabled. If it isn't,
103 * do it here. We cannot call this twice since it results in a double
104 * banner and CI tests fail.
105 */
106 if (!IS_ENABLED(CONFIG_SPL_BOARD_INIT))
107 preloader_console_init();
Simon Glass2f002162021-03-15 18:11:18 +1300108#if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
Simon Glass030777d2017-01-16 07:03:56 -0700109 ret = print_cpuinfo();
110 if (ret) {
111 debug("%s: print_cpuinfo() failed\n", __func__);
112 return ret;
113 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600114#endif
Simon Glass030777d2017-01-16 07:03:56 -0700115 ret = dram_init();
116 if (ret) {
117 debug("%s: dram_init() failed\n", __func__);
118 return ret;
119 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600120 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
121 ret = mrccache_spl_save();
122 if (ret)
123 debug("%s: Failed to write to mrccache (err=%d)\n",
124 __func__, ret);
125 }
126
Simon Glassdae11532020-04-30 21:21:42 -0600127#ifndef CONFIG_SYS_COREBOOT
Simon Glass05dc07b2023-05-04 16:50:54 -0600128 debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start,
129 (ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass030777d2017-01-16 07:03:56 -0700130 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass47717592021-01-24 10:06:10 -0700131# ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -0700132
133 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
134 ret = interrupt_init();
135 if (ret) {
136 debug("%s: interrupt_init() failed\n", __func__);
137 return ret;
138 }
139
140 /*
141 * The stack grows down from ptr. Put the global data at ptr. This
142 * will only be used for SPL. Once SPL loads U-Boot proper it will
143 * set up its own stack.
144 */
145 gd->new_gd = (struct global_data *)ptr;
146 memcpy(gd->new_gd, gd, sizeof(*gd));
Simon Glass23ae5c32023-07-15 21:39:05 -0600147
148 /*
149 * Make sure logging is disabled when we switch, since the log system
150 * list head will move
151 */
152 gd->new_gd->flags &= ~GD_FLG_LOG_READY;
Simon Glass030777d2017-01-16 07:03:56 -0700153 arch_setup_gd(gd->new_gd);
154 gd->start_addr_sp = (ulong)ptr;
155
Simon Glass23ae5c32023-07-15 21:39:05 -0600156 /* start up logging again, with the new list-head location */
157 ret = log_init();
158 if (ret) {
159 log_debug("Log setup failed (err=%d)\n", ret);
160 return ret;
161 }
162
Simon Glassfb842432023-07-15 21:38:36 -0600163 if (_LOG_DEBUG) {
164 ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP);
165 if (ret)
166 printf("mtrr_list failed\n");
167 }
168
Simon Glass030777d2017-01-16 07:03:56 -0700169 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
170 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
171 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
172 CONFIG_XIP_ROM_SIZE);
173 if (ret) {
Simon Glass7cf5fe02019-05-02 10:52:12 -0600174 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass030777d2017-01-16 07:03:56 -0700175 return ret;
176 }
Simon Glassdae11532020-04-30 21:21:42 -0600177# else
Simon Glass0b3c5762019-10-20 21:37:49 -0600178 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
179 if (ret)
180 debug("Could not find PUNIT (err=%d)\n", ret);
181
182 ret = set_max_freq();
183 if (ret)
184 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glassdae11532020-04-30 21:21:42 -0600185# endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600186#endif
Simon Glass030777d2017-01-16 07:03:56 -0700187
188 return 0;
189}
190
191void board_init_f(ulong flags)
192{
193 int ret;
194
195 ret = x86_spl_init();
196 if (ret) {
Simon Glassa0185fa2020-05-27 06:58:48 -0600197 printf("x86_spl_init: error %d\n", ret);
198 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700199 }
Simon Glassdae11532020-04-30 21:21:42 -0600200#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
Simon Glass7cf5fe02019-05-02 10:52:12 -0600201 gd->bd = malloc(sizeof(*gd->bd));
202 if (!gd->bd) {
203 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
204 hang();
205 }
206 board_init_r(gd, 0);
207#else
Simon Glass030777d2017-01-16 07:03:56 -0700208 /* Uninit CAR and jump to board_init_f_r() */
209 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600210#endif
Simon Glass030777d2017-01-16 07:03:56 -0700211}
212
213void board_init_f_r(void)
214{
Simon Glass6e7b1b52023-05-04 16:50:57 -0600215 mtrr_commit(false);
216 init_cache();
Simon Glass030777d2017-01-16 07:03:56 -0700217 gd->flags &= ~GD_FLG_SERIAL_READY;
218 debug("cache status %d\n", dcache_status());
219 board_init_r(gd, 0);
220}
221
222u32 spl_boot_device(void)
223{
Simon Glass19da9c42019-09-25 08:11:39 -0600224 return BOOT_DEVICE_SPI_MMAP;
Simon Glass030777d2017-01-16 07:03:56 -0700225}
226
227int spl_start_uboot(void)
228{
229 return 0;
230}
231
232void spl_board_announce_boot_device(void)
233{
234 printf("SPI flash");
235}
236
237static int spl_board_load_image(struct spl_image_info *spl_image,
238 struct spl_boot_device *bootdev)
239{
240 spl_image->size = CONFIG_SYS_MONITOR_LEN;
Simon Glass72cc5382022-10-20 18:22:39 -0600241 spl_image->entry_point = CONFIG_TEXT_BASE;
242 spl_image->load_addr = CONFIG_TEXT_BASE;
Simon Glass030777d2017-01-16 07:03:56 -0700243 spl_image->os = IH_OS_U_BOOT;
244 spl_image->name = "U-Boot";
245
Simon Glass91fcd1d2020-04-30 21:21:41 -0600246 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
Simon Glass53ea0f62023-05-04 16:50:55 -0600247 /* Copy U-Boot from ROM */
248 memcpy((void *)spl_image->load_addr,
249 (void *)spl_get_image_pos(), spl_get_image_size());
Simon Glass91fcd1d2020-04-30 21:21:41 -0600250 }
251
Simon Glass030777d2017-01-16 07:03:56 -0700252 debug("Loading to %lx\n", spl_image->load_addr);
253
254 return 0;
255}
Simon Glass19da9c42019-09-25 08:11:39 -0600256SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass030777d2017-01-16 07:03:56 -0700257
258int spl_spi_load_image(void)
259{
260 return -EPERM;
261}
262
Simon Glass7cf5fe02019-05-02 10:52:12 -0600263#ifdef CONFIG_X86_RUN_64BIT
Simon Glass030777d2017-01-16 07:03:56 -0700264void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
265{
266 int ret;
267
268 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
269 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
270 debug("ret=%d\n", ret);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600271 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700272}
Simon Glass7cf5fe02019-05-02 10:52:12 -0600273#endif
274
275void spl_board_init(void)
276{
277#ifndef CONFIG_TPL
278 preloader_console_init();
279#endif
Simon Glasse50c4552023-07-15 21:39:01 -0600280
281 if (CONFIG_IS_ENABLED(VIDEO)) {
282 struct udevice *dev;
283
284 /* Set up PCI video in SPL if required */
285 uclass_first_device_err(UCLASS_PCI, &dev);
286 uclass_first_device_err(UCLASS_VIDEO, &dev);
287 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600288}