Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 1 | // 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 Vutla | 6ce424a | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 14 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | a9a8448 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 15 | #include <fdt_support.h> |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Lokesh Vutla | 6ce424a | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 17 | |
| 18 | struct ti_sci_handle *get_ti_sci_handle(void) |
| 19 | { |
| 20 | struct udevice *dev; |
| 21 | int ret; |
| 22 | |
Lokesh Vutla | e8d3a18 | 2019-09-09 12:47:37 +0530 | [diff] [blame] | 23 | ret = uclass_get_device(UCLASS_FIRMWARE, 0, &dev); |
Lokesh Vutla | 6ce424a | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 24 | 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 Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 29 | |
| 30 | #ifdef CONFIG_SYS_K3_SPL_ATF |
| 31 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 32 | { |
Lokesh Vutla | c0669d2 | 2019-06-07 19:24:43 +0530 | [diff] [blame] | 33 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 34 | int ret; |
| 35 | |
Lokesh Vutla | c0669d2 | 2019-06-07 19:24:43 +0530 | [diff] [blame] | 36 | /* Release all the exclusive devices held by SPL before starting ATF */ |
| 37 | ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci); |
| 38 | |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 39 | /* |
| 40 | * It is assumed that remoteproc device 1 is the corresponding |
Andreas Dannenberg | 4a1fa52 | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 41 | * Cortex-A core which runs ATF. Make sure DT reflects the same. |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 42 | */ |
| 43 | ret = rproc_dev_init(1); |
Andreas Dannenberg | 4a1fa52 | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 44 | if (ret) |
| 45 | panic("%s: ATF failed to initialize on rproc (%d)\n", __func__, |
| 46 | ret); |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 47 | |
| 48 | ret = rproc_load(1, spl_image->entry_point, 0x200); |
Andreas Dannenberg | 4a1fa52 | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 49 | if (ret) |
| 50 | panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 51 | |
Andreas Dannenberg | 4a1fa52 | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 52 | /* Add an extra newline to differentiate the ATF logs from SPL */ |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 53 | printf("Starting ATF on ARM64 core...\n\n"); |
| 54 | |
| 55 | ret = rproc_start(1); |
Andreas Dannenberg | 4a1fa52 | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 56 | if (ret) |
| 57 | panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 58 | |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 59 | debug("Releasing resources...\n"); |
| 60 | release_resources_for_core_shutdown(); |
| 61 | |
| 62 | debug("Finalizing core shutdown...\n"); |
Lokesh Vutla | a3501a4 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 63 | while (1) |
| 64 | asm volatile("wfe"); |
| 65 | } |
| 66 | #endif |
Lokesh Vutla | a9a8448 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 67 | |
| 68 | #if defined(CONFIG_OF_LIBFDT) |
| 69 | int 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 | } |
Andrew F. Davis | 29c9db4 | 2019-09-17 17:15:40 -0400 | [diff] [blame^] | 140 | |
| 141 | int fdt_disable_node(void *blob, char *node_path) |
| 142 | { |
| 143 | int offs; |
| 144 | int ret; |
| 145 | |
| 146 | offs = fdt_path_offset(blob, node_path); |
| 147 | if (offs < 0) { |
| 148 | debug("Node %s not found.\n", node_path); |
| 149 | return 0; |
| 150 | } |
| 151 | ret = fdt_setprop_string(blob, offs, "status", "disabled"); |
| 152 | if (ret < 0) { |
| 153 | printf("Could not add status property to node %s: %s\n", |
| 154 | node_path, fdt_strerror(ret)); |
| 155 | return ret; |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
Lokesh Vutla | a9a8448 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 160 | #endif |
Lokesh Vutla | c2562d7 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 161 | |
| 162 | #ifndef CONFIG_SYSRESET |
| 163 | void reset_cpu(ulong ignored) |
| 164 | { |
| 165 | } |
| 166 | #endif |