1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments Incorporated - https://www.ti.com/
10 #include <remoteproc.h>
13 * print_remoteproc_list() - print all the remote processor devices
15 * Return: 0 if no error, else returns appropriate error value.
17 static int print_remoteproc_list(void)
24 ret = uclass_get(UCLASS_REMOTEPROC, &uc);
26 printf("Cannot find Remote processor class\n");
30 uclass_foreach_dev(dev, uc) {
31 struct dm_rproc_uclass_pdata *uc_pdata;
32 const struct dm_rproc_ops *ops = rproc_get_ops(dev);
34 uc_pdata = dev_get_uclass_plat(dev);
36 /* Do not print if rproc is not probed */
37 if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED))
40 switch (uc_pdata->mem_type) {
41 case RPROC_INTERNAL_MEMORY_MAPPED:
42 type = "internal memory mapped";
48 printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n",
52 ops->load ? "load " : "",
53 ops->start ? "start " : "",
54 ops->stop ? "stop " : "",
55 ops->reset ? "reset " : "",
56 ops->is_running ? "is_running " : "",
57 ops->ping ? "ping " : "");
63 * do_rproc_init() - do basic initialization
69 * Return: 0 if no error, else returns appropriate error value.
71 static int do_rproc_init(struct cmd_tbl *cmdtp, int flag, int argc,
76 if (rproc_is_initialized()) {
77 printf("\tRemote Processors are already initialized\n");
78 return CMD_RET_FAILURE;
84 printf("Few Remote Processors failed to be initialized\n");
85 } else if (argc == 2) {
86 id = (int)dectoul(argv[1], NULL);
87 if (!rproc_dev_init(id))
89 printf("Remote Processor %d failed to be initialized\n", id);
92 return CMD_RET_FAILURE;
96 * do_remoteproc_list() - print list of remote proc devices.
102 * Return: 0 if no error, else returns appropriate error value.
104 static int do_remoteproc_list(struct cmd_tbl *cmdtp, int flag, int argc,
107 if (print_remoteproc_list())
108 return CMD_RET_FAILURE;
114 * do_remoteproc_load() - Load a remote processor with binary image
117 * @argc: argument count for the load function
118 * @argv: arguments for the load function
120 * Return: 0 if no error, else returns appropriate error value.
122 static int do_remoteproc_load(struct cmd_tbl *cmdtp, int flag, int argc,
129 return CMD_RET_USAGE;
131 id = (int)dectoul(argv[1], NULL);
132 addr = hextoul(argv[2], NULL);
134 size = hextoul(argv[3], NULL);
137 printf("\t Expect some size??\n");
138 return CMD_RET_USAGE;
141 ret = rproc_load(id, addr, size);
142 printf("Load Remote Processor %d with data@addr=0x%08lx %lu bytes:%s\n",
143 id, addr, size, ret ? " Failed!" : " Success!");
145 return ret ? CMD_RET_FAILURE : 0;
149 * do_remoteproc_wrapper() - wrapper for various rproc commands
152 * @argc: argument count for the rproc command
153 * @argv: arguments for the rproc command
155 * Most of the commands just take id as a parameter andinvoke various
156 * helper routines in remote processor core. by using a set of
157 * common checks, we can reduce the amount of code used for this.
159 * Return: 0 if no error, else returns appropriate error value.
161 static int do_remoteproc_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
164 int id, ret = CMD_RET_USAGE;
167 return CMD_RET_USAGE;
169 id = (int)dectoul(argv[1], NULL);
171 if (!strcmp(argv[0], "start")) {
172 ret = rproc_start(id);
173 } else if (!strcmp(argv[0], "stop")) {
174 ret = rproc_stop(id);
175 } else if (!strcmp(argv[0], "reset")) {
176 ret = rproc_reset(id);
177 } else if (!strcmp(argv[0], "is_running")) {
178 ret = rproc_is_running(id);
180 printf("Remote processor is Running\n");
181 } else if (ret == 1) {
182 printf("Remote processor is NOT Running\n");
186 } else if (!strcmp(argv[0], "ping")) {
187 ret = rproc_ping(id);
189 printf("Remote processor responds 'Pong'\n");
190 } else if (ret == 1) {
191 printf("No response from Remote processor\n");
198 printf("Operation Failed with error (%d)\n", ret);
200 return ret ? CMD_RET_FAILURE : 0;
203 static struct cmd_tbl cmd_remoteproc_sub[] = {
204 U_BOOT_CMD_MKENT(init, 1, 1, do_rproc_init,
205 "Enumerate and initialize the remote processor(s)",
206 "id - ID of the remote processor\n"
207 "If id is not passed, initialize all the remote processors"),
208 U_BOOT_CMD_MKENT(list, 0, 1, do_remoteproc_list,
209 "list remote processors", ""),
210 U_BOOT_CMD_MKENT(load, 5, 1, do_remoteproc_load,
211 "Load remote processor with provided image",
212 "<id> [addr] [size]\n"
213 "- id: ID of the remote processor(see 'list' cmd)\n"
214 "- addr: Address in memory of the image to loadup\n"
215 "- size: Size of the image to loadup\n"),
216 U_BOOT_CMD_MKENT(start, 1, 1, do_remoteproc_wrapper,
217 "Start remote processor",
218 "id - ID of the remote processor (see 'list' cmd)\n"),
219 U_BOOT_CMD_MKENT(stop, 1, 1, do_remoteproc_wrapper,
220 "Stop remote processor",
221 "id - ID of the remote processor (see 'list' cmd)\n"),
222 U_BOOT_CMD_MKENT(reset, 1, 1, do_remoteproc_wrapper,
223 "Reset remote processor",
224 "id - ID of the remote processor (see 'list' cmd)\n"),
225 U_BOOT_CMD_MKENT(is_running, 1, 1, do_remoteproc_wrapper,
226 "Check to see if remote processor is running\n",
227 "id - ID of the remote processor (see 'list' cmd)\n"),
228 U_BOOT_CMD_MKENT(ping, 1, 1, do_remoteproc_wrapper,
229 "Ping to communicate with remote processor\n",
230 "id - ID of the remote processor (see 'list' cmd)\n"),
234 * do_remoteproc() - (replace: short desc)
237 * @argc: argument count
238 * @argv: argument list
240 * parses up the command table to invoke the correct command.
242 * Return: 0 if no error, else returns appropriate error value.
244 static int do_remoteproc(struct cmd_tbl *cmdtp, int flag, int argc,
247 struct cmd_tbl *c = NULL;
249 /* Strip off leading 'rproc' command argument */
254 c = find_cmd_tbl(argv[0], cmd_remoteproc_sub,
255 ARRAY_SIZE(cmd_remoteproc_sub));
257 return c->cmd(cmdtp, flag, argc, argv);
259 return CMD_RET_USAGE;
262 U_BOOT_CMD(rproc, 5, 1, do_remoteproc,
263 "Control operation of remote processors in an SoC",
264 " [init|list|load|start|stop|reset|is_running|ping]\n"
266 "\t\t[addr] is a memory address\n"
267 "\t\t<id> is a numerical identifier for the remote processor\n"
268 "\t\t provided by 'list' command.\n"
269 "\t\tNote: Remote processors must be initalized prior to usage\n"
270 "\t\tNote: Services are dependent on the driver capability\n"
271 "\t\t 'list' command shows the capability of each device\n"
273 "\tinit <id> - Enumerate and initalize the remote processor.\n"
274 "\t if id is not passed, initialize all the remote prcessors\n"
275 "\tlist - list available remote processors\n"
276 "\tload <id> [addr] [size]- Load the remote processor with binary\n"
277 "\t image stored at address [addr] in memory\n"
278 "\tstart <id> - Start the remote processor(must be loaded)\n"
279 "\tstop <id> - Stop the remote processor\n"
280 "\treset <id> - Reset the remote processor\n"
281 "\tis_running <id> - Reports if the remote processor is running\n"
282 "\tping <id> - Ping the remote processor for communication\n");