blob: f0e2bf053d74160145bf0ff5379a689d1077ad48 [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 Glass9b61c7c2019-11-14 12:57:41 -070010#include <irq_func.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060011#include <malloc.h>
Simon Glass030777d2017-01-16 07:03:56 -070012#include <spl.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060013#include <syscon.h>
Simon Glass030777d2017-01-16 07:03:56 -070014#include <asm/cpu.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060015#include <asm/cpu_common.h>
Simon Glass7cf5fe02019-05-02 10:52:12 -060016#include <asm/mrccache.h>
Simon Glass030777d2017-01-16 07:03:56 -070017#include <asm/mtrr.h>
Simon Glass0b3c5762019-10-20 21:37:49 -060018#include <asm/pci.h>
Simon Glass030777d2017-01-16 07:03:56 -070019#include <asm/processor.h>
Simon Glass19da9c42019-09-25 08:11:39 -060020#include <asm/spl.h>
Simon Glass030777d2017-01-16 07:03:56 -070021#include <asm-generic/sections.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
Bin Meng2240fde2017-01-18 03:32:53 -080025__weak int arch_cpu_init_dm(void)
26{
27 return 0;
28}
29
Simon Glass0b3c5762019-10-20 21:37:49 -060030#ifdef CONFIG_TPL
31
32static int set_max_freq(void)
33{
34 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
35 /*
36 * Burst Mode has been factory-configured as disabled and is not
37 * available in this physical processor package
38 */
39 debug("Burst Mode is factory-disabled\n");
40 return -ENOENT;
41 }
42
43 /* Enable burst mode */
44 cpu_set_burst_mode(true);
45
46 /* Enable speed step */
47 cpu_set_eist(true);
48
49 /* Set P-State ratio */
50 cpu_set_p_state_to_turbo_ratio();
51
52 return 0;
53}
54#endif
55
Simon Glass030777d2017-01-16 07:03:56 -070056static int x86_spl_init(void)
57{
Simon Glass7cf5fe02019-05-02 10:52:12 -060058#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070059 /*
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.
64 */
65 char *ptr = (char *)0x110000;
Simon Glass0b3c5762019-10-20 21:37:49 -060066#else
67 struct udevice *punit;
Simon Glass7cf5fe02019-05-02 10:52:12 -060068#endif
Simon Glass030777d2017-01-16 07:03:56 -070069 int ret;
70
71 debug("%s starting\n", __func__);
Simon Glass81f14622019-10-20 21:37:55 -060072 if (IS_ENABLED(TPL))
73 ret = x86_cpu_reinit_f();
74 else
75 ret = x86_cpu_init_f();
Simon Glass030777d2017-01-16 07:03:56 -070076 ret = spl_init();
77 if (ret) {
78 debug("%s: spl_init() failed\n", __func__);
79 return ret;
80 }
Simon Glass030777d2017-01-16 07:03:56 -070081 ret = arch_cpu_init();
82 if (ret) {
83 debug("%s: arch_cpu_init() failed\n", __func__);
84 return ret;
85 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060086#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070087 ret = arch_cpu_init_dm();
88 if (ret) {
89 debug("%s: arch_cpu_init_dm() failed\n", __func__);
90 return ret;
91 }
Simon Glass7cf5fe02019-05-02 10:52:12 -060092#endif
Simon Glass6b19b4d2017-03-19 12:59:21 -060093 preloader_console_init();
Simon Glass7cf5fe02019-05-02 10:52:12 -060094#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -070095 ret = print_cpuinfo();
96 if (ret) {
97 debug("%s: print_cpuinfo() failed\n", __func__);
98 return ret;
99 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600100#endif
Simon Glass030777d2017-01-16 07:03:56 -0700101 ret = dram_init();
102 if (ret) {
103 debug("%s: dram_init() failed\n", __func__);
104 return ret;
105 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600106 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
107 ret = mrccache_spl_save();
108 if (ret)
109 debug("%s: Failed to write to mrccache (err=%d)\n",
110 __func__, ret);
111 }
112
113#ifndef CONFIG_TPL
Simon Glass030777d2017-01-16 07:03:56 -0700114 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
115
116 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
117 ret = interrupt_init();
118 if (ret) {
119 debug("%s: interrupt_init() failed\n", __func__);
120 return ret;
121 }
122
123 /*
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.
127 */
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;
132
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);
137 if (ret) {
Simon Glass7cf5fe02019-05-02 10:52:12 -0600138 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass030777d2017-01-16 07:03:56 -0700139 return ret;
140 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600141 mtrr_commit(true);
Simon Glass0b3c5762019-10-20 21:37:49 -0600142#else
143 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
144 if (ret)
145 debug("Could not find PUNIT (err=%d)\n", ret);
146
147 ret = set_max_freq();
148 if (ret)
149 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600150#endif
Simon Glass030777d2017-01-16 07:03:56 -0700151
152 return 0;
153}
154
155void board_init_f(ulong flags)
156{
157 int ret;
158
159 ret = x86_spl_init();
160 if (ret) {
161 debug("Error %d\n", ret);
Simon Glass11ba7142019-09-25 08:56:51 -0600162 panic("x86_spl_init fail");
Simon Glass030777d2017-01-16 07:03:56 -0700163 }
Simon Glass7cf5fe02019-05-02 10:52:12 -0600164#ifdef CONFIG_TPL
165 gd->bd = malloc(sizeof(*gd->bd));
166 if (!gd->bd) {
167 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
168 hang();
169 }
170 board_init_r(gd, 0);
171#else
Simon Glass030777d2017-01-16 07:03:56 -0700172 /* Uninit CAR and jump to board_init_f_r() */
173 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7cf5fe02019-05-02 10:52:12 -0600174#endif
Simon Glass030777d2017-01-16 07:03:56 -0700175}
176
177void board_init_f_r(void)
178{
179 init_cache_f_r();
180 gd->flags &= ~GD_FLG_SERIAL_READY;
181 debug("cache status %d\n", dcache_status());
182 board_init_r(gd, 0);
183}
184
185u32 spl_boot_device(void)
186{
Simon Glass19da9c42019-09-25 08:11:39 -0600187 return BOOT_DEVICE_SPI_MMAP;
Simon Glass030777d2017-01-16 07:03:56 -0700188}
189
190int spl_start_uboot(void)
191{
192 return 0;
193}
194
195void spl_board_announce_boot_device(void)
196{
197 printf("SPI flash");
198}
199
200static int spl_board_load_image(struct spl_image_info *spl_image,
201 struct spl_boot_device *bootdev)
202{
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";
208
209 debug("Loading to %lx\n", spl_image->load_addr);
210
211 return 0;
212}
Simon Glass19da9c42019-09-25 08:11:39 -0600213SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass030777d2017-01-16 07:03:56 -0700214
215int spl_spi_load_image(void)
216{
217 return -EPERM;
218}
219
Simon Glass7cf5fe02019-05-02 10:52:12 -0600220#ifdef CONFIG_X86_RUN_64BIT
Simon Glass030777d2017-01-16 07:03:56 -0700221void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
222{
223 int ret;
224
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);
Simon Glass39c6f9b2019-09-25 08:11:38 -0600228 hang();
Simon Glass030777d2017-01-16 07:03:56 -0700229}
Simon Glass7cf5fe02019-05-02 10:52:12 -0600230#endif
231
232void spl_board_init(void)
233{
234#ifndef CONFIG_TPL
235 preloader_console_init();
236#endif
237}