blob: 6699de49c63699f2f706bcb36ed38ea6b7fcfe3e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass4bbc0242017-01-16 07:03:56 -07002/*
3 * Copyright (c) 2016 Google, Inc
Simon Glass4bbc0242017-01-16 07:03:56 -07004 */
5
6#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glass4bbc0242017-01-16 07:03:56 -07008#include <debug_uart.h>
Simon Glassc0e2c812019-10-20 21:37:49 -06009#include <dm.h>
Simon Glassdb41d652019-12-28 10:45:07 -070010#include <hang.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060011#include <image.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glassc30b7ad2019-11-14 12:57:41 -070013#include <irq_func.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass7c03caf2019-05-02 10:52:12 -060015#include <malloc.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070016#include <spl.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060017#include <syscon.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070018#include <asm/cpu.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060019#include <asm/cpu_common.h>
Simon Glass7c03caf2019-05-02 10:52:12 -060020#include <asm/mrccache.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070021#include <asm/mtrr.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060022#include <asm/pci.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070023#include <asm/processor.h>
Simon Glassdaade112019-09-25 08:11:39 -060024#include <asm/spl.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070025#include <asm-generic/sections.h>
26
27DECLARE_GLOBAL_DATA_PTR;
28
Bin Meng8f60ea02017-01-18 03:32:53 -080029__weak int arch_cpu_init_dm(void)
30{
31 return 0;
32}
33
Simon Glassc0e2c812019-10-20 21:37:49 -060034#ifdef CONFIG_TPL
35
36static int set_max_freq(void)
37{
38 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
39 /*
40 * Burst Mode has been factory-configured as disabled and is not
41 * available in this physical processor package
42 */
43 debug("Burst Mode is factory-disabled\n");
44 return -ENOENT;
45 }
46
47 /* Enable burst mode */
48 cpu_set_burst_mode(true);
49
50 /* Enable speed step */
51 cpu_set_eist(true);
52
53 /* Set P-State ratio */
54 cpu_set_p_state_to_turbo_ratio();
55
56 return 0;
57}
58#endif
59
Simon Glass4bbc0242017-01-16 07:03:56 -070060static int x86_spl_init(void)
61{
Simon Glass7c03caf2019-05-02 10:52:12 -060062#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070063 /*
64 * TODO(sjg@chromium.org): We use this area of RAM for the stack
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.
68 */
Simon Glassfc486372020-04-30 21:21:42 -060069 __maybe_unused char *ptr = (char *)0x110000;
Simon Glassc0e2c812019-10-20 21:37:49 -060070#else
71 struct udevice *punit;
Simon Glass7c03caf2019-05-02 10:52:12 -060072#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070073 int ret;
74
75 debug("%s starting\n", __func__);
Simon Glass0e72ac72019-10-20 21:37:55 -060076 if (IS_ENABLED(TPL))
77 ret = x86_cpu_reinit_f();
78 else
79 ret = x86_cpu_init_f();
Simon Glass4bbc0242017-01-16 07:03:56 -070080 ret = spl_init();
81 if (ret) {
82 debug("%s: spl_init() failed\n", __func__);
83 return ret;
84 }
Simon Glass4bbc0242017-01-16 07:03:56 -070085 ret = arch_cpu_init();
86 if (ret) {
87 debug("%s: arch_cpu_init() failed\n", __func__);
88 return ret;
89 }
Simon Glass7c03caf2019-05-02 10:52:12 -060090#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070091 ret = arch_cpu_init_dm();
92 if (ret) {
93 debug("%s: arch_cpu_init_dm() failed\n", __func__);
94 return ret;
95 }
Simon Glass7c03caf2019-05-02 10:52:12 -060096#endif
Simon Glass3ff09002017-03-19 12:59:21 -060097 preloader_console_init();
Simon Glass7c03caf2019-05-02 10:52:12 -060098#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070099 ret = print_cpuinfo();
100 if (ret) {
101 debug("%s: print_cpuinfo() failed\n", __func__);
102 return ret;
103 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600104#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700105 ret = dram_init();
106 if (ret) {
107 debug("%s: dram_init() failed\n", __func__);
108 return ret;
109 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600110 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
111 ret = mrccache_spl_save();
112 if (ret)
113 debug("%s: Failed to write to mrccache (err=%d)\n",
114 __func__, ret);
115 }
116
Simon Glassfc486372020-04-30 21:21:42 -0600117#ifndef CONFIG_SYS_COREBOOT
Simon Glass4bbc0242017-01-16 07:03:56 -0700118 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
Simon Glass02840ca2021-01-24 10:06:10 -0700119# ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -0700120
121 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
122 ret = interrupt_init();
123 if (ret) {
124 debug("%s: interrupt_init() failed\n", __func__);
125 return ret;
126 }
127
128 /*
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.
132 */
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;
137
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);
142 if (ret) {
Simon Glass7c03caf2019-05-02 10:52:12 -0600143 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass4bbc0242017-01-16 07:03:56 -0700144 return ret;
145 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600146 mtrr_commit(true);
Simon Glassfc486372020-04-30 21:21:42 -0600147# else
Simon Glassc0e2c812019-10-20 21:37:49 -0600148 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
149 if (ret)
150 debug("Could not find PUNIT (err=%d)\n", ret);
151
152 ret = set_max_freq();
153 if (ret)
154 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glassfc486372020-04-30 21:21:42 -0600155# endif
Simon Glass7c03caf2019-05-02 10:52:12 -0600156#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700157
158 return 0;
159}
160
161void board_init_f(ulong flags)
162{
163 int ret;
164
165 ret = x86_spl_init();
166 if (ret) {
Simon Glassd7413de2020-05-27 06:58:48 -0600167 printf("x86_spl_init: error %d\n", ret);
168 hang();
Simon Glass4bbc0242017-01-16 07:03:56 -0700169 }
Simon Glassfc486372020-04-30 21:21:42 -0600170#if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT)
Simon Glass7c03caf2019-05-02 10:52:12 -0600171 gd->bd = malloc(sizeof(*gd->bd));
172 if (!gd->bd) {
173 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
174 hang();
175 }
176 board_init_r(gd, 0);
177#else
Simon Glass4bbc0242017-01-16 07:03:56 -0700178 /* Uninit CAR and jump to board_init_f_r() */
179 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7c03caf2019-05-02 10:52:12 -0600180#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700181}
182
183void board_init_f_r(void)
184{
185 init_cache_f_r();
186 gd->flags &= ~GD_FLG_SERIAL_READY;
187 debug("cache status %d\n", dcache_status());
188 board_init_r(gd, 0);
189}
190
191u32 spl_boot_device(void)
192{
Simon Glassdaade112019-09-25 08:11:39 -0600193 return BOOT_DEVICE_SPI_MMAP;
Simon Glass4bbc0242017-01-16 07:03:56 -0700194}
195
196int spl_start_uboot(void)
197{
198 return 0;
199}
200
201void spl_board_announce_boot_device(void)
202{
203 printf("SPI flash");
204}
205
206static int spl_board_load_image(struct spl_image_info *spl_image,
207 struct spl_boot_device *bootdev)
208{
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";
214
Simon Glass37897c42020-04-30 21:21:41 -0600215 if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) {
216 /*
217 * Copy U-Boot from ROM
218 * TODO(sjg@chromium.org): Figure out a way to get the text base
219 * correctly here, and in the device-tree binman definition.
220 *
221 * Also consider using FIT so we get the correct image length
222 * and parameters.
223 */
224 memcpy((char *)spl_image->load_addr, (char *)0xfff00000,
225 0x100000);
226 }
227
Simon Glass4bbc0242017-01-16 07:03:56 -0700228 debug("Loading to %lx\n", spl_image->load_addr);
229
230 return 0;
231}
Simon Glassdaade112019-09-25 08:11:39 -0600232SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass4bbc0242017-01-16 07:03:56 -0700233
234int spl_spi_load_image(void)
235{
236 return -EPERM;
237}
238
Simon Glass7c03caf2019-05-02 10:52:12 -0600239#ifdef CONFIG_X86_RUN_64BIT
Simon Glass4bbc0242017-01-16 07:03:56 -0700240void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
241{
242 int ret;
243
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);
Simon Glass14dd93b2019-09-25 08:11:38 -0600247 hang();
Simon Glass4bbc0242017-01-16 07:03:56 -0700248}
Simon Glass7c03caf2019-05-02 10:52:12 -0600249#endif
250
251void spl_board_init(void)
252{
253#ifndef CONFIG_TPL
254 preloader_console_init();
255#endif
256}