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> |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 16 | |
| 17 | struct 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 Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 28 | |
| 29 | #ifdef CONFIG_SYS_K3_SPL_ATF |
| 30 | void __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 Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 36 | * Cortex-A core which runs ATF. Make sure DT reflects the same. |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 37 | */ |
| 38 | ret = rproc_dev_init(1); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 39 | if (ret) |
| 40 | panic("%s: ATF failed to initialize on rproc (%d)\n", __func__, |
| 41 | ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 42 | |
| 43 | ret = rproc_load(1, spl_image->entry_point, 0x200); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 44 | if (ret) |
| 45 | panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 46 | |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 47 | /* Add an extra newline to differentiate the ATF logs from SPL */ |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 48 | printf("Starting ATF on ARM64 core...\n\n"); |
| 49 | |
| 50 | ret = rproc_start(1); |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 51 | if (ret) |
| 52 | panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 53 | |
Andreas Dannenberg | 376c0fe | 2019-02-04 12:58:47 -0600 | [diff] [blame] | 54 | debug("ATF started. Waiting indefinitely...\n"); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 55 | while (1) |
| 56 | asm volatile("wfe"); |
| 57 | } |
| 58 | #endif |
Lokesh Vutla | 16cf5d2 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 59 | |
| 60 | #if defined(CONFIG_OF_LIBFDT) |
| 61 | int 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 |