blob: 73f2e72263d6edd8d6873fae952c72bcc0959858 [file] [log] [blame]
Peng Fan313af252022-07-26 16:41:04 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 NXP
4 */
5
Peng Fan313af252022-07-26 16:41:04 +08006#include <command.h>
7#include <log.h>
8#include <imx_sip.h>
Tom Rinidec7ea02024-05-20 13:35:03 -06009#include <vsprintf.h>
Peng Fan313af252022-07-26 16:41:04 +080010#include <linux/arm-smccc.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060011#include <linux/errno.h>
Peng Fan313af252022-07-26 16:41:04 +080012
13int arch_auxiliary_core_check_up(u32 core_id)
14{
15 struct arm_smccc_res res;
16
Peng Fane9015f32023-06-15 18:09:18 +080017 arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_MCU_STARTED, 0, 0,
Peng Fan313af252022-07-26 16:41:04 +080018 0, 0, 0, 0, &res);
19
20 return res.a0;
21}
22
23int arch_auxiliary_core_down(u32 core_id)
24{
25 struct arm_smccc_res res;
26
27 printf("## Stopping auxiliary core\n");
28
Peng Fane9015f32023-06-15 18:09:18 +080029 arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_MCU_STOP, 0, 0,
Peng Fan313af252022-07-26 16:41:04 +080030 0, 0, 0, 0, &res);
31
32 return 0;
33}
34
35int arch_auxiliary_core_up(u32 core_id, ulong addr)
36{
37 struct arm_smccc_res res;
Peng Fan313af252022-07-26 16:41:04 +080038
39 if (!addr)
40 return -EINVAL;
41
Ye Li905fa832023-04-28 12:08:36 +080042 printf("## Starting auxiliary core addr = 0x%08lX...\n", addr);
Peng Fan313af252022-07-26 16:41:04 +080043
Peng Fane9015f32023-06-15 18:09:18 +080044 arm_smccc_smc(IMX_SIP_SRC, IMX_SIP_SRC_MCU_START, addr, 0,
Peng Fan313af252022-07-26 16:41:04 +080045 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 */
63static 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
98static 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
116U_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
124U_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 Li905fa832023-04-28 12:08:36 +0800129 " at address <address> of auxiliary core view\n"
Peng Fan313af252022-07-26 16:41:04 +0800130);