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 | |
Aradhya Bhatia | 5b09538 | 2024-02-12 15:36:35 +0530 | [diff] [blame] | 31 | #include <asm/arch/k3-qos.h> |
| 32 | |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 33 | struct ti_sci_handle *get_ti_sci_handle(void) |
| 34 | { |
| 35 | struct udevice *dev; |
| 36 | int ret; |
| 37 | |
Lokesh Vutla | 00a1513 | 2019-09-27 13:32:15 +0530 | [diff] [blame] | 38 | ret = uclass_get_device_by_driver(UCLASS_FIRMWARE, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 39 | DM_DRIVER_GET(ti_sci), &dev); |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 40 | if (ret) |
| 41 | panic("Failed to get SYSFW (%d)\n", ret); |
| 42 | |
| 43 | return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev); |
| 44 | } |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 45 | |
Lokesh Vutla | 5fafe44 | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 46 | void k3_sysfw_print_ver(void) |
| 47 | { |
| 48 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 49 | char fw_desc[sizeof(ti_sci->version.firmware_description) + 1]; |
| 50 | |
| 51 | /* |
| 52 | * Output System Firmware version info. Note that since the |
| 53 | * 'firmware_description' field is not guaranteed to be zero- |
| 54 | * terminated we manually add a \0 terminator if needed. Further |
| 55 | * note that we intentionally no longer rely on the extended |
| 56 | * printf() formatter '%.*s' to not having to require a more |
| 57 | * full-featured printf() implementation. |
| 58 | */ |
| 59 | strncpy(fw_desc, ti_sci->version.firmware_description, |
| 60 | sizeof(ti_sci->version.firmware_description)); |
| 61 | fw_desc[sizeof(fw_desc) - 1] = '\0'; |
| 62 | |
| 63 | printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n", |
| 64 | ti_sci->version.abi_major, ti_sci->version.abi_minor, |
| 65 | ti_sci->version.firmware_revision, fw_desc); |
| 66 | } |
| 67 | |
Matthias Schiffer | 0262dcd | 2023-09-27 15:43:14 +0200 | [diff] [blame] | 68 | void mmr_unlock(uintptr_t base, u32 partition) |
Lokesh Vutla | ff7ab09 | 2020-08-05 22:44:17 +0530 | [diff] [blame] | 69 | { |
| 70 | /* Translate the base address */ |
Matthias Schiffer | 0262dcd | 2023-09-27 15:43:14 +0200 | [diff] [blame] | 71 | uintptr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE; |
Lokesh Vutla | ff7ab09 | 2020-08-05 22:44:17 +0530 | [diff] [blame] | 72 | |
| 73 | /* Unlock the requested partition if locked using two-step sequence */ |
| 74 | writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0); |
| 75 | writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1); |
| 76 | } |
| 77 | |
Lokesh Vutla | 8be6bbf | 2020-08-05 22:44:23 +0530 | [diff] [blame] | 78 | bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data) |
| 79 | { |
| 80 | if (strncmp(data->header, K3_ROM_BOOT_HEADER_MAGIC, 7)) |
| 81 | return false; |
| 82 | |
| 83 | return data->num_components > 1; |
| 84 | } |
| 85 | |
Andreas Dannenberg | d13ec8c | 2019-08-15 15:55:28 -0500 | [diff] [blame] | 86 | DECLARE_GLOBAL_DATA_PTR; |
| 87 | |
| 88 | #ifdef CONFIG_K3_EARLY_CONS |
| 89 | int early_console_init(void) |
| 90 | { |
| 91 | struct udevice *dev; |
| 92 | int ret; |
| 93 | |
| 94 | gd->baudrate = CONFIG_BAUDRATE; |
| 95 | |
| 96 | ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX, |
| 97 | &dev); |
| 98 | if (ret) { |
| 99 | printf("Error getting serial dev for early console! (%d)\n", |
| 100 | ret); |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | gd->cur_serial_dev = dev; |
| 105 | gd->flags |= GD_FLG_SERIAL_READY; |
| 106 | gd->have_console = 1; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | #endif |
| 111 | |
Andrew Davis | ef880db | 2024-02-01 18:24:45 -0600 | [diff] [blame] | 112 | #if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) && !IS_ENABLED(CONFIG_SYS_K3_SPL_ATF) |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 113 | void board_fit_image_post_process(const void *fit, int node, void **p_image, |
| 114 | size_t *p_size) |
| 115 | { |
Andrew Davis | ef880db | 2024-02-01 18:24:45 -0600 | [diff] [blame] | 116 | ti_secure_image_check_binary(p_image, p_size); |
| 117 | ti_secure_image_post_process(p_image, p_size); |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 118 | } |
| 119 | #endif |
| 120 | |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 121 | #ifndef CONFIG_SYSRESET |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 122 | void reset_cpu(void) |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 123 | { |
| 124 | } |
| 125 | #endif |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 126 | |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 127 | enum k3_device_type get_device_type(void) |
| 128 | { |
| 129 | u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS); |
| 130 | |
| 131 | u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >> |
| 132 | SYS_STATUS_DEV_TYPE_SHIFT; |
| 133 | |
| 134 | u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >> |
| 135 | SYS_STATUS_SUB_TYPE_SHIFT; |
| 136 | |
| 137 | switch (sys_dev_type) { |
| 138 | case SYS_STATUS_DEV_TYPE_GP: |
| 139 | return K3_DEVICE_TYPE_GP; |
| 140 | case SYS_STATUS_DEV_TYPE_TEST: |
| 141 | return K3_DEVICE_TYPE_TEST; |
| 142 | case SYS_STATUS_DEV_TYPE_EMU: |
| 143 | return K3_DEVICE_TYPE_EMU; |
| 144 | case SYS_STATUS_DEV_TYPE_HS: |
| 145 | if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS) |
| 146 | return K3_DEVICE_TYPE_HS_FS; |
| 147 | else |
| 148 | return K3_DEVICE_TYPE_HS_SE; |
| 149 | default: |
| 150 | return K3_DEVICE_TYPE_BAD; |
| 151 | } |
| 152 | } |
| 153 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 154 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 155 | static const char *get_device_type_name(void) |
| 156 | { |
| 157 | enum k3_device_type type = get_device_type(); |
| 158 | |
| 159 | switch (type) { |
| 160 | case K3_DEVICE_TYPE_GP: |
| 161 | return "GP"; |
| 162 | case K3_DEVICE_TYPE_TEST: |
| 163 | return "TEST"; |
| 164 | case K3_DEVICE_TYPE_EMU: |
| 165 | return "EMU"; |
| 166 | case K3_DEVICE_TYPE_HS_FS: |
| 167 | return "HS-FS"; |
| 168 | case K3_DEVICE_TYPE_HS_SE: |
| 169 | return "HS-SE"; |
| 170 | default: |
| 171 | return "BAD"; |
| 172 | } |
| 173 | } |
| 174 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 175 | int print_cpuinfo(void) |
| 176 | { |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 177 | struct udevice *soc; |
| 178 | char name[64]; |
| 179 | int ret; |
Dave Gerlach | 3373ee0 | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 180 | |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 181 | printf("SoC: "); |
Dave Gerlach | 3373ee0 | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 182 | |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 183 | ret = soc_get(&soc); |
| 184 | if (ret) { |
| 185 | printf("UNKNOWN\n"); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | ret = soc_get_family(soc, name, 64); |
| 190 | if (!ret) { |
| 191 | printf("%s ", name); |
| 192 | } |
| 193 | |
| 194 | ret = soc_get_revision(soc, name, 64); |
| 195 | if (!ret) { |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 196 | printf("%s ", name); |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 197 | } |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 198 | |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 199 | printf("%s\n", get_device_type_name()); |
| 200 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | #endif |
Lokesh Vutla | 362beda | 2019-10-07 13:52:17 +0530 | [diff] [blame] | 204 | |
| 205 | #ifdef CONFIG_ARM64 |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 206 | void board_prep_linux(struct bootm_headers *images) |
Lokesh Vutla | 362beda | 2019-10-07 13:52:17 +0530 | [diff] [blame] | 207 | { |
| 208 | debug("Linux kernel Image start = 0x%lx end = 0x%lx\n", |
| 209 | images->os.start, images->os.end); |
| 210 | __asm_flush_dcache_range(images->os.start, |
| 211 | ROUND(images->os.end, |
| 212 | CONFIG_SYS_CACHELINE_SIZE)); |
| 213 | } |
| 214 | #endif |
Lokesh Vutla | 5fbd6fe | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 215 | |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 216 | void spl_enable_cache(void) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 217 | { |
| 218 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 219 | gd->ram_top = CFG_SYS_SDRAM_BASE; |
| 220 | int ret = 0; |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 221 | |
Georgi Vlaev | a5076cd | 2022-06-14 17:45:30 +0300 | [diff] [blame] | 222 | dram_init(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 223 | |
| 224 | /* reserve TLB table */ |
| 225 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 226 | |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 227 | gd->ram_top += get_effective_memsize(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 228 | /* keep ram_top in the 32-bit address space */ |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 229 | if (gd->ram_top >= 0x100000000) |
| 230 | gd->ram_top = (phys_addr_t)0x100000000; |
| 231 | |
| 232 | gd->relocaddr = gd->ram_top; |
| 233 | |
| 234 | ret = spl_reserve_video_from_ram_top(); |
| 235 | if (ret) |
| 236 | panic("Failed to reserve framebuffer memory (%d)\n", ret); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 237 | |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 238 | gd->arch.tlb_addr = gd->relocaddr - gd->arch.tlb_size; |
Nikhil M Jain | 3683681 | 2023-07-18 14:27:28 +0530 | [diff] [blame] | 239 | gd->arch.tlb_addr &= ~(0x10000 - 1); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 240 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
| 241 | gd->arch.tlb_addr + gd->arch.tlb_size); |
Nikhil M Jain | 3683681 | 2023-07-18 14:27:28 +0530 | [diff] [blame] | 242 | gd->relocaddr = gd->arch.tlb_addr; |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 243 | |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 244 | enable_caches(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 245 | #endif |
| 246 | } |
| 247 | |
| 248 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
| 249 | void spl_board_prepare_for_boot(void) |
| 250 | { |
| 251 | dcache_disable(); |
| 252 | } |
| 253 | |
Patrick Delaunay | 35c949c | 2020-07-07 14:25:15 +0200 | [diff] [blame] | 254 | void spl_board_prepare_for_linux(void) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 255 | { |
| 256 | dcache_disable(); |
| 257 | } |
| 258 | #endif |
Vignesh Raghavendra | 030f405 | 2021-12-24 12:55:29 +0530 | [diff] [blame] | 259 | |
| 260 | int misc_init_r(void) |
| 261 | { |
| 262 | if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) { |
| 263 | struct udevice *dev; |
| 264 | int ret; |
| 265 | |
| 266 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 267 | DM_DRIVER_GET(am65_cpsw_nuss), |
| 268 | &dev); |
| 269 | if (ret) |
| 270 | printf("Failed to probe am65_cpsw_nuss driver\n"); |
| 271 | } |
| 272 | |
Vignesh Raghavendra | ae17d36 | 2023-04-20 21:42:21 +0530 | [diff] [blame] | 273 | /* Default FIT boot on HS-SE devices */ |
| 274 | if (get_device_type() == K3_DEVICE_TYPE_HS_SE) |
Andrew Davis | f1d7205 | 2022-10-07 11:27:46 -0500 | [diff] [blame] | 275 | env_set("boot_fit", "1"); |
| 276 | |
Vignesh Raghavendra | 030f405 | 2021-12-24 12:55:29 +0530 | [diff] [blame] | 277 | return 0; |
| 278 | } |
Andrew Davis | 2dde9a7 | 2023-04-06 11:38:17 -0500 | [diff] [blame] | 279 | |
| 280 | /** |
| 281 | * do_board_detect() - Detect board description |
| 282 | * |
| 283 | * Function to detect board description. This is expected to be |
| 284 | * overridden in the SoC family board file where desired. |
| 285 | */ |
| 286 | void __weak do_board_detect(void) |
| 287 | { |
| 288 | } |
Aradhya Bhatia | 5b09538 | 2024-02-12 15:36:35 +0530 | [diff] [blame] | 289 | |
| 290 | #if (IS_ENABLED(CONFIG_K3_QOS)) |
| 291 | void setup_qos(void) |
| 292 | { |
| 293 | u32 i; |
| 294 | |
| 295 | for (i = 0; i < qos_count; i++) |
| 296 | writel(qos_data[i].val, (uintptr_t)qos_data[i].reg); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 297 | } |
Aradhya Bhatia | 5b09538 | 2024-02-12 15:36:35 +0530 | [diff] [blame] | 298 | #endif |