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 | 9b61c7c | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 11 | #include <irq_func.h> |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 14 | #include <syscon.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 15 | #include <asm/cpu.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 16 | #include <asm/cpu_common.h> |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 17 | #include <asm/mrccache.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 18 | #include <asm/mtrr.h> |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 19 | #include <asm/pci.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 20 | #include <asm/processor.h> |
Simon Glass | 19da9c4 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 21 | #include <asm/spl.h> |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 22 | #include <asm-generic/sections.h> |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Bin Meng | 2240fde | 2017-01-18 03:32:53 -0800 | [diff] [blame] | 26 | __weak int arch_cpu_init_dm(void) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 31 | #ifdef CONFIG_TPL |
| 32 | |
| 33 | static 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 Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 57 | static int x86_spl_init(void) |
| 58 | { |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 59 | #ifndef CONFIG_TPL |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 60 | /* |
| 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 | */ |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 66 | __maybe_unused char *ptr = (char *)0x110000; |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 67 | #else |
| 68 | struct udevice *punit; |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 69 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 70 | int ret; |
| 71 | |
| 72 | debug("%s starting\n", __func__); |
Simon Glass | 81f1462 | 2019-10-20 21:37:55 -0600 | [diff] [blame] | 73 | if (IS_ENABLED(TPL)) |
| 74 | ret = x86_cpu_reinit_f(); |
| 75 | else |
| 76 | ret = x86_cpu_init_f(); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 77 | ret = spl_init(); |
| 78 | if (ret) { |
| 79 | debug("%s: spl_init() failed\n", __func__); |
| 80 | return ret; |
| 81 | } |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 82 | ret = arch_cpu_init(); |
| 83 | if (ret) { |
| 84 | debug("%s: arch_cpu_init() failed\n", __func__); |
| 85 | return ret; |
| 86 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 87 | #ifndef CONFIG_TPL |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 88 | ret = arch_cpu_init_dm(); |
| 89 | if (ret) { |
| 90 | debug("%s: arch_cpu_init_dm() failed\n", __func__); |
| 91 | return ret; |
| 92 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 93 | #endif |
Simon Glass | 6b19b4d | 2017-03-19 12:59:21 -0600 | [diff] [blame] | 94 | preloader_console_init(); |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 95 | #ifndef CONFIG_TPL |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 96 | ret = print_cpuinfo(); |
| 97 | if (ret) { |
| 98 | debug("%s: print_cpuinfo() failed\n", __func__); |
| 99 | return ret; |
| 100 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 101 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 102 | ret = dram_init(); |
| 103 | if (ret) { |
| 104 | debug("%s: dram_init() failed\n", __func__); |
| 105 | return ret; |
| 106 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 107 | 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 | |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 114 | #ifndef CONFIG_SYS_COREBOOT |
| 115 | # ifndef CONFIG_TPL |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 116 | memset(&__bss_start, 0, (ulong)&__bss_end - (ulong)&__bss_start); |
| 117 | |
| 118 | /* TODO(sjg@chromium.org): Consider calling cpu_init_r() here */ |
| 119 | ret = interrupt_init(); |
| 120 | if (ret) { |
| 121 | debug("%s: interrupt_init() failed\n", __func__); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * The stack grows down from ptr. Put the global data at ptr. This |
| 127 | * will only be used for SPL. Once SPL loads U-Boot proper it will |
| 128 | * set up its own stack. |
| 129 | */ |
| 130 | gd->new_gd = (struct global_data *)ptr; |
| 131 | memcpy(gd->new_gd, gd, sizeof(*gd)); |
| 132 | arch_setup_gd(gd->new_gd); |
| 133 | gd->start_addr_sp = (ulong)ptr; |
| 134 | |
| 135 | /* Cache the SPI flash. Otherwise copying the code to RAM takes ages */ |
| 136 | ret = mtrr_add_request(MTRR_TYPE_WRBACK, |
| 137 | (1ULL << 32) - CONFIG_XIP_ROM_SIZE, |
| 138 | CONFIG_XIP_ROM_SIZE); |
| 139 | if (ret) { |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 140 | debug("%s: SPI cache setup failed (err=%d)\n", __func__, ret); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 141 | return ret; |
| 142 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 143 | mtrr_commit(true); |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 144 | # else |
Simon Glass | 0b3c576 | 2019-10-20 21:37:49 -0600 | [diff] [blame] | 145 | ret = syscon_get_by_driver_data(X86_SYSCON_PUNIT, &punit); |
| 146 | if (ret) |
| 147 | debug("Could not find PUNIT (err=%d)\n", ret); |
| 148 | |
| 149 | ret = set_max_freq(); |
| 150 | if (ret) |
| 151 | debug("Failed to set CPU frequency (err=%d)\n", ret); |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 152 | # endif |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 153 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | void board_init_f(ulong flags) |
| 159 | { |
| 160 | int ret; |
| 161 | |
| 162 | ret = x86_spl_init(); |
| 163 | if (ret) { |
| 164 | debug("Error %d\n", ret); |
Simon Glass | 11ba714 | 2019-09-25 08:56:51 -0600 | [diff] [blame] | 165 | panic("x86_spl_init fail"); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 166 | } |
Simon Glass | dae1153 | 2020-04-30 21:21:42 -0600 | [diff] [blame] | 167 | #if IS_ENABLED(CONFIG_TPL) || IS_ENABLED(CONFIG_SYS_COREBOOT) |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 168 | gd->bd = malloc(sizeof(*gd->bd)); |
| 169 | if (!gd->bd) { |
| 170 | printf("Out of memory for bd_info size %x\n", sizeof(*gd->bd)); |
| 171 | hang(); |
| 172 | } |
| 173 | board_init_r(gd, 0); |
| 174 | #else |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 175 | /* Uninit CAR and jump to board_init_f_r() */ |
| 176 | board_init_f_r_trampoline(gd->start_addr_sp); |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 177 | #endif |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void board_init_f_r(void) |
| 181 | { |
| 182 | init_cache_f_r(); |
| 183 | gd->flags &= ~GD_FLG_SERIAL_READY; |
| 184 | debug("cache status %d\n", dcache_status()); |
| 185 | board_init_r(gd, 0); |
| 186 | } |
| 187 | |
| 188 | u32 spl_boot_device(void) |
| 189 | { |
Simon Glass | 19da9c4 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 190 | return BOOT_DEVICE_SPI_MMAP; |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | int spl_start_uboot(void) |
| 194 | { |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | void spl_board_announce_boot_device(void) |
| 199 | { |
| 200 | printf("SPI flash"); |
| 201 | } |
| 202 | |
| 203 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 204 | struct spl_boot_device *bootdev) |
| 205 | { |
| 206 | spl_image->size = CONFIG_SYS_MONITOR_LEN; |
| 207 | spl_image->entry_point = CONFIG_SYS_TEXT_BASE; |
| 208 | spl_image->load_addr = CONFIG_SYS_TEXT_BASE; |
| 209 | spl_image->os = IH_OS_U_BOOT; |
| 210 | spl_image->name = "U-Boot"; |
| 211 | |
Simon Glass | 91fcd1d | 2020-04-30 21:21:41 -0600 | [diff] [blame] | 212 | if (!IS_ENABLED(CONFIG_SYS_COREBOOT)) { |
| 213 | /* |
| 214 | * Copy U-Boot from ROM |
| 215 | * TODO(sjg@chromium.org): Figure out a way to get the text base |
| 216 | * correctly here, and in the device-tree binman definition. |
| 217 | * |
| 218 | * Also consider using FIT so we get the correct image length |
| 219 | * and parameters. |
| 220 | */ |
| 221 | memcpy((char *)spl_image->load_addr, (char *)0xfff00000, |
| 222 | 0x100000); |
| 223 | } |
| 224 | |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 225 | debug("Loading to %lx\n", spl_image->load_addr); |
| 226 | |
| 227 | return 0; |
| 228 | } |
Simon Glass | 19da9c4 | 2019-09-25 08:11:39 -0600 | [diff] [blame] | 229 | 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] | 230 | |
| 231 | int spl_spi_load_image(void) |
| 232 | { |
| 233 | return -EPERM; |
| 234 | } |
| 235 | |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 236 | #ifdef CONFIG_X86_RUN_64BIT |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 237 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 238 | { |
| 239 | int ret; |
| 240 | |
| 241 | printf("Jumping to 64-bit U-Boot: Note many features are missing\n"); |
| 242 | ret = cpu_jump_to_64bit_uboot(spl_image->entry_point); |
| 243 | debug("ret=%d\n", ret); |
Simon Glass | 39c6f9b | 2019-09-25 08:11:38 -0600 | [diff] [blame] | 244 | hang(); |
Simon Glass | 030777d | 2017-01-16 07:03:56 -0700 | [diff] [blame] | 245 | } |
Simon Glass | 7cf5fe0 | 2019-05-02 10:52:12 -0600 | [diff] [blame] | 246 | #endif |
| 247 | |
| 248 | void spl_board_init(void) |
| 249 | { |
| 250 | #ifndef CONFIG_TPL |
| 251 | preloader_console_init(); |
| 252 | #endif |
| 253 | } |