blob: 3c5b6a05b1afef2bac4aeade13550ecad5e23f16 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nishanth Menon08b9dc22015-09-17 15:42:39 -05002/*
3 * (C) Copyright 2015
Nishanth Menoneaa39c62023-11-01 15:56:03 -05004 * Texas Instruments Incorporated - https://www.ti.com/
Nishanth Menon08b9dc22015-09-17 15:42:39 -05005 */
Nishanth Menon08b9dc22015-09-17 15:42:39 -05006#include <command.h>
7#include <dm.h>
8#include <errno.h>
9#include <malloc.h>
10#include <remoteproc.h>
11
12/**
13 * print_remoteproc_list() - print all the remote processor devices
14 *
15 * Return: 0 if no error, else returns appropriate error value.
16 */
17static int print_remoteproc_list(void)
18{
19 struct udevice *dev;
20 struct uclass *uc;
21 int ret;
22 char *type;
23
24 ret = uclass_get(UCLASS_REMOTEPROC, &uc);
25 if (ret) {
26 printf("Cannot find Remote processor class\n");
27 return ret;
28 }
29
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);
33
Simon Glass71fa5b42020-12-03 16:55:18 -070034 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon08b9dc22015-09-17 15:42:39 -050035
Lokesh Vutla298cf842019-06-07 19:25:56 +053036 /* Do not print if rproc is not probed */
Simon Glass6211d762020-12-19 10:40:10 -070037 if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED))
Lokesh Vutla298cf842019-06-07 19:25:56 +053038 continue;
39
Nishanth Menon08b9dc22015-09-17 15:42:39 -050040 switch (uc_pdata->mem_type) {
41 case RPROC_INTERNAL_MEMORY_MAPPED:
42 type = "internal memory mapped";
43 break;
44 default:
45 type = "unknown";
46 break;
47 }
48 printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n",
Simon Glass75e534b2020-12-16 21:20:07 -070049 dev_seq(dev),
Nishanth Menon08b9dc22015-09-17 15:42:39 -050050 uc_pdata->name,
51 type,
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 " : "");
58 }
59 return 0;
60}
61
62/**
63 * do_rproc_init() - do basic initialization
64 * @cmdtp: unused
65 * @flag: unused
66 * @argc: unused
67 * @argv: unused
68 *
69 * Return: 0 if no error, else returns appropriate error value.
70 */
Simon Glassed38aef2020-05-10 11:40:03 -060071static int do_rproc_init(struct cmd_tbl *cmdtp, int flag, int argc,
Nishanth Menon08b9dc22015-09-17 15:42:39 -050072 char *const argv[])
73{
Lokesh Vutlaa316dd52019-06-07 19:25:55 +053074 int id;
75
Nishanth Menon08b9dc22015-09-17 15:42:39 -050076 if (rproc_is_initialized()) {
77 printf("\tRemote Processors are already initialized\n");
Lokesh Vutlaa316dd52019-06-07 19:25:55 +053078 return CMD_RET_FAILURE;
79 }
80
81 if (argc == 1) {
Nishanth Menon08b9dc22015-09-17 15:42:39 -050082 if (!rproc_init())
83 return 0;
Lokesh Vutlaa316dd52019-06-07 19:25:55 +053084 printf("Few Remote Processors failed to be initialized\n");
85 } else if (argc == 2) {
Simon Glassff9b9032021-07-24 09:03:30 -060086 id = (int)dectoul(argv[1], NULL);
Lokesh Vutlaa316dd52019-06-07 19:25:55 +053087 if (!rproc_dev_init(id))
88 return 0;
89 printf("Remote Processor %d failed to be initialized\n", id);
Nishanth Menon08b9dc22015-09-17 15:42:39 -050090 }
91
92 return CMD_RET_FAILURE;
93}
94
95/**
96 * do_remoteproc_list() - print list of remote proc devices.
97 * @cmdtp: unused
98 * @flag: unused
99 * @argc: unused
100 * @argv: unused
101 *
102 * Return: 0 if no error, else returns appropriate error value.
103 */
Simon Glassed38aef2020-05-10 11:40:03 -0600104static int do_remoteproc_list(struct cmd_tbl *cmdtp, int flag, int argc,
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500105 char *const argv[])
106{
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500107 if (print_remoteproc_list())
108 return CMD_RET_FAILURE;
109
110 return 0;
111}
112
113/**
114 * do_remoteproc_load() - Load a remote processor with binary image
115 * @cmdtp: unused
116 * @flag: unused
117 * @argc: argument count for the load function
118 * @argv: arguments for the load function
119 *
120 * Return: 0 if no error, else returns appropriate error value.
121 */
Simon Glassed38aef2020-05-10 11:40:03 -0600122static int do_remoteproc_load(struct cmd_tbl *cmdtp, int flag, int argc,
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500123 char *const argv[])
124{
125 ulong addr, size;
126 int id, ret;
127
128 if (argc != 4)
129 return CMD_RET_USAGE;
130
Simon Glassff9b9032021-07-24 09:03:30 -0600131 id = (int)dectoul(argv[1], NULL);
Simon Glass3ff49ec2021-07-24 09:03:29 -0600132 addr = hextoul(argv[2], NULL);
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500133
Simon Glass3ff49ec2021-07-24 09:03:29 -0600134 size = hextoul(argv[3], NULL);
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500135
136 if (!size) {
137 printf("\t Expect some size??\n");
138 return CMD_RET_USAGE;
139 }
140
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500141 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!");
144
145 return ret ? CMD_RET_FAILURE : 0;
146}
147
148/**
149 * do_remoteproc_wrapper() - wrapper for various rproc commands
150 * @cmdtp: unused
151 * @flag: unused
152 * @argc: argument count for the rproc command
153 * @argv: arguments for the rproc command
154 *
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.
158 *
159 * Return: 0 if no error, else returns appropriate error value.
160 */
Simon Glassed38aef2020-05-10 11:40:03 -0600161static int do_remoteproc_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500162 char *const argv[])
163{
164 int id, ret = CMD_RET_USAGE;
165
166 if (argc != 2)
167 return CMD_RET_USAGE;
168
Simon Glassff9b9032021-07-24 09:03:30 -0600169 id = (int)dectoul(argv[1], NULL);
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500170
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500171 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);
179 if (!ret) {
180 printf("Remote processor is Running\n");
181 } else if (ret == 1) {
182 printf("Remote processor is NOT Running\n");
183 ret = 0;
184 }
185 /* Else error.. */
186 } else if (!strcmp(argv[0], "ping")) {
187 ret = rproc_ping(id);
188 if (!ret) {
189 printf("Remote processor responds 'Pong'\n");
190 } else if (ret == 1) {
191 printf("No response from Remote processor\n");
192 ret = 0;
193 }
194 /* Else error.. */
195 }
196
197 if (ret < 0)
198 printf("Operation Failed with error (%d)\n", ret);
199
200 return ret ? CMD_RET_FAILURE : 0;
201}
202
Simon Glassed38aef2020-05-10 11:40:03 -0600203static struct cmd_tbl cmd_remoteproc_sub[] = {
Lokesh Vutlaa316dd52019-06-07 19:25:55 +0530204 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"),
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500208 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"),
231};
232
233/**
234 * do_remoteproc() - (replace: short desc)
235 * @cmdtp: unused
236 * @flag: unused
237 * @argc: argument count
238 * @argv: argument list
239 *
240 * parses up the command table to invoke the correct command.
241 *
242 * Return: 0 if no error, else returns appropriate error value.
243 */
Simon Glassed38aef2020-05-10 11:40:03 -0600244static int do_remoteproc(struct cmd_tbl *cmdtp, int flag, int argc,
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500245 char *const argv[])
246{
Simon Glassed38aef2020-05-10 11:40:03 -0600247 struct cmd_tbl *c = NULL;
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500248
249 /* Strip off leading 'rproc' command argument */
250 argc--;
251 argv++;
252
253 if (argc)
254 c = find_cmd_tbl(argv[0], cmd_remoteproc_sub,
255 ARRAY_SIZE(cmd_remoteproc_sub));
256 if (c)
257 return c->cmd(cmdtp, flag, argc, argv);
258
259 return CMD_RET_USAGE;
260}
261
262U_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"
265 "\t\t Where:\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"
272 "\n\tSubcommands:\n"
Lokesh Vutlaa316dd52019-06-07 19:25:55 +0530273 "\tinit <id> - Enumerate and initalize the remote processor.\n"
274 "\t if id is not passed, initialize all the remote prcessors\n"
Nishanth Menon08b9dc22015-09-17 15:42:39 -0500275 "\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");