Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * K3: Common Architecture initialization |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | */ |
| 8 | |
Tom Rini | b7f7046 | 2023-12-14 13:16:45 -0500 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 10 | #include <cpu_func.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 | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 16 | #include <linux/printk.h> |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 17 | #include "common.h" |
| 18 | #include <dm.h> |
| 19 | #include <remoteproc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <asm/cache.h> |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 21 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | 16cf5d2 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 22 | #include <fdt_support.h> |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 23 | #include <asm/hardware.h> |
| 24 | #include <asm/io.h> |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 25 | #include <fs_loader.h> |
| 26 | #include <fs.h> |
| 27 | #include <env.h> |
| 28 | #include <elf.h> |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 29 | #include <soc.h> |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 30 | |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 31 | #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF) |
| 32 | enum { |
| 33 | IMAGE_ID_ATF, |
| 34 | IMAGE_ID_OPTEE, |
| 35 | IMAGE_ID_SPL, |
| 36 | IMAGE_ID_DM_FW, |
| 37 | IMAGE_AMT, |
| 38 | }; |
| 39 | |
| 40 | #if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) |
| 41 | static const char *image_os_match[IMAGE_AMT] = { |
| 42 | "arm-trusted-firmware", |
| 43 | "tee", |
| 44 | "U-Boot", |
| 45 | "DM", |
| 46 | }; |
| 47 | #endif |
| 48 | |
| 49 | static struct image_info fit_image_info[IMAGE_AMT]; |
| 50 | #endif |
| 51 | |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 52 | struct ti_sci_handle *get_ti_sci_handle(void) |
| 53 | { |
| 54 | struct udevice *dev; |
| 55 | int ret; |
| 56 | |
Lokesh Vutla | 00a1513 | 2019-09-27 13:32:15 +0530 | [diff] [blame] | 57 | ret = uclass_get_device_by_driver(UCLASS_FIRMWARE, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 58 | DM_DRIVER_GET(ti_sci), &dev); |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 59 | if (ret) |
| 60 | panic("Failed to get SYSFW (%d)\n", ret); |
| 61 | |
| 62 | return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev); |
| 63 | } |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 64 | |
Lokesh Vutla | 5fafe44 | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 65 | void k3_sysfw_print_ver(void) |
| 66 | { |
| 67 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 68 | char fw_desc[sizeof(ti_sci->version.firmware_description) + 1]; |
| 69 | |
| 70 | /* |
| 71 | * Output System Firmware version info. Note that since the |
| 72 | * 'firmware_description' field is not guaranteed to be zero- |
| 73 | * terminated we manually add a \0 terminator if needed. Further |
| 74 | * note that we intentionally no longer rely on the extended |
| 75 | * printf() formatter '%.*s' to not having to require a more |
| 76 | * full-featured printf() implementation. |
| 77 | */ |
| 78 | strncpy(fw_desc, ti_sci->version.firmware_description, |
| 79 | sizeof(ti_sci->version.firmware_description)); |
| 80 | fw_desc[sizeof(fw_desc) - 1] = '\0'; |
| 81 | |
| 82 | printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n", |
| 83 | ti_sci->version.abi_major, ti_sci->version.abi_minor, |
| 84 | ti_sci->version.firmware_revision, fw_desc); |
| 85 | } |
| 86 | |
Matthias Schiffer | 0262dcd | 2023-09-27 15:43:14 +0200 | [diff] [blame] | 87 | void mmr_unlock(uintptr_t base, u32 partition) |
Lokesh Vutla | ff7ab09 | 2020-08-05 22:44:17 +0530 | [diff] [blame] | 88 | { |
| 89 | /* Translate the base address */ |
Matthias Schiffer | 0262dcd | 2023-09-27 15:43:14 +0200 | [diff] [blame] | 90 | uintptr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE; |
Lokesh Vutla | ff7ab09 | 2020-08-05 22:44:17 +0530 | [diff] [blame] | 91 | |
| 92 | /* Unlock the requested partition if locked using two-step sequence */ |
| 93 | writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0); |
| 94 | writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1); |
| 95 | } |
| 96 | |
Lokesh Vutla | 8be6bbf | 2020-08-05 22:44:23 +0530 | [diff] [blame] | 97 | bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data) |
| 98 | { |
| 99 | if (strncmp(data->header, K3_ROM_BOOT_HEADER_MAGIC, 7)) |
| 100 | return false; |
| 101 | |
| 102 | return data->num_components > 1; |
| 103 | } |
| 104 | |
Andreas Dannenberg | d13ec8c | 2019-08-15 15:55:28 -0500 | [diff] [blame] | 105 | DECLARE_GLOBAL_DATA_PTR; |
| 106 | |
| 107 | #ifdef CONFIG_K3_EARLY_CONS |
| 108 | int early_console_init(void) |
| 109 | { |
| 110 | struct udevice *dev; |
| 111 | int ret; |
| 112 | |
| 113 | gd->baudrate = CONFIG_BAUDRATE; |
| 114 | |
| 115 | ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX, |
| 116 | &dev); |
| 117 | if (ret) { |
| 118 | printf("Error getting serial dev for early console! (%d)\n", |
| 119 | ret); |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | gd->cur_serial_dev = dev; |
| 124 | gd->flags |= GD_FLG_SERIAL_READY; |
| 125 | gd->have_console = 1; |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | #endif |
| 130 | |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 131 | #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF) |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 132 | |
| 133 | void init_env(void) |
| 134 | { |
| 135 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 136 | char *part; |
| 137 | |
| 138 | env_init(); |
| 139 | env_relocate(); |
| 140 | switch (spl_boot_device()) { |
| 141 | case BOOT_DEVICE_MMC2: |
| 142 | part = env_get("bootpart"); |
| 143 | env_set("storage_interface", "mmc"); |
| 144 | env_set("fw_dev_part", part); |
| 145 | break; |
| 146 | case BOOT_DEVICE_SPI: |
| 147 | env_set("storage_interface", "ubi"); |
| 148 | env_set("fw_ubi_mtdpart", "UBI"); |
| 149 | env_set("fw_ubi_volume", "UBI0"); |
| 150 | break; |
| 151 | default: |
| 152 | printf("%s from device %u not supported!\n", |
| 153 | __func__, spl_boot_device()); |
| 154 | return; |
| 155 | } |
| 156 | #endif |
| 157 | } |
| 158 | |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 159 | int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr) |
| 160 | { |
| 161 | struct udevice *fsdev; |
| 162 | char *name = NULL; |
| 163 | int size = 0; |
| 164 | |
Keerthy | fe8f609 | 2022-01-27 13:16:53 +0100 | [diff] [blame] | 165 | if (!IS_ENABLED(CONFIG_FS_LOADER)) |
| 166 | return 0; |
| 167 | |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 168 | *loadaddr = 0; |
| 169 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 170 | switch (spl_boot_device()) { |
| 171 | case BOOT_DEVICE_MMC2: |
| 172 | name = env_get(name_fw); |
| 173 | *loadaddr = env_get_hex(name_loadaddr, *loadaddr); |
| 174 | break; |
| 175 | default: |
| 176 | printf("Loading rproc fw image from device %u not supported!\n", |
| 177 | spl_boot_device()); |
| 178 | return 0; |
| 179 | } |
| 180 | #endif |
| 181 | if (!*loadaddr) |
| 182 | return 0; |
| 183 | |
Sean Anderson | 5cd0cb3 | 2022-12-29 11:52:59 -0500 | [diff] [blame] | 184 | if (!get_fs_loader(&fsdev)) { |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 185 | size = request_firmware_into_buf(fsdev, name, (void *)*loadaddr, |
| 186 | 0, 0); |
| 187 | } |
| 188 | |
| 189 | return size; |
| 190 | } |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 191 | |
Andrew Davis | c178e6d | 2023-04-06 11:38:15 -0500 | [diff] [blame] | 192 | void release_resources_for_core_shutdown(void) |
Suman Anna | 3457410 | 2021-07-27 18:24:40 -0500 | [diff] [blame] | 193 | { |
Andrew Davis | c178e6d | 2023-04-06 11:38:15 -0500 | [diff] [blame] | 194 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 195 | struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops; |
| 196 | struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops; |
| 197 | int ret; |
| 198 | u32 i; |
| 199 | |
| 200 | /* Iterate through list of devices to put (shutdown) */ |
| 201 | for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) { |
| 202 | u32 id = put_device_ids[i]; |
| 203 | |
| 204 | ret = dev_ops->put_device(ti_sci, id); |
| 205 | if (ret) |
| 206 | panic("Failed to put device %u (%d)\n", id, ret); |
| 207 | } |
| 208 | |
| 209 | /* Iterate through list of cores to put (shutdown) */ |
| 210 | for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) { |
| 211 | u32 id = put_core_ids[i]; |
| 212 | |
| 213 | /* |
| 214 | * Queue up the core shutdown request. Note that this call |
| 215 | * needs to be followed up by an actual invocation of an WFE |
| 216 | * or WFI CPU instruction. |
| 217 | */ |
| 218 | ret = proc_ops->proc_shutdown_no_wait(ti_sci, id); |
| 219 | if (ret) |
| 220 | panic("Failed sending core %u shutdown message (%d)\n", |
| 221 | id, ret); |
| 222 | } |
Suman Anna | 3457410 | 2021-07-27 18:24:40 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 225 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 226 | { |
Keerthy | 20c87b0 | 2020-02-12 13:55:06 +0530 | [diff] [blame] | 227 | typedef void __noreturn (*image_entry_noargs_t)(void); |
Lokesh Vutla | 005476d | 2019-06-07 19:24:43 +0530 | [diff] [blame] | 228 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
Keerthy | 20c87b0 | 2020-02-12 13:55:06 +0530 | [diff] [blame] | 229 | u32 loadaddr = 0; |
Nishanth Menon | 1535e2a | 2021-08-31 13:20:48 -0500 | [diff] [blame] | 230 | int ret, size = 0, shut_cpu = 0; |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 231 | |
Lokesh Vutla | 005476d | 2019-06-07 19:24:43 +0530 | [diff] [blame] | 232 | /* Release all the exclusive devices held by SPL before starting ATF */ |
| 233 | ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci); |
| 234 | |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 235 | ret = rproc_init(); |
| 236 | if (ret) |
| 237 | panic("rproc failed to be initialized (%d)\n", ret); |
| 238 | |
| 239 | init_env(); |
Dave Gerlach | cdd0245 | 2021-06-11 11:45:21 +0300 | [diff] [blame] | 240 | |
| 241 | if (!fit_image_info[IMAGE_ID_DM_FW].image_start) { |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 242 | size = load_firmware("name_mcur5f0_0fw", "addr_mcur5f0_0load", |
| 243 | &loadaddr); |
Dave Gerlach | cdd0245 | 2021-06-11 11:45:21 +0300 | [diff] [blame] | 244 | } |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 245 | |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 246 | /* |
| 247 | * It is assumed that remoteproc device 1 is the corresponding |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 248 | * Cortex-A core which runs ATF. Make sure DT reflects the same. |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 249 | */ |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 250 | if (!fit_image_info[IMAGE_ID_ATF].image_start) |
| 251 | fit_image_info[IMAGE_ID_ATF].image_start = |
| 252 | spl_image->entry_point; |
| 253 | |
| 254 | ret = rproc_load(1, fit_image_info[IMAGE_ID_ATF].image_start, 0x200); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 255 | if (ret) |
| 256 | panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 257 | |
Manorit Chawdhry | c20edd3 | 2023-04-14 09:48:01 +0530 | [diff] [blame] | 258 | #if (CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) && IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)) |
| 259 | /* Authenticate ATF */ |
| 260 | void *image_addr = (void *)fit_image_info[IMAGE_ID_ATF].image_start; |
| 261 | |
| 262 | debug("%s: Authenticating image: addr=%lx, size=%ld, os=%s\n", __func__, |
| 263 | fit_image_info[IMAGE_ID_ATF].image_start, |
| 264 | fit_image_info[IMAGE_ID_ATF].image_len, |
| 265 | image_os_match[IMAGE_ID_ATF]); |
| 266 | |
| 267 | ti_secure_image_post_process(&image_addr, |
| 268 | (size_t *)&fit_image_info[IMAGE_ID_ATF].image_len); |
| 269 | |
| 270 | /* Authenticate OPTEE */ |
| 271 | image_addr = (void *)fit_image_info[IMAGE_ID_OPTEE].image_start; |
| 272 | |
| 273 | debug("%s: Authenticating image: addr=%lx, size=%ld, os=%s\n", __func__, |
| 274 | fit_image_info[IMAGE_ID_OPTEE].image_start, |
| 275 | fit_image_info[IMAGE_ID_OPTEE].image_len, |
| 276 | image_os_match[IMAGE_ID_OPTEE]); |
| 277 | |
| 278 | ti_secure_image_post_process(&image_addr, |
| 279 | (size_t *)&fit_image_info[IMAGE_ID_OPTEE].image_len); |
| 280 | |
| 281 | #endif |
| 282 | |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 283 | if (!fit_image_info[IMAGE_ID_DM_FW].image_len && |
| 284 | !(size > 0 && valid_elf_image(loadaddr))) { |
Nishanth Menon | 1535e2a | 2021-08-31 13:20:48 -0500 | [diff] [blame] | 285 | shut_cpu = 1; |
| 286 | goto start_arm64; |
Keerthy | 20c87b0 | 2020-02-12 13:55:06 +0530 | [diff] [blame] | 287 | } |
| 288 | |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 289 | if (!fit_image_info[IMAGE_ID_DM_FW].image_start) { |
| 290 | loadaddr = load_elf_image_phdr(loadaddr); |
| 291 | } else { |
| 292 | loadaddr = fit_image_info[IMAGE_ID_DM_FW].image_start; |
| 293 | if (valid_elf_image(loadaddr)) |
| 294 | loadaddr = load_elf_image_phdr(loadaddr); |
| 295 | } |
| 296 | |
| 297 | debug("%s: jumping to address %x\n", __func__, loadaddr); |
| 298 | |
Nishanth Menon | 1535e2a | 2021-08-31 13:20:48 -0500 | [diff] [blame] | 299 | start_arm64: |
| 300 | /* Add an extra newline to differentiate the ATF logs from SPL */ |
| 301 | printf("Starting ATF on ARM64 core...\n\n"); |
| 302 | |
| 303 | ret = rproc_start(1); |
| 304 | if (ret) |
| 305 | panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret); |
| 306 | |
| 307 | if (shut_cpu) { |
| 308 | debug("Shutting down...\n"); |
| 309 | release_resources_for_core_shutdown(); |
| 310 | |
| 311 | while (1) |
| 312 | asm volatile("wfe"); |
| 313 | } |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 314 | image_entry_noargs_t image_entry = (image_entry_noargs_t)loadaddr; |
Andreas Dannenberg | 31175f8 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 315 | |
Keerthy | 20c87b0 | 2020-02-12 13:55:06 +0530 | [diff] [blame] | 316 | image_entry(); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 317 | } |
| 318 | #endif |
Lokesh Vutla | 16cf5d2 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 319 | |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 320 | #if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) |
| 321 | void board_fit_image_post_process(const void *fit, int node, void **p_image, |
| 322 | size_t *p_size) |
| 323 | { |
| 324 | #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF) |
| 325 | int len; |
| 326 | int i; |
| 327 | const char *os; |
| 328 | u32 addr; |
| 329 | |
| 330 | os = fdt_getprop(fit, node, "os", &len); |
| 331 | addr = fdt_getprop_u32_default_node(fit, node, 0, "entry", -1); |
| 332 | |
| 333 | debug("%s: processing image: addr=%x, size=%d, os=%s\n", __func__, |
| 334 | addr, *p_size, os); |
| 335 | |
| 336 | for (i = 0; i < IMAGE_AMT; i++) { |
| 337 | if (!strcmp(os, image_os_match[i])) { |
| 338 | fit_image_info[i].image_start = addr; |
| 339 | fit_image_info[i].image_len = *p_size; |
| 340 | debug("%s: matched image for ID %d\n", __func__, i); |
| 341 | break; |
| 342 | } |
| 343 | } |
Manorit Chawdhry | c20edd3 | 2023-04-14 09:48:01 +0530 | [diff] [blame] | 344 | /* |
| 345 | * Only DM and the DTBs are being authenticated here, |
| 346 | * rest will be authenticated when A72 cluster is up |
| 347 | */ |
| 348 | if ((i != IMAGE_ID_ATF) && (i != IMAGE_ID_OPTEE)) |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 349 | #endif |
Manorit Chawdhry | c20edd3 | 2023-04-14 09:48:01 +0530 | [diff] [blame] | 350 | { |
Manorit Chawdhry | db01bcc | 2023-05-18 12:44:17 +0530 | [diff] [blame] | 351 | ti_secure_image_check_binary(p_image, p_size); |
Manorit Chawdhry | c20edd3 | 2023-04-14 09:48:01 +0530 | [diff] [blame] | 352 | ti_secure_image_post_process(p_image, p_size); |
| 353 | } |
Manorit Chawdhry | db01bcc | 2023-05-18 12:44:17 +0530 | [diff] [blame] | 354 | #if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF) |
| 355 | else |
| 356 | ti_secure_image_check_binary(p_image, p_size); |
| 357 | #endif |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 358 | } |
| 359 | #endif |
| 360 | |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 361 | #ifndef CONFIG_SYSRESET |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 362 | void reset_cpu(void) |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 363 | { |
| 364 | } |
| 365 | #endif |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 366 | |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 367 | enum k3_device_type get_device_type(void) |
| 368 | { |
| 369 | u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS); |
| 370 | |
| 371 | u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >> |
| 372 | SYS_STATUS_DEV_TYPE_SHIFT; |
| 373 | |
| 374 | u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >> |
| 375 | SYS_STATUS_SUB_TYPE_SHIFT; |
| 376 | |
| 377 | switch (sys_dev_type) { |
| 378 | case SYS_STATUS_DEV_TYPE_GP: |
| 379 | return K3_DEVICE_TYPE_GP; |
| 380 | case SYS_STATUS_DEV_TYPE_TEST: |
| 381 | return K3_DEVICE_TYPE_TEST; |
| 382 | case SYS_STATUS_DEV_TYPE_EMU: |
| 383 | return K3_DEVICE_TYPE_EMU; |
| 384 | case SYS_STATUS_DEV_TYPE_HS: |
| 385 | if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS) |
| 386 | return K3_DEVICE_TYPE_HS_FS; |
| 387 | else |
| 388 | return K3_DEVICE_TYPE_HS_SE; |
| 389 | default: |
| 390 | return K3_DEVICE_TYPE_BAD; |
| 391 | } |
| 392 | } |
| 393 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 394 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 395 | static const char *get_device_type_name(void) |
| 396 | { |
| 397 | enum k3_device_type type = get_device_type(); |
| 398 | |
| 399 | switch (type) { |
| 400 | case K3_DEVICE_TYPE_GP: |
| 401 | return "GP"; |
| 402 | case K3_DEVICE_TYPE_TEST: |
| 403 | return "TEST"; |
| 404 | case K3_DEVICE_TYPE_EMU: |
| 405 | return "EMU"; |
| 406 | case K3_DEVICE_TYPE_HS_FS: |
| 407 | return "HS-FS"; |
| 408 | case K3_DEVICE_TYPE_HS_SE: |
| 409 | return "HS-SE"; |
| 410 | default: |
| 411 | return "BAD"; |
| 412 | } |
| 413 | } |
| 414 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 415 | int print_cpuinfo(void) |
| 416 | { |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 417 | struct udevice *soc; |
| 418 | char name[64]; |
| 419 | int ret; |
Dave Gerlach | 3373ee0 | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 420 | |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 421 | printf("SoC: "); |
Dave Gerlach | 3373ee0 | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 422 | |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 423 | ret = soc_get(&soc); |
| 424 | if (ret) { |
| 425 | printf("UNKNOWN\n"); |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | ret = soc_get_family(soc, name, 64); |
| 430 | if (!ret) { |
| 431 | printf("%s ", name); |
| 432 | } |
| 433 | |
| 434 | ret = soc_get_revision(soc, name, 64); |
| 435 | if (!ret) { |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 436 | printf("%s ", name); |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 437 | } |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 438 | |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 439 | printf("%s\n", get_device_type_name()); |
| 440 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | #endif |
Lokesh Vutla | 362beda | 2019-10-07 13:52:17 +0530 | [diff] [blame] | 444 | |
| 445 | #ifdef CONFIG_ARM64 |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 446 | void board_prep_linux(struct bootm_headers *images) |
Lokesh Vutla | 362beda | 2019-10-07 13:52:17 +0530 | [diff] [blame] | 447 | { |
| 448 | debug("Linux kernel Image start = 0x%lx end = 0x%lx\n", |
| 449 | images->os.start, images->os.end); |
| 450 | __asm_flush_dcache_range(images->os.start, |
| 451 | ROUND(images->os.end, |
| 452 | CONFIG_SYS_CACHELINE_SIZE)); |
| 453 | } |
| 454 | #endif |
Lokesh Vutla | 5fbd6fe | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 455 | |
| 456 | #ifdef CONFIG_CPU_V7R |
| 457 | void disable_linefill_optimization(void) |
| 458 | { |
| 459 | u32 actlr; |
| 460 | |
| 461 | /* |
| 462 | * On K3 devices there are 2 conditions where R5F can deadlock: |
| 463 | * 1.When software is performing series of store operations to |
| 464 | * cacheable write back/write allocate memory region and later |
| 465 | * on software execute barrier operation (DSB or DMB). R5F may |
| 466 | * hang at the barrier instruction. |
| 467 | * 2.When software is performing a mix of load and store operations |
| 468 | * within a tight loop and store operations are all writing to |
| 469 | * cacheable write back/write allocates memory regions, R5F may |
| 470 | * hang at one of the load instruction. |
| 471 | * |
| 472 | * To avoid the above two conditions disable linefill optimization |
| 473 | * inside Cortex R5F. |
| 474 | */ |
| 475 | asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr)); |
| 476 | actlr |= (1 << 13); /* Set DLFO bit */ |
| 477 | asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr)); |
| 478 | } |
| 479 | #endif |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 480 | |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 481 | static void remove_fwl_regions(struct fwl_data fwl_data, size_t num_regions, |
| 482 | enum k3_firewall_region_type fwl_type) |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 483 | { |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 484 | struct ti_sci_fwl_ops *fwl_ops; |
| 485 | struct ti_sci_handle *ti_sci; |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 486 | struct ti_sci_msg_fwl_region region; |
| 487 | size_t j; |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 488 | |
| 489 | ti_sci = get_ti_sci_handle(); |
| 490 | fwl_ops = &ti_sci->ops.fwl_ops; |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 491 | |
| 492 | for (j = 0; j < fwl_data.regions; j++) { |
| 493 | region.fwl_id = fwl_data.fwl_id; |
| 494 | region.region = j; |
| 495 | region.n_permission_regs = 3; |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 496 | |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 497 | fwl_ops->get_fwl_region(ti_sci, ®ion); |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 498 | |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 499 | /* Don't disable the background regions */ |
| 500 | if (region.control != 0 && |
Manorit Chawdhry | a2cfec4 | 2023-07-14 11:22:27 +0530 | [diff] [blame] | 501 | ((region.control >> K3_FIREWALL_BACKGROUND_BIT) & 1) == fwl_type) { |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 502 | pr_debug("Attempting to disable firewall %5d (%25s)\n", |
| 503 | region.fwl_id, fwl_data.name); |
| 504 | region.control = 0; |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 505 | |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 506 | if (fwl_ops->set_fwl_region(ti_sci, ®ion)) |
| 507 | pr_err("Could not disable firewall %5d (%25s)\n", |
| 508 | region.fwl_id, fwl_data.name); |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | } |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 512 | |
Manorit Chawdhry | 33f75ee | 2023-05-05 15:54:00 +0530 | [diff] [blame] | 513 | void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size) |
| 514 | { |
| 515 | size_t i; |
| 516 | |
| 517 | for (i = 0; i < fwl_data_size; i++) { |
| 518 | remove_fwl_regions(fwl_data[i], fwl_data[i].regions, |
| 519 | K3_FIREWALL_REGION_FOREGROUND); |
| 520 | remove_fwl_regions(fwl_data[i], fwl_data[i].regions, |
| 521 | K3_FIREWALL_REGION_BACKGROUND); |
| 522 | } |
| 523 | } |
| 524 | |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 525 | void spl_enable_cache(void) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 526 | { |
| 527 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 528 | phys_addr_t ram_top = CFG_SYS_SDRAM_BASE; |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 529 | |
Georgi Vlaev | a5076cd | 2022-06-14 17:45:30 +0300 | [diff] [blame] | 530 | dram_init(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 531 | |
| 532 | /* reserve TLB table */ |
| 533 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 534 | |
| 535 | ram_top += get_effective_memsize(); |
| 536 | /* keep ram_top in the 32-bit address space */ |
| 537 | if (ram_top >= 0x100000000) |
| 538 | ram_top = (phys_addr_t) 0x100000000; |
| 539 | |
| 540 | gd->arch.tlb_addr = ram_top - gd->arch.tlb_size; |
Nikhil M Jain | 3683681 | 2023-07-18 14:27:28 +0530 | [diff] [blame] | 541 | gd->arch.tlb_addr &= ~(0x10000 - 1); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 542 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
| 543 | gd->arch.tlb_addr + gd->arch.tlb_size); |
Nikhil M Jain | 3683681 | 2023-07-18 14:27:28 +0530 | [diff] [blame] | 544 | gd->relocaddr = gd->arch.tlb_addr; |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 545 | |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 546 | enable_caches(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 547 | #endif |
| 548 | } |
| 549 | |
| 550 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
| 551 | void spl_board_prepare_for_boot(void) |
| 552 | { |
| 553 | dcache_disable(); |
| 554 | } |
| 555 | |
Patrick Delaunay | 35c949c | 2020-07-07 14:25:15 +0200 | [diff] [blame] | 556 | void spl_board_prepare_for_linux(void) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 557 | { |
| 558 | dcache_disable(); |
| 559 | } |
| 560 | #endif |
Vignesh Raghavendra | 030f405 | 2021-12-24 12:55:29 +0530 | [diff] [blame] | 561 | |
| 562 | int misc_init_r(void) |
| 563 | { |
| 564 | if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) { |
| 565 | struct udevice *dev; |
| 566 | int ret; |
| 567 | |
| 568 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 569 | DM_DRIVER_GET(am65_cpsw_nuss), |
| 570 | &dev); |
| 571 | if (ret) |
| 572 | printf("Failed to probe am65_cpsw_nuss driver\n"); |
| 573 | } |
| 574 | |
Vignesh Raghavendra | ae17d36 | 2023-04-20 21:42:21 +0530 | [diff] [blame] | 575 | /* Default FIT boot on HS-SE devices */ |
| 576 | if (get_device_type() == K3_DEVICE_TYPE_HS_SE) |
Andrew Davis | f1d7205 | 2022-10-07 11:27:46 -0500 | [diff] [blame] | 577 | env_set("boot_fit", "1"); |
| 578 | |
Vignesh Raghavendra | 030f405 | 2021-12-24 12:55:29 +0530 | [diff] [blame] | 579 | return 0; |
| 580 | } |
Andrew Davis | 2dde9a7 | 2023-04-06 11:38:17 -0500 | [diff] [blame] | 581 | |
| 582 | /** |
| 583 | * do_board_detect() - Detect board description |
| 584 | * |
| 585 | * Function to detect board description. This is expected to be |
| 586 | * overridden in the SoC family board file where desired. |
| 587 | */ |
| 588 | void __weak do_board_detect(void) |
| 589 | { |
| 590 | } |