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