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>
21 struct ti_sci_handle *get_ti_sci_handle(void)
26 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
27 DM_GET_DRIVER(ti_sci), &dev);
29 panic("Failed to get SYSFW (%d)\n", ret);
31 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
34 DECLARE_GLOBAL_DATA_PTR;
36 #ifdef CONFIG_K3_EARLY_CONS
37 int early_console_init(void)
42 gd->baudrate = CONFIG_BAUDRATE;
44 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
47 printf("Error getting serial dev for early console! (%d)\n",
52 gd->cur_serial_dev = dev;
53 gd->flags |= GD_FLG_SERIAL_READY;
60 #ifdef CONFIG_SYS_K3_SPL_ATF
61 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
63 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
66 /* Release all the exclusive devices held by SPL before starting ATF */
67 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
70 * It is assumed that remoteproc device 1 is the corresponding
71 * Cortex-A core which runs ATF. Make sure DT reflects the same.
73 ret = rproc_dev_init(1);
75 panic("%s: ATF failed to initialize on rproc (%d)\n", __func__,
78 ret = rproc_load(1, spl_image->entry_point, 0x200);
80 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
82 /* Add an extra newline to differentiate the ATF logs from SPL */
83 printf("Starting ATF on ARM64 core...\n\n");
87 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
89 debug("Releasing resources...\n");
90 release_resources_for_core_shutdown();
92 debug("Finalizing core shutdown...\n");
98 #if defined(CONFIG_OF_LIBFDT)
99 int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
101 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
102 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
103 int ret, node, subnode, len, prev_node;
104 u32 range[4], addr, size;
105 const fdt32_t *sub_reg;
107 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
108 msmc_size = msmc_end - msmc_start + 1;
109 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
110 msmc_start, msmc_size);
112 /* find or create "msmc_sram node */
113 ret = fdt_path_offset(blob, parent_path);
117 node = fdt_find_or_add_subnode(blob, ret, node_name);
121 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
125 reg[0] = cpu_to_fdt64(msmc_start);
126 reg[1] = cpu_to_fdt64(msmc_size);
127 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
131 fdt_setprop_cell(blob, node, "#address-cells", 1);
132 fdt_setprop_cell(blob, node, "#size-cells", 1);
135 range[1] = cpu_to_fdt32(msmc_start >> 32);
136 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
137 range[3] = cpu_to_fdt32(msmc_size);
138 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
142 subnode = fdt_first_subnode(blob, node);
145 /* Look for invalid subnodes and delete them */
146 while (subnode >= 0) {
147 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
148 addr = fdt_read_number(sub_reg, 1);
150 size = fdt_read_number(sub_reg, 1);
151 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
152 subnode, addr, size);
153 if (addr + size > msmc_size ||
154 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
155 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
156 fdt_del_node(blob, subnode);
157 debug("%s: deleting subnode %d\n", __func__, subnode);
159 subnode = fdt_first_subnode(blob, node);
161 subnode = fdt_next_subnode(blob, prev_node);
164 subnode = fdt_next_subnode(blob, prev_node);
171 int fdt_disable_node(void *blob, char *node_path)
176 offs = fdt_path_offset(blob, node_path);
178 printf("Node %s not found.\n", node_path);
181 ret = fdt_setprop_string(blob, offs, "status", "disabled");
183 printf("Could not add status property to node %s: %s\n",
184 node_path, fdt_strerror(ret));
192 #ifndef CONFIG_SYSRESET
193 void reset_cpu(ulong ignored)
198 #if defined(CONFIG_DISPLAY_CPUINFO)
199 int print_cpuinfo(void)
204 soc = (readl(CTRLMMR_WKUP_JTAG_DEVICE_ID) &
205 DEVICE_ID_FAMILY_MASK) >> DEVICE_ID_FAMILY_SHIFT;
206 rev = (readl(CTRLMMR_WKUP_JTAG_ID) &
207 JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
218 name = "Unknown Silicon";
221 printf("%s PG ", name);
230 name = "Unknown Revision";
232 printf("%s\n", name);
239 void board_prep_linux(bootm_headers_t *images)
241 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
242 images->os.start, images->os.end);
243 __asm_flush_dcache_range(images->os.start,
244 ROUND(images->os.end,
245 CONFIG_SYS_CACHELINE_SIZE));
249 #ifdef CONFIG_CPU_V7R
250 void disable_linefill_optimization(void)
255 * On K3 devices there are 2 conditions where R5F can deadlock:
256 * 1.When software is performing series of store operations to
257 * cacheable write back/write allocate memory region and later
258 * on software execute barrier operation (DSB or DMB). R5F may
259 * hang at the barrier instruction.
260 * 2.When software is performing a mix of load and store operations
261 * within a tight loop and store operations are all writing to
262 * cacheable write back/write allocates memory regions, R5F may
263 * hang at one of the load instruction.
265 * To avoid the above two conditions disable linefill optimization
268 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
269 actlr |= (1 << 13); /* Set DLFO bit */
270 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
274 void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size)
276 struct ti_sci_msg_fwl_region region;
277 struct ti_sci_fwl_ops *fwl_ops;
278 struct ti_sci_handle *ti_sci;
281 ti_sci = get_ti_sci_handle();
282 fwl_ops = &ti_sci->ops.fwl_ops;
283 for (i = 0; i < fwl_data_size; i++) {
284 for (j = 0; j < fwl_data[i].regions; j++) {
285 region.fwl_id = fwl_data[i].fwl_id;
287 region.n_permission_regs = 3;
289 fwl_ops->get_fwl_region(ti_sci, ®ion);
291 if (region.control != 0) {
292 pr_debug("Attempting to disable firewall %5d (%25s)\n",
293 region.fwl_id, fwl_data[i].name);
296 if (fwl_ops->set_fwl_region(ti_sci, ®ion))
297 pr_err("Could not disable firewall %5d (%25s)\n",
298 region.fwl_id, fwl_data[i].name);