blob: 4f2e14c3105472da1b391f9cba383b52f6e71c98 [file] [log] [blame]
Lokesh Vutla5d83fd22018-11-02 19:51:05 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * K3: Common Architecture initialization
4 *
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
9#include <common.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>
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053016#include "common.h"
17#include <dm.h>
18#include <remoteproc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060019#include <asm/cache.h>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053020#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutla16cf5d22019-03-08 11:47:34 +053021#include <fdt_support.h>
Andreas Dannenberg31175f82019-06-07 19:24:42 +053022#include <asm/arch/sys_proto.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
Tero Kristo738c5902021-06-11 11:45:19 +030031#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
32enum {
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)
41static const char *image_os_match[IMAGE_AMT] = {
42 "arm-trusted-firmware",
43 "tee",
44 "U-Boot",
45 "DM",
46};
47#endif
48
49static struct image_info fit_image_info[IMAGE_AMT];
50#endif
51
Lokesh Vutla28cd8242019-03-08 11:47:33 +053052struct ti_sci_handle *get_ti_sci_handle(void)
53{
54 struct udevice *dev;
55 int ret;
56
Lokesh Vutla00a15132019-09-27 13:32:15 +053057 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
Simon Glass65130cd2020-12-28 20:34:56 -070058 DM_DRIVER_GET(ti_sci), &dev);
Lokesh Vutla28cd8242019-03-08 11:47:33 +053059 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 Vutla5d83fd22018-11-02 19:51:05 +053064
Lokesh Vutla5fafe442020-03-10 16:50:58 +053065void 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
Lokesh Vutlaff7ab092020-08-05 22:44:17 +053087void mmr_unlock(phys_addr_t base, u32 partition)
88{
89 /* Translate the base address */
90 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
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 Vutla8be6bbf2020-08-05 22:44:23 +053097bool 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 Dannenbergd13ec8c2019-08-15 15:55:28 -0500105DECLARE_GLOBAL_DATA_PTR;
106
107#ifdef CONFIG_K3_EARLY_CONS
108int 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 Kristo738c5902021-06-11 11:45:19 +0300131#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
Keerthy7007adc2020-02-12 13:55:04 +0530132
133void 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
Keerthy7007adc2020-02-12 13:55:04 +0530159int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr)
160{
161 struct udevice *fsdev;
162 char *name = NULL;
163 int size = 0;
164
Keerthyfe8f6092022-01-27 13:16:53 +0100165 if (!IS_ENABLED(CONFIG_FS_LOADER))
166 return 0;
167
Keerthy7007adc2020-02-12 13:55:04 +0530168 *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 Anderson5cd0cb32022-12-29 11:52:59 -0500184 if (!get_fs_loader(&fsdev)) {
Keerthy7007adc2020-02-12 13:55:04 +0530185 size = request_firmware_into_buf(fsdev, name, (void *)*loadaddr,
186 0, 0);
187 }
188
189 return size;
190}
Keerthy7007adc2020-02-12 13:55:04 +0530191
Andrew Davisc178e6d2023-04-06 11:38:15 -0500192void release_resources_for_core_shutdown(void)
Suman Anna34574102021-07-27 18:24:40 -0500193{
Andrew Davisc178e6d2023-04-06 11:38:15 -0500194 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 Anna34574102021-07-27 18:24:40 -0500223}
224
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530225void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
226{
Keerthy20c87b02020-02-12 13:55:06 +0530227 typedef void __noreturn (*image_entry_noargs_t)(void);
Lokesh Vutla005476d2019-06-07 19:24:43 +0530228 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
Keerthy20c87b02020-02-12 13:55:06 +0530229 u32 loadaddr = 0;
Nishanth Menon1535e2a2021-08-31 13:20:48 -0500230 int ret, size = 0, shut_cpu = 0;
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530231
Lokesh Vutla005476d2019-06-07 19:24:43 +0530232 /* Release all the exclusive devices held by SPL before starting ATF */
233 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
234
Keerthy7007adc2020-02-12 13:55:04 +0530235 ret = rproc_init();
236 if (ret)
237 panic("rproc failed to be initialized (%d)\n", ret);
238
239 init_env();
Dave Gerlachcdd02452021-06-11 11:45:21 +0300240
241 if (!fit_image_info[IMAGE_ID_DM_FW].image_start) {
Tero Kristo738c5902021-06-11 11:45:19 +0300242 size = load_firmware("name_mcur5f0_0fw", "addr_mcur5f0_0load",
243 &loadaddr);
Dave Gerlachcdd02452021-06-11 11:45:21 +0300244 }
Keerthy7007adc2020-02-12 13:55:04 +0530245
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530246 /*
247 * It is assumed that remoteproc device 1 is the corresponding
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -0600248 * Cortex-A core which runs ATF. Make sure DT reflects the same.
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530249 */
Tero Kristo738c5902021-06-11 11:45:19 +0300250 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 Dannenberg376c0fe2019-02-04 12:58:47 -0600255 if (ret)
256 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530257
Tero Kristo738c5902021-06-11 11:45:19 +0300258 if (!fit_image_info[IMAGE_ID_DM_FW].image_len &&
259 !(size > 0 && valid_elf_image(loadaddr))) {
Nishanth Menon1535e2a2021-08-31 13:20:48 -0500260 shut_cpu = 1;
261 goto start_arm64;
Keerthy20c87b02020-02-12 13:55:06 +0530262 }
263
Tero Kristo738c5902021-06-11 11:45:19 +0300264 if (!fit_image_info[IMAGE_ID_DM_FW].image_start) {
265 loadaddr = load_elf_image_phdr(loadaddr);
266 } else {
267 loadaddr = fit_image_info[IMAGE_ID_DM_FW].image_start;
268 if (valid_elf_image(loadaddr))
269 loadaddr = load_elf_image_phdr(loadaddr);
270 }
271
272 debug("%s: jumping to address %x\n", __func__, loadaddr);
273
Nishanth Menon1535e2a2021-08-31 13:20:48 -0500274start_arm64:
275 /* Add an extra newline to differentiate the ATF logs from SPL */
276 printf("Starting ATF on ARM64 core...\n\n");
277
278 ret = rproc_start(1);
279 if (ret)
280 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
281
282 if (shut_cpu) {
283 debug("Shutting down...\n");
284 release_resources_for_core_shutdown();
285
286 while (1)
287 asm volatile("wfe");
288 }
Tero Kristo738c5902021-06-11 11:45:19 +0300289 image_entry_noargs_t image_entry = (image_entry_noargs_t)loadaddr;
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530290
Keerthy20c87b02020-02-12 13:55:06 +0530291 image_entry();
Lokesh Vutla5d83fd22018-11-02 19:51:05 +0530292}
293#endif
Lokesh Vutla16cf5d22019-03-08 11:47:34 +0530294
Tero Kristo738c5902021-06-11 11:45:19 +0300295#if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS)
296void board_fit_image_post_process(const void *fit, int node, void **p_image,
297 size_t *p_size)
298{
299#if IS_ENABLED(CONFIG_SYS_K3_SPL_ATF)
300 int len;
301 int i;
302 const char *os;
303 u32 addr;
304
305 os = fdt_getprop(fit, node, "os", &len);
306 addr = fdt_getprop_u32_default_node(fit, node, 0, "entry", -1);
307
308 debug("%s: processing image: addr=%x, size=%d, os=%s\n", __func__,
309 addr, *p_size, os);
310
311 for (i = 0; i < IMAGE_AMT; i++) {
312 if (!strcmp(os, image_os_match[i])) {
313 fit_image_info[i].image_start = addr;
314 fit_image_info[i].image_len = *p_size;
315 debug("%s: matched image for ID %d\n", __func__, i);
316 break;
317 }
318 }
319#endif
320
Tero Kristo738c5902021-06-11 11:45:19 +0300321 ti_secure_image_post_process(p_image, p_size);
Tero Kristo738c5902021-06-11 11:45:19 +0300322}
323#endif
324
Lokesh Vutla16cf5d22019-03-08 11:47:34 +0530325#if defined(CONFIG_OF_LIBFDT)
326int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
327{
328 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
329 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
330 int ret, node, subnode, len, prev_node;
331 u32 range[4], addr, size;
332 const fdt32_t *sub_reg;
333
334 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
335 msmc_size = msmc_end - msmc_start + 1;
336 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
337 msmc_start, msmc_size);
338
339 /* find or create "msmc_sram node */
340 ret = fdt_path_offset(blob, parent_path);
341 if (ret < 0)
342 return ret;
343
344 node = fdt_find_or_add_subnode(blob, ret, node_name);
345 if (node < 0)
346 return node;
347
348 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
349 if (ret < 0)
350 return ret;
351
352 reg[0] = cpu_to_fdt64(msmc_start);
353 reg[1] = cpu_to_fdt64(msmc_size);
354 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
355 if (ret < 0)
356 return ret;
357
358 fdt_setprop_cell(blob, node, "#address-cells", 1);
359 fdt_setprop_cell(blob, node, "#size-cells", 1);
360
361 range[0] = 0;
362 range[1] = cpu_to_fdt32(msmc_start >> 32);
363 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
364 range[3] = cpu_to_fdt32(msmc_size);
365 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
366 if (ret < 0)
367 return ret;
368
369 subnode = fdt_first_subnode(blob, node);
370 prev_node = 0;
371
372 /* Look for invalid subnodes and delete them */
373 while (subnode >= 0) {
374 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
375 addr = fdt_read_number(sub_reg, 1);
376 sub_reg++;
377 size = fdt_read_number(sub_reg, 1);
378 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
379 subnode, addr, size);
380 if (addr + size > msmc_size ||
381 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
382 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
383 fdt_del_node(blob, subnode);
384 debug("%s: deleting subnode %d\n", __func__, subnode);
385 if (!prev_node)
386 subnode = fdt_first_subnode(blob, node);
387 else
388 subnode = fdt_next_subnode(blob, prev_node);
389 } else {
390 prev_node = subnode;
391 subnode = fdt_next_subnode(blob, prev_node);
392 }
393 }
394
395 return 0;
396}
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400397
398int fdt_disable_node(void *blob, char *node_path)
399{
400 int offs;
401 int ret;
402
403 offs = fdt_path_offset(blob, node_path);
404 if (offs < 0) {
Andrew F. Davis7e13f2c2020-01-07 18:12:40 -0500405 printf("Node %s not found.\n", node_path);
406 return offs;
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400407 }
408 ret = fdt_setprop_string(blob, offs, "status", "disabled");
409 if (ret < 0) {
410 printf("Could not add status property to node %s: %s\n",
411 node_path, fdt_strerror(ret));
412 return ret;
413 }
414 return 0;
415}
416
Andrew Davisb1c29792023-04-06 11:38:10 -0500417#if defined(CONFIG_OF_SYSTEM_SETUP)
418int ft_system_setup(void *blob, struct bd_info *bd)
419{
420 int ret;
421
422 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
423 if (ret < 0)
424 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
425 "sram@70000000");
426 if (ret)
427 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
428
429 return ret;
430}
431#endif
432
Lokesh Vutla16cf5d22019-03-08 11:47:34 +0530433#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530434
435#ifndef CONFIG_SYSRESET
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100436void reset_cpu(void)
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530437{
438}
439#endif
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530440
Andrew Davisf8c98362022-07-15 11:34:32 -0500441enum k3_device_type get_device_type(void)
442{
443 u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS);
444
445 u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >>
446 SYS_STATUS_DEV_TYPE_SHIFT;
447
448 u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >>
449 SYS_STATUS_SUB_TYPE_SHIFT;
450
451 switch (sys_dev_type) {
452 case SYS_STATUS_DEV_TYPE_GP:
453 return K3_DEVICE_TYPE_GP;
454 case SYS_STATUS_DEV_TYPE_TEST:
455 return K3_DEVICE_TYPE_TEST;
456 case SYS_STATUS_DEV_TYPE_EMU:
457 return K3_DEVICE_TYPE_EMU;
458 case SYS_STATUS_DEV_TYPE_HS:
459 if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS)
460 return K3_DEVICE_TYPE_HS_FS;
461 else
462 return K3_DEVICE_TYPE_HS_SE;
463 default:
464 return K3_DEVICE_TYPE_BAD;
465 }
466}
467
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530468#if defined(CONFIG_DISPLAY_CPUINFO)
Andrew Davisf8c98362022-07-15 11:34:32 -0500469static const char *get_device_type_name(void)
470{
471 enum k3_device_type type = get_device_type();
472
473 switch (type) {
474 case K3_DEVICE_TYPE_GP:
475 return "GP";
476 case K3_DEVICE_TYPE_TEST:
477 return "TEST";
478 case K3_DEVICE_TYPE_EMU:
479 return "EMU";
480 case K3_DEVICE_TYPE_HS_FS:
481 return "HS-FS";
482 case K3_DEVICE_TYPE_HS_SE:
483 return "HS-SE";
484 default:
485 return "BAD";
486 }
487}
488
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530489int print_cpuinfo(void)
490{
Dave Gerlachc74227f2020-07-15 23:40:04 -0500491 struct udevice *soc;
492 char name[64];
493 int ret;
Dave Gerlach3373ee02020-07-15 23:40:04 -0500494
Tom Rini5a9ecb22020-07-24 08:42:06 -0400495 printf("SoC: ");
Dave Gerlach3373ee02020-07-15 23:40:04 -0500496
Dave Gerlachc74227f2020-07-15 23:40:04 -0500497 ret = soc_get(&soc);
498 if (ret) {
499 printf("UNKNOWN\n");
500 return 0;
501 }
502
503 ret = soc_get_family(soc, name, 64);
504 if (!ret) {
505 printf("%s ", name);
506 }
507
508 ret = soc_get_revision(soc, name, 64);
509 if (!ret) {
Andrew Davisf8c98362022-07-15 11:34:32 -0500510 printf("%s ", name);
Dave Gerlachc74227f2020-07-15 23:40:04 -0500511 }
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530512
Andrew Davisf8c98362022-07-15 11:34:32 -0500513 printf("%s\n", get_device_type_name());
514
Lokesh Vutlaa04cf3b2019-09-27 13:32:11 +0530515 return 0;
516}
517#endif
Lokesh Vutla362beda2019-10-07 13:52:17 +0530518
519#ifdef CONFIG_ARM64
Simon Glassdf00afa2022-09-06 20:26:50 -0600520void board_prep_linux(struct bootm_headers *images)
Lokesh Vutla362beda2019-10-07 13:52:17 +0530521{
522 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
523 images->os.start, images->os.end);
524 __asm_flush_dcache_range(images->os.start,
525 ROUND(images->os.end,
526 CONFIG_SYS_CACHELINE_SIZE));
527}
528#endif
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530529
530#ifdef CONFIG_CPU_V7R
531void disable_linefill_optimization(void)
532{
533 u32 actlr;
534
535 /*
536 * On K3 devices there are 2 conditions where R5F can deadlock:
537 * 1.When software is performing series of store operations to
538 * cacheable write back/write allocate memory region and later
539 * on software execute barrier operation (DSB or DMB). R5F may
540 * hang at the barrier instruction.
541 * 2.When software is performing a mix of load and store operations
542 * within a tight loop and store operations are all writing to
543 * cacheable write back/write allocates memory regions, R5F may
544 * hang at one of the load instruction.
545 *
546 * To avoid the above two conditions disable linefill optimization
547 * inside Cortex R5F.
548 */
549 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
550 actlr |= (1 << 13); /* Set DLFO bit */
551 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
552}
553#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500554
555void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size)
556{
557 struct ti_sci_msg_fwl_region region;
558 struct ti_sci_fwl_ops *fwl_ops;
559 struct ti_sci_handle *ti_sci;
560 size_t i, j;
561
562 ti_sci = get_ti_sci_handle();
563 fwl_ops = &ti_sci->ops.fwl_ops;
564 for (i = 0; i < fwl_data_size; i++) {
565 for (j = 0; j < fwl_data[i].regions; j++) {
566 region.fwl_id = fwl_data[i].fwl_id;
567 region.region = j;
568 region.n_permission_regs = 3;
569
570 fwl_ops->get_fwl_region(ti_sci, &region);
571
572 if (region.control != 0) {
573 pr_debug("Attempting to disable firewall %5d (%25s)\n",
574 region.fwl_id, fwl_data[i].name);
575 region.control = 0;
576
577 if (fwl_ops->set_fwl_region(ti_sci, &region))
578 pr_err("Could not disable firewall %5d (%25s)\n",
579 region.fwl_id, fwl_data[i].name);
580 }
581 }
582 }
583}
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200584
585void spl_enable_dcache(void)
586{
587#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Tom Rinibb4dd962022-11-16 13:10:37 -0500588 phys_addr_t ram_top = CFG_SYS_SDRAM_BASE;
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200589
Georgi Vlaeva5076cd2022-06-14 17:45:30 +0300590 dram_init();
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200591
592 /* reserve TLB table */
593 gd->arch.tlb_size = PGTABLE_SIZE;
594
595 ram_top += get_effective_memsize();
596 /* keep ram_top in the 32-bit address space */
597 if (ram_top >= 0x100000000)
598 ram_top = (phys_addr_t) 0x100000000;
599
600 gd->arch.tlb_addr = ram_top - gd->arch.tlb_size;
601 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
602 gd->arch.tlb_addr + gd->arch.tlb_size);
603
604 dcache_enable();
605#endif
606}
607
608#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
609void spl_board_prepare_for_boot(void)
610{
611 dcache_disable();
612}
613
Patrick Delaunay35c949c2020-07-07 14:25:15 +0200614void spl_board_prepare_for_linux(void)
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200615{
616 dcache_disable();
617}
618#endif
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530619
620int misc_init_r(void)
621{
622 if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) {
623 struct udevice *dev;
624 int ret;
625
626 ret = uclass_get_device_by_driver(UCLASS_MISC,
627 DM_DRIVER_GET(am65_cpsw_nuss),
628 &dev);
629 if (ret)
630 printf("Failed to probe am65_cpsw_nuss driver\n");
631 }
632
Andrew Davisf1d72052022-10-07 11:27:46 -0500633 /* Default FIT boot on non-GP devices */
634 if (get_device_type() != K3_DEVICE_TYPE_GP)
635 env_set("boot_fit", "1");
636
Vignesh Raghavendra030f4052021-12-24 12:55:29 +0530637 return 0;
638}