Commit e87b0708 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull rpmsg updates from Bjorn Andersson:
 "This extracts the 'nameserver' previously used only by the virtio
  rpmsg transport to work ontop of any rpmsg implementation and
  clarifies the endianness of the data types used in rpmsg"

* tag 'rpmsg-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/andersson/remoteproc:
  rpmsg: Turn name service into a stand alone driver
  rpmsg: Make rpmsg_{register|unregister}_device() public
  rpmsg: virtio: Add rpmsg channel device ops
  rpmsg: core: Add channel creation internal API
  rpmsg: virtio: Rename rpmsg_create_channel
  rpmsg: Move structure rpmsg_ns_msg to header file
  rpmsg: virtio: Move from virtio to rpmsg byte conversion
  rpmsg: Introduce __rpmsg{16|32|64} types
parents 0e10f9c8 950a7388
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -15,6 +15,14 @@ config RPMSG_CHAR
	  in /dev. They make it possible for user-space programs to send and
	  receive rpmsg packets.

config RPMSG_NS
	tristate "RPMSG name service announcement"
	depends on RPMSG
	help
	  Say Y here to enable the support of the name service announcement
	  channel that probes the associated RPMsg device on remote endpoint
	  service announcement.

config RPMSG_MTK_SCP
	tristate "MediaTek SCP"
	depends on MTK_SCP
@@ -62,6 +70,7 @@ config RPMSG_VIRTIO
	tristate "Virtio RPMSG bus driver"
	depends on HAS_DMA
	select RPMSG
	select RPMSG_NS
	select VIRTIO

endmenu
+1 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_RPMSG)		+= rpmsg_core.o
obj-$(CONFIG_RPMSG_CHAR)	+= rpmsg_char.o
obj-$(CONFIG_RPMSG_NS)		+= rpmsg_ns.o
obj-$(CONFIG_RPMSG_MTK_SCP)	+= mtk_rpmsg.o
qcom_glink-objs			:= qcom_glink_native.o qcom_glink_ssr.o
obj-$(CONFIG_RPMSG_QCOM_GLINK) += qcom_glink.o
+44 −0
Original line number Diff line number Diff line
@@ -20,6 +20,50 @@

#include "rpmsg_internal.h"

/**
 * rpmsg_create_channel() - create a new rpmsg channel
 * using its name and address info.
 * @rpdev: rpmsg device
 * @chinfo: channel_info to bind
 *
 * Returns a pointer to the new rpmsg device on success, or NULL on error.
 */
struct rpmsg_device *rpmsg_create_channel(struct rpmsg_device *rpdev,
					  struct rpmsg_channel_info *chinfo)
{
	if (WARN_ON(!rpdev))
		return NULL;
	if (!rpdev->ops || !rpdev->ops->create_channel) {
		dev_err(&rpdev->dev, "no create_channel ops found\n");
		return NULL;
	}

	return rpdev->ops->create_channel(rpdev, chinfo);
}
EXPORT_SYMBOL(rpmsg_create_channel);

/**
 * rpmsg_release_channel() - release a rpmsg channel
 * using its name and address info.
 * @rpdev: rpmsg device
 * @chinfo: channel_info to bind
 *
 * Returns 0 on success or an appropriate error value.
 */
int rpmsg_release_channel(struct rpmsg_device *rpdev,
			  struct rpmsg_channel_info *chinfo)
{
	if (WARN_ON(!rpdev))
		return -EINVAL;
	if (!rpdev->ops || !rpdev->ops->release_channel) {
		dev_err(&rpdev->dev, "no release_channel ops found\n");
		return -ENXIO;
	}

	return rpdev->ops->release_channel(rpdev, chinfo);
}
EXPORT_SYMBOL(rpmsg_release_channel);

/**
 * rpmsg_create_ept() - create a new rpmsg_endpoint
 * @rpdev: rpmsg channel device
+10 −4
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

/**
 * struct rpmsg_device_ops - indirection table for the rpmsg_device operations
 * @create_channel:	create backend-specific channel, optional
 * @release_channel:	release backend-specific channel, optional
 * @create_ept:		create backend-specific endpoint, required
 * @announce_create:	announce presence of new channel, optional
 * @announce_destroy:	announce destruction of channel, optional
@@ -29,6 +31,10 @@
 * advertise new channels implicitly by creating the endpoints.
 */
struct rpmsg_device_ops {
	struct rpmsg_device *(*create_channel)(struct rpmsg_device *rpdev,
					       struct rpmsg_channel_info *chinfo);
	int (*release_channel)(struct rpmsg_device *rpdev,
			       struct rpmsg_channel_info *chinfo);
	struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,
					    rpmsg_rx_cb_t cb, void *priv,
					    struct rpmsg_channel_info chinfo);
@@ -68,13 +74,13 @@ struct rpmsg_endpoint_ops {
			     poll_table *wait);
};

