blob: 479889aec6f02745544281c6d105c57982ebf649 [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 Glass7cf5fe02019-05-02 10:52:12 -060022#include <asm/mrccache.h>
Simon Glass030777d2017-01-16 07:03:56 -070023#include <asm/mtrr.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060024#include <asm/pci.h>
Simon Glass030777d2017-01-16 07:03:56 -070025#include <asm/processor.h>
Simon Glass19da9c42019-09-25 08:11:39 -060026#include <asm/spl.h>
Simon Glass030777d2017-01-16 07:03:56 -070027#include <asm-generic/sections.h>
28
29DECLARE_GLOBAL_DATA_PTR;
30
Simon Glassfc557362022-03-04 08:43:05 -070031__weak int fsp_setup_pinctrl(void *ctx, struct event *event)
Bin Meng2240fde2017-01-18 03:32:53 -080032{
33 return 0;
34}
35
Simon Glass0b3c5762019-10-20 21:37:49 -060036#ifdef CONFIG_TPL
37
38static int set_max_freq(void)
39{
40 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
41 /*
42 * Burst Mode has been factory-configured as disabled and is not
43 * available in this physical processor package
44 */
45 debug("Burst Mode is factory-disabled\n");
46 return -ENOENT;
47 }
48
49 /* Enable burst mode */
50 cpu_set_burst_mode(true);
51
52 /* Enable speed step */
53 cpu_set_eist(true);
54
55 /* Set P-State ratio */
56 cpu_set_p_state_to_turbo_ratio();
57
58 return 0;
59}
60#endif
61
Simon Glass030777d2017-01-16 07:03:56 -070062static int x86_spl_init(void)
63{
Simon Glass7cf5fe02019-05-02 10:52:12 -060064#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070065 /*
66 * TODO(sjg@chromium.org): We use this area of RAM for the stack
67 * and global_data in SPL. Once U-Boot starts up and releocates it
68 * is not needed. We could make this a CONFIG option or perhaps
Simon Glass72cc5382022-10-20 18:22:39 -060069 * place it immediately below CONFIG_TEXT_BASE.
Simon Glass030777d2017-01-16 07:03:56 -070070 */
Simon Glassdae11532020-04-30 21:21:42 -060071 __maybe_unused char *ptr = (char *)0x110000;
Simon Glass0b3c5762019-10-20 21:37:49 -060072#else
73 struct udevice *punit;
Simon Glass7cf5fe02019-05-02 10:52:12 -060074#endif
Simon Glass030777d2017-01-16 07:03:56 -070075 int ret;
76
77 debug("%s starting\n", __func__);
Simon Glass81f14622019-10-20 21:37:55 -060078 if (IS_ENABLED(TPL))
79 ret = x86_cpu_reinit_f();
80 else
81 ret = x86_cpu_init_f();
Simon Glass030777d2017-01-16 07:03:56 -070082 ret = spl_init();
83 if (ret) {
84 debug("%s: spl_init() failed\n", __func__);
85 return ret;
86 }
Simon Glass030777d2017-01-16 07:03:56 -070087 ret = arch_cpu_init();
88 if (ret) {
89 debug("%s: arch_cpu_init() failed\n", __func__);
90 return ret;
91 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060092#ifndef CONFIG_TPL
Simon Glassfc557362022-03-04 08:43:05 -070093 ret = fsp_setup_pinctrl(NULL, NULL);
Simon Glass030777d2017-01-16 07:03:56 -070094 if (ret) {
Tom Rinif5af9512023-01-14 15:49:35 -050095 debug("%s: fsp_setup_pinctrl() failed\n", __func__);
Simon Glass030777d2017-01-16 07:03:56 -070096 return ret;
97 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060098#endif
Simon Glass6b19b4d2017-03-19 12:59:21 -060099 preloader_console_init();
Simon Glass2f002162021-03-15 18:11:18 +1300100#if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU)
Simon Glass030777d2017-01-16 07:03:56 -0700101 ret = print_cpuinfo();
102 if (ret) {
103 debug("%s: print_cpuinfo() failed\n", __func__);
104 return ret;
105 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600106#endif
Simon Glass030777d2017-01-16 07:03:56 -0700107 ret = dram_init();
108 if (ret) {
109 debug("%s: dram_init() failed\n", __func__);
110 return ret;
111 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600112 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
113 ret = mrccache_spl_save();
114 if (ret)
115 debug("%s: Failed to write to mrccache (err=%d)\n",
116 __func__, ret);
117 }
118
Simon Glassdae11532020-04-30 21:21:42 -0600119#ifndef CONFIG_SYS_COREBOOT
Simon Glass05dc07b2023-05-04 16:50:54 -0600120 debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start,
121 (ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass030777d2017-01-16 07:03:56 -0700122 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass47717592021-01-24 10:06:10 -0700123# ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -0700124
125 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
126 ret = interrupt_init();
127 if (ret) {
128 debug("%s: interrupt_init() failed\n", __func__);
129 return ret;
130 }
131
132 /*
133 * The stack grows down from ptr. Put the global data at ptr. This
134 * will only be used for SPL. Once SPL loads U-Boot proper it will
135 * set up its own stack.
136 */
137 gd->new_gd = (struct global_data *)ptr;
138 memcpy(gd->new_gd, gd, sizeof(*gd));
139 arch_setup_gd(gd->new_gd);
140 gd->start_addr_sp = (ulong)ptr;
141
142 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
143 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
144 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
145 CONFIG_XIP_ROM_SIZE);
146 if (ret) {
Simon Glass7cf5fe02019-05-02 10:52:12 -0600147 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass030777d2017-01-16 07:03:56 -0700148 return ret;
149 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600150 mtrr_commit(true);
Simon Glassdae11532020-04-30 21:21:42 -0600151# else
Simon Glass0b3c5762019-10-20 21:37:49 -0600152 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
153 if (ret)
154 debug("Could not find PUNIT (err=%d)\n", ret);
155
156 ret = set_max_freq();
157 if (ret)
158 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glassdae11532020-04-30 21:21:42 -0600159# endif
Simon Glass7cf5fe02019-05-02 10:52:12 -0600160#endif
Simon Glass030777d2017-01-16 07:03:56 -0700161
162 return 0;
163}
164
165void board_init_f(ulong flags)
166{
167 int ret;
168
169 ret = x86_spl_init();
170 if (ret) {
Simon Glassa0185fa2020-05-27 06:58:48 -0600171 printf("x86_spl_init: error %d\n", ret);
172 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700173 }
Simon Glassdae11532020-04-30 21:21:42 -0600174#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
Simon Glass7cf5fe02019-05-02 10:52:12 -0600175 gd->bd = malloc(sizeof(*gd->bd));
176 if (!gd->bd) {
177 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
178 hang();
179 }
180 board_init_r(gd, 0);
181#else
Simon Glass030777d2017-01-16 07:03:56 -0700182 /* Uninit CAR and jump to board_init_f_r() */
183 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600184#endif
Simon Glass030777d2017-01-16 07:03:56 -0700185}
186
187void board_init_f_r(void)
188{
189 init_cache_f_r();
190 gd->flags &= ~GD_FLG_SERIAL_READY;
191 debug("cache status %d\n", dcache_status());
192 board_init_r(gd, 0);
193}
194
195u32 spl_boot_device(void)
196{
Simon Glass19da9c42019-09-25 08:11:39 -0600197 return BOOT_DEVICE_SPI_MMAP;
Simon Glass030777d2017-01-16 07:03:56 -0700198}
199
200int spl_start_uboot(void)
201{
202 return 0;
203}
204
205void spl_board_announce_boot_device(void)
206{
207 printf("SPI flash");
208}
209
210static int spl_board_load_image(struct spl_image_info *spl_image,
211 struct spl_boot_device *bootdev)
212{
213 spl_image->size = CONFIG_SYS_MONITOR_LEN;
Simon Glass72cc5382022-10-20 18:22:39 -0600214 spl_image->entry_point = CONFIG_TEXT_BASE;
215 spl_image->load_addr = CONFIG_TEXT_BASE;
Simon Glass030777d2017-01-16 07:03:56 -0700216 spl_image->os = IH_OS_U_BOOT;
217 spl_image->name = "U-Boot";
218
Simon Glass91fcd1d2020-04-30 21:21:41 -0600219 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
Simon Glass53ea0f62023-05-04 16:50:55 -0600220 /* Copy U-Boot from ROM */
221 memcpy((void *)spl_image->load_addr,
222 (void *)spl_get_image_pos(), spl_get_image_size());
Simon Glass91fcd1d2020-04-30 21:21:41 -0600223 }
224
Simon Glass030777d2017-01-16 07:03:56 -0700225 debug("Loading to %lx\n", spl_image->load_addr);
226
227 return 0;
228}
Simon Glass19da9c42019-09-25 08:11:39 -0600229SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass030777d2017-01-16 07:03:56 -0700230
231int spl_spi_load_image(void)
232{
233 return -EPERM;
234}
235
Simon Glass7cf5fe02019-05-02 10:52:12 -0600236#ifdef CONFIG_X86_RUN_64BIT
Simon Glass030777d2017-01-16 07:03:56 -0700237void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
238{
239 int ret;
240
241 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
242 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
243 debug("ret=%d\n", ret);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600244 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700245}
Simon Glass7cf5fe02019-05-02 10:52:12 -0600246#endif
247
248void spl_board_init(void)
249{
250#ifndef CONFIG_TPL
251 preloader_console_init();
252#endif
253}