1 // SPDX-License-Identifier: GPL-2.0+
3 * K3: Common Architecture initialization
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
14 #include <remoteproc.h>
15 #include <linux/soc/ti/ti_sci_protocol.h>
16 #include <fdt_support.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/hardware.h>
20 #include <fs_loader.h>
25 struct ti_sci_handle *get_ti_sci_handle(void)
30 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
31 DM_GET_DRIVER(ti_sci), &dev);
33 panic("Failed to get SYSFW (%d)\n", ret);
35 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
38 void k3_sysfw_print_ver(void)
40 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
41 char fw_desc[sizeof(ti_sci->version.firmware_description) + 1];
44 * Output System Firmware version info. Note that since the
45 * 'firmware_description' field is not guaranteed to be zero-
46 * terminated we manually add a \0 terminator if needed. Further
47 * note that we intentionally no longer rely on the extended
48 * printf() formatter '%.*s' to not having to require a more
49 * full-featured printf() implementation.
51 strncpy(fw_desc, ti_sci->version.firmware_description,
52 sizeof(ti_sci->version.firmware_description));
53 fw_desc[sizeof(fw_desc) - 1] = '\0';
55 printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n",
56 ti_sci->version.abi_major, ti_sci->version.abi_minor,
57 ti_sci->version.firmware_revision, fw_desc);
60 DECLARE_GLOBAL_DATA_PTR;
62 #ifdef CONFIG_K3_EARLY_CONS
63 int early_console_init(void)
68 gd->baudrate = CONFIG_BAUDRATE;
70 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
73 printf("Error getting serial dev for early console! (%d)\n",
78 gd->cur_serial_dev = dev;
79 gd->flags |= GD_FLG_SERIAL_READY;
86 #ifdef CONFIG_SYS_K3_SPL_ATF
90 #ifdef CONFIG_SPL_ENV_SUPPORT
95 switch (spl_boot_device()) {
96 case BOOT_DEVICE_MMC2:
97 part = env_get("bootpart");
98 env_set("storage_interface", "mmc");
99 env_set("fw_dev_part", part);
101 case BOOT_DEVICE_SPI:
102 env_set("storage_interface", "ubi");
103 env_set("fw_ubi_mtdpart", "UBI");
104 env_set("fw_ubi_volume", "UBI0");
107 printf("%s from device %u not supported!\n",
108 __func__, spl_boot_device());
114 #ifdef CONFIG_FS_LOADER
115 int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr)
117 struct udevice *fsdev;
122 #ifdef CONFIG_SPL_ENV_SUPPORT
123 switch (spl_boot_device()) {
124 case BOOT_DEVICE_MMC2:
125 name = env_get(name_fw);
126 *loadaddr = env_get_hex(name_loadaddr, *loadaddr);
129 printf("Loading rproc fw image from device %u not supported!\n",
137 if (!uclass_get_device(UCLASS_FS_FIRMWARE_LOADER, 0, &fsdev)) {
138 size = request_firmware_into_buf(fsdev, name, (void *)*loadaddr,
145 int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr)
151 __weak void start_non_linux_remote_cores(void)
155 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
157 typedef void __noreturn (*image_entry_noargs_t)(void);
158 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
162 /* Release all the exclusive devices held by SPL before starting ATF */
163 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
167 panic("rproc failed to be initialized (%d)\n", ret);
170 start_non_linux_remote_cores();
171 size = load_firmware("name_mcur5f0_0fw", "addr_mcur5f0_0load",
176 * It is assumed that remoteproc device 1 is the corresponding
177 * Cortex-A core which runs ATF. Make sure DT reflects the same.
179 ret = rproc_load(1, spl_image->entry_point, 0x200);
181 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
183 /* Add an extra newline to differentiate the ATF logs from SPL */
184 printf("Starting ATF on ARM64 core...\n\n");
186 ret = rproc_start(1);
188 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
189 if (!(size > 0 && valid_elf_image(loadaddr))) {
190 debug("Shutting down...\n");
191 release_resources_for_core_shutdown();
197 image_entry_noargs_t image_entry =
198 (image_entry_noargs_t)load_elf_image_phdr(loadaddr);
204 #if defined(CONFIG_OF_LIBFDT)
205 int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
207 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
208 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
209 int ret, node, subnode, len, prev_node;
210 u32 range[4], addr, size;
211 const fdt32_t *sub_reg;
213 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
214 msmc_size = msmc_end - msmc_start + 1;
215 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
216 msmc_start, msmc_size);
218 /* find or create "msmc_sram node */
219 ret = fdt_path_offset(blob, parent_path);
223 node = fdt_find_or_add_subnode(blob, ret, node_name);
227 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
231 reg[0] = cpu_to_fdt64(msmc_start);
232 reg[1] = cpu_to_fdt64(msmc_size);
233 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
237 fdt_setprop_cell(blob, node, "#address-cells", 1);
238 fdt_setprop_cell(blob, node, "#size-cells", 1);
241 range[1] = cpu_to_fdt32(msmc_start >> 32);
242 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
243 range[3] = cpu_to_fdt32(msmc_size);
244 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
248 subnode = fdt_first_subnode(blob, node);
251 /* Look for invalid subnodes and delete them */
252 while (subnode >= 0) {
253 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
254 addr = fdt_read_number(sub_reg, 1);
256 size = fdt_read_number(sub_reg, 1);
257 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
258 subnode, addr, size);
259 if (addr + size > msmc_size ||
260 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
261 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
262 fdt_del_node(blob, subnode);
263 debug("%s: deleting subnode %d\n", __func__, subnode);
265 subnode = fdt_first_subnode(blob, node);
267 subnode = fdt_next_subnode(blob, prev_node);
270 subnode = fdt_next_subnode(blob, prev_node);
277 int fdt_disable_node(void *blob, char *node_path)
282 offs = fdt_path_offset(blob, node_path);
284 printf("Node %s not found.\n", node_path);
287 ret = fdt_setprop_string(blob, offs, "status", "disabled");
289 printf("Could not add status property to node %s: %s\n",
290 node_path, fdt_strerror(ret));
298 #ifndef CONFIG_SYSRESET
299 void reset_cpu(ulong ignored)
304 #if defined(CONFIG_DISPLAY_CPUINFO)
305 int print_cpuinfo(void)
310 soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
311 JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
312 rev = (readl(CTRLMMR_WKUP_JTAG_ID) &
313 JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
324 name = "Unknown Silicon";
327 printf("%s SR ", name);
336 name = "Unknown Revision";
338 printf("%s\n", name);
345 void board_prep_linux(bootm_headers_t *images)
347 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
348 images->os.start, images->os.end);
349 __asm_flush_dcache_range(images->os.start,
350 ROUND(images->os.end,
351 CONFIG_SYS_CACHELINE_SIZE));
355 #ifdef CONFIG_CPU_V7R
356 void disable_linefill_optimization(void)
361 * On K3 devices there are 2 conditions where R5F can deadlock:
362 * 1.When software is performing series of store operations to
363 * cacheable write back/write allocate memory region and later
364 * on software execute barrier operation (DSB or DMB). R5F may
365 * hang at the barrier instruction.
366 * 2.When software is performing a mix of load and store operations
367 * within a tight loop and store operations are all writing to
368 * cacheable write back/write allocates memory regions, R5F may
369 * hang at one of the load instruction.
371 * To avoid the above two conditions disable linefill optimization
374 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
375 actlr |= (1 << 13); /* Set DLFO bit */
376 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
380 void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size)
382 struct ti_sci_msg_fwl_region region;
383 struct ti_sci_fwl_ops *fwl_ops;
384 struct ti_sci_handle *ti_sci;
387 ti_sci = get_ti_sci_handle();
388 fwl_ops = &ti_sci->ops.fwl_ops;
389 for (i = 0; i < fwl_data_size; i++) {
390 for (j = 0; j < fwl_data[i].regions; j++) {
391 region.fwl_id = fwl_data[i].fwl_id;
393 region.n_permission_regs = 3;
395 fwl_ops->get_fwl_region(ti_sci, ®ion);
397 if (region.control != 0) {
398 pr_debug("Attempting to disable firewall %5d (%25s)\n",
399 region.fwl_id, fwl_data[i].name);
402 if (fwl_ops->set_fwl_region(ti_sci, ®ion))
403 pr_err("Could not disable firewall %5d (%25s)\n",
404 region.fwl_id, fwl_data[i].name);