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