blob: b54f2ddc47299f86c24d2ec804cbc3f421e58edd [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>
27#include <env.h>
28#include <elf.h>
Dave Gerlachc74227f2020-07-15 23:40:04 -050029#include <soc.h>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053030
Aradhya Bhatia5b095382024-02-12 15:36:35 +053031#include <asm/arch/k3-qos.h>
32
Tero Kristo738c5902021-06-11 11:45:19 +030033#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
34enum {
35 IMAGE_ID_ATF,
36 IMAGE_ID_OPTEE,
37 IMAGE_ID_SPL,
38 IMAGE_ID_DM_FW,
39 IMAGE_AMT,
40};
41
42#if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS)
43static const char *image_os_match[IMAGE_AMT] = {
44 "arm-trusted-firmware",
45 "tee",
46 "U-Boot",
47 "DM",
48};
49#endif
50
51static struct image_info fit_image_info[IMAGE_AMT];
52#endif
53
Lokesh Vutla28cd8242019-03-08 11:47:33 +053054struct ti_sci_handle *get_ti_sci_handle(void)
55{
56 struct udevice *dev;
57 int ret;
58
Lokesh Vutla00a15132019-09-27 13:32:15 +053059 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
Simon Glass65130cd2020-12-28 20:34:56 -070060 DM_DRIVER_GET(ti_sci), &dev);
Lokesh Vutla28cd8242019-03-08 11:47:33 +053061 if (ret)
62 panic("Failed to get SYSFW (%d)\n", ret);
63
64 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
65}
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053066
Lokesh Vutla5fafe442020-03-10 16:50:58 +053067void k3_sysfw_print_ver(void)
68{
69 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
70 char fw_desc[sizeof(ti_sci->version.firmware_description) + 1];
71
72 /*
73 * Output System Firmware version info. Note that since the
74 * 'firmware_description' field is not guaranteed to be zero-
75 * terminated we manually add a \0 terminator if needed. Further
76 * note that we intentionally no longer rely on the extended
77 * printf() formatter '%.*s' to not having to require a more
78 * full-featured printf() implementation.
79 */
80 strncpy(fw_desc, ti_sci->version.firmware_description,
81 sizeof(ti_sci->version.firmware_description));
82 fw_desc[sizeof(fw_desc) - 1] = '\0';
83
84 printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n",
85 ti_sci->version.abi_major, ti_sci->version.abi_minor,
86 ti_sci->version.firmware_revision, fw_desc);
87}
88
Matthias Schiffer0262dcd2023-09-27 15:43:14 +020089void mmr_unlock(uintptr_t base, u32 partition)
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053090{
91 /* Translate the base address */
Matthias Schiffer0262dcd2023-09-27 15:43:14 +020092 uintptr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053093
94 /* Unlock the requested partition if locked using two-step sequence */
95 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
96 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
97}
98
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +053099bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data)
100{
101 if (strncmp(data->header, K3_ROM_BOOT_HEADER_MAGIC, 7))
102 return false;
103
104 return data->num_components > 1;
105}
106
Andreas Dannenbergd13ec8c2019-08-15 15:55:28 -0500107DECLARE_GLOBAL_DATA_PTR;
108
109#ifdef CONFIG_K3_EARLY_CONS
110int early_console_init(void)
111{
112 struct udevice *dev;
113 int ret;
114
115 gd->baudrate = CONFIG_BAUDRATE;
116
117 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
118 &dev);
119 if (ret) {
120 printf("Error getting serial dev for early console! (%d)\n",
121 ret);
122 return ret;
123 }
124
125 gd->cur_serial_dev = dev;
126 gd->flags |= GD_FLG_SERIAL_READY;
127 gd->have_console = 1;
128
129 return 0;
130}
131#endif
132
Tero Kristo738c5902021-06-11 11:45:19 +0300133#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
Keerthy7007adc2020-02-12 13:55:04 +0530134
135void init_env(void)
136{
137#ifdef CONFIG_SPL_ENV_SUPPORT
138 char *part;
139
140 env_init();
141 env_relocate();
142 switch (spl_boot_device()) {
143 case BOOT_DEVICE_MMC2:
144 part = env_get("bootpart");
145 env_set("storage_interface", "mmc");
146 env_set("fw_dev_part", part);
147 break;
148 case BOOT_DEVICE_SPI:
149 env_set("storage_interface", "ubi");
150 env_set("fw_ubi_mtdpart", "UBI");
151 env_set("fw_ubi_volume", "UBI0");
152 break;
153 default:
154 printf("%s from device %u not supported!\n",
155 __func__, spl_boot_device());
156 return;
157 }
158#endif
159}
160
Keerthy7007adc2020-02-12 13:55:04 +0530161int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr)
162{
163 struct udevice *fsdev;
164 char *name = NULL;
165 int size = 0;
166
Keerthyfe8f6092022-01-27 13:16:53 +0100167 if (!IS_ENABLED(CONFIG_FS_LOADER))
168 return 0;
169
Keerthy7007adc2020-02-12 13:55:04 +0530170 *loadaddr = 0;
171#ifdef CONFIG_SPL_ENV_SUPPORT
172 switch (spl_boot_device()) {
173 case BOOT_DEVICE_MMC2:
174 name = env_get(name_fw);
175 *loadaddr = env_get_hex(name_loadaddr, *loadaddr);
176 break;
177 default:
178 printf("Loading rproc fw image from device %u not supported!\n",
179 spl_boot_device());
180 return 0;
181 }
182#endif
183 if (!*loadaddr)
184 return 0;
185
Sean Anderson5cd0cb32022-12-29 11:52:59 -0500186 if (!get_fs_loader(&fsdev)) {
Keerthy7007adc2020-02-12 13:55:04 +0530187 size = request_firmware_into_buf(fsdev, name, (void *)*loadaddr,
188 0, 0);
189 }
190
191 return size;
192}
Keerthy7007adc2020-02-12 13:55:04 +0530193
Andrew Davisc178e6d2023-04-06 11:38:15 -0500194void release_resources_for_core_shutdown(void)
Suman Anna34574102021-07-27 18:24:40 -0500195{
Andrew Davisc178e6d2023-04-06 11:38:15 -0500196 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
197 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
198 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
199 int ret;
200 u32 i;
201
202 /* Iterate through list of devices to put (shutdown) */
203 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
204 u32 id = put_device_ids[i];
205
206 ret = dev_ops->put_device(ti_sci, id);
207 if (ret)
208 panic("Failed to put device %u (%d)\n", id, ret);
209 }
210
211 /* Iterate through list of cores to put (shutdown) */
212 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
213 u32 id = put_core_ids[i];
214
215 /*
216 * Queue up the core shutdown request. Note that this call
217 * needs to be followed up by an actual invocation of an WFE
218 * or WFI CPU instruction.
219 */
220 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
221 if (ret)
222 panic("Failed sending core %u shutdown message (%d)\n",
223 id, ret);
224 }
Suman Anna34574102021-07-27 18:24:40 -0500225}
226
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530227void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
228{
Keerthy20c87b02020-02-12 13:55:06 +0530229 typedef void __noreturn (*image_entry_noargs_t)(void);
Lokesh Vutla005476d2019-06-07 19:24:43 +0530230 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
Keerthy20c87b02020-02-12 13:55:06 +0530231 u32 loadaddr = 0;
Nishanth Menon1535e2a2021-08-31 13:20:48 -0500232 int ret, size = 0, shut_cpu = 0;
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530233
Lokesh Vutla005476d2019-06-07 19:24:43 +0530234 /* Release all the exclusive devices held by SPL before starting ATF */
235 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
236
Keerthy7007adc2020-02-12 13:55:04 +0530237 ret = rproc_init();
238 if (ret)
239 panic("rproc failed to be initialized (%d)\n", ret);
240
241 init_env();
Dave Gerlachcdd02452021-06-11 11:45:21 +0300242
243 if (!fit_image_info[IMAGE_ID_DM_FW].image_start) {
Tero Kristo738c5902021-06-11 11:45:19 +0300244 size = load_firmware("name_mcur5f0_0fw", "addr_mcur5f0_0load",
245 &loadaddr);
Dave Gerlachcdd02452021-06-11 11:45:21 +0300246 }
Keerthy7007adc2020-02-12 13:55:04 +0530247
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530248 /*
249 * It is assumed that remoteproc device 1 is the corresponding
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -0600250 * Cortex-A core which runs ATF. Make sure DT reflects the same.
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530251 */
Tero Kristo738c5902021-06-11 11:45:19 +0300252 if (!fit_image_info[IMAGE_ID_ATF].image_start)
253 fit_image_info[IMAGE_ID_ATF].image_start =
254 spl_image->entry_point;
255
256 ret = rproc_load(1, fit_image_info[IMAGE_ID_ATF].image_start, 0x200);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -0600257 if (ret)
258 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530259
Manorit Chawdhryc20edd32023-04-14 09:48:01 +0530260#if (CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) && IS_ENABLED(CONFIG_SYS_K3_SPL_ATF))
261 /* Authenticate ATF */
262 void *image_addr = (void *)fit_image_info[IMAGE_ID_ATF].image_start;
263
264 debug("%s: Authenticating image: addr=%lx, size=%ld, os=%s\n", __func__,
265 fit_image_info[IMAGE_ID_ATF].image_start,
266 fit_image_info[IMAGE_ID_ATF].image_len,
267 image_os_match[IMAGE_ID_ATF]);
268
269 ti_secure_image_post_process(&image_addr,
270 (size_t *)&fit_image_info[IMAGE_ID_ATF].image_len);
271
272 /* Authenticate OPTEE */
273 image_addr = (void *)fit_image_info[IMAGE_ID_OPTEE].image_start;
274
275 debug("%s: Authenticating image: addr=%lx, size=%ld, os=%s\n", __func__,
276 fit_image_info[IMAGE_ID_OPTEE].image_start,
277 fit_image_info[IMAGE_ID_OPTEE].image_len,
278 image_os_match[IMAGE_ID_OPTEE]);
279
280 ti_secure_image_post_process(&image_addr,
281 (size_t *)&fit_image_info[IMAGE_ID_OPTEE].image_len);
282
283#endif
284
Tero Kristo738c5902021-06-11 11:45:19 +0300285 if (!fit_image_info[IMAGE_ID_DM_FW].image_len &&
286 !(size > 0 && valid_elf_image(loadaddr))) {
Nishanth Menon1535e2a2021-08-31 13:20:48 -0500287 shut_cpu = 1;
288 goto start_arm64;
Keerthy20c87b02020-02-12 13:55:06 +0530289 }
290
Tero Kristo738c5902021-06-11 11:45:19 +0300291 if (!fit_image_info[IMAGE_ID_DM_FW].image_start) {
292 loadaddr = load_elf_image_phdr(loadaddr);
293 } else {
294 loadaddr = fit_image_info[IMAGE_ID_DM_FW].image_start;
295 if (valid_elf_image(loadaddr))
296 loadaddr = load_elf_image_phdr(loadaddr);
297 }
298
299 debug("%s: jumping to address %x\n", __func__, loadaddr);
300
Nishanth Menon1535e2a2021-08-31 13:20:48 -0500301start_arm64:
302 /* Add an extra newline to differentiate the ATF logs from SPL */
303 printf("Starting ATF on ARM64 core...\n\n");
304
305 ret = rproc_start(1);
306 if (ret)
307 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
308
309 if (shut_cpu) {
310 debug("Shutting down...\n");
311 release_resources_for_core_shutdown();
312
313 while (1)
314 asm volatile("wfe");
315 }
Tero Kristo738c5902021-06-11 11:45:19 +0300316 image_entry_noargs_t image_entry = (image_entry_noargs_t)loadaddr;
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530317
Keerthy20c87b02020-02-12 13:55:06 +0530318 image_entry();
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530319}
320#endif
Lokesh Vutla16cf5d22019-03-08 11:47:34 +0530321
Tero Kristo738c5902021-06-11 11:45:19 +0300322#if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS)
323void board_fit_image_post_process(const void *fit, int node, void **p_image,
324 size_t *p_size)
325{
326#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
327 int len;
328 int i;
329 const char *os;
330 u32 addr;
331
332 os = fdt_getprop(fit, node, "os", &len);
333 addr = fdt_getprop_u32_default_node(fit, node, 0, "entry", -1);
334
335 debug("%s: processing image: addr=%x, size=%d, os=%s\n", __func__,
336 addr, *p_size, os);
337
338 for (i = 0; i < IMAGE_AMT; i++) {
339 if (!strcmp(os, image_os_match[i])) {
340 fit_image_info[i].image_start = addr;
341 fit_image_info[i].image_len = *p_size;
342 debug("%s: matched image for ID %d\n", __func__, i);
343 break;
344 }
345 }
Manorit Chawdhryc20edd32023-04-14 09:48:01 +0530346 /*
347 * Only DM and the DTBs are being authenticated here,
348 * rest will be authenticated when A72 cluster is up
349 */
350 if ((i != IMAGE_ID_ATF) && (i != IMAGE_ID_OPTEE))
Tero Kristo738c5902021-06-11 11:45:19 +0300351#endif
Manorit Chawdhryc20edd32023-04-14 09:48:01 +0530352 {
Manorit Chawdhrydb01bcc2023-05-18 12:44:17 +0530353 ti_secure_image_check_binary(p_image, p_size);
Manorit Chawdhryc20edd32023-04-14 09:48:01 +0530354 ti_secure_image_post_process(p_image, p_size);
355 }
Manorit Chawdhrydb01bcc2023-05-18 12:44:17 +0530356#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
357 else
358 ti_secure_image_check_binary(p_image, p_size);
359#endif
Tero Kristo738c5902021-06-11 11:45:19 +0300360}
361#endif
362
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530363#ifndef CONFIG_SYSRESET
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100364void reset_cpu(void)
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530365{
366}
367#endif
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530368
Andrew Davisf8c98362022-07-15 11:34:32 -0500369enum k3_device_type get_device_type(void)
370{
371 u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS);
372
373 u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >>
374 SYS_STATUS_DEV_TYPE_SHIFT;
375
376 u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >>
377 SYS_STATUS_SUB_TYPE_SHIFT;
378
379 switch (sys_dev_type) {
380 case SYS_STATUS_DEV_TYPE_GP:
381 return K3_DEVICE_TYPE_GP;
382 case SYS_STATUS_DEV_TYPE_TEST:
383 return K3_DEVICE_TYPE_TEST;
384 case SYS_STATUS_DEV_TYPE_EMU:
385 return K3_DEVICE_TYPE_EMU;
386 case SYS_STATUS_DEV_TYPE_HS:
387 if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS)
388 return K3_DEVICE_TYPE_HS_FS;
389 else
390 return K3_DEVICE_TYPE_HS_SE;
391 default:
392 return K3_DEVICE_TYPE_BAD;
393 }
394}
395
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530396#if defined(CONFIG_DISPLAY_CPUINFO)
Andrew Davisf8c98362022-07-15 11:34:32 -0500397static const char *get_device_type_name(void)
398{
399 enum k3_device_type type = get_device_type();
400
401 switch (type) {
402 case K3_DEVICE_TYPE_GP:
403 return "GP";
404 case K3_DEVICE_TYPE_TEST:
405 return "TEST";
406 case K3_DEVICE_TYPE_EMU:
407 return "EMU";
408 case K3_DEVICE_TYPE_HS_FS:
409 return "HS-FS";
410 case K3_DEVICE_TYPE_HS_SE:
411 return "HS-SE";
412 default:
413 return "BAD";
414 }
415}
416
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530417int print_cpuinfo(void)
418{
Dave Gerlachc74227f2020-07-15 23:40:04 -0500419 struct udevice *soc;
420 char name[64];
421 int ret;
Dave Gerlach3373ee02020-07-15 23:40:04 -0500422
Tom Rini5a9ecb22020-07-24 08:42:06 -0400423 printf("SoC: ");
Dave Gerlach3373ee02020-07-15 23:40:04 -0500424
Dave Gerlachc74227f2020-07-15 23:40:04 -0500425 ret = soc_get(&soc);
426 if (ret) {
427 printf("UNKNOWN\n");
428 return 0;
429 }
430
431 ret = soc_get_family(soc, name, 64);
432 if (!ret) {
433 printf("%s ", name);
434 }
435
436 ret = soc_get_revision(soc, name, 64);
437 if (!ret) {
Andrew Davisf8c98362022-07-15 11:34:32 -0500438 printf("%s ", name);
Dave Gerlachc74227f2020-07-15 23:40:04 -0500439 }
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530440
Andrew Davisf8c98362022-07-15 11:34:32 -0500441 printf("%s\n", get_device_type_name());
442
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530443 return 0;
444}
445#endif
Lokesh Vutla362beda2019-10-07 13:52:17 +0530446
447#ifdef CONFIG_ARM64
Simon Glassdf00afa2022-09-06 20:26:50 -0600448void board_prep_linux(struct bootm_headers *images)
Lokesh Vutla362beda2019-10-07 13:52:17 +0530449{
450 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
451 images->os.start, images->os.end);
452 __asm_flush_dcache_range(images->os.start,
453 ROUND(images->os.end,
454 CONFIG_SYS_CACHELINE_SIZE));
455}
456#endif
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530457
458#ifdef CONFIG_CPU_V7R
459void disable_linefill_optimization(void)
460{
461 u32 actlr;
462
463 /*
464 * On K3 devices there are 2 conditions where R5F can deadlock:
465 * 1.When software is performing series of store operations to
466 * cacheable write back/write allocate memory region and later
467 * on software execute barrier operation (DSB or DMB). R5F may
468 * hang at the barrier instruction.
469 * 2.When software is performing a mix of load and store operations
470 * within a tight loop and store operations are all writing to
471 * cacheable write back/write allocates memory regions, R5F may
472 * hang at one of the load instruction.
473 *
474 * To avoid the above two conditions disable linefill optimization
475 * inside Cortex R5F.
476 */
477 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
478 actlr |= (1 << 13); /* Set DLFO bit */
479 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
480}
481#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500482
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530483static void remove_fwl_regions(struct fwl_data fwl_data, size_t num_regions,
484 enum k3_firewall_region_type fwl_type)
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500485{
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500486 struct ti_sci_fwl_ops *fwl_ops;
487 struct ti_sci_handle *ti_sci;
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530488 struct ti_sci_msg_fwl_region region;
489 size_t j;
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500490
491 ti_sci = get_ti_sci_handle();
492 fwl_ops = &ti_sci->ops.fwl_ops;
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530493
494 for (j = 0; j < fwl_data.regions; j++) {
495 region.fwl_id = fwl_data.fwl_id;
496 region.region = j;
497 region.n_permission_regs = 3;
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500498
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530499 fwl_ops->get_fwl_region(ti_sci, &region);
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500500
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530501 /* Don't disable the background regions */
502 if (region.control != 0 &&
Manorit Chawdhrya2cfec42023-07-14 11:22:27 +0530503 ((region.control >> K3_FIREWALL_BACKGROUND_BIT) & 1) == fwl_type) {
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530504 pr_debug("Attempting to disable firewall %5d (%25s)\n",
505 region.fwl_id, fwl_data.name);
506 region.control = 0;
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500507
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530508 if (fwl_ops->set_fwl_region(ti_sci, &region))
509 pr_err("Could not disable firewall %5d (%25s)\n",
510 region.fwl_id, fwl_data.name);
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500511 }
512 }
513}
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200514
Manorit Chawdhry33f75ee2023-05-05 15:54:00 +0530515void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size)
516{
517 size_t i;
518
519 for (i = 0; i < fwl_data_size; i++) {
520 remove_fwl_regions(fwl_data[i], fwl_data[i].regions,
521 K3_FIREWALL_REGION_FOREGROUND);
522 remove_fwl_regions(fwl_data[i], fwl_data[i].regions,
523 K3_FIREWALL_REGION_BACKGROUND);
524 }
525}
526
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300527void spl_enable_cache(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200528{
529#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530530 gd->ram_top = CFG_SYS_SDRAM_BASE;
531 int ret = 0;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200532
Georgi Vlaeva5076cd2022-06-14 17:45:30 +0300533 dram_init();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200534
535 /* reserve TLB table */
536 gd->arch.tlb_size = PGTABLE_SIZE;
537
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530538 gd->ram_top += get_effective_memsize();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200539 /* keep ram_top in the 32-bit address space */
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530540 if (gd->ram_top >= 0x100000000)
541 gd->ram_top = (phys_addr_t)0x100000000;
542
543 gd->relocaddr = gd->ram_top;
544
545 ret = spl_reserve_video_from_ram_top();
546 if (ret)
547 panic("Failed to reserve framebuffer memory (%d)\n", ret);
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200548
Devarsh Thakkar3a7a44d2023-12-05 21:25:17 +0530549 gd->arch.tlb_addr = gd->relocaddr - gd->arch.tlb_size;
Nikhil M Jain36836812023-07-18 14:27:28 +0530550 gd->arch.tlb_addr &= ~(0x10000 - 1);
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200551 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
552 gd->arch.tlb_addr + gd->arch.tlb_size);
Nikhil M Jain36836812023-07-18 14:27:28 +0530553 gd->relocaddr = gd->arch.tlb_addr;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200554
Joao Paulo Goncalvesfc3557f2023-11-13 16:07:21 -0300555 enable_caches();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200556#endif
557}
558
559#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
560void spl_board_prepare_for_boot(void)
561{
562 dcache_disable();
563}
564
Patrick Delaunay35c949c2020-07-07 14:25:15 +0200565void spl_board_prepare_for_linux(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200566{
567 dcache_disable();
568}
569#endif
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530570
571int misc_init_r(void)
572{
573 if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) {
574 struct udevice *dev;
575 int ret;
576
577 ret = uclass_get_device_by_driver(UCLASS_MISC,
578 DM_DRIVER_GET(am65_cpsw_nuss),
579 &dev);
580 if (ret)
581 printf("Failed to probe am65_cpsw_nuss driver\n");
582 }
583
Vignesh Raghavendraae17d362023-04-20 21:42:21 +0530584 /* Default FIT boot on HS-SE devices */
585 if (get_device_type() == K3_DEVICE_TYPE_HS_SE)
Andrew Davisf1d72052022-10-07 11:27:46 -0500586 env_set("boot_fit", "1");
587
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530588 return 0;
589}
Andrew Davis2dde9a72023-04-06 11:38:17 -0500590
591/**
592 * do_board_detect() - Detect board description
593 *
594 * Function to detect board description. This is expected to be
595 * overridden in the SoC family board file where desired.
596 */
597void __weak do_board_detect(void)
598{
599}
Aradhya Bhatia5b095382024-02-12 15:36:35 +0530600
601#if (IS_ENABLED(CONFIG_K3_QOS))
602void setup_qos(void)
603{
604 u32 i;
605
606 for (i = 0; i < qos_count; i++)
607 writel(qos_data[i].val, (uintptr_t)qos_data[i].reg);
608}
609#endif