blob: b9d23e6bfe18be4c8ef88df20bc6f101b1790b61 [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 Glass030777d2017-01-16 07:03:56 -070018#include <asm/cpu.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060019#include <asm/cpu_common.h>
Simon Glassfc557362022-03-04 08:43:05 -070020#include <asm/fsp2/fsp_api.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Simon Glassfb842432023-07-15 21:38:36 -060022#include <asm/mp.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060023#include <asm/mrccache.h>
Simon Glass030777d2017-01-16 07:03:56 -070024#include <asm/mtrr.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060025#include <asm/pci.h>
Simon Glass030777d2017-01-16 07:03:56 -070026#include <asm/processor.h>
Simon Glass19da9c42019-09-25 08:11:39 -060027#include <asm/spl.h>
Simon Glass030777d2017-01-16 07:03:56 -070028#include <asm-generic/sections.h>
29
30DECLARE_GLOBAL_DATA_PTR;
31
Simon Glassfc557362022-03-04 08:43:05 -070032__weak int fsp_setup_pinctrl(void *ctx, struct event *event)
Bin Meng2240fde2017-01-18 03:32:53 -080033{
34 return 0;
35}
36
Simon Glass0b3c5762019-10-20 21:37:49 -060037#ifdef CONFIG_TPL
38
39static int set_max_freq(void)
40{
41 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
42 /*
43 * Burst Mode has been factory-configured as disabled and is not
44 * available in this physical processor package
45 */
46 debug("Burst Mode is factory-disabled\n");
47 return -ENOENT;
48 }
49
50 /* Enable burst mode */
51 cpu_set_burst_mode(true);
52
53 /* Enable speed step */
54 cpu_set_eist(true);
55
56 /* Set P-State ratio */
57 cpu_set_p_state_to_turbo_ratio();
58
59 return 0;
60}
61#endif
62
Simon Glass030777d2017-01-16 07:03:56 -070063static int x86_spl_init(void)
64{
Simon Glass7cf5fe02019-05-02 10:52:12 -060065#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070066 /*
67 * TODO(sjg@chromium.org): We use this area of RAM for the stack
68 * and global_data in SPL. Once U-Boot starts up and releocates it
69 * is not needed. We could make this a CONFIG option or perhaps
Simon Glass72cc5382022-10-20 18:22:39 -060070 * place it immediately below CONFIG_TEXT_BASE.
Simon Glass030777d2017-01-16 07:03:56 -070071 */
Simon Glassdae11532020-04-30 21:21:42 -060072 __maybe_unused char *ptr = (char *)0x110000;
Simon Glass0b3c5762019-10-20 21:37:49 -060073#else
74 struct udevice *punit;
Simon Glass7cf5fe02019-05-02 10:52:12 -060075#endif
Simon Glass030777d2017-01-16 07:03:56 -070076 int ret;
77
78 debug("%s starting\n", __func__);
Simon Glass81f14622019-10-20 21:37:55 -060079 if (IS_ENABLED(TPL))
80 ret = x86_cpu_reinit_f();
81 else
82 ret = x86_cpu_init_f();
Simon Glass030777d2017-01-16 07:03:56 -070083 ret = spl_init();
84 if (ret) {
85 debug("%s: spl_init() failed\n", __func__);
86 return ret;
87 }
Simon Glass030777d2017-01-16 07:03:56 -070088 ret = arch_cpu_init();
89 if (ret) {
90 debug("%s: arch_cpu_init() failed\n", __func__);
91 return ret;
92 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060093#ifndef CONFIG_TPL
Simon Glassfc557362022-03-04 08:43:05 -070094 ret = fsp_setup_pinctrl(NULL, NULL);
Simon Glass030777d2017-01-16 07:03:56 -070095 if (ret) {
Tom Rinif5af9512023-01-14 15:49:35 -050096 debug("%s: fsp_setup_pinctrl() failed\n", __func__);
Simon Glass030777d2017-01-16 07:03:56 -070097 return ret;
98 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060099#endif
Simon Glass6b19b4d2017-03-19 12:59:21 -0600100 preloader_console_init();
Simon Glass2f002162021-03-15 18:11:18 +1300101#if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
Simon Glass030777d2017-01-16 07:03:56 -0700102 ret = print_cpuinfo();
103 if (ret) {
104 debug("%s: print_cpuinfo() failed\n", __func__);
105 return ret;
106 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600107#endif
Simon Glass030777d2017-01-16 07:03:56 -0700108 ret = dram_init();
109 if (ret) {
110 debug("%s: dram_init() failed\n", __func__);
111 return ret;
112 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600113 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
114 ret = mrccache_spl_save();
115 if (ret)
116 debug("%s: Failed to write to mrccache (err=%d)\n",
117 __func__, ret);
118 }
119
Simon Glassdae11532020-04-30 21:21:42 -0600120#ifndef CONFIG_SYS_COREBOOT
Simon Glass05dc07b2023-05-04 16:50:54 -0600121 debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start,
122 (ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass030777d2017-01-16 07:03:56 -0700123 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass47717592021-01-24 10:06:10 -0700124# ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -0700125
126 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
127 ret = interrupt_init();
128 if (ret) {
129 debug("%s: interrupt_init() failed\n", __func__);
130 return ret;
131 }
132
133 /*
134 * The stack grows down from ptr. Put the global data at ptr. This
135 * will only be used for SPL. Once SPL loads U-Boot proper it will
136 * set up its own stack.
137 */
138 gd->new_gd = (struct global_data *)ptr;
139 memcpy(gd->new_gd, gd, sizeof(*gd));
140 arch_setup_gd(gd->new_gd);
141 gd->start_addr_sp = (ulong)ptr;
142
Simon Glassfb842432023-07-15 21:38:36 -0600143 if (_LOG_DEBUG) {
144 ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP);
145 if (ret)
146 printf("mtrr_list failed\n");
147 }
148
Simon Glass030777d2017-01-16 07:03:56 -0700149 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
150 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
151 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
152 CONFIG_XIP_ROM_SIZE);
153 if (ret) {
Simon Glass7cf5fe02019-05-02 10:52:12 -0600154 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass030777d2017-01-16 07:03:56 -0700155 return ret;
156 }
Simon Glassdae11532020-04-30 21:21:42 -0600157# else
Simon Glass0b3c5762019-10-20 21:37:49 -0600158 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
159 if (ret)
160 debug("Could not find PUNIT (err=%d)\n", ret);
161
162 ret = set_max_freq();
163 if (ret)
164 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glassdae11532020-04-30 21:21:42 -0600165# endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600166#endif
Simon Glass030777d2017-01-16 07:03:56 -0700167
168 return 0;
169}
170
171void board_init_f(ulong flags)
172{
173 int ret;
174
175 ret = x86_spl_init();
176 if (ret) {
Simon Glassa0185fa2020-05-27 06:58:48 -0600177 printf("x86_spl_init: error %d\n", ret);
178 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700179 }
Simon Glassdae11532020-04-30 21:21:42 -0600180#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
Simon Glass7cf5fe02019-05-02 10:52:12 -0600181 gd->bd = malloc(sizeof(*gd->bd));
182 if (!gd->bd) {
183 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
184 hang();
185 }
186 board_init_r(gd, 0);
187#else
Simon Glass030777d2017-01-16 07:03:56 -0700188 /* Uninit CAR and jump to board_init_f_r() */
189 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600190#endif
Simon Glass030777d2017-01-16 07:03:56 -0700191}
192
193void board_init_f_r(void)
194{
Simon Glass6e7b1b52023-05-04 16:50:57 -0600195 mtrr_commit(false);
196 init_cache();
Simon Glass030777d2017-01-16 07:03:56 -0700197 gd->flags &= ~GD_FLG_SERIAL_READY;
198 debug("cache status %d\n", dcache_status());
199 board_init_r(gd, 0);
200}
201
202u32 spl_boot_device(void)
203{
Simon Glass19da9c42019-09-25 08:11:39 -0600204 return BOOT_DEVICE_SPI_MMAP;
Simon Glass030777d2017-01-16 07:03:56 -0700205}
206
207int spl_start_uboot(void)
208{
209 return 0;
210}
211
212void spl_board_announce_boot_device(void)
213{
214 printf("SPI flash");
215}
216
217static int spl_board_load_image(struct spl_image_info *spl_image,
218 struct spl_boot_device *bootdev)
219{
220 spl_image->size = CONFIG_SYS_MONITOR_LEN;
Simon Glass72cc5382022-10-20 18:22:39 -0600221 spl_image->entry_point = CONFIG_TEXT_BASE;
222 spl_image->load_addr = CONFIG_TEXT_BASE;
Simon Glass030777d2017-01-16 07:03:56 -0700223 spl_image->os = IH_OS_U_BOOT;
224 spl_image->name = "U-Boot";
225
Simon Glass91fcd1d2020-04-30 21:21:41 -0600226 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
Simon Glass53ea0f62023-05-04 16:50:55 -0600227 /* Copy U-Boot from ROM */
228 memcpy((void *)spl_image->load_addr,
229 (void *)spl_get_image_pos(), spl_get_image_size());
Simon Glass91fcd1d2020-04-30 21:21:41 -0600230 }
231
Simon Glass030777d2017-01-16 07:03:56 -0700232 debug("Loading to %lx\n", spl_image->load_addr);
233
234 return 0;
235}
Simon Glass19da9c42019-09-25 08:11:39 -0600236SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass030777d2017-01-16 07:03:56 -0700237
238int spl_spi_load_image(void)
239{
240 return -EPERM;
241}
242
Simon Glass7cf5fe02019-05-02 10:52:12 -0600243#ifdef CONFIG_X86_RUN_64BIT
Simon Glass030777d2017-01-16 07:03:56 -0700244void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
245{
246 int ret;
247
248 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
249 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
250 debug("ret=%d\n", ret);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600251 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700252}
Simon Glass7cf5fe02019-05-02 10:52:12 -0600253#endif
254
255void spl_board_init(void)
256{
257#ifndef CONFIG_TPL
258 preloader_console_init();
259#endif
260}