blob: fa8cd93d664858560227f82d474d0a4d559338a8 [file] [log] [blame]
Lokesh Vutla5d83fd22018-11-02 19:51:05 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * K3: Common Architecture initialization
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
Lokesh Vutla5d83fd22018-11-02 19:51:05 +05306 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
Tom Rinib7f70462023-12-14 13:16:45 -05009#include <config.h>
Simon Glassafb02152019-12-28 10:45:01 -070010#include <cpu_func.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053014#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060016#include <linux/printk.h>
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053017#include "common.h"
18#include <dm.h>
19#include <remoteproc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060020#include <asm/cache.h>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053021#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutla16cf5d22019-03-08 11:47:34 +053022#include <fdt_support.h>
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +053023#include <asm/hardware.h>
24#include <asm/io.h>
Keerthy7007adc2020-02-12 13:55:04 +053025#include <fs_loader.h>
26#include <fs.h>
Vitor Soaresa7e364b2024-03-28 10:05:48 +000027#include <efi_loader.h>
Keerthy7007adc2020-02-12 13:55:04 +053028#include <env.h>
29#include <elf.h>
Dave Gerlachc74227f2020-07-15 23:40:04 -050030#include <soc.h>
Prasanth Babu Mantena871bde22024-10-09 20:27:00 +053031#include <dm/uclass-internal.h>
32#include <dm/device-internal.h>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053033
Aradhya Bhatia5b095382024-02-12 15:36:35 +053034#include <asm/arch/k3-qos.h>
35
Lokesh Vutla28cd8242019-03-08 11:47:33 +053036struct ti_sci_handle *get_ti_sci_handle(void)
37{
38 struct udevice *dev;
39 int ret;
40
Lokesh Vutla00a15132019-09-27 13:32:15 +053041 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
Simon Glass65130cd2020-12-28 20:34:56 -070042 DM_DRIVER_GET(ti_sci), &dev);
Lokesh Vutla28cd8242019-03-08 11:47:33 +053043 if (ret)
44 panic("Failed to get SYSFW (%d)\n", ret);
45
46 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
47}
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053048
Lokesh Vutla5fafe442020-03-10 16:50:58 +053049void k3_sysfw_print_ver(void)
50{
51 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
52 char fw_desc[sizeof(ti_sci->version.firmware_description) + 1];
53
54 /*
55 * Output System Firmware version info. Note that since the
56 * 'firmware_description' field is not guaranteed to be zero-
57 * terminated we manually add a \0 terminator if needed. Further
58 * note that we intentionally no longer rely on the extended
59 * printf() formatter '%.*s' to not having to require a more
60 * full-featured printf() implementation.
61 */
62 strncpy(fw_desc, ti_sci->version.firmware_description,
63 sizeof(ti_sci->version.firmware_description));
64 fw_desc[sizeof(fw_desc) - 1] = '\0';
65
66 printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n",
67 ti_sci->version.abi_major, ti_sci->version.abi_minor,
68 ti_sci->version.firmware_revision, fw_desc);
69}
70
Matthias Schiffer0262dcd2023-09-27 15:43:14 +020071void mmr_unlock(uintptr_t base, u32 partition)
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053072{
73 /* Translate the base address */
Matthias Schiffer0262dcd2023-09-27 15:43:14 +020074 uintptr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053075
76 /* Unlock the requested partition if locked using two-step sequence */
77 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
78 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
79}
80
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +053081bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data)
82{
83 if (strncmp(data->header, K3_ROM_BOOT_HEADER_MAGIC, 7))
84 return false;
85
86 return data->num_components > 1;
87}
88
Andreas Dannenbergd13ec8c2019-08-15 15:55:28 -050089DECLARE_GLOBAL_DATA_PTR;
90
91#ifdef CONFIG_K3_EARLY_CONS
92int early_console_init(void)
93{
94 struct udevice *dev;
95 int ret;
96
97 gd->baudrate = CONFIG_BAUDRATE;
98
99 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
100 &dev);
101 if (ret) {
102 printf("Error getting serial dev for early console! (%d)\n",
103 ret);
104 return ret;
105 }
106
107 gd->cur_serial_dev = dev;
108 gd->flags |= GD_FLG_SERIAL_READY;
Simon Glassd4b0fdb2024-08-21 10:19:04 -0600109 gd->flags |= GD_FLG_HAVE_CONSOLE;
Andreas Dannenbergd13ec8c2019-08-15 15:55:28 -0500110
111 return 0;
112}
113#endif
114
Andrew Davisef880db2024-02-01 18:24:45 -0600115#if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) && !IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
Tero Kristo738c5902021-06-11 11:45:19 +0300116void board_fit_image_post_process(const void *fit, int node, void **p_image,
117 size_t *p_size)
118{
Andrew Davisef880db2024-02-01 18:24:45 -0600119 ti_secure_image_check_binary(p_image, p_size);
120 ti_secure_image_post_process(p_image, p_size);
Tero Kristo738c5902021-06-11 11:45:19 +0300121}
122#endif
123
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530124#ifndef CONFIG_SYSRESET
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100125void reset_cpu(void)
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530126{
127}
128#endif
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530129
Andrew Davisf8c98362022-07-15 11:34:32 -0500130enum k3_device_type get_device_type(void)
131{
132 u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS);
133
134 u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >>
135 SYS_STATUS_DEV_TYPE_SHIFT;
136
137 u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >>
138 SYS_STATUS_SUB_TYPE_SHIFT;
139
140 switch (sys_dev_type) {
141 case SYS_STATUS_DEV_TYPE_GP:
142 return K3_DEVICE_TYPE_GP;
143 case SYS_STATUS_DEV_TYPE_TEST:
144 return K3_DEVICE_TYPE_TEST;
145 case SYS_STATUS_DEV_TYPE_EMU:
146 return K3_DEVICE_TYPE_EMU;
147 case SYS_STATUS_DEV_TYPE_HS:
148 if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS)
149 return K3_DEVICE_TYPE_HS_FS;
150 else
151 return K3_DEVICE_TYPE_HS_SE;
152 default:
153 return K3_DEVICE_TYPE_BAD;
154 }
155}
156
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530157#if defined(CONFIG_DISPLAY_CPUINFO)
Andrew Davisf8c98362022-07-15 11:34:32 -0500158static const char *get_device_type_name(void)
159{
160 enum k3_device_type type = get_device_type();
161
162 switch (type) {
163 case K3_DEVICE_TYPE_GP:
164 return "GP";
165 case K3_DEVICE_TYPE_TEST:
166 return "TEST";
167 case K3_DEVICE_TYPE_EMU:
168 return "EMU";
169 case K3_DEVICE_TYPE_HS_FS:
170 return "HS-FS";
171 case K3_DEVICE_TYPE_HS_SE:
172 return "HS-SE";
173 default:
174 return "BAD";
175 }
176}
177
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530178int print_cpuinfo(void)
179{
Dave Gerlachc74227f2020-07-15 23:40:04 -0500180 struct udevice *soc;
181 char name[64];
182 int ret;
Dave Gerlach3373ee02020-07-15 23:40:04 -0500183
Tom Rini5a9ecb22020-07-24 08:42:06 -0400184 printf("SoC: ");
Dave Gerlach3373ee02020-07-15 23:40:04 -0500185
Dave Gerlachc74227f2020-07-15 23:40:04 -0500186 ret = soc_get(&soc);
187 if (ret) {
188 printf("UNKNOWN\n");
189 return 0;
190 }
191
192 ret = soc_get_family(soc, name, 64);
193 if (!ret) {
194 printf("%s ", name);
195 }
196
197 ret = soc_get_revision(soc, name, 64);
198 if (!ret) {
Andrew Davisf8c98362022-07-15 11:34:32 -0500199 printf("%s ", name);
Dave Gerlachc74227f2020-07-15 23:40:04 -0500200 }
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530201
Andrew Davisf8c98362022-07-15 11:34:32 -0500202 printf("%s\n", get_device_type_name());
203
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530204 return 0;
205}
206#endif
Lokesh Vutla362beda2019-10-07 13:52:17 +0530207
208#ifdef CONFIG_ARM64
Simon Glassdf00afa2022-09-06 20:26:50 -0600209void board_prep_linux(struct bootm_headers *images)
Lokesh Vutla362beda2019-10-07 13:52:17 +0530210{
211 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
212 images->os.start, images->os.end);
213 __asm_flush_dcache_range(images->os.start,
214 ROUND(images->os.end,
215 CONFIG_SYS_CACHELINE_SIZE));
216}
217#endif
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530218
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300219void spl_enable_cache(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200220{
221#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530222 gd->ram_top = CFG_SYS_SDRAM_BASE;
223 int ret = 0;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200224
Georgi Vlaeva5076cd2022-06-14 17:45:30 +0300225 dram_init();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200226
227 /* reserve TLB table */
228 gd->arch.tlb_size = PGTABLE_SIZE;
229
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530230 gd->ram_top += get_effective_memsize();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200231 /* keep ram_top in the 32-bit address space */
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530232 if (gd->ram_top >= 0x100000000)
233 gd->ram_top = (phys_addr_t)0x100000000;
234
235 gd->relocaddr = gd->ram_top;
236
237 ret = spl_reserve_video_from_ram_top();
238 if (ret)
239 panic("Failed to reserve framebuffer memory (%d)\n", ret);
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200240
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530241 gd->arch.tlb_addr = gd->relocaddr - gd->arch.tlb_size;
Nikhil M Jain36836812023-07-18 14:27:28 +0530242 gd->arch.tlb_addr &= ~(0x10000 - 1);
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200243 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
244 gd->arch.tlb_addr + gd->arch.tlb_size);
Nikhil M Jain36836812023-07-18 14:27:28 +0530245 gd->relocaddr = gd->arch.tlb_addr;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200246
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300247 enable_caches();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200248#endif
249}
250
Prasanth Babu Mantena871bde22024-10-09 20:27:00 +0530251static __maybe_unused void k3_dma_remove(void)
252{
253 struct udevice *dev;
254 int rc;
255
256 rc = uclass_find_device(UCLASS_DMA, 0, &dev);
257 if (!rc && dev) {
258 rc = device_remove(dev, DM_REMOVE_NORMAL);
259 if (rc)
260 pr_warn("Cannot remove dma device '%s' (err=%d)\n",
261 dev->name, rc);
262 } else
263 pr_warn("DMA Device not found (err=%d)\n", rc);
264}
265
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200266void spl_board_prepare_for_boot(void)
267{
Prasanth Babu Mantena871bde22024-10-09 20:27:00 +0530268#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200269 dcache_disable();
Prasanth Babu Mantena871bde22024-10-09 20:27:00 +0530270#endif
271#if IS_ENABLED(CONFIG_SPL_DMA) && IS_ENABLED(CONFIG_SPL_DM_DEVICE_REMOVE)
272 k3_dma_remove();
273#endif
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200274}
275
Prasanth Babu Mantena871bde22024-10-09 20:27:00 +0530276#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Patrick Delaunay35c949c2020-07-07 14:25:15 +0200277void spl_board_prepare_for_linux(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200278{
279 dcache_disable();
280}
281#endif
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530282
283int misc_init_r(void)
284{
285 if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) {
286 struct udevice *dev;
287 int ret;
288
289 ret = uclass_get_device_by_driver(UCLASS_MISC,
290 DM_DRIVER_GET(am65_cpsw_nuss),
291 &dev);
292 if (ret)
293 printf("Failed to probe am65_cpsw_nuss driver\n");
294 }
295
MD Danish Anwardd18b892024-04-04 12:38:02 +0530296 if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
297 struct udevice *dev;
298 int ret;
299
300 ret = uclass_get_device_by_driver(UCLASS_MISC,
301 DM_DRIVER_GET(prueth),
302 &dev);
303 if (ret)
304 printf("Failed to probe prueth driver\n");
305 }
306
Vignesh Raghavendraae17d362023-04-20 21:42:21 +0530307 /* Default FIT boot on HS-SE devices */
Manorit Chawdhryf6f1d9b2024-05-21 16:26:48 +0530308 if (get_device_type() == K3_DEVICE_TYPE_HS_SE) {
Andrew Davisf1d72052022-10-07 11:27:46 -0500309 env_set("boot_fit", "1");
Manorit Chawdhryf6f1d9b2024-05-21 16:26:48 +0530310 env_set("secure_rprocs", "1");
311 }
Andrew Davisf1d72052022-10-07 11:27:46 -0500312
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530313 return 0;
314}
Andrew Davis2dde9a72023-04-06 11:38:17 -0500315
316/**
317 * do_board_detect() - Detect board description
318 *
319 * Function to detect board description. This is expected to be
320 * overridden in the SoC family board file where desired.
321 */
322void __weak do_board_detect(void)
323{
324}
Aradhya Bhatia5b095382024-02-12 15:36:35 +0530325
326#if (IS_ENABLED(CONFIG_K3_QOS))
327void setup_qos(void)
328{
329 u32 i;
330
331 for (i = 0; i < qos_count; i++)
332 writel(qos_data[i].val, (uintptr_t)qos_data[i].reg);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530333}
Aradhya Bhatia5b095382024-02-12 15:36:35 +0530334#endif