Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 NXP |
| 4 | */ |
| 5 | |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 6 | #include <command.h> |
| 7 | #include <log.h> |
| 8 | #include <imx_sip.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <vsprintf.h> |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 10 | #include <linux/arm-smccc.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 11 | #include <linux/errno.h> |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 12 | |
| 13 | int arch_auxiliary_core_check_up(u32 core_id) |
| 14 | { |
| 15 | struct arm_smccc_res res; |
| 16 | |
Peng Fan | e9015f3 | 2023-06-15 18:09:18 +0800 | [diff] [blame] | 17 | arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_MCU_STARTED, 0, 0, |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 18 | 0, 0, 0, 0, &res); |
| 19 | |
| 20 | return res.a0; |
| 21 | } |
| 22 | |
| 23 | int arch_auxiliary_core_down(u32 core_id) |
| 24 | { |
| 25 | struct arm_smccc_res res; |
| 26 | |
| 27 | printf("## Stopping auxiliary core\n"); |
| 28 | |
Peng Fan | e9015f3 | 2023-06-15 18:09:18 +0800 | [diff] [blame] | 29 | arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_MCU_STOP, 0, 0, |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 30 | 0, 0, 0, 0, &res); |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | int arch_auxiliary_core_up(u32 core_id, ulong addr) |
| 36 | { |
| 37 | struct arm_smccc_res res; |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 38 | |
| 39 | if (!addr) |
| 40 | return -EINVAL; |
| 41 | |
Ye Li | 905fa83 | 2023-04-28 12:08:36 +0800 | [diff] [blame] | 42 | printf("## Starting auxiliary core addr = 0x%08lX...\n", addr); |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 43 | |
Peng Fan | e9015f3 | 2023-06-15 18:09:18 +0800 | [diff] [blame] | 44 | arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_MCU_START, addr, 0, |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 45 | 0, 0, 0, 0, &res); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * To i.MX6SX and i.MX7D, the image supported by bootaux needs |
| 52 | * the reset vector at the head for the image, with SP and PC |
| 53 | * as the first two words. |
| 54 | * |
| 55 | * Per the cortex-M reference manual, the reset vector of M4/M7 needs |
| 56 | * to exist at 0x0 (TCMUL/IDTCM). The PC and SP are the first two addresses |
| 57 | * of that vector. So to boot M4/M7, the A core must build the M4/M7's reset |
| 58 | * vector with getting the PC and SP from image and filling them to |
| 59 | * TCMUL/IDTCM. When M4/M7 is kicked, it will load the PC and SP by itself. |
| 60 | * The TCMUL/IDTCM is mapped to (MCU_BOOTROM_BASE_ADDR) at A core side for |
| 61 | * accessing the M4/M7 TCMUL/IDTCM. |
| 62 | */ |
| 63 | static int do_bootaux(struct cmd_tbl *cmdtp, int flag, int argc, |
| 64 | char *const argv[]) |
| 65 | { |
| 66 | ulong addr; |
| 67 | int ret, up; |
| 68 | u32 core = 0; |
| 69 | u32 stop = 0; |
| 70 | |
| 71 | if (argc < 2) |
| 72 | return CMD_RET_USAGE; |
| 73 | |
| 74 | if (argc > 2) |
| 75 | core = simple_strtoul(argv[2], NULL, 10); |
| 76 | |
| 77 | if (argc > 3) |
| 78 | stop = simple_strtoul(argv[3], NULL, 10); |
| 79 | |
| 80 | up = arch_auxiliary_core_check_up(core); |
| 81 | if (up) { |
| 82 | printf("## Auxiliary core is already up\n"); |
| 83 | return CMD_RET_SUCCESS; |
| 84 | } |
| 85 | |
| 86 | addr = simple_strtoul(argv[1], NULL, 16); |
| 87 | |
| 88 | if (!addr) |
| 89 | return CMD_RET_FAILURE; |
| 90 | |
| 91 | ret = arch_auxiliary_core_up(core, addr); |
| 92 | if (ret) |
| 93 | return CMD_RET_FAILURE; |
| 94 | |
| 95 | return CMD_RET_SUCCESS; |
| 96 | } |
| 97 | |
| 98 | static int do_stopaux(struct cmd_tbl *cmdtp, int flag, int argc, |
| 99 | char *const argv[]) |
| 100 | { |
| 101 | int ret, up; |
| 102 | |
| 103 | up = arch_auxiliary_core_check_up(0); |
| 104 | if (!up) { |
| 105 | printf("## Auxiliary core is already down\n"); |
| 106 | return CMD_RET_SUCCESS; |
| 107 | } |
| 108 | |
| 109 | ret = arch_auxiliary_core_down(0); |
| 110 | if (ret) |
| 111 | return CMD_RET_FAILURE; |
| 112 | |
| 113 | return CMD_RET_SUCCESS; |
| 114 | } |
| 115 | |
| 116 | U_BOOT_CMD( |
| 117 | stopaux, CONFIG_SYS_MAXARGS, 1, do_stopaux, |
| 118 | "Stop auxiliary core", |
| 119 | "<address> [<core>]\n" |
| 120 | " - start auxiliary core [<core>] (default 0),\n" |
| 121 | " at address <address>\n" |
| 122 | ); |
| 123 | |
| 124 | U_BOOT_CMD( |
| 125 | bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux, |
| 126 | "Start auxiliary core", |
| 127 | "<address> [<core>]\n" |
| 128 | " - start auxiliary core [<core>] (default 0),\n" |
Ye Li | 905fa83 | 2023-04-28 12:08:36 +0800 | [diff] [blame] | 129 | " at address <address> of auxiliary core view\n" |
Peng Fan | 313af25 | 2022-07-26 16:41:04 +0800 | [diff] [blame] | 130 | ); |