int rpmsg_register_device(struct rpmsg_device *rpdev);
int rpmsg_unregister_device(struct device *parent,
			    struct rpmsg_channel_info *chinfo);

struct device *rpmsg_find_device(struct device *parent,
				 struct rpmsg_channel_info *chinfo);

struct rpmsg_device *rpmsg_create_channel(struct rpmsg_device *rpdev,
					  struct rpmsg_channel_info *chinfo);
int rpmsg_release_channel(struct rpmsg_device *rpdev,
			  struct rpmsg_channel_info *chinfo);
/**
 * rpmsg_chrdev_register_device() - register chrdev device based on rpdev
 * @rpdev:	prepared rpdev to be used for creating endpoints
+126 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) STMicroelectronics 2020 - All Rights Reserved
 */
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rpmsg.h>
#include <linux/rpmsg/ns.h>
#include <linux/slab.h>

#include "rpmsg_internal.h"

/**
 * rpmsg_ns_register_device() - register name service device based on rpdev
 * @rpdev: prepared rpdev to be used for creating endpoints
 *
 * This function wraps rpmsg_register_device() preparing the rpdev for use as
 * basis for the rpmsg name service device.
 */
int rpmsg_ns_register_device(struct rpmsg_device *rpdev)
{
	strcpy(rpdev->id.name, "rpmsg_ns");
	rpdev->driver_override = "rpmsg_ns";
	rpdev->src = RPMSG_NS_ADDR;
	rpdev->dst = RPMSG_NS_ADDR;

	return rpmsg_register_device(rpdev);
}
EXPORT_SYMBOL(rpmsg_ns_register_device);

/* invoked when a name service announcement arrives */
static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
		       void *priv, u32 src)
{
	struct rpmsg_ns_msg *msg = data;
	struct rpmsg_device *newch;
	struct rpmsg_channel_info chinfo;
	struct device *dev = rpdev->dev.parent;
	int ret;

#if defined(CONFIG_DYNAMIC_DEBUG)
	dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
			 data, len, true);
#endif

	if (len != sizeof(*msg)) {
		dev_err(dev, "malformed ns msg (%d)\n", len);
		return -EINVAL;
	}

	/* don't trust the remote processor for null terminating the name */
	msg->name[RPMSG_NAME_SIZE - 1] = '\0';

	strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
	chinfo.src = RPMSG_ADDR_ANY;
	chinfo.dst = rpmsg32_to_cpu(rpdev, msg->addr);

	dev_info(dev, "%sing channel %s addr 0x%x\n",
		 rpmsg32_to_cpu(rpdev, msg->flags) & RPMSG_NS_DESTROY ?
		 "destroy" : "creat", msg->name, chinfo.dst);

	if (rpmsg32_to_cpu(rpdev, msg->flags) & RPMSG_NS_DESTROY) {
		ret = rpmsg_release_channel(rpdev, &chinfo);
		if (ret)
			dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret);
	} else {
		newch = rpmsg_create_channel(rpdev, &chinfo);
		if (!newch)
			dev_err(dev, "rpmsg_create_channel failed\n");
	}

	return 0;
}

static int rpmsg_ns_probe(struct rpmsg_device *rpdev)
{
	struct rpmsg_endpoint *ns_ept;
	struct rpmsg_channel_info ns_chinfo = {
		.src = RPMSG_NS_ADDR,
		.dst = RPMSG_NS_ADDR,
		.name = "name_service",
	};

	/*
	 * Create the NS announcement service endpoint associated to the RPMsg
	 * device. The endpoint will be automatically destroyed when the RPMsg
	 * device will be deleted.
	 */
	ns_ept = rpmsg_create_ept(rpdev, rpmsg_ns_cb, NULL, ns_chinfo);
	if (!ns_ept) {
		dev_err(&rpdev->dev, "failed to create the ns ept\n");
		return -ENOMEM;
	}
	rpdev->ept = ns_ept;

	return 0;
}

static struct rpmsg_driver rpmsg_ns_driver = {
	.drv.name = KBUILD_MODNAME,
	.probe = rpmsg_ns_probe,
};

static int rpmsg_ns_init(void)
{
	int ret;

	ret = register_rpmsg_driver(&rpmsg_ns_driver);
	if (ret < 0)
		pr_err("%s: Failed to register rpmsg driver\n", __func__);

	return ret;
}
postcore_initcall(rpmsg_ns_init);

static void rpmsg_ns_exit(void)
{
	unregister_rpmsg_driver(&rpmsg_ns_driver);
}
module_exit(rpmsg_ns_exit);

MODULE_DESCRIPTION("Name service announcement rpmsg driver");
MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@st.com>");
MODULE_ALIAS("rpmsg:" KBUILD_MODNAME);
MODULE_LICENSE("GPL v2");
Loading