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,
73 if (rproc_is_initialized()) {
74 printf("\tRemote Processors are already initialized\n");
75 return CMD_RET_FAILURE;
81 printf("Few Remote Processors failed to be initialized\n");
82 } else if (argc == 2) {
83 id = (int)simple_strtoul(argv[1], NULL, 10);
84 if (!rproc_dev_init(id))
86 printf("Remote Processor %d failed to be initialized\n", id);
89 return CMD_RET_FAILURE;
93 * do_remoteproc_list() - print list of remote proc devices.
99 * Return: 0 if no error, else returns appropriate error value.
101 static int do_remoteproc_list(cmd_tbl_t *cmdtp, int flag, int argc,
104 if (!rproc_is_initialized()) {
105 printf("\t Remote Processors is not initialized\n");
106 return CMD_RET_USAGE;
109 if (print_remoteproc_list())
110 return CMD_RET_FAILURE;
116 * do_remoteproc_load() - Load a remote processor with binary image
119 * @argc: argument count for the load function
120 * @argv: arguments for the load function
122 * Return: 0 if no error, else returns appropriate error value.
124 static int do_remoteproc_load(cmd_tbl_t *cmdtp, int flag, int argc,
131 return CMD_RET_USAGE;
133 id = (int)simple_strtoul(argv[1], NULL, 10);
134 addr = simple_strtoul(argv[2], NULL, 16);
136 size = simple_strtoul(argv[3], NULL, 16);
139 printf("\t Expect some size??\n");
140 return CMD_RET_USAGE;
143 ret = rproc_load(id, addr, size);
144 printf("Load Remote Processor %d with data@addr=0x%08lx %lu bytes:%s\n",
145 id, addr, size, ret ? " Failed!" : " Success!");
147 return ret ? CMD_RET_FAILURE : 0;
151 * do_remoteproc_wrapper() - wrapper for various rproc commands
154 * @argc: argument count for the rproc command
155 * @argv: arguments for the rproc command
157 * Most of the commands just take id as a parameter andinvoke various
158 * helper routines in remote processor core. by using a set of
159 * common checks, we can reduce the amount of code used for this.
161 * Return: 0 if no error, else returns appropriate error value.
163 static int do_remoteproc_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
166 int id, ret = CMD_RET_USAGE;
169 return CMD_RET_USAGE;
171 id = (int)simple_strtoul(argv[1], NULL, 10);
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, 1, 1, do_rproc_init,
207 "Enumerate and initialize the remote processor(s)",
208 "id - ID of the remote processor\n"
209 "If id is not passed, initialize all the remote processors"),
210 U_BOOT_CMD_MKENT(list, 0, 1, do_remoteproc_list,
211 "list remote processors", ""),
212 U_BOOT_CMD_MKENT(load, 5, 1, do_remoteproc_load,
213 "Load remote processor with provided image",
214 "<id> [addr] [size]\n"
215 "- id: ID of the remote processor(see 'list' cmd)\n"
216 "- addr: Address in memory of the image to loadup\n"
217 "- size: Size of the image to loadup\n"),
218 U_BOOT_CMD_MKENT(start, 1, 1, do_remoteproc_wrapper,
219 "Start remote processor",
220 "id - ID of the remote processor (see 'list' cmd)\n"),
221 U_BOOT_CMD_MKENT(stop, 1, 1, do_remoteproc_wrapper,
222 "Stop remote processor",
223 "id - ID of the remote processor (see 'list' cmd)\n"),
224 U_BOOT_CMD_MKENT(reset, 1, 1, do_remoteproc_wrapper,
225 "Reset remote processor",
226 "id - ID of the remote processor (see 'list' cmd)\n"),
227 U_BOOT_CMD_MKENT(is_running, 1, 1, do_remoteproc_wrapper,
228 "Check to see if remote processor is running\n",
229 "id - ID of the remote processor (see 'list' cmd)\n"),
230 U_BOOT_CMD_MKENT(ping, 1, 1, do_remoteproc_wrapper,
231 "Ping to communicate with remote processor\n",
232 "id - ID of the remote processor (see 'list' cmd)\n"),
236 * do_remoteproc() - (replace: short desc)
239 * @argc: argument count
240 * @argv: argument list
242 * parses up the command table to invoke the correct command.
244 * Return: 0 if no error, else returns appropriate error value.
246 static int do_remoteproc(cmd_tbl_t *cmdtp, int flag, int argc,
251 /* Strip off leading 'rproc' command argument */
256 c = find_cmd_tbl(argv[0], cmd_remoteproc_sub,
257 ARRAY_SIZE(cmd_remoteproc_sub));
259 return c->cmd(cmdtp, flag, argc, argv);
261 return CMD_RET_USAGE;
264 U_BOOT_CMD(rproc, 5, 1, do_remoteproc,
265 "Control operation of remote processors in an SoC",
266 " [init|list|load|start|stop|reset|is_running|ping]\n"
268 "\t\t[addr] is a memory address\n"
269 "\t\t<id> is a numerical identifier for the remote processor\n"
270 "\t\t provided by 'list' command.\n"
271 "\t\tNote: Remote processors must be initalized prior to usage\n"
272 "\t\tNote: Services are dependent on the driver capability\n"
273 "\t\t 'list' command shows the capability of each device\n"
275 "\tinit <id> - Enumerate and initalize the remote processor.\n"
276 "\t if id is not passed, initialize all the remote prcessors\n"
277 "\tlist - list available remote processors\n"
278 "\tload <id> [addr] [size]- Load the remote processor with binary\n"
279 "\t image stored at address [addr] in memory\n"
280 "\tstart <id> - Start the remote processor(must be loaded)\n"
281 "\tstop <id> - Stop the remote processor\n"
282 "\treset <id> - Reset the remote processor\n"
283 "\tis_running <id> - Reports if the remote processor is running\n"
284 "\tping <id> - Ping the remote processor for communication\n");