Lokesh Vutla | 5d83fd2 | 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 | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 14 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | 16cf5d2 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 15 | #include <fdt_support.h> |
Andreas Dannenberg | 31175f8 | 2019-06-07 19:24:42 +0530 | [diff] [blame^] | 16 | #include <asm/arch/sys_proto.h> |
Lokesh Vutla | 28cd824 | 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 | |
| 23 | ret = uclass_get_device_by_name(UCLASS_FIRMWARE, "dmsc", &dev); |
| 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 | 5d83fd2 | 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 | { |
| 33 | int ret; |
| 34 | |
| 35 | /* |
| 36 | * It is assumed that remoteproc device 1 is the corresponding |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 37 | * Cortex-A core which runs ATF. Make sure DT reflects the same. |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 38 | */ |
| 39 | ret = rproc_dev_init(1); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 40 | if (ret) |
| 41 | panic("%s: ATF failed to initialize on rproc (%d)\n", __func__, |
| 42 | ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 43 | |
| 44 | ret = rproc_load(1, spl_image->entry_point, 0x200); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 45 | if (ret) |
| 46 | panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 47 | |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 48 | /* Add an extra newline to differentiate the ATF logs from SPL */ |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 49 | printf("Starting ATF on ARM64 core...\n\n"); |
| 50 | |
| 51 | ret = rproc_start(1); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 52 | if (ret) |
| 53 | panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 54 | |
Andreas Dannenberg | 31175f8 | 2019-06-07 19:24:42 +0530 | [diff] [blame^] | 55 | debug("Releasing resources...\n"); |
| 56 | release_resources_for_core_shutdown(); |
| 57 | |
| 58 | debug("Finalizing core shutdown...\n"); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 59 | while (1) |
| 60 | asm volatile("wfe"); |
| 61 | } |
| 62 | #endif |
Lokesh Vutla | 16cf5d2 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 63 | |
| 64 | #if defined(CONFIG_OF_LIBFDT) |
| 65 | int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name) |
| 66 | { |
| 67 | u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2]; |
| 68 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 69 | int ret, node, subnode, len, prev_node; |
| 70 | u32 range[4], addr, size; |
| 71 | const fdt32_t *sub_reg; |
| 72 | |
| 73 | ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end); |
| 74 | msmc_size = msmc_end - msmc_start + 1; |
| 75 | debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__, |
| 76 | msmc_start, msmc_size); |
| 77 | |
| 78 | /* find or create "msmc_sram node */ |
| 79 | ret = fdt_path_offset(blob, parent_path); |
| 80 | if (ret < 0) |
| 81 | return ret; |
| 82 | |
| 83 | node = fdt_find_or_add_subnode(blob, ret, node_name); |
| 84 | if (node < 0) |
| 85 | return node; |
| 86 | |
| 87 | ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram"); |
| 88 | if (ret < 0) |
| 89 | return ret; |
| 90 | |
| 91 | reg[0] = cpu_to_fdt64(msmc_start); |
| 92 | reg[1] = cpu_to_fdt64(msmc_size); |
| 93 | ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg)); |
| 94 | if (ret < 0) |
| 95 | return ret; |
| 96 | |
| 97 | fdt_setprop_cell(blob, node, "#address-cells", 1); |
| 98 | fdt_setprop_cell(blob, node, "#size-cells", 1); |
| 99 | |
| 100 | range[0] = 0; |
| 101 | range[1] = cpu_to_fdt32(msmc_start >> 32); |
| 102 | range[2] = cpu_to_fdt32(msmc_start & 0xffffffff); |
| 103 | range[3] = cpu_to_fdt32(msmc_size); |
| 104 | ret = fdt_setprop(blob, node, "ranges", range, sizeof(range)); |
| 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
| 108 | subnode = fdt_first_subnode(blob, node); |
| 109 | prev_node = 0; |
| 110 | |
| 111 | /* Look for invalid subnodes and delete them */ |
| 112 | while (subnode >= 0) { |
| 113 | sub_reg = fdt_getprop(blob, subnode, "reg", &len); |
| 114 | addr = fdt_read_number(sub_reg, 1); |
| 115 | sub_reg++; |
| 116 | size = fdt_read_number(sub_reg, 1); |
| 117 | debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__, |
| 118 | subnode, addr, size); |
| 119 | if (addr + size > msmc_size || |
| 120 | !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) || |
| 121 | !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) { |
| 122 | fdt_del_node(blob, subnode); |
| 123 | debug("%s: deleting subnode %d\n", __func__, subnode); |
| 124 | if (!prev_node) |
| 125 | subnode = fdt_first_subnode(blob, node); |
| 126 | else |
| 127 | subnode = fdt_next_subnode(blob, prev_node); |
| 128 | } else { |
| 129 | prev_node = subnode; |
| 130 | subnode = fdt_next_subnode(blob, prev_node); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | #endif |