1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments Incorporated - http://www.ti.com/
11 #include <remoteproc.h>
14 * print_remoteproc_list() - print all the remote processor devices
16 * Return: 0 if no error, else returns appropriate error value.
18 static int print_remoteproc_list(void)
25 ret = uclass_get(UCLASS_REMOTEPROC, &uc);
27 printf("Cannot find Remote processor class\n");
31 uclass_foreach_dev(dev, uc) {
32 struct dm_rproc_uclass_pdata *uc_pdata;
33 const struct dm_rproc_ops *ops = rproc_get_ops(dev);
35 uc_pdata = dev_get_uclass_platdata(dev);
37 switch (uc_pdata->mem_type) {
38 case RPROC_INTERNAL_MEMORY_MAPPED:
39 type = "internal memory mapped";
45 printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n",
49 ops->load ? "load " : "",
50 ops->start ? "start " : "",
51 ops->stop ? "stop " : "",
52 ops->reset ? "reset " : "",
53 ops->is_running ? "is_running " : "",
54 ops->ping ? "ping " : "");
60 * do_rproc_init() - do basic initialization
66 * Return: 0 if no error, else returns appropriate error value.
68 static int do_rproc_init(cmd_tbl_t *cmdtp, int flag, int argc,
71 if (rproc_is_initialized()) {
72 printf("\tRemote Processors are already initialized\n");
76 printf("Few Remote Processors failed to be initalized\n");
79 return CMD_RET_FAILURE;
83 * do_remoteproc_list() - print list of remote proc devices.
89 * Return: 0 if no error, else returns appropriate error value.
91 static int do_remoteproc_list(cmd_tbl_t *cmdtp, int flag, int argc,
94 if (!rproc_is_initialized()) {
95 printf("\t Remote Processors is not initialized\n");
99 if (print_remoteproc_list())
100 return CMD_RET_FAILURE;
106 * do_remoteproc_load() - Load a remote processor with binary image
109 * @argc: argument count for the load function
110 * @argv: arguments for the load function
112 * Return: 0 if no error, else returns appropriate error value.
114 static int do_remoteproc_load(cmd_tbl_t *cmdtp, int flag, int argc,
121 return CMD_RET_USAGE;
123 id = (int)simple_strtoul(argv[1], NULL, 10);
124 addr = simple_strtoul(argv[2], NULL, 16);
126 size = simple_strtoul(argv[3], NULL, 16);
129 printf("\t Expect some size??\n");
130 return CMD_RET_USAGE;
133 if (!rproc_is_initialized()) {
134 printf("\tRemote Processors are not initialized\n");
135 return CMD_RET_USAGE;
138 ret = rproc_load(id, addr, size);
139 printf("Load Remote Processor %d with data@addr=0x%08lx %lu bytes:%s\n",
140 id, addr, size, ret ? " Failed!" : " Success!");
142 return ret ? CMD_RET_FAILURE : 0;
146 * do_remoteproc_wrapper() - wrapper for various rproc commands
149 * @argc: argument count for the rproc command
150 * @argv: arguments for the rproc command
152 * Most of the commands just take id as a parameter andinvoke various
153 * helper routines in remote processor core. by using a set of
154 * common checks, we can reduce the amount of code used for this.
156 * Return: 0 if no error, else returns appropriate error value.
158 static int do_remoteproc_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
161 int id, ret = CMD_RET_USAGE;
164 return CMD_RET_USAGE;
166 id = (int)simple_strtoul(argv[1], NULL, 10);
168 if (!rproc_is_initialized()) {
169 printf("\tRemote Processors are not initialized\n");
170 return CMD_RET_USAGE;
173 if (!strcmp(argv[0], "start")) {
174 ret = rproc_start(id);
175 } else if (!strcmp(argv[0], "stop")) {
176 ret = rproc_stop(id);
177 } else if (!strcmp(argv[0], "reset")) {
178 ret = rproc_reset(id);
179 } else if (!strcmp(argv[0], "is_running")) {
180 ret = rproc_is_running(id);
182 printf("Remote processor is Running\n");
183 } else if (ret == 1) {
184 printf("Remote processor is NOT Running\n");
188 } else if (!strcmp(argv[0], "ping")) {
189 ret = rproc_ping(id);
191 printf("Remote processor responds 'Pong'\n");
192 } else if (ret == 1) {
193 printf("No response from Remote processor\n");
200 printf("Operation Failed with error (%d)\n", ret);
202 return ret ? CMD_RET_FAILURE : 0;
205 static cmd_tbl_t cmd_remoteproc_sub[] = {
206 U_BOOT_CMD_MKENT(init, 0, 1, do_rproc_init,
207 "Enumerate and initialize all 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(cmd_tbl_t *cmdtp, int flag, int argc,
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 - Enumerate and initalize the remote processors\n"
274 "\tlist - list available remote processors\n"
275 "\tload <id> [addr] [size]- Load the remote processor with binary\n"
276 "\t image stored at address [addr] in memory\n"
277 "\tstart <id> - Start the remote processor(must be loaded)\n"
278 "\tstop <id> - Stop the remote processor\n"
279 "\treset <id> - Reset the remote processor\n"
280 "\tis_running <id> - Reports if the remote processor is running\n"
281 "\tping <id> - Ping the remote processor for communication\n");