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 DECLARE_GLOBAL_DATA_PTR;
40 #ifdef CONFIG_K3_EARLY_CONS
41 int early_console_init(void)
46 gd->baudrate = CONFIG_BAUDRATE;
48 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
51 printf("Error getting serial dev for early console! (%d)\n",
56 gd->cur_serial_dev = dev;
57 gd->flags |= GD_FLG_SERIAL_READY;
64 #ifdef CONFIG_SYS_K3_SPL_ATF
68 #ifdef CONFIG_SPL_ENV_SUPPORT
73 switch (spl_boot_device()) {
74 case BOOT_DEVICE_MMC2:
75 part = env_get("bootpart");
76 env_set("storage_interface", "mmc");
77 env_set("fw_dev_part", part);
80 env_set("storage_interface", "ubi");
81 env_set("fw_ubi_mtdpart", "UBI");
82 env_set("fw_ubi_volume", "UBI0");
85 printf("%s from device %u not supported!\n",
86 __func__, spl_boot_device());
92 #ifdef CONFIG_FS_LOADER
93 int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr)
95 struct udevice *fsdev;
100 #ifdef CONFIG_SPL_ENV_SUPPORT
101 switch (spl_boot_device()) {
102 case BOOT_DEVICE_MMC2:
103 name = env_get(name_fw);
104 *loadaddr = env_get_hex(name_loadaddr, *loadaddr);
107 printf("Loading rproc fw image from device %u not supported!\n",
115 if (!uclass_get_device(UCLASS_FS_FIRMWARE_LOADER, 0, &fsdev)) {
116 size = request_firmware_into_buf(fsdev, name, (void *)*loadaddr,
123 int load_firmware(char *name_fw, char *name_loadaddr, u32 *loadaddr)
129 __weak void start_non_linux_remote_cores(void)
133 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
135 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
138 /* Release all the exclusive devices held by SPL before starting ATF */
139 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
143 panic("rproc failed to be initialized (%d)\n", ret);
146 start_non_linux_remote_cores();
149 * It is assumed that remoteproc device 1 is the corresponding
150 * Cortex-A core which runs ATF. Make sure DT reflects the same.
152 ret = rproc_load(1, spl_image->entry_point, 0x200);
154 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
156 /* Add an extra newline to differentiate the ATF logs from SPL */
157 printf("Starting ATF on ARM64 core...\n\n");
159 ret = rproc_start(1);
161 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
163 debug("Releasing resources...\n");
164 release_resources_for_core_shutdown();
166 debug("Finalizing core shutdown...\n");
172 #if defined(CONFIG_OF_LIBFDT)
173 int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
175 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
176 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
177 int ret, node, subnode, len, prev_node;
178 u32 range[4], addr, size;
179 const fdt32_t *sub_reg;
181 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
182 msmc_size = msmc_end - msmc_start + 1;
183 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
184 msmc_start, msmc_size);
186 /* find or create "msmc_sram node */
187 ret = fdt_path_offset(blob, parent_path);
191 node = fdt_find_or_add_subnode(blob, ret, node_name);
195 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
199 reg[0] = cpu_to_fdt64(msmc_start);
200 reg[1] = cpu_to_fdt64(msmc_size);
201 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
205 fdt_setprop_cell(blob, node, "#address-cells", 1);
206 fdt_setprop_cell(blob, node, "#size-cells", 1);
209 range[1] = cpu_to_fdt32(msmc_start >> 32);
210 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
211 range[3] = cpu_to_fdt32(msmc_size);
212 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
216 subnode = fdt_first_subnode(blob, node);
219 /* Look for invalid subnodes and delete them */
220 while (subnode >= 0) {
221 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
222 addr = fdt_read_number(sub_reg, 1);
224 size = fdt_read_number(sub_reg, 1);
225 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
226 subnode, addr, size);
227 if (addr + size > msmc_size ||
228 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
229 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
230 fdt_del_node(blob, subnode);
231 debug("%s: deleting subnode %d\n", __func__, subnode);
233 subnode = fdt_first_subnode(blob, node);
235 subnode = fdt_next_subnode(blob, prev_node);
238 subnode = fdt_next_subnode(blob, prev_node);
245 int fdt_disable_node(void *blob, char *node_path)
250 offs = fdt_path_offset(blob, node_path);
252 printf("Node %s not found.\n", node_path);
255 ret = fdt_setprop_string(blob, offs, "status", "disabled");
257 printf("Could not add status property to node %s: %s\n",
258 node_path, fdt_strerror(ret));
266 #ifndef CONFIG_SYSRESET
267 void reset_cpu(ulong ignored)
272 #if defined(CONFIG_DISPLAY_CPUINFO)
273 int print_cpuinfo(void)
278 soc = (readl(CTRLMMR_WKUP_JTAG_DEVICE_ID) &
279 DEVICE_ID_FAMILY_MASK) >> DEVICE_ID_FAMILY_SHIFT;
280 rev = (readl(CTRLMMR_WKUP_JTAG_ID) &
281 JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
292 name = "Unknown Silicon";
295 printf("%s SR ", name);
304 name = "Unknown Revision";
306 printf("%s\n", name);
313 void board_prep_linux(bootm_headers_t *images)
315 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
316 images->os.start, images->os.end);
317 __asm_flush_dcache_range(images->os.start,
318 ROUND(images->os.end,
319 CONFIG_SYS_CACHELINE_SIZE));
323 #ifdef CONFIG_CPU_V7R
324 void disable_linefill_optimization(void)
329 * On K3 devices there are 2 conditions where R5F can deadlock:
330 * 1.When software is performing series of store operations to
331 * cacheable write back/write allocate memory region and later
332 * on software execute barrier operation (DSB or DMB). R5F may
333 * hang at the barrier instruction.
334 * 2.When software is performing a mix of load and store operations
335 * within a tight loop and store operations are all writing to
336 * cacheable write back/write allocates memory regions, R5F may
337 * hang at one of the load instruction.
339 * To avoid the above two conditions disable linefill optimization
342 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
343 actlr |= (1 << 13); /* Set DLFO bit */
344 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
348 void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size)
350 struct ti_sci_msg_fwl_region region;
351 struct ti_sci_fwl_ops *fwl_ops;
352 struct ti_sci_handle *ti_sci;
355 ti_sci = get_ti_sci_handle();
356 fwl_ops = &ti_sci->ops.fwl_ops;
357 for (i = 0; i < fwl_data_size; i++) {
358 for (j = 0; j < fwl_data[i].regions; j++) {
359 region.fwl_id = fwl_data[i].fwl_id;
361 region.n_permission_regs = 3;
363 fwl_ops->get_fwl_region(ti_sci, ®ion);
365 if (region.control != 0) {
366 pr_debug("Attempting to disable firewall %5d (%25s)\n",
367 region.fwl_id, fwl_data[i].name);
370 if (fwl_ops->set_fwl_region(ti_sci, ®ion))
371 pr_err("Could not disable firewall %5d (%25s)\n",
372 region.fwl_id, fwl_data[i].name);