Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 6 | #define LOG_CATEGORY LOGC_BOOT |
| 7 | |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 10 | #include <debug_uart.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 12 | #include <hang.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 13 | #include <image.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 14 | #include <init.h> |
Simon Glass | 9b61c7c | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 15 | #include <irq_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 18 | #include <spl.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 19 | #include <syscon.h> |
Simon Glass | e50c455 | 2023-07-15 21:39:01 -0600 | [diff] [blame] | 20 | #include <vesa.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 21 | #include <asm/cpu.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 22 | #include <asm/cpu_common.h> |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 23 | #include <asm/fsp2/fsp_api.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 24 | #include <asm/global_data.h> |
Simon Glass | fb84243 | 2023-07-15 21:38:36 -0600 | [diff] [blame] | 25 | #include <asm/mp.h> |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 26 | #include <asm/mrccache.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 27 | #include <asm/mtrr.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 28 | #include <asm/pci.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 29 | #include <asm/processor.h> |
Simon Glass | 19da9c4 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 30 | #include <asm/spl.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 31 | #include <asm-generic/sections.h> |
| 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 35 | __weak int fsp_setup_pinctrl(void *ctx, struct event *event) |
Bin Meng | 2240fde | 2017-01-18 03:32:53 -0800 | [diff] [blame] | 36 | { |
| 37 | return 0; |
| 38 | } |
| 39 | |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 40 | #ifdef CONFIG_TPL |
| 41 | |
| 42 | static int set_max_freq(void) |
| 43 | { |
| 44 | if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) { |
| 45 | /* |
| 46 | * Burst Mode has been factory-configured as disabled and is not |
| 47 | * available in this physical processor package |
| 48 | */ |
| 49 | debug("Burst Mode is factory-disabled\n"); |
| 50 | return -ENOENT; |
| 51 | } |
| 52 | |
| 53 | /* Enable burst mode */ |
| 54 | cpu_set_burst_mode(true); |
| 55 | |
| 56 | /* Enable speed step */ |
| 57 | cpu_set_eist(true); |
| 58 | |
| 59 | /* Set P-State ratio */ |
| 60 | cpu_set_p_state_to_turbo_ratio(); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | #endif |
| 65 | |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 66 | static int x86_spl_init(void) |
| 67 | { |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 68 | #ifndef CONFIG_TPL |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 69 | /* |
| 70 | * TODO(sjg@chromium.org): We use this area of RAM for the stack |
| 71 | * and global_data in SPL. Once U-Boot starts up and releocates it |
| 72 | * is not needed. We could make this a CONFIG option or perhaps |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 73 | * place it immediately below CONFIG_TEXT_BASE. |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 74 | */ |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 75 | __maybe_unused char *ptr = (char *)0x110000; |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 76 | #else |
| 77 | struct udevice *punit; |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 78 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 79 | int ret; |
| 80 | |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 81 | log_debug("x86 spl starting\n"); |
Simon Glass | 81f1462 | 2019-10-20 21:37:55 -0600 | [diff] [blame] | 82 | if (IS_ENABLED(TPL)) |
| 83 | ret = x86_cpu_reinit_f(); |
| 84 | else |
| 85 | ret = x86_cpu_init_f(); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 86 | ret = spl_init(); |
| 87 | if (ret) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 88 | log_debug("spl_init() failed (err=%d)\n", ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 89 | return ret; |
| 90 | } |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 91 | ret = arch_cpu_init(); |
| 92 | if (ret) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 93 | log_debug("arch_cpu_init() failed (err=%d)\n", ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 94 | return ret; |
| 95 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 96 | #ifndef CONFIG_TPL |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 97 | ret = fsp_setup_pinctrl(NULL, NULL); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 98 | if (ret) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 99 | log_debug("fsp_setup_pinctrl() failed (err=%d)\n", ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 100 | return ret; |
| 101 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 102 | #endif |
Simon Glass | fbfb476 | 2023-07-15 21:39:00 -0600 | [diff] [blame] | 103 | /* |
| 104 | * spl_board_init() below sets up the console if enabled. If it isn't, |
| 105 | * do it here. We cannot call this twice since it results in a double |
| 106 | * banner and CI tests fail. |
| 107 | */ |
| 108 | if (!IS_ENABLED(CONFIG_SPL_BOARD_INIT)) |
| 109 | preloader_console_init(); |
Simon Glass | 2f00216 | 2021-03-15 18:11:18 +1300 | [diff] [blame] | 110 | #if !defined(CONFIG_TPL) && !CONFIG_IS_ENABLED(CPU) |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 111 | ret = print_cpuinfo(); |
| 112 | if (ret) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 113 | log_debug("print_cpuinfo() failed (err=%d)\n", ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 114 | return ret; |
| 115 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 116 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 117 | ret = dram_init(); |
| 118 | if (ret) { |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 119 | log_debug("dram_init() failed (err=%d)\n", ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 120 | return ret; |
| 121 | } |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 122 | log_debug("mrc\n"); |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 123 | if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE)) { |
| 124 | ret = mrccache_spl_save(); |
| 125 | if (ret) |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 126 | log_debug("Failed to write to mrccache (err=%d)\n", |
| 127 | ret); |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 128 | } |
| 129 | |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 130 | #ifndef CONFIG_SYS_COREBOOT |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 131 | log_debug("bss\n"); |
Simon Glass | 05dc07b | 2023-05-04 16:50:54 -0600 | [diff] [blame] | 132 | debug("BSS clear from %lx to %lx len %lx\n", (ulong)&__bss_start, |
| 133 | (ulong)&__bss_end, (ulong)&__bss_end - (ulong)&__bss_start); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 134 | memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start); |
Simon Glass | 4771759 | 2021-01-24 10:06:10 -0700 | [diff] [blame] | 135 | # ifndef CONFIG_TPL |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 136 | |
| 137 | /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */ |
| 138 | ret = interrupt_init(); |
| 139 | if (ret) { |
| 140 | debug("%s: interrupt_init() failed\n", __func__); |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * The stack grows down from ptr. Put the global data at ptr. This |
| 146 | * will only be used for SPL. Once SPL loads U-Boot proper it will |
| 147 | * set up its own stack. |
| 148 | */ |
| 149 | gd->new_gd = (struct global_data *)ptr; |
| 150 | memcpy(gd->new_gd, gd, sizeof(*gd)); |
Simon Glass | 23ae5c3 | 2023-07-15 21:39:05 -0600 | [diff] [blame] | 151 | |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 152 | log_debug("logging\n"); |
Simon Glass | 23ae5c3 | 2023-07-15 21:39:05 -0600 | [diff] [blame] | 153 | /* |
| 154 | * Make sure logging is disabled when we switch, since the log system |
| 155 | * list head will move |
| 156 | */ |
| 157 | gd->new_gd->flags &= ~GD_FLG_LOG_READY; |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 158 | arch_setup_gd(gd->new_gd); |
| 159 | gd->start_addr_sp = (ulong)ptr; |
| 160 | |
Simon Glass | 23ae5c3 | 2023-07-15 21:39:05 -0600 | [diff] [blame] | 161 | /* start up logging again, with the new list-head location */ |
| 162 | ret = log_init(); |
| 163 | if (ret) { |
| 164 | log_debug("Log setup failed (err=%d)\n", ret); |
| 165 | return ret; |
| 166 | } |
| 167 | |
Simon Glass | fb84243 | 2023-07-15 21:38:36 -0600 | [diff] [blame] | 168 | if (_LOG_DEBUG) { |
| 169 | ret = mtrr_list(mtrr_get_var_count(), MP_SELECT_BSP); |
| 170 | if (ret) |
| 171 | printf("mtrr_list failed\n"); |
| 172 | } |
| 173 | |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 174 | /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */ |
| 175 | ret = mtrr_add_request(MTRR_TYPE_WRBACK, |
| 176 | (1ULL << 32) - CONFIG_XIP_ROM_SIZE, |
| 177 | CONFIG_XIP_ROM_SIZE); |
| 178 | if (ret) { |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 179 | debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 180 | return ret; |
| 181 | } |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 182 | # else |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 183 | ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit); |
| 184 | if (ret) |
| 185 | debug("Could not find PUNIT (err=%d)\n", ret); |
| 186 | |
| 187 | ret = set_max_freq(); |
| 188 | if (ret) |
| 189 | debug("Failed to set CPU frequency (err=%d)\n", ret); |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 190 | # endif |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 191 | #endif |
Simon Glass | 3a1d96f | 2023-07-15 21:39:11 -0600 | [diff] [blame] | 192 | log_debug("done\n"); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | void board_init_f(ulong flags) |
| 198 | { |
| 199 | int ret; |
| 200 | |
| 201 | ret = x86_spl_init(); |
| 202 | if (ret) { |
Simon Glass | a0185fa | 2020-05-27 06:58:48 -0600 | [diff] [blame] | 203 | printf("x86_spl_init: error %d\n", ret); |
| 204 | hang(); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 205 | } |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 206 | #if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT) |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 207 | gd->bd = malloc(sizeof(*gd->bd)); |
| 208 | if (!gd->bd) { |
| 209 | printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd)); |
| 210 | hang(); |
| 211 | } |
| 212 | board_init_r(gd, 0); |
| 213 | #else |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 214 | /* Uninit CAR and jump to board_init_f_r() */ |
| 215 | board_init_f_r_trampoline(gd->start_addr_sp); |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 216 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void board_init_f_r(void) |
| 220 | { |
Simon Glass | 6e7b1b5 | 2023-05-04 16:50:57 -0600 | [diff] [blame] | 221 | mtrr_commit(false); |
| 222 | init_cache(); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 223 | gd->flags &= ~GD_FLG_SERIAL_READY; |
| 224 | debug("cache status %d\n", dcache_status()); |
| 225 | board_init_r(gd, 0); |
| 226 | } |
| 227 | |
| 228 | u32 spl_boot_device(void) |
| 229 | { |
Simon Glass | 19da9c4 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 230 | return BOOT_DEVICE_SPI_MMAP; |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | int spl_start_uboot(void) |
| 234 | { |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | void spl_board_announce_boot_device(void) |
| 239 | { |
| 240 | printf("SPI flash"); |
| 241 | } |
| 242 | |
| 243 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 244 | struct spl_boot_device *bootdev) |
| 245 | { |
| 246 | spl_image->size = CONFIG_SYS_MONITOR_LEN; |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 247 | spl_image->entry_point = CONFIG_TEXT_BASE; |
| 248 | spl_image->load_addr = CONFIG_TEXT_BASE; |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 249 | spl_image->os = IH_OS_U_BOOT; |
| 250 | spl_image->name = "U-Boot"; |
| 251 | |
Simon Glass | 91fcd1d | 2020-04-30 21:21:41 -0600 | [diff] [blame] | 252 | if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) { |
Simon Glass | 53ea0f6 | 2023-05-04 16:50:55 -0600 | [diff] [blame] | 253 | /* Copy U-Boot from ROM */ |
| 254 | memcpy((void *)spl_image->load_addr, |
| 255 | (void *)spl_get_image_pos(), spl_get_image_size()); |
Simon Glass | 91fcd1d | 2020-04-30 21:21:41 -0600 | [diff] [blame] | 256 | } |
| 257 | |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 258 | debug("Loading to %lx\n", spl_image->load_addr); |
| 259 | |
| 260 | return 0; |
| 261 | } |
Simon Glass | 19da9c4 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 262 | SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 263 | |
| 264 | int spl_spi_load_image(void) |
| 265 | { |
| 266 | return -EPERM; |
| 267 | } |
| 268 | |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 269 | #ifdef CONFIG_X86_RUN_64BIT |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 270 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 271 | { |
| 272 | int ret; |
| 273 | |
| 274 | printf("Jumping to 64-bit U-Boot: Note many features are missing\n"); |
| 275 | ret = cpu_jump_to_64bit_uboot(spl_image->entry_point); |
| 276 | debug("ret=%d\n", ret); |
Simon Glass | 39c6f9b | 2019-09-25 08:11:38 -0600 | [diff] [blame] | 277 | hang(); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 278 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 279 | #endif |
| 280 | |
| 281 | void spl_board_init(void) |
| 282 | { |
| 283 | #ifndef CONFIG_TPL |
| 284 | preloader_console_init(); |
| 285 | #endif |
Simon Glass | e50c455 | 2023-07-15 21:39:01 -0600 | [diff] [blame] | 286 | |
| 287 | if (CONFIG_IS_ENABLED(VIDEO)) { |
| 288 | struct udevice *dev; |
| 289 | |
| 290 | /* Set up PCI video in SPL if required */ |
| 291 | uclass_first_device_err(UCLASS_PCI, &dev); |
| 292 | uclass_first_device_err(UCLASS_VIDEO, &dev); |
| 293 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 294 | } |