blob: 90baec2a175e3de4100764606db64b368104ac8b [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 Glassc30b7ad2019-11-14 12:57:41 -070011#include <irq_func.h>
Simon Glass7c03caf2019-05-02 10:52:12 -060012#include <malloc.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070013#include <spl.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060014#include <syscon.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070015#include <asm/cpu.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060016#include <asm/cpu_common.h>
Simon Glass7c03caf2019-05-02 10:52:12 -060017#include <asm/mrccache.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070018#include <asm/mtrr.h>
Simon Glassc0e2c812019-10-20 21:37:49 -060019#include <asm/pci.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070020#include <asm/processor.h>
Simon Glassdaade112019-09-25 08:11:39 -060021#include <asm/spl.h>
Simon Glass4bbc0242017-01-16 07:03:56 -070022#include <asm-generic/sections.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
Bin Meng8f60ea02017-01-18 03:32:53 -080026__weak int arch_cpu_init_dm(void)
27{
28 return 0;
29}
30
Simon Glassc0e2c812019-10-20 21:37:49 -060031#ifdef CONFIG_TPL
32
33static int set_max_freq(void)
34{
35 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
36 /*
37 * Burst Mode has been factory-configured as disabled and is not
38 * available in this physical processor package
39 */
40 debug("Burst Mode is factory-disabled\n");
41 return -ENOENT;
42 }
43
44 /* Enable burst mode */
45 cpu_set_burst_mode(true);
46
47 /* Enable speed step */
48 cpu_set_eist(true);
49
50 /* Set P-State ratio */
51 cpu_set_p_state_to_turbo_ratio();
52
53 return 0;
54}
55#endif
56
Simon Glass4bbc0242017-01-16 07:03:56 -070057static int x86_spl_init(void)
58{
Simon Glass7c03caf2019-05-02 10:52:12 -060059#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070060 /*
61 * TODO(sjg@chromium.org): We use this area of RAM for the stack
62 * and global_data in SPL. Once U-Boot starts up and releocates it
63 * is not needed. We could make this a CONFIG option or perhaps
64 * place it immediately below CONFIG_SYS_TEXT_BASE.
65 */
66 char *ptr = (char *)0x110000;
Simon Glassc0e2c812019-10-20 21:37:49 -060067#else
68 struct udevice *punit;
Simon Glass7c03caf2019-05-02 10:52:12 -060069#endif
Simon Glass4bbc0242017-01-16 07:03:56 -070070 int ret;
71
72 debug("%s starting\n", __func__);
Simon Glass0e72ac72019-10-20 21:37:55 -060073 if (IS_ENABLED(TPL))
74 ret = x86_cpu_reinit_f();
75 else
76 ret = x86_cpu_init_f();
Simon Glass4bbc0242017-01-16 07:03:56 -070077 ret = spl_init();
78 if (ret) {
79 debug("%s: spl_init() failed\n", __func__);
80 return ret;
81 }
Simon Glass4bbc0242017-01-16 07:03:56 -070082 ret = arch_cpu_init();
83 if (ret) {
84 debug("%s: arch_cpu_init() failed\n", __func__);
85 return ret;
86 }
Simon Glass7c03caf2019-05-02 10:52:12 -060087#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070088 ret = arch_cpu_init_dm();
89 if (ret) {
90 debug("%s: arch_cpu_init_dm() failed\n", __func__);
91 return ret;
92 }
Simon Glass7c03caf2019-05-02 10:52:12 -060093#endif
Simon Glass3ff09002017-03-19 12:59:21 -060094 preloader_console_init();
Simon Glass7c03caf2019-05-02 10:52:12 -060095#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -070096 ret = print_cpuinfo();
97 if (ret) {
98 debug("%s: print_cpuinfo() failed\n", __func__);
99 return ret;
100 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600101#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700102 ret = dram_init();
103 if (ret) {
104 debug("%s: dram_init() failed\n", __func__);
105 return ret;
106 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600107 if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) {
108 ret = mrccache_spl_save();
109 if (ret)
110 debug("%s: Failed to write to mrccache (err=%d)\n",
111 __func__, ret);
112 }
113
114#ifndef CONFIG_TPL
Simon Glass4bbc0242017-01-16 07:03:56 -0700115 memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start);
116
117 /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */
118 ret = interrupt_init();
119 if (ret) {
120 debug("%s: interrupt_init() failed\n", __func__);
121 return ret;
122 }
123
124 /*
125 * The stack grows down from ptr. Put the global data at ptr. This
126 * will only be used for SPL. Once SPL loads U-Boot proper it will
127 * set up its own stack.
128 */
129 gd->new_gd = (struct global_data *)ptr;
130 memcpy(gd->new_gd, gd, sizeof(*gd));
131 arch_setup_gd(gd->new_gd);
132 gd->start_addr_sp = (ulong)ptr;
133
134 /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */
135 ret = mtrr_add_request(MTRR_TYPE_WRBACK,
136 (1ULL << 32) - CONFIG_XIP_ROM_SIZE,
137 CONFIG_XIP_ROM_SIZE);
138 if (ret) {
Simon Glass7c03caf2019-05-02 10:52:12 -0600139 debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret);
Simon Glass4bbc0242017-01-16 07:03:56 -0700140 return ret;
141 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600142 mtrr_commit(true);
Simon Glassc0e2c812019-10-20 21:37:49 -0600143#else
144 ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit);
145 if (ret)
146 debug("Could not find PUNIT (err=%d)\n", ret);
147
148 ret = set_max_freq();
149 if (ret)
150 debug("Failed to set CPU frequency (err=%d)\n", ret);
Simon Glass7c03caf2019-05-02 10:52:12 -0600151#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700152
153 return 0;
154}
155
156void board_init_f(ulong flags)
157{
158 int ret;
159
160 ret = x86_spl_init();
161 if (ret) {
162 debug("Error %d\n", ret);
Simon Glass3d956882019-09-25 08:56:51 -0600163 panic("x86_spl_init fail");
Simon Glass4bbc0242017-01-16 07:03:56 -0700164 }
Simon Glass7c03caf2019-05-02 10:52:12 -0600165#ifdef CONFIG_TPL
166 gd->bd = malloc(sizeof(*gd->bd));
167 if (!gd->bd) {
168 printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd));
169 hang();
170 }
171 board_init_r(gd, 0);
172#else
Simon Glass4bbc0242017-01-16 07:03:56 -0700173 /* Uninit CAR and jump to board_init_f_r() */
174 board_init_f_r_trampoline(gd->start_addr_sp);
Simon Glass7c03caf2019-05-02 10:52:12 -0600175#endif
Simon Glass4bbc0242017-01-16 07:03:56 -0700176}
177
178void board_init_f_r(void)
179{
180 init_cache_f_r();
181 gd->flags &= ~GD_FLG_SERIAL_READY;
182 debug("cache status %d\n", dcache_status());
183 board_init_r(gd, 0);
184}
185
186u32 spl_boot_device(void)
187{
Simon Glassdaade112019-09-25 08:11:39 -0600188 return BOOT_DEVICE_SPI_MMAP;
Simon Glass4bbc0242017-01-16 07:03:56 -0700189}
190
191int spl_start_uboot(void)
192{
193 return 0;
194}
195
196void spl_board_announce_boot_device(void)
197{
198 printf("SPI flash");
199}
200
201static int spl_board_load_image(struct spl_image_info *spl_image,
202 struct spl_boot_device *bootdev)
203{
204 spl_image->size = CONFIG_SYS_MONITOR_LEN;
205 spl_image->entry_point = CONFIG_SYS_TEXT_BASE;
206 spl_image->load_addr = CONFIG_SYS_TEXT_BASE;
207 spl_image->os = IH_OS_U_BOOT;
208 spl_image->name = "U-Boot";
209
210 debug("Loading to %lx\n", spl_image->load_addr);
211
212 return 0;
213}
Simon Glassdaade112019-09-25 08:11:39 -0600214SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
Simon Glass4bbc0242017-01-16 07:03:56 -0700215
216int spl_spi_load_image(void)
217{
218 return -EPERM;
219}
220
Simon Glass7c03caf2019-05-02 10:52:12 -0600221#ifdef CONFIG_X86_RUN_64BIT
Simon Glass4bbc0242017-01-16 07:03:56 -0700222void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
223{
224 int ret;
225
226 printf("Jumping to 64-bit U-Boot: Note many features are missing\n");
227 ret = cpu_jump_to_64bit_uboot(spl_image->entry_point);
228 debug("ret=%d\n", ret);
Simon Glass14dd93b2019-09-25 08:11:38 -0600229 hang();
Simon Glass4bbc0242017-01-16 07:03:56 -0700230}
Simon Glass7c03caf2019-05-02 10:52:12 -0600231#endif
232
233void spl_board_init(void)
234{
235#ifndef CONFIG_TPL
236 preloader_console_init();
237#endif
238}