Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Freescale Semiconductor, Inc. |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 8 | #include <asm/io.h> |
Peng Fan | ecd7ab5 | 2018-01-10 13:20:33 +0800 | [diff] [blame] | 9 | #include <asm/mach-imx/sys_proto.h> |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 10 | #include <command.h> |
Igor Opaniuk | c0f037f | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 11 | #include <elf.h> |
Peng Fan | ecd7ab5 | 2018-01-10 13:20:33 +0800 | [diff] [blame] | 12 | #include <imx_sip.h> |
Peng Fan | bf26b94 | 2020-05-11 15:15:21 +0800 | [diff] [blame] | 13 | #include <linux/arm-smccc.h> |
Tom Rini | 20b9f2e | 2018-01-03 08:52:39 -0500 | [diff] [blame] | 14 | #include <linux/compiler.h> |
Igor Opaniuk | 8903826 | 2019-11-28 15:56:20 +0200 | [diff] [blame] | 15 | #include <cpu_func.h> |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 16 | |
Igor Opaniuk | c0f037f | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 17 | int arch_auxiliary_core_up(u32 core_id, ulong addr) |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 18 | { |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 19 | ulong stack, pc; |
| 20 | |
Igor Opaniuk | c0f037f | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 21 | if (!addr) |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 22 | return -EINVAL; |
| 23 | |
Igor Opaniuk | c0f037f | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 24 | #ifdef CONFIG_IMX8M |
| 25 | stack = *(u32 *)addr; |
| 26 | pc = *(u32 *)(addr + 4); |
| 27 | #else |
| 28 | /* |
| 29 | * handling ELF64 binaries |
| 30 | * isn't supported yet. |
| 31 | */ |
| 32 | if (valid_elf_image(addr)) { |
| 33 | stack = 0x0; |
| 34 | pc = load_elf_image_phdr(addr); |
| 35 | if (!pc) |
| 36 | return CMD_RET_FAILURE; |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 37 | |
Igor Opaniuk | c0f037f | 2019-12-30 13:56:44 +0200 | [diff] [blame] | 38 | } else { |
| 39 | /* |
| 40 | * Assume binary file with vector table at the beginning. |
| 41 | * Cortex-M4 vector tables start with the stack pointer (SP) |
| 42 | * and reset vector (initial PC). |
| 43 | */ |
| 44 | stack = *(u32 *)addr; |
| 45 | pc = *(u32 *)(addr + 4); |
| 46 | } |
| 47 | #endif |
Igor Opaniuk | 0ba1b4d | 2019-11-28 15:56:19 +0200 | [diff] [blame] | 48 | printf("## Starting auxiliary core stack = 0x%08lX, pc = 0x%08lX...\n", |
| 49 | stack, pc); |
| 50 | |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 51 | /* Set the stack and pc to M4 bootROM */ |
| 52 | writel(stack, M4_BOOTROM_BASE_ADDR); |
| 53 | writel(pc, M4_BOOTROM_BASE_ADDR + 4); |
| 54 | |
Igor Opaniuk | 8903826 | 2019-11-28 15:56:20 +0200 | [diff] [blame] | 55 | flush_dcache_all(); |
| 56 | |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 57 | /* Enable M4 */ |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_IMX8M |
Peng Fan | bf26b94 | 2020-05-11 15:15:21 +0800 | [diff] [blame] | 59 | arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0, |
| 60 | 0, 0, 0, 0, NULL); |
Peng Fan | ecd7ab5 | 2018-01-10 13:20:33 +0800 | [diff] [blame] | 61 | #else |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 62 | clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET, |
| 63 | SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK); |
Peng Fan | ecd7ab5 | 2018-01-10 13:20:33 +0800 | [diff] [blame] | 64 | #endif |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 65 | |
| 66 | return 0; |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 67 | } |
| 68 | |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 69 | int arch_auxiliary_core_check_up(u32 core_id) |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 70 | { |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 71 | #ifdef CONFIG_IMX8M |
Peng Fan | bf26b94 | 2020-05-11 15:15:21 +0800 | [diff] [blame] | 72 | struct arm_smccc_res res; |
| 73 | |
| 74 | arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0, |
| 75 | 0, 0, 0, 0, &res); |
| 76 | |
| 77 | return res.a0; |
Peng Fan | ecd7ab5 | 2018-01-10 13:20:33 +0800 | [diff] [blame] | 78 | #else |
Peng Fan | 8cf2231 | 2018-01-10 13:20:32 +0800 | [diff] [blame] | 79 | unsigned int val; |
| 80 | |
| 81 | val = readl(SRC_BASE_ADDR + SRC_M4_REG_OFFSET); |
| 82 | |
| 83 | if (val & SRC_M4C_NON_SCLR_RST_MASK) |
| 84 | return 0; /* assert in reset */ |
| 85 | |
| 86 | return 1; |
Peng Fan | ecd7ab5 | 2018-01-10 13:20:33 +0800 | [diff] [blame] | 87 | #endif |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 88 | } |
| 89 | |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 90 | /* |
| 91 | * To i.MX6SX and i.MX7D, the image supported by bootaux needs |
| 92 | * the reset vector at the head for the image, with SP and PC |
| 93 | * as the first two words. |
| 94 | * |
| 95 | * Per the cortex-M reference manual, the reset vector of M4 needs |
| 96 | * to exist at 0x0 (TCMUL). The PC and SP are the first two addresses |
| 97 | * of that vector. So to boot M4, the A core must build the M4's reset |
| 98 | * vector with getting the PC and SP from image and filling them to |
| 99 | * TCMUL. When M4 is kicked, it will load the PC and SP by itself. |
| 100 | * The TCMUL is mapped to (M4_BOOTROM_BASE_ADDR) at A core side for |
| 101 | * accessing the M4 TCMUL. |
| 102 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 103 | static int do_bootaux(struct cmd_tbl *cmdtp, int flag, int argc, |
| 104 | char *const argv[]) |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 105 | { |
| 106 | ulong addr; |
| 107 | int ret, up; |
| 108 | |
| 109 | if (argc < 2) |
| 110 | return CMD_RET_USAGE; |
| 111 | |
| 112 | up = arch_auxiliary_core_check_up(0); |
| 113 | if (up) { |
| 114 | printf("## Auxiliary core is already up\n"); |
| 115 | return CMD_RET_SUCCESS; |
| 116 | } |
| 117 | |
| 118 | addr = simple_strtoul(argv[1], NULL, 16); |
| 119 | |
Igor Opaniuk | 0ba1b4d | 2019-11-28 15:56:19 +0200 | [diff] [blame] | 120 | if (!addr) |
| 121 | return CMD_RET_FAILURE; |
Peng Fan | 6f6058b | 2016-01-28 16:55:04 +0800 | [diff] [blame] | 122 | |
| 123 | ret = arch_auxiliary_core_up(0, addr); |
| 124 | if (ret) |
| 125 | return CMD_RET_FAILURE; |
| 126 | |
| 127 | return CMD_RET_SUCCESS; |
| 128 | } |
| 129 | |
| 130 | U_BOOT_CMD( |
| 131 | bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux, |
| 132 | "Start auxiliary core", |
| 133 | "" |
| 134 | ); |