From: Richard Zhu <richard....@freescale.com> Add one pingpong rpmsg sample, that demostrate the how to communicate with an AMP-configured remote processor over rpmsg bus.
In this sample, A# core of imx AMP SOC would send out one unsigned int data "rpmsg_pingpong", the initialized value is "0", to the remote M# core when this driver is loaded. The "rpmsg_pingpong" would be plus one at M# core side, then sent back to A# core. A# would do the same operations, after receive the "rpmsg_pingpong" sent out by M# core, then send it back to M#. The demonstration would be stopped after 10000 times Signed-off-by: Richard Zhu <hongxing....@nxp.com> --- samples/Kconfig | 8 +++ samples/rpmsg/Makefile | 1 + samples/rpmsg/imx_rpmsg_pingpong.c | 99 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 samples/rpmsg/imx_rpmsg_pingpong.c diff --git a/samples/Kconfig b/samples/Kconfig index d54f28c..49e0b62 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -63,6 +63,14 @@ config SAMPLE_RPMSG_CLIENT to communicate with an AMP-configured remote processor over the rpmsg bus. +config IMX_RPMSG_PINGPONG + tristate "Build imx rpmsg pingpong sample -- loadable modules only" + depends on RPMSG && m + help + Build an imx rpmsg pingpong sample driver, which demonstrates + the data transactions on the AMP-configured imx processor over + the rpmsg bus. + config SAMPLE_LIVEPATCH tristate "Build live patching sample -- loadable modules only" depends on LIVEPATCH && m diff --git a/samples/rpmsg/Makefile b/samples/rpmsg/Makefile index 2d4973c..c01daae 100644 --- a/samples/rpmsg/Makefile +++ b/samples/rpmsg/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_SAMPLE_RPMSG_CLIENT) += rpmsg_client_sample.o +obj-$(CONFIG_IMX_RPMSG_PINGPONG) += imx_rpmsg_pingpong.o diff --git a/samples/rpmsg/imx_rpmsg_pingpong.c b/samples/rpmsg/imx_rpmsg_pingpong.c new file mode 100644 index 0000000..f46ebe1 --- /dev/null +++ b/samples/rpmsg/imx_rpmsg_pingpong.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * + * derived from the omap-rpmsg implementation. + * Remote processor messaging transport - pingpong driver + * + * The code contained herein is licensed under the GNU General Public + * License. You may obtain a copy of the GNU General Public License + * Version 2 or later at the following locations: + * + * http://www.opensource.org/licenses/gpl-license.html + * http://www.gnu.org/copyleft/gpl.html + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/virtio.h> +#include <linux/rpmsg.h> + +#define MSG_LIMIT 100000 +static unsigned int rpmsg_pingpong; +static int rx_count; + +static void rpmsg_pingpong_cb(struct rpmsg_channel *rpdev, void *data, int len, + void *priv, u32 src) +{ + int err; + + /* reply */ + rpmsg_pingpong = *(unsigned int *)data; + pr_info("get %d (src: 0x%x)\n", + rpmsg_pingpong, src); + rx_count++; + + /* pingpongs should not live forever */ + if (rx_count >= MSG_LIMIT) { + dev_info(&rpdev->dev, "goodbye!\n"); + return; + } + rpmsg_pingpong++; + err = rpmsg_sendto(rpdev, (void *)(&rpmsg_pingpong), 4, src); + + if (err) + dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err); +} + +static int rpmsg_pingpong_probe(struct rpmsg_channel *rpdev) +{ + int err; + + dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n", + rpdev->src, rpdev->dst); + + rpmsg_pingpong = 0; + rx_count = 0; + err = rpmsg_sendto(rpdev, (void *)(&rpmsg_pingpong), 4, rpdev->dst); + if (err) { + dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err); + return err; + } + + return 0; +} + +static void rpmsg_pingpong_remove(struct rpmsg_channel *rpdev) +{ + dev_info(&rpdev->dev, "rpmsg pingpong driver is removed\n"); +} + +static struct rpmsg_device_id rpmsg_driver_pingpong_id_table[] = { + { .name = "rpmsg-openamp-demo-channel" }, + { }, +}; +MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_pingpong_id_table); + +static struct rpmsg_driver rpmsg_pingpong_driver = { + .drv.name = KBUILD_MODNAME, + .drv.owner = THIS_MODULE, + .id_table = rpmsg_driver_pingpong_id_table, + .probe = rpmsg_pingpong_probe, + .callback = rpmsg_pingpong_cb, + .remove = rpmsg_pingpong_remove, +}; + +static int __init init(void) +{ + return register_rpmsg_driver(&rpmsg_pingpong_driver); +} + +static void __exit fini(void) +{ + unregister_rpmsg_driver(&rpmsg_pingpong_driver); +} +module_init(init); +module_exit(fini); + +MODULE_AUTHOR("Freescale Semiconductor, Inc."); +MODULE_DESCRIPTION("iMX virtio remote processor messaging pingpong driver"); +MODULE_LICENSE("GPL v2"); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/