blob: 1a269d6934a3644f0f756d7cbb0e6b7595930e60 [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>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053031
Aradhya Bhatia5b095382024-02-12 15:36:35 +053032#include <asm/arch/k3-qos.h>
33
Lokesh Vutla28cd8242019-03-08 11:47:33 +053034struct ti_sci_handle *get_ti_sci_handle(void)
35{
36 struct udevice *dev;
37 int ret;
38
Lokesh Vutla00a15132019-09-27 13:32:15 +053039 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
Simon Glass65130cd2020-12-28 20:34:56 -070040 DM_DRIVER_GET(ti_sci), &dev);
Lokesh Vutla28cd8242019-03-08 11:47:33 +053041 if (ret)
42 panic("Failed to get SYSFW (%d)\n", ret);
43
44 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
45}
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053046
Lokesh Vutla5fafe442020-03-10 16:50:58 +053047void k3_sysfw_print_ver(void)
48{
49 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
50 char fw_desc[sizeof(ti_sci->version.firmware_description) + 1];
51
52 /*
53 * Output System Firmware version info. Note that since the
54 * 'firmware_description' field is not guaranteed to be zero-
55 * terminated we manually add a \0 terminator if needed. Further
56 * note that we intentionally no longer rely on the extended
57 * printf() formatter '%.*s' to not having to require a more
58 * full-featured printf() implementation.
59 */
60 strncpy(fw_desc, ti_sci->version.firmware_description,
61 sizeof(ti_sci->version.firmware_description));
62 fw_desc[sizeof(fw_desc) - 1] = '\0';
63
64 printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n",
65 ti_sci->version.abi_major, ti_sci->version.abi_minor,
66 ti_sci->version.firmware_revision, fw_desc);
67}
68
Matthias Schiffer0262dcd2023-09-27 15:43:14 +020069void mmr_unlock(uintptr_t base, u32 partition)
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053070{
71 /* Translate the base address */
Matthias Schiffer0262dcd2023-09-27 15:43:14 +020072 uintptr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053073
74 /* Unlock the requested partition if locked using two-step sequence */
75 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
76 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
77}
78
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +053079bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data)
80{
81 if (strncmp(data->header, K3_ROM_BOOT_HEADER_MAGIC, 7))
82 return false;
83
84 return data->num_components > 1;
85}
86
Andreas Dannenbergd13ec8c2019-08-15 15:55:28 -050087DECLARE_GLOBAL_DATA_PTR;
88
89#ifdef CONFIG_K3_EARLY_CONS
90int early_console_init(void)
91{
92 struct udevice *dev;
93 int ret;
94
95 gd->baudrate = CONFIG_BAUDRATE;
96
97 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
98 &dev);
99 if (ret) {
100 printf("Error getting serial dev for early console! (%d)\n",
101 ret);
102 return ret;
103 }
104
105 gd->cur_serial_dev = dev;
106 gd->flags |= GD_FLG_SERIAL_READY;
107 gd->have_console = 1;
108
109 return 0;
110}
111#endif
112
Andrew Davisef880db2024-02-01 18:24:45 -0600113#if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) && !IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
Tero Kristo738c5902021-06-11 11:45:19 +0300114void board_fit_image_post_process(const void *fit, int node, void **p_image,
115 size_t *p_size)
116{
Andrew Davisef880db2024-02-01 18:24:45 -0600117 ti_secure_image_check_binary(p_image, p_size);
118 ti_secure_image_post_process(p_image, p_size);
Tero Kristo738c5902021-06-11 11:45:19 +0300119}
120#endif
121
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530122#ifndef CONFIG_SYSRESET
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100123void reset_cpu(void)
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530124{
125}
126#endif
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530127
Andrew Davisf8c98362022-07-15 11:34:32 -0500128enum k3_device_type get_device_type(void)
129{
130 u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS);
131
132 u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >>
133 SYS_STATUS_DEV_TYPE_SHIFT;
134
135 u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >>
136 SYS_STATUS_SUB_TYPE_SHIFT;
137
138 switch (sys_dev_type) {
139 case SYS_STATUS_DEV_TYPE_GP:
140 return K3_DEVICE_TYPE_GP;
141 case SYS_STATUS_DEV_TYPE_TEST:
142 return K3_DEVICE_TYPE_TEST;
143 case SYS_STATUS_DEV_TYPE_EMU:
144 return K3_DEVICE_TYPE_EMU;
145 case SYS_STATUS_DEV_TYPE_HS:
146 if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS)
147 return K3_DEVICE_TYPE_HS_FS;
148 else
149 return K3_DEVICE_TYPE_HS_SE;
150 default:
151 return K3_DEVICE_TYPE_BAD;
152 }
153}
154
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530155#if defined(CONFIG_DISPLAY_CPUINFO)
Andrew Davisf8c98362022-07-15 11:34:32 -0500156static const char *get_device_type_name(void)
157{
158 enum k3_device_type type = get_device_type();
159
160 switch (type) {
161 case K3_DEVICE_TYPE_GP:
162 return "GP";
163 case K3_DEVICE_TYPE_TEST:
164 return "TEST";
165 case K3_DEVICE_TYPE_EMU:
166 return "EMU";
167 case K3_DEVICE_TYPE_HS_FS:
168 return "HS-FS";
169 case K3_DEVICE_TYPE_HS_SE:
170 return "HS-SE";
171 default:
172 return "BAD";
173 }
174}
175
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530176int print_cpuinfo(void)
177{
Dave Gerlachc74227f2020-07-15 23:40:04 -0500178 struct udevice *soc;
179 char name[64];
180 int ret;
Dave Gerlach3373ee02020-07-15 23:40:04 -0500181
Tom Rini5a9ecb22020-07-24 08:42:06 -0400182 printf("SoC: ");
Dave Gerlach3373ee02020-07-15 23:40:04 -0500183
Dave Gerlachc74227f2020-07-15 23:40:04 -0500184 ret = soc_get(&soc);
185 if (ret) {
186 printf("UNKNOWN\n");
187 return 0;
188 }
189
190 ret = soc_get_family(soc, name, 64);
191 if (!ret) {
192 printf("%s ", name);
193 }
194
195 ret = soc_get_revision(soc, name, 64);
196 if (!ret) {
Andrew Davisf8c98362022-07-15 11:34:32 -0500197 printf("%s ", name);
Dave Gerlachc74227f2020-07-15 23:40:04 -0500198 }
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530199
Andrew Davisf8c98362022-07-15 11:34:32 -0500200 printf("%s\n", get_device_type_name());
201
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530202 return 0;
203}
204#endif
Lokesh Vutla362beda2019-10-07 13:52:17 +0530205
206#ifdef CONFIG_ARM64
Simon Glassdf00afa2022-09-06 20:26:50 -0600207void board_prep_linux(struct bootm_headers *images)
Lokesh Vutla362beda2019-10-07 13:52:17 +0530208{
209 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
210 images->os.start, images->os.end);
211 __asm_flush_dcache_range(images->os.start,
212 ROUND(images->os.end,
213 CONFIG_SYS_CACHELINE_SIZE));
214}
215#endif
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530216
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300217void spl_enable_cache(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200218{
219#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530220 gd->ram_top = CFG_SYS_SDRAM_BASE;
221 int ret = 0;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200222
Georgi Vlaeva5076cd2022-06-14 17:45:30 +0300223 dram_init();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200224
225 /* reserve TLB table */
226 gd->arch.tlb_size = PGTABLE_SIZE;
227
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530228 gd->ram_top += get_effective_memsize();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200229 /* keep ram_top in the 32-bit address space */
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530230 if (gd->ram_top >= 0x100000000)
231 gd->ram_top = (phys_addr_t)0x100000000;
232
233 gd->relocaddr = gd->ram_top;
234
235 ret = spl_reserve_video_from_ram_top();
236 if (ret)
237 panic("Failed to reserve framebuffer memory (%d)\n", ret);
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200238
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530239 gd->arch.tlb_addr = gd->relocaddr - gd->arch.tlb_size;
Nikhil M Jain36836812023-07-18 14:27:28 +0530240 gd->arch.tlb_addr &= ~(0x10000 - 1);
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200241 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
242 gd->arch.tlb_addr + gd->arch.tlb_size);
Nikhil M Jain36836812023-07-18 14:27:28 +0530243 gd->relocaddr = gd->arch.tlb_addr;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200244
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300245 enable_caches();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200246#endif
247}
248
249#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
250void spl_board_prepare_for_boot(void)
251{
252 dcache_disable();
253}
254
Patrick Delaunay35c949c2020-07-07 14:25:15 +0200255void spl_board_prepare_for_linux(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200256{
257 dcache_disable();
258}
259#endif
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530260
261int misc_init_r(void)
262{
263 if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) {
264 struct udevice *dev;
265 int ret;
266
267 ret = uclass_get_device_by_driver(UCLASS_MISC,
268 DM_DRIVER_GET(am65_cpsw_nuss),
269 &dev);
270 if (ret)
271 printf("Failed to probe am65_cpsw_nuss driver\n");
272 }
273
MD Danish Anwardd18b892024-04-04 12:38:02 +0530274 if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
275 struct udevice *dev;
276 int ret;
277
278 ret = uclass_get_device_by_driver(UCLASS_MISC,
279 DM_DRIVER_GET(prueth),
280 &dev);
281 if (ret)
282 printf("Failed to probe prueth driver\n");
283 }
284
Vignesh Raghavendraae17d362023-04-20 21:42:21 +0530285 /* Default FIT boot on HS-SE devices */
286 if (get_device_type() == K3_DEVICE_TYPE_HS_SE)
Andrew Davisf1d72052022-10-07 11:27:46 -0500287 env_set("boot_fit", "1");
288
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530289 return 0;
290}
Andrew Davis2dde9a72023-04-06 11:38:17 -0500291
292/**
293 * do_board_detect() - Detect board description
294 *
295 * Function to detect board description. This is expected to be
296 * overridden in the SoC family board file where desired.
297 */
298void __weak do_board_detect(void)
299{
300}
Aradhya Bhatia5b095382024-02-12 15:36:35 +0530301
302#if (IS_ENABLED(CONFIG_K3_QOS))
303void setup_qos(void)
304{
305 u32 i;
306
307 for (i = 0; i < qos_count; i++)
308 writel(qos_data[i].val, (uintptr_t)qos_data[i].reg);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530309}
Aradhya Bhatia5b095382024-02-12 15:36:35 +0530310#endif
Vitor Soaresa7e364b2024-03-28 10:05:48 +0000311
312void efi_add_known_memory(void)
313{
314 if (IS_ENABLED(CONFIG_EFI_LOADER))
315 /*
316 * Memory over ram_top can be used by various firmware
317 * Declare to EFI only memory area below ram_top
318 */
319 efi_add_memory_map(gd->ram_base, gd->ram_top - gd->ram_base,
320 EFI_CONVENTIONAL_MEMORY);
321}