123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #include <common.h>
- #include <command.h>
- #include <dm.h>
- #include <errno.h>
- #include <malloc.h>
- #include <remoteproc.h>
- static int print_remoteproc_list(void)
- {
- struct udevice *dev;
- struct uclass *uc;
- int ret;
- char *type;
- ret = uclass_get(UCLASS_REMOTEPROC, &uc);
- if (ret) {
- printf("Cannot find Remote processor class\n");
- return ret;
- }
- uclass_foreach_dev(dev, uc) {
- struct dm_rproc_uclass_pdata *uc_pdata;
- const struct dm_rproc_ops *ops = rproc_get_ops(dev);
- uc_pdata = dev_get_uclass_platdata(dev);
- switch (uc_pdata->mem_type) {
- case RPROC_INTERNAL_MEMORY_MAPPED:
- type = "internal memory mapped";
- break;
- default:
- type = "unknown";
- break;
- }
- printf("%d - Name:'%s' type:'%s' supports: %s%s%s%s%s%s\n",
- dev->seq,
- uc_pdata->name,
- type,
- ops->load ? "load " : "",
- ops->start ? "start " : "",
- ops->stop ? "stop " : "",
- ops->reset ? "reset " : "",
- ops->is_running ? "is_running " : "",
- ops->ping ? "ping " : "");
- }
- return 0;
- }
- static int do_rproc_init(cmd_tbl_t *cmdtp, int flag, int argc,
- char *const argv[])
- {
- if (rproc_is_initialized()) {
- printf("\tRemote Processors are already initialized\n");
- } else {
- if (!rproc_init())
- return 0;
- printf("Few Remote Processors failed to be initalized\n");
- }
- return CMD_RET_FAILURE;
- }
- static int do_remoteproc_list(cmd_tbl_t *cmdtp, int flag, int argc,
- char *const argv[])
- {
- if (!rproc_is_initialized()) {
- printf("\t Remote Processors is not initialized\n");
- return CMD_RET_USAGE;
- }
- if (print_remoteproc_list())
- return CMD_RET_FAILURE;
- return 0;
- }
- static int do_remoteproc_load(cmd_tbl_t *cmdtp, int flag, int argc,
- char *const argv[])
- {
- ulong addr, size;
- int id, ret;
- if (argc != 4)
- return CMD_RET_USAGE;
- id = (int)simple_strtoul(argv[1], NULL, 3);
- addr = simple_strtoul(argv[2], NULL, 16);
- size = simple_strtoul(argv[3], NULL, 16);
- if (!size) {
- printf("\t Expect some size??\n");
- return CMD_RET_USAGE;
- }
- if (!rproc_is_initialized()) {
- printf("\tRemote Processors are not initialized\n");
- return CMD_RET_USAGE;
- }
- ret = rproc_load(id, addr, size);
- printf("Load Remote Processor %d with data@addr=0x%08lx %lu bytes:%s\n",
- id, addr, size, ret ? " Failed!" : " Success!");
- return ret ? CMD_RET_FAILURE : 0;
- }
- static int do_remoteproc_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
- char *const argv[])
- {
- int id, ret = CMD_RET_USAGE;
- if (argc != 2)
- return CMD_RET_USAGE;
- id = (int)simple_strtoul(argv[1], NULL, 3);
- if (!rproc_is_initialized()) {
- printf("\tRemote Processors are not initialized\n");
- return CMD_RET_USAGE;
- }
- if (!strcmp(argv[0], "start")) {
- ret = rproc_start(id);
- } else if (!strcmp(argv[0], "stop")) {
- ret = rproc_stop(id);
- } else if (!strcmp(argv[0], "reset")) {
- ret = rproc_reset(id);
- } else if (!strcmp(argv[0], "is_running")) {
- ret = rproc_is_running(id);
- if (!ret) {
- printf("Remote processor is Running\n");
- } else if (ret == 1) {
- printf("Remote processor is NOT Running\n");
- ret = 0;
- }
-
- } else if (!strcmp(argv[0], "ping")) {
- ret = rproc_ping(id);
- if (!ret) {
- printf("Remote processor responds 'Pong'\n");
- } else if (ret == 1) {
- printf("No response from Remote processor\n");
- ret = 0;
- }
-
- }
- if (ret < 0)
- printf("Operation Failed with error (%d)\n", ret);
- return ret ? CMD_RET_FAILURE : 0;
- }
- static cmd_tbl_t cmd_remoteproc_sub[] = {
- U_BOOT_CMD_MKENT(init, 0, 1, do_rproc_init,
- "Enumerate and initialize all processors", ""),
- U_BOOT_CMD_MKENT(list, 0, 1, do_remoteproc_list,
- "list remote processors", ""),
- U_BOOT_CMD_MKENT(load, 5, 1, do_remoteproc_load,
- "Load remote processor with provided image",
- "<id> [addr] [size]\n"
- "- id: ID of the remote processor(see 'list' cmd)\n"
- "- addr: Address in memory of the image to loadup\n"
- "- size: Size of the image to loadup\n"),
- U_BOOT_CMD_MKENT(start, 1, 1, do_remoteproc_wrapper,
- "Start remote processor",
- "id - ID of the remote processor (see 'list' cmd)\n"),
- U_BOOT_CMD_MKENT(stop, 1, 1, do_remoteproc_wrapper,
- "Stop remote processor",
- "id - ID of the remote processor (see 'list' cmd)\n"),
- U_BOOT_CMD_MKENT(reset, 1, 1, do_remoteproc_wrapper,
- "Reset remote processor",
- "id - ID of the remote processor (see 'list' cmd)\n"),
- U_BOOT_CMD_MKENT(is_running, 1, 1, do_remoteproc_wrapper,
- "Check to see if remote processor is running\n",
- "id - ID of the remote processor (see 'list' cmd)\n"),
- U_BOOT_CMD_MKENT(ping, 1, 1, do_remoteproc_wrapper,
- "Ping to communicate with remote processor\n",
- "id - ID of the remote processor (see 'list' cmd)\n"),
- };
- static int do_remoteproc(cmd_tbl_t *cmdtp, int flag, int argc,
- char *const argv[])
- {
- cmd_tbl_t *c = NULL;
-
- argc--;
- argv++;
- if (argc)
- c = find_cmd_tbl(argv[0], cmd_remoteproc_sub,
- ARRAY_SIZE(cmd_remoteproc_sub));
- if (c)
- return c->cmd(cmdtp, flag, argc, argv);
- return CMD_RET_USAGE;
- }
- U_BOOT_CMD(rproc, 5, 1, do_remoteproc,
- "Control operation of remote processors in an SoC",
- " [init|list|load|start|stop|reset|is_running|ping]\n"
- "\t\t Where:\n"
- "\t\t[addr] is a memory address\n"
- "\t\t<id> is a numerical identifier for the remote processor\n"
- "\t\t provided by 'list' command.\n"
- "\t\tNote: Remote processors must be initalized prior to usage\n"
- "\t\tNote: Services are dependent on the driver capability\n"
- "\t\t 'list' command shows the capability of each device\n"
- "\n\tSubcommands:\n"
- "\tinit - Enumerate and initalize the remote processors\n"
- "\tlist - list available remote processors\n"
- "\tload <id> [addr] [size]- Load the remote processor with binary\n"
- "\t image stored at address [addr] in memory\n"
- "\tstart <id> - Start the remote processor(must be loaded)\n"
- "\tstop <id> - Stop the remote processor\n"
- "\treset <id> - Reset the remote processor\n"
- "\tis_running <id> - Reports if the remote processor is running\n"
- "\tping <id> - Ping the remote processor for communication\n");
|