linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ohad@wizery.com (Ohad Ben-Cohen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 7/7] samples/amp: add an rpmsg driver sample
Date: Tue, 25 Oct 2011 11:48:26 +0200	[thread overview]
Message-ID: <1319536106-25802-8-git-send-email-ohad@wizery.com> (raw)
In-Reply-To: <1319536106-25802-1-git-send-email-ohad@wizery.com>

Add an rpmsg driver sample, which demonstrates how to communicate with
an AMP-configured remote processor over the rpmsg bus.

The driver repeatedly sends a "Hello World!" message to the remote
processor.

Note that once probed, the driver can immediately start sending messages
using the rpmsg_send() API, without having to worry about creating endpoints
or allocating rpmsg addresses: all that work is done by the rpmsg bus,
and the required information is already embedded in the rpmsg channel
that the driver is probed with.

Designed with Brian Swetland <swetland@google.com>.

Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Cc: Brian Swetland <swetland@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg KH <greg@kroah.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
---
 samples/Kconfig                   |    8 +++
 samples/Makefile                  |    2 +-
 samples/amp/Makefile              |    1 +
 samples/amp/rpmsg_client_sample.c |  100 +++++++++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 1 deletions(-)
 create mode 100644 samples/amp/Makefile
 create mode 100644 samples/amp/rpmsg_client_sample.c

diff --git a/samples/Kconfig b/samples/Kconfig
index 96a7572..997ddd3 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -67,4 +67,12 @@ config SAMPLE_HIDRAW
 	help
 	  Build an example of how to use hidraw from userspace.
 
+config SAMPLE_RPMSG_CLIENT
+	tristate "Build rpmsg client sample -- loadable modules only"
+	depends on RPMSG && m
+	help
+	  Build an rpmsg client sample driver, which demonstrates how
+	  to communicate with an AMP-configured remote processor over
+	  the rpmsg bus.
+
 endif # SAMPLES
diff --git a/samples/Makefile b/samples/Makefile
index 6280817..040f424 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,4 +1,4 @@
 # Makefile for Linux samples code
 
 obj-$(CONFIG_SAMPLES)	+= kobject/ kprobes/ tracepoints/ trace_events/ \
