[RFC PATCH 06/10] cmd: add rpmsg framework commands

Tanmay Shah tanmay.shah at amd.com
Tue Jul 25 16:06:46 CEST 2023


This patch introduces commands to use rpmsg framework

rpmsg init <core id>
  - Initialize rpmsg framework for remote core

rpmsg debug_data <core id> <"tx" / "rx">
  - debug tx or rx virtqueues. This command simply uses
    virtqueue_dump_data and prints virtqueue for rpmsg device
    mapped to <core id>

Signed-off-by: Tanmay Shah <tanmay.shah at amd.com>
---
 MAINTAINERS     |  1 +
 cmd/Kconfig     |  6 +++++
 cmd/Makefile    |  1 +
 cmd/rpmsg.c     | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/rpmsg.h |  5 ++++
 5 files changed, 74 insertions(+)
 create mode 100644 cmd/rpmsg.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 876a7fdbdf..8e40da38e7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1368,6 +1368,7 @@ F:	doc/README.rockusb
 RPMSG
 M:	Tanmay Shah <tanmay.shah at amd.com>
 S:	Maintained
+F:	cmd/rpmsg.c
 F:	drivers/rpmsg/*
 F:	include/rpmsg.h
 F:	test/dm/rpmsg.c
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2d6e5f993f..355644a3fa 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1450,6 +1450,12 @@ config CMD_REMOTEPROC
 	help
 	  Support for Remote Processor control
 
+config CMD_RPMSG
+	bool "rpmsg"
+	help
+	  Support for RPMsg protocol over virtio for data transfer between
+	  U-Boot and remote processor firmware
+
 config CMD_SATA
 	bool "sata - Access SATA subsystem"
 	select SATA
diff --git a/cmd/Makefile b/cmd/Makefile
index 9f8c0b058b..23838698ea 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -149,6 +149,7 @@ obj-$(CONFIG_CMD_REGINFO) += reginfo.o
 obj-$(CONFIG_CMD_REISER) += reiser.o
 obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o
 obj-$(CONFIG_CMD_RNG) += rng.o
+obj-$(CONFIG_CMD_RPMSG) += rpmsg.o
 obj-$(CONFIG_CMD_KASLRSEED) += kaslrseed.o
 obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o
 obj-$(CONFIG_CMD_RTC) += rtc.o
diff --git a/cmd/rpmsg.c b/cmd/rpmsg.c
new file mode 100644
index 0000000000..da8aa05c9d
--- /dev/null
+++ b/cmd/rpmsg.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023, Advanced Micro Devices, Inc.
+ */
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+#include <rpmsg.h>
+
+static int do_rpmsg_init(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	/* Expect args to  <core id> <data string> */
+
+	int core_id, ret = CMD_RET_USAGE;
+
+	if (argc != 2)
+		return ret;
+
+	core_id = strtoul(argv[1], NULL, 16);
+	rpmsg_init(core_id);
+
+	return 0;
+}
+
+static int do_rpmsg_debug_data(struct cmd_tbl *cmdtp, int flag, int argc,
+			       char *const argv[])
+{
+	/*
+	 * Expect args to  <core id> <data string>
+	 */
+	int core_id, vq_id;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	core_id = strtoul(argv[1], NULL, 10);
+	if (!strcmp(argv[2], "rx"))
+		vq_id = 0;
+	else if (!strcmp(argv[2], "tx"))
+		vq_id = 1;
+	else
+		return CMD_RET_USAGE;
+
+	rpmsg_debug_data(core_id, vq_id);
+
+	return 0;
+}
+
+static char rpmsg_cmd_help[] =
+	   "Send/Recv data over RPMsg channel from U-Boot to remote processor.\n"
+	   "commands:\n"
+	   "rpmsg init <rproc core id>\n"
+	   "rpmsg debug_data <rproc core id> <vq name (tx or rx)>\n";
+
+U_BOOT_CMD_WITH_SUBCMDS(rpmsg, "rpmsg subsystem", rpmsg_cmd_help,
+			U_BOOT_SUBCMD_MKENT(init, 2, 0, do_rpmsg_init),
+			U_BOOT_SUBCMD_MKENT(debug_data, 3, 1,
+					    do_rpmsg_debug_data));
diff --git a/include/rpmsg.h b/include/rpmsg.h
index bed61240ca..18e8ee1ee2 100644
--- a/include/rpmsg.h
+++ b/include/rpmsg.h
@@ -118,6 +118,7 @@ typedef int (*rpmsg_rx_cb_t)(void *buf, int msg_len, u32 msgs_received);
 int rpmsg_init(int core_id);
 int rpmsg_send(int core_id, void *data, int len);
 int rpmsg_recv(int core_id, rpmsg_rx_cb_t cb);
+void rpmsg_debug_data(int core_id, int vq_id);
 
 #else
 int rpmsg_init(int core_id)
@@ -135,6 +136,10 @@ int rpmsg_recv(int core_id, rpmsg_rx_cb_t cb)
 	return -ENODEV;
 }
 
+void rpmsg_debug_data(int core_id, int vq_id)
+{
+}
+
 #endif /* IS_ENABLED(CONFIG_RPMSG) */
 
 #endif /* _RPMSG_H */
-- 
2.25.1



More information about the U-Boot mailing list