blob: 03f01d07eacf7c551f234c873a0d8a78a4e3e0ce [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>
Lokesh Vutla28cd8242019-03-08 11:47:33 +053016
17struct ti_sci_handle *get_ti_sci_handle(void)
18{
19 struct udevice *dev;
20 int ret;
21
22 ret = uclass_get_device_by_name(UCLASS_FIRMWARE, "dmsc", &dev);
23 if (ret)
24 panic("Failed to get SYSFW (%d)\n", ret);
25
26 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
27}
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053028
29#ifdef CONFIG_SYS_K3_SPL_ATF
30void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
31{
32 int ret;
33
34 /*
35 * It is assumed that remoteproc device 1 is the corresponding
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060036 * Cortex-A core which runs ATF. Make sure DT reflects the same.
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053037 */
38 ret = rproc_dev_init(1);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060039 if (ret)
40 panic("%s: ATF failed to initialize on rproc (%d)\n", __func__,
41 ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053042
43 ret = rproc_load(1, spl_image->entry_point, 0x200);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060044 if (ret)
45 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053046
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060047 /* Add an extra newline to differentiate the ATF logs from SPL */
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053048 printf("Starting ATF on ARM64 core...\n\n");
49
50 ret = rproc_start(1);
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060051 if (ret)
52 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053053
Andreas Dannenberg376c0fe2019-02-04 12:58:47 -060054 debug("ATF started. Waiting indefinitely...\n");
Lokesh Vutla5d83fd22018-11-02 19:51:05 +053055 while (1)
56 asm volatile("wfe");
57}
58#endif
Lokesh Vutla16cf5d22019-03-08 11:47:34 +053059
60#if defined(CONFIG_OF_LIBFDT)
61int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
62{
63 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
64 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
65 int ret, node, subnode, len, prev_node;
66 u32 range[4], addr, size;
67 const fdt32_t *sub_reg;
68
69 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
70 msmc_size = msmc_end - msmc_start + 1;
71 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
72 msmc_start, msmc_size);
73
74 /* find or create "msmc_sram node */
75 ret = fdt_path_offset(blob, parent_path);
76 if (ret < 0)
77 return ret;
78
79 node = fdt_find_or_add_subnode(blob, ret, node_name);
80 if (node < 0)
81 return node;
82
83 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
84 if (ret < 0)
85 return ret;
86
87 reg[0] = cpu_to_fdt64(msmc_start);
88 reg[1] = cpu_to_fdt64(msmc_size);
89 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
90 if (ret < 0)
91 return ret;
92
93 fdt_setprop_cell(blob, node, "#address-cells", 1);
94 fdt_setprop_cell(blob, node, "#size-cells", 1);
95
96 range[0] = 0;
97 range[1] = cpu_to_fdt32(msmc_start >> 32);
98 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
99 range[3] = cpu_to_fdt32(msmc_size);
100 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
101 if (ret < 0)
102 return ret;
103
104 subnode = fdt_first_subnode(blob, node);
105 prev_node = 0;
106
107 /* Look for invalid subnodes and delete them */
108 while (subnode >= 0) {
109 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
110 addr = fdt_read_number(sub_reg, 1);
111 sub_reg++;
112 size = fdt_read_number(sub_reg, 1);
113 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
114 subnode, addr, size);
115 if (addr + size > msmc_size ||
116 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
117 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
118 fdt_del_node(blob, subnode);
119 debug("%s: deleting subnode %d\n", __func__, subnode);
120 if (!prev_node)
121 subnode = fdt_first_subnode(blob, node);
122 else
123 subnode = fdt_next_subnode(blob, prev_node);
124 } else {
125 prev_node = subnode;
126 subnode = fdt_next_subnode(blob, prev_node);
127 }
128 }
129
130 return 0;
131}
132#endif