-			   hw_breakpoint/ kfifo/ kdb/ hidraw/
+			   hw_breakpoint/ kfifo/ kdb/ hidraw/ amp/
diff --git a/samples/amp/Makefile b/samples/amp/Makefile
new file mode 100644
index 0000000..2d4973c
--- /dev/null
+++ b/samples/amp/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_SAMPLE_RPMSG_CLIENT) += rpmsg_client_sample.o
diff --git a/samples/amp/rpmsg_client_sample.c b/samples/amp/rpmsg_client_sample.c
new file mode 100644
index 0000000..7b23380
--- /dev/null
+++ b/samples/amp/rpmsg_client_sample.c
@@ -0,0 +1,100 @@
+/*
+ * Remote processor messaging - sample client driver
+ *
+ * Copyright (C) 2011 Texas Instruments, Inc.
+ * Copyright (C) 2011 Google, Inc.
+ *
+ * Ohad Ben-Cohen <ohad@wizery.com>
+ * Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/amp/rpmsg.h>
+
+#define MSG		"hello world!"
+#define MSG_LIMIT	100
+
+static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
+						void *priv, u32 src)
+{
+	int ret;
+	static int rx_count;
+
+	dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", ++rx_count, src);
+
+	print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
+		       data, len,  true);
+
+	/* samples should not live forever */
+	if (rx_count >= MSG_LIMIT) {
+		dev_info(&rpdev->dev, "goodbye!\n");
+		return;
+	}
+
+	/* send a new message now */
+	ret = rpmsg_send(rpdev, MSG, strlen(MSG));
+	if (ret)
+		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
+}
+
+static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
+{
+	int ret;
+
+	dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
+					rpdev->src, rpdev->dst);
+
+	/* send a message to our remote processor */
+	ret = rpmsg_send(rpdev, MSG, strlen(MSG));
+	if (ret) {
+		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static void __devexit rpmsg_sample_remove(struct rpmsg_channel *rpdev)
+{
+	dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
+}
+
+static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
+	{ .name	= "rpmsg-client-sample" },
+	{ },
+};
+MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
+
+static struct rpmsg_driver rpmsg_sample_client = {
+	.drv.name	= KBUILD_MODNAME,
+	.drv.owner	= THIS_MODULE,
+	.id_table	= rpmsg_driver_sample_id_table,
+	.probe		= rpmsg_sample_probe,
+	.callback	= rpmsg_sample_cb,
+	.remove		= __devexit_p(rpmsg_sample_remove),
+};
+
+static int __init rpmsg_client_sample_init(void)
+{
+	return register_rpmsg_driver(&rpmsg_sample_client);
+}
+module_init(rpmsg_client_sample_init);
+
+static void __exit rpmsg_client_sample_fini(void)
+{
+	unregister_rpmsg_driver(&rpmsg_sample_client);
+}
+module_exit(rpmsg_client_sample_fini);
+
+MODULE_DESCRIPTION("Remote processor messaging sample client driver");
+MODULE_LICENSE("GPL v2");
-- 
1.7.5.4

  parent reply	other threads:[~2011-10-25  9:48 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-25  9:48 [PATCH 0/7] Introducing a generic AMP framework Ohad Ben-Cohen
2011-10-25  9:48 ` [PATCH 1/7] amp/remoteproc: add framework for controlling remote processors Ohad Ben-Cohen
2011-10-26  5:16   ` Jean-Christophe PLAGNIOL-VILLARD
2011-10-26  5:25     ` Ohad Ben-Cohen
2011-11-23  3:27   ` Stephen Boyd
2011-11-23 15:34     ` Ohad Ben-Cohen
2012-01-03 23:35   ` Grant Likely
2012-01-04  7:29     ` Mark Grosen
2012-01-05 13:58     ` Ohad Ben-Cohen
2011-10-25  9:48 ` [PATCH 2/7] amp/remoteproc: add debugfs entries Ohad Ben-Cohen
2012-01-03 23:36   ` Grant Likely
2011-10-25  9:48 ` [PATCH 3/7] amp/remoteproc: create rpmsg virtio device Ohad Ben-Cohen
2011-10-25  9:48 ` [PATCH 4/7] amp/omap: add a remoteproc driver Ohad Ben-Cohen
2011-12-08  7:57   ` Ohad Ben-Cohen
2011-12-08 17:01     ` Tony Lindgren
2011-12-08 17:08       ` Ohad Ben-Cohen
2011-10-25  9:48 ` [PATCH 5/7] ARM: OMAP: add amp/remoteproc support Ohad Ben-Cohen
2011-10-25  9:48 ` [PATCH 6/7] amp/rpmsg: add virtio-based remote processor messaging bus Ohad Ben-Cohen
2011-10-25  9:48 ` Ohad Ben-Cohen [this message]
2011-10-26  4:00 ` [PATCH 0/7] Introducing a generic AMP framework Rusty Russell
2011-10-26  5:26   ` Ohad Ben-Cohen
2011-11-22 11:40   ` Ohad Ben-Cohen
2011-11-23  1:33     ` Rusty Russell
2011-11-23  9:58       ` Ohad Ben-Cohen
2011-12-08  7:50         ` Ohad Ben-Cohen
2011-12-09  5:38           ` Rusty Russell
2011-12-09 14:15             ` Ohad Ben-Cohen
2011-11-23  3:25 ` Saravana Kannan
2011-11-23 10:27   ` Ohad Ben-Cohen
2011-11-23 16:10     ` Mark Brown
2011-11-23 20:28       ` Saravana Kannan
2011-11-24  8:43         ` Ohad Ben-Cohen
2011-12-06 22:09           ` Saravana Kannan
2011-12-07 18:53             ` Ohad Ben-Cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1319536106-25802-8-git-send-email-ohad@wizery.com \
    --to=ohad@wizery.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).