blob: 1677f80b25c23421435c213bdfeea046de981231 [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>
7#include <debug_uart.h>
Simon Glassc0e2c812019-10-20 21:37:49 -06008#include <dm.h>
Simon Glass7c03caf2019-05-02 10:52:12 -06009#include <malloc.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070010#include <spl.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060011#include <syscon.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070012#include <asm/cpu.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060013#include <asm/cpu_common.h>
Simon Glass7c03caf2019-05-02 10:52:12 -060014#include <asm/mrccache.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070015#include <asm/mtrr.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060016#include <asm/pci.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070017#include <asm/processor.h>
Simon Glassdaade112019-09-25 08:11:39 -060018#include <asm/spl.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070019#include <asm-generic/sections.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
Bin Meng8f60ea02017-01-18 03:32:53 -080023__weak int arch_cpu_init_dm(void)
24{
25 return 0;
26}
27
Simon Glassc0e2c812019-10-20 21:37:49 -060028#ifdef CONFIG_TPL
29
30static int set_max_freq(void)
31{
32 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
33 /*
34 * Burst Mode has been factory-configured as disabled and is not
35 * available in this physical processor package
36 */
37 debug("Burst Mode is factory-disabled\n");
38 return -ENOENT;
39 }
40
41 /* Enable burst mode */
42 cpu_set_burst_mode(true);
43
44 /* Enable speed step */
45 cpu_set_eist(true);
46
47 /* Set P-State ratio */
48 cpu_set_p_state_to_turbo_ratio();
49
50 return 0;
51}
52#endif
53
Simon Glass4bbc0242017-01-16 07:03:56 -070054static int x86_spl_init(void)
55{
Simon Glass7c03caf2019-05-02 10:52:12 -060056#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070057 /*
58 * TODO(sjg@chromium.org): We use this area of RAM for the stack
59 * and global_data in SPL. Once U-Boot starts up and releocates it
60 * is not needed. We could make this a CONFIG option or perhaps
61 * place it immediately below CONFIG_SYS_TEXT_BASE.
62 */
63 char *ptr = (char *)0x110000;
Simon Glassc0e2c812019-10-20 21:37:49 -060064#else
65 struct udevice *punit;
Simon Glass7c03caf2019-05-02 10:52:12 -060066#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070067 int ret;
68
69 debug("%s starting\n", __func__);
Simon Glass0e72ac72019-10-20 21:37:55 -060070 if (IS_ENABLED(TPL))
71 ret = x86_cpu_reinit_f();
72 else
73 ret = x86_cpu_init_f();
Simon Glass4bbc0242017-01-16 07:03:56 -070074 ret = spl_init();
75 if (ret) {
76 debug("%s: spl_init() failed\n", __func__);
77 return ret;
78 }
Simon Glass4bbc0242017-01-16 07:03:56 -070079 ret = arch_cpu_init();
80 if (ret) {
81 debug("%s: arch_cpu_init() failed\n", __func__);
82 return ret;
83 }
Simon Glass7c03caf2019-05-02 10:52:12 -060084#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070085 ret = arch_cpu_init_dm();
86 if (ret) {
87 debug("%s: arch_cpu_init_dm() failed\n", __func__);
88 return ret;
89 }
Simon Glass7c03caf2019-05-02 10:52:12 -060090#endif
Simon Glass3ff09002017-03-19 12:59:21 -060091 preloader_console_init();
Simon Glass7c03caf2019-05-02 10:52:12 -060092#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070093 ret = print_cpuinfo();
94 if (ret) {
95 debug("%s: print_cpuinfo() failed\n", __func__);
96 return ret;
97 }
Simon Glass7c03caf2019-05-02 10:52:12 -060098#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070099 ret = dram_init();
100 if (ret) {
101 debug("%s: dram_init() failed\n", __func__);
102 return ret;
103 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600104 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
105 ret = mrccache_spl_save();
106 if (ret)
107 debug("%s: Failed to write to mrccache (err=%d)\n",
108 __func__, ret);
109 }
110
111#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -0700112 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
113
114 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
115 ret = interrupt_init();
116 if (ret) {
117 debug("%s: interrupt_init() failed\n", __func__);
118 return ret;
119 }
120
121 /*
122 * The stack grows down from ptr. Put the global data at ptr. This
123 * will only be used for SPL. Once SPL loads U-Boot proper it will
124 * set up its own stack.
125 */
126 gd->new_gd = (struct global_data *)ptr;
127 memcpy(gd->new_gd, gd, sizeof(*gd));
128 arch_setup_gd(gd->new_gd);
129 gd->start_addr_sp = (ulong)ptr;
130
131 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
132 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
133 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
134 CONFIG_XIP_ROM_SIZE);
135 if (ret) {
Simon Glass7c03caf2019-05-02 10:52:12 -0600136 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass4bbc0242017-01-16 07:03:56 -0700137 return ret;
138 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600139 mtrr_commit(true);
Simon Glassc0e2c812019-10-20 21:37:49 -0600140#else
141 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
142 if (ret)
143 debug("Could not find PUNIT (err=%d)\n", ret);
144
145 ret = set_max_freq();
146 if (ret)
147 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glass7c03caf2019-05-02 10:52:12 -0600148#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700149
150 return 0;
151}
152
153void board_init_f(ulong flags)
154{
155 int ret;
156
157 ret = x86_spl_init();
158 if (ret) {
159 debug("Error %d\n", ret);
Simon Glass3d956882019-09-25 08:56:51 -0600160 panic("x86_spl_init fail");
Simon Glass4bbc0242017-01-16 07:03:56 -0700161 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600162#ifdef CONFIG_TPL
163 gd->bd = malloc(sizeof(*gd->bd));
164 if (!gd->bd) {
165 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
166 hang();
167 }
168 board_init_r(gd, 0);
169#else
Simon Glass4bbc0242017-01-16 07:03:56 -0700170 /* Uninit CAR and jump to board_init_f_r() */
171 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7c03caf2019-05-02 10:52:12 -0600172#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700173}
174
175void board_init_f_r(void)
176{
177 init_cache_f_r();
178 gd->flags &= ~GD_FLG_SERIAL_READY;
179 debug("cache status %d\n", dcache_status());
180 board_init_r(gd, 0);
181}
182
183u32 spl_boot_device(void)
184{
Simon Glassdaade112019-09-25 08:11:39 -0600185 return BOOT_DEVICE_SPI_MMAP;
Simon Glass4bbc0242017-01-16 07:03:56 -0700186}
187
188int spl_start_uboot(void)
189{
190 return 0;
191}
192
193void spl_board_announce_boot_device(void)
194{
195 printf("SPI flash");
196}
197
198static int spl_board_load_image(struct spl_image_info *spl_image,
199 struct spl_boot_device *bootdev)
200{
201 spl_image->size = CONFIG_SYS_MONITOR_LEN;
202 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
203 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
204 spl_image->os = IH_OS_U_BOOT;
205 spl_image->name = "U-Boot";
206
207 debug("Loading to %lx\n", spl_image->load_addr);
208
209 return 0;
210}
Simon Glassdaade112019-09-25 08:11:39 -0600211SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass4bbc0242017-01-16 07:03:56 -0700212
213int spl_spi_load_image(void)
214{
215 return -EPERM;
216}
217
Simon Glass7c03caf2019-05-02 10:52:12 -0600218#ifdef CONFIG_X86_RUN_64BIT
Simon Glass4bbc0242017-01-16 07:03:56 -0700219void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
220{
221 int ret;
222
223 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
224 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
225 debug("ret=%d\n", ret);
Simon Glass14dd93b2019-09-25 08:11:38 -0600226 hang();
Simon Glass4bbc0242017-01-16 07:03:56 -0700227}
Simon Glass7c03caf2019-05-02 10:52:12 -0600228#endif
229
230void spl_board_init(void)
231{
232#ifndef CONFIG_TPL
233 preloader_console_init();
234#endif
235}