blob: 3e36d90aceff0d9677b146c29ea5aaeb1c2f79a9 [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>
10#include <spl.h>
11#include "common.h"
12#include <dm.h>
13#include <remoteproc.h>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053014#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutla16cf5d22019-03-08 11:47:34 +053015#include <fdt_support.h>
Andreas Dannenberg31175f82019-06-07 19:24:42 +053016#include <asm/arch/sys_proto.h>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053017
18struct ti_sci_handle *get_ti_sci_handle(void)
19{
20 struct udevice *dev;
21 int ret;
22
Lokesh Vutlabbb33de2019-09-09 12:47:37 +053023 ret = uclass_get_device(UCLASS_FIRMWARE, 0, &dev);
Lokesh Vutla28cd8242019-03-08 11:47:33 +053024 if (ret)
25 panic("Failed to get SYSFW (%d)\n", ret);
26
27 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
28}
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053029
30#ifdef CONFIG_SYS_K3_SPL_ATF
31void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
32{
Lokesh Vutla005476d2019-06-07 19:24:43 +053033 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053034 int ret;
35
Lokesh Vutla005476d2019-06-07 19:24:43 +053036 /* Release all the exclusive devices held by SPL before starting ATF */
37 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
38
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053039 /*
40 * It is assumed that remoteproc device 1 is the corresponding
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060041 * Cortex-A core which runs ATF. Make sure DT reflects the same.
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053042 */
43 ret = rproc_dev_init(1);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060044 if (ret)
45 panic("%s: ATF failed to initialize on rproc (%d)\n", __func__,
46 ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053047
48 ret = rproc_load(1, spl_image->entry_point, 0x200);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060049 if (ret)
50 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053051
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060052 /* Add an extra newline to differentiate the ATF logs from SPL */
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053053 printf("Starting ATF on ARM64 core...\n\n");
54
55 ret = rproc_start(1);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060056 if (ret)
57 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053058
Andreas Dannenberg31175f82019-06-07 19:24:42 +053059 debug("Releasing resources...\n");
60 release_resources_for_core_shutdown();
61
62 debug("Finalizing core shutdown...\n");
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053063 while (1)
64 asm volatile("wfe");
65}
66#endif
Lokesh Vutla16cf5d22019-03-08 11:47:34 +053067
68#if defined(CONFIG_OF_LIBFDT)
69int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
70{
71 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
72 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
73 int ret, node, subnode, len, prev_node;
74 u32 range[4], addr, size;
75 const fdt32_t *sub_reg;
76
77 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
78 msmc_size = msmc_end - msmc_start + 1;
79 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
80 msmc_start, msmc_size);
81
82 /* find or create "msmc_sram node */
83 ret = fdt_path_offset(blob, parent_path);
84 if (ret < 0)
85 return ret;
86
87 node = fdt_find_or_add_subnode(blob, ret, node_name);
88 if (node < 0)
89 return node;
90
91 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
92 if (ret < 0)
93 return ret;
94
95 reg[0] = cpu_to_fdt64(msmc_start);
96 reg[1] = cpu_to_fdt64(msmc_size);
97 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
98 if (ret < 0)
99 return ret;
100
101 fdt_setprop_cell(blob, node, "#address-cells", 1);
102 fdt_setprop_cell(blob, node, "#size-cells", 1);
103
104 range[0] = 0;
105 range[1] = cpu_to_fdt32(msmc_start >> 32);
106 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
107 range[3] = cpu_to_fdt32(msmc_size);
108 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
109 if (ret < 0)
110 return ret;
111
112 subnode = fdt_first_subnode(blob, node);
113 prev_node = 0;
114
115 /* Look for invalid subnodes and delete them */
116 while (subnode >= 0) {
117 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
118 addr = fdt_read_number(sub_reg, 1);
119 sub_reg++;
120 size = fdt_read_number(sub_reg, 1);
121 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
122 subnode, addr, size);
123 if (addr + size > msmc_size ||
124 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
125 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
126 fdt_del_node(blob, subnode);
127 debug("%s: deleting subnode %d\n", __func__, subnode);
128 if (!prev_node)
129 subnode = fdt_first_subnode(blob, node);
130 else
131 subnode = fdt_next_subnode(blob, prev_node);
132 } else {
133 prev_node = subnode;
134 subnode = fdt_next_subnode(blob, prev_node);
135 }
136 }
137
138 return 0;
139}
140#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530141
142#ifndef CONFIG_SYSRESET
143void reset_cpu(ulong ignored)
144{
145}
146#endif