[RFC PATCH v2 1/1] rpmsg: add syslog driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allows the remote firmware to log into syslog.

Signed-off-by: Christian Gmeiner <christian.gmeiner@xxxxxxxxx>
---
 drivers/rpmsg/Kconfig        |  8 +++++
 drivers/rpmsg/Makefile       |  1 +
 drivers/rpmsg/rpmsg_syslog.c | 65 ++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 drivers/rpmsg/rpmsg_syslog.c

diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig
index 0b4407abdf13..801f9956ec21 100644
--- a/drivers/rpmsg/Kconfig
+++ b/drivers/rpmsg/Kconfig
@@ -73,4 +73,12 @@ config RPMSG_VIRTIO
 	select RPMSG_NS
 	select VIRTIO
 
+config RPMSG_SYSLOG
+	tristate "SYSLOG device interface"
+	depends on RPMSG
+	help
+	  Say Y here to export rpmsg endpoints as device files, usually found
+	  in /dev. They make it possible for user-space programs to send and
+	  receive rpmsg packets.
+
 endmenu
diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile
index 8d452656f0ee..75b2ec7133a5 100644
--- a/drivers/rpmsg/Makefile
+++ b/drivers/rpmsg/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_RPMSG_QCOM_GLINK_RPM) += qcom_glink_rpm.o
 obj-$(CONFIG_RPMSG_QCOM_GLINK_SMEM) += qcom_glink_smem.o
 obj-$(CONFIG_RPMSG_QCOM_SMD)	+= qcom_smd.o
 obj-$(CONFIG_RPMSG_VIRTIO)	+= virtio_rpmsg_bus.o
+obj-$(CONFIG_RPMSG_SYSLOG)	+= rpmsg_syslog.o
diff --git a/drivers/rpmsg/rpmsg_syslog.c b/drivers/rpmsg/rpmsg_syslog.c
new file mode 100644
index 000000000000..b3fdae495fd9
--- /dev/null
+++ b/drivers/rpmsg/rpmsg_syslog.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/rpmsg.h>
+
+static int rpmsg_syslog_cb(struct rpmsg_device *rpdev, void *data, int len,
+			   void *priv, u32 src)
+{
+	const char *buffer = data;
+
+	switch (buffer[0]) {
+	case 'e':
+		dev_err(&rpdev->dev, "%s", buffer + 1);
+		break;
+	case 'w':
+		dev_warn(&rpdev->dev, "%s", buffer + 1);
+		break;
+	case 'i':
+		dev_info(&rpdev->dev, "%s", buffer + 1);
+		break;
+	default:
+		dev_info(&rpdev->dev, "%s", buffer);
+		break;
+	}
+
+	return 0;
+}
+
+static int rpmsg_syslog_probe(struct rpmsg_device *rpdev)
+{
+	struct rpmsg_endpoint *syslog_ept;
+	struct rpmsg_channel_info syslog_chinfo = {
+		.src = 42,
+		.dst = 42,
+		.name = "syslog",
+	};
+
+	/*
+	 * Create the syslog service endpoint associated to the RPMsg
+	 * device. The endpoint will be automatically destroyed when the RPMsg
+	 * device will be deleted.
+	 */
+	syslog_ept = rpmsg_create_ept(rpdev, rpmsg_syslog_cb, NULL, syslog_chinfo);
+	if (!syslog_ept) {
+		dev_err(&rpdev->dev, "failed to create the syslog ept\n");
+		return -ENOMEM;
+	}
+	rpdev->ept = syslog_ept;
+
+	return 0;
+}
+
+static struct rpmsg_device_id rpmsg_driver_syslog_id_table[] = {
+	{ .name = "syslog" },
+	{ },
+};
+MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_syslog_id_table);
+
+static struct rpmsg_driver rpmsg_syslog_client = {
+	.drv.name       = KBUILD_MODNAME,
+	.id_table       = rpmsg_driver_syslog_id_table,
+	.probe          = rpmsg_syslog_probe,
+};
+module_rpmsg_driver(rpmsg_syslog_client);
-- 
2.33.1




[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux