You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge tag 'rpmsg-v4.9' of git://github.com/andersson/remoteproc
Pull rpmsg updates from Bjorn Andersson: "The bulk of these patches involve splitting the rpmsg implementation into a framework/API part and a virtio specific backend part. It then adds the Qualcomm Shared Memory Device (SMD) as an additional supported wire format. Also included is a set of code style cleanups that have been lingering for a while" * tag 'rpmsg-v4.9' of git://github.com/andersson/remoteproc: (26 commits) rpmsg: smd: fix dependency on QCOM_SMD=n rpmsg: Introduce Qualcomm SMD backend rpmsg: Allow callback to return errors rpmsg: Move virtio specifics from public header rpmsg: virtio: Hide vrp pointer from the public API rpmsg: Hide rpmsg indirection tables rpmsg: Split rpmsg core and virtio backend rpmsg: Split off generic tail of create_channel() rpmsg: Move helper for finding rpmsg devices to core rpmsg: Move endpoint related interface to rpmsg core rpmsg: Indirection table for rpmsg_endpoint operations rpmsg: Move rpmsg_device API to new file rpmsg: Introduce indirection table for rpmsg_device operations rpmsg: Clean up rpmsg device vs channel naming rpmsg: Make rpmsg_create_ept() take channel_info struct rpmsg: rpmsg_send() operations takes rpmsg_endpoint rpmsg: Name rpmsg devices based on channel id rpmsg: Enable matching devices with drivers based on DT rpmsg: Drop prototypes for non-existing functions samples/rpmsg: add support for multiple instances ...
This commit is contained in:
@@ -17,7 +17,7 @@ config OMAP_REMOTEPROC
|
||||
select REMOTEPROC
|
||||
select MAILBOX
|
||||
select OMAP2PLUS_MBOX
|
||||
select RPMSG
|
||||
select RPMSG_VIRTIO
|
||||
help
|
||||
Say y here to support OMAP's remote processors (dual M3
|
||||
and DSP on OMAP4) via the remote processor framework.
|
||||
@@ -59,7 +59,7 @@ config DA8XX_REMOTEPROC
|
||||
depends on ARCH_DAVINCI_DA8XX
|
||||
select CMA if MMU
|
||||
select REMOTEPROC
|
||||
select RPMSG
|
||||
select RPMSG_VIRTIO
|
||||
help
|
||||
Say y here to support DA8xx/OMAP-L13x remote processors via the
|
||||
remote processor framework.
|
||||
|
||||
@@ -3,6 +3,20 @@ menu "Rpmsg drivers"
|
||||
# RPMSG always gets selected by whoever wants it
|
||||
config RPMSG
|
||||
tristate
|
||||
|
||||
config RPMSG_QCOM_SMD
|
||||
tristate "Qualcomm Shared Memory Driver (SMD)"
|
||||
depends on QCOM_SMEM
|
||||
depends on QCOM_SMD=n
|
||||
select RPMSG
|
||||
help
|
||||
Say y here to enable support for the Qualcomm Shared Memory Driver
|
||||
providing communication channels to remote processors in Qualcomm
|
||||
platforms.
|
||||
|
||||
config RPMSG_VIRTIO
|
||||
tristate
|
||||
select RPMSG
|
||||
select VIRTIO
|
||||
select VIRTUALIZATION
|
||||
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
obj-$(CONFIG_RPMSG) += virtio_rpmsg_bus.o
|
||||
obj-$(CONFIG_RPMSG) += rpmsg_core.o
|
||||
obj-$(CONFIG_RPMSG_QCOM_SMD) += qcom_smd.o
|
||||
obj-$(CONFIG_RPMSG_VIRTIO) += virtio_rpmsg_bus.o
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* remote processor messaging bus
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) "%s: " fmt, __func__
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/rpmsg.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "rpmsg_internal.h"
|
||||
|
||||
/**
|
||||
* rpmsg_create_ept() - create a new rpmsg_endpoint
|
||||
* @rpdev: rpmsg channel device
|
||||
* @cb: rx callback handler
|
||||
* @priv: private data for the driver's use
|
||||
* @chinfo: channel_info with the local rpmsg address to bind with @cb
|
||||
*
|
||||
* Every rpmsg address in the system is bound to an rx callback (so when
|
||||
* inbound messages arrive, they are dispatched by the rpmsg bus using the
|
||||
* appropriate callback handler) by means of an rpmsg_endpoint struct.
|
||||
*
|
||||
* This function allows drivers to create such an endpoint, and by that,
|
||||
* bind a callback, and possibly some private data too, to an rpmsg address
|
||||
* (either one that is known in advance, or one that will be dynamically
|
||||
* assigned for them).
|
||||
*
|
||||
* Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint
|
||||
* is already created for them when they are probed by the rpmsg bus
|
||||
* (using the rx callback provided when they registered to the rpmsg bus).
|
||||
*
|
||||
* So things should just work for simple drivers: they already have an
|
||||
* endpoint, their rx callback is bound to their rpmsg address, and when
|
||||
* relevant inbound messages arrive (i.e. messages which their dst address
|
||||
* equals to the src address of their rpmsg channel), the driver's handler
|
||||
* is invoked to process it.
|
||||
*
|
||||
* That said, more complicated drivers might do need to allocate
|
||||
* additional rpmsg addresses, and bind them to different rx callbacks.
|
||||
* To accomplish that, those drivers need to call this function.
|
||||
*
|
||||
* Drivers should provide their @rpdev channel (so the new endpoint would belong
|
||||
* to the same remote processor their channel belongs to), an rx callback
|
||||
* function, an optional private data (which is provided back when the
|
||||
* rx callback is invoked), and an address they want to bind with the
|
||||
* callback. If @addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will
|
||||
* dynamically assign them an available rpmsg address (drivers should have
|
||||
* a very good reason why not to always use RPMSG_ADDR_ANY here).
|
||||
*
|
||||
* Returns a pointer to the endpoint on success, or NULL on error.
|
||||
*/
|
||||
struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
|
||||
rpmsg_rx_cb_t cb, void *priv,
|
||||
struct rpmsg_channel_info chinfo)
|
||||
{
|
||||
return rpdev->ops->create_ept(rpdev, cb, priv, chinfo);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_create_ept);
|
||||
|
||||
/**
|
||||
* rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
|
||||
* @ept: endpoing to destroy
|
||||
*
|
||||
* Should be used by drivers to destroy an rpmsg endpoint previously
|
||||
* created with rpmsg_create_ept().
|
||||
*/
|
||||
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
|
||||
{
|
||||
ept->ops->destroy_ept(ept);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_destroy_ept);
|
||||
|
||||
/**
|
||||
* rpmsg_send() - send a message across to the remote processor
|
||||
* @ept: the rpmsg endpoint
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len on the @ept endpoint.
|
||||
* The message will be sent to the remote processor which the @ept
|
||||
* endpoint belongs to, using @ept's address and its associated rpmsg
|
||||
* device destination addresses.
|
||||
* In case there are no TX buffers available, the function will block until
|
||||
* one becomes available, or a timeout of 15 seconds elapses. When the latter
|
||||
* happens, -ERESTARTSYS is returned.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
|
||||
{
|
||||
return ept->ops->send(ept, data, len);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_send);
|
||||
|
||||
/**
|
||||
* rpmsg_sendto() - send a message across to the remote processor, specify dst
|
||||
* @ept: the rpmsg endpoint
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
* @dst: destination address
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address.
|
||||
* The message will be sent to the remote processor which the @ept
|
||||
* endpoint belongs to, using @ept's address as source.
|
||||
* In case there are no TX buffers available, the function will block until
|
||||
* one becomes available, or a timeout of 15 seconds elapses. When the latter
|
||||
* happens, -ERESTARTSYS is returned.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
|
||||
{
|
||||
return ept->ops->sendto(ept, data, len, dst);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_sendto);
|
||||
|
||||
/**
|
||||
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
|
||||
* @ept: the rpmsg endpoint
|
||||
* @src: source address
|
||||
* @dst: destination address
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address,
|
||||
* and uses @src as the source address.
|
||||
* The message will be sent to the remote processor which the @ept
|
||||
* endpoint belongs to.
|
||||
* In case there are no TX buffers available, the function will block until
|
||||
* one becomes available, or a timeout of 15 seconds elapses. When the latter
|
||||
* happens, -ERESTARTSYS is returned.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
||||
void *data, int len)
|
||||
{
|
||||
return ept->ops->send_offchannel(ept, src, dst, data, len);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_send_offchannel);
|
||||
|
||||
/**
|
||||
* rpmsg_send() - send a message across to the remote processor
|
||||
* @ept: the rpmsg endpoint
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len on the @ept endpoint.
|
||||
* The message will be sent to the remote processor which the @ept
|
||||
* endpoint belongs to, using @ept's address as source and its associated
|
||||
* rpdev's address as destination.
|
||||
* In case there are no TX buffers available, the function will immediately
|
||||
* return -ENOMEM without waiting until one becomes available.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
|
||||
{
|
||||
return ept->ops->trysend(ept, data, len);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_trysend);
|
||||
|
||||
/**
|
||||
* rpmsg_sendto() - send a message across to the remote processor, specify dst
|
||||
* @ept: the rpmsg endpoint
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
* @dst: destination address
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address.
|
||||
* The message will be sent to the remote processor which the @ept
|
||||
* endpoint belongs to, using @ept's address as source.
|
||||
* In case there are no TX buffers available, the function will immediately
|
||||
* return -ENOMEM without waiting until one becomes available.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
|
||||
{
|
||||
return ept->ops->trysendto(ept, data, len, dst);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_trysendto);
|
||||
|
||||
/**
|
||||
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
|
||||
* @ept: the rpmsg endpoint
|
||||
* @src: source address
|
||||
* @dst: destination address
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address,
|
||||
* and uses @src as the source address.
|
||||
* The message will be sent to the remote processor which the @ept
|
||||
* endpoint belongs to.
|
||||
* In case there are no TX buffers available, the function will immediately
|
||||
* return -ENOMEM without waiting until one becomes available.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
||||
void *data, int len)
|
||||
{
|
||||
return ept->ops->trysend_offchannel(ept, src, dst, data, len);
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_trysend_offchannel);
|
||||
|
||||
/*
|
||||
* match an rpmsg channel with a channel info struct.
|
||||
* this is used to make sure we're not creating rpmsg devices for channels
|
||||
* that already exist.
|
||||
*/
|
||||
static int rpmsg_device_match(struct device *dev, void *data)
|
||||
{
|
||||
struct rpmsg_channel_info *chinfo = data;
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
|
||||
if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
|
||||
return 0;
|
||||
|
||||
if (chinfo->dst != RPMSG_ADDR_ANY && chinfo->dst != rpdev->dst)
|
||||
return 0;
|
||||
|
||||
if (strncmp(chinfo->name, rpdev->id.name, RPMSG_NAME_SIZE))
|
||||
return 0;
|
||||
|
||||
/* found a match ! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct device *rpmsg_find_device(struct device *parent,
|
||||
struct rpmsg_channel_info *chinfo)
|
||||
{
|
||||
return device_find_child(parent, chinfo, rpmsg_device_match);
|
||||
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_find_device);
|
||||
|
||||
/* sysfs show configuration fields */
|
||||
#define rpmsg_show_attr(field, path, format_string) \
|
||||
static ssize_t \
|
||||
field##_show(struct device *dev, \
|
||||
struct device_attribute *attr, char *buf) \
|
||||
{ \
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev); \
|
||||
\
|
||||
return sprintf(buf, format_string, rpdev->path); \
|
||||
}
|
||||
|
||||
/* for more info, see Documentation/ABI/testing/sysfs-bus-rpmsg */
|
||||
rpmsg_show_attr(name, id.name, "%s\n");
|
||||
rpmsg_show_attr(src, src, "0x%x\n");
|
||||
rpmsg_show_attr(dst, dst, "0x%x\n");
|
||||
rpmsg_show_attr(announce, announce ? "true" : "false", "%s\n");
|
||||
|
||||
static ssize_t modalias_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
|
||||
return sprintf(buf, RPMSG_DEVICE_MODALIAS_FMT "\n", rpdev->id.name);
|
||||
}
|
||||
|
||||
static struct device_attribute rpmsg_dev_attrs[] = {
|
||||
__ATTR_RO(name),
|
||||
__ATTR_RO(modalias),
|
||||
__ATTR_RO(dst),
|
||||
__ATTR_RO(src),
|
||||
__ATTR_RO(announce),
|
||||
__ATTR_NULL
|
||||
};
|
||||
|
||||
/* rpmsg devices and drivers are matched using the service name */
|
||||
static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
|
||||
const struct rpmsg_device_id *id)
|
||||
{
|
||||
return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
|
||||
}
|
||||
|
||||
/* match rpmsg channel and rpmsg driver */
|
||||
static int rpmsg_dev_match(struct device *dev, struct device_driver *drv)
|
||||
{
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
struct rpmsg_driver *rpdrv = to_rpmsg_driver(drv);
|
||||
const struct rpmsg_device_id *ids = rpdrv->id_table;
|
||||
unsigned int i;
|
||||
|
||||
if (ids)
|
||||
for (i = 0; ids[i].name[0]; i++)
|
||||
if (rpmsg_id_match(rpdev, &ids[i]))
|
||||
return 1;
|
||||
|
||||
return of_driver_match_device(dev, drv);
|
||||
}
|
||||
|
||||
static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env)
|
||||
{
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
|
||||
return add_uevent_var(env, "MODALIAS=" RPMSG_DEVICE_MODALIAS_FMT,
|
||||
rpdev->id.name);
|
||||
}
|
||||
|
||||
/*
|
||||
* when an rpmsg driver is probed with a channel, we seamlessly create
|
||||
* it an endpoint, binding its rx callback to a unique local rpmsg
|
||||
* address.
|
||||
*
|
||||
* if we need to, we also announce about this channel to the remote
|
||||
* processor (needed in case the driver is exposing an rpmsg service).
|
||||
*/
|
||||
static int rpmsg_dev_probe(struct device *dev)
|
||||
{
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
|
||||
struct rpmsg_channel_info chinfo = {};
|
||||
struct rpmsg_endpoint *ept;
|
||||
int err;
|
||||
|
||||
strncpy(chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE);
|
||||
chinfo.src = rpdev->src;
|
||||
chinfo.dst = RPMSG_ADDR_ANY;
|
||||
|
||||
ept = rpmsg_create_ept(rpdev, rpdrv->callback, NULL, chinfo);
|
||||
if (!ept) {
|
||||
dev_err(dev, "failed to create endpoint\n");
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rpdev->ept = ept;
|
||||
rpdev->src = ept->addr;
|
||||
|
||||
err = rpdrv->probe(rpdev);
|
||||
if (err) {
|
||||
dev_err(dev, "%s: failed: %d\n", __func__, err);
|
||||
rpmsg_destroy_ept(ept);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (rpdev->ops->announce_create)
|
||||
err = rpdev->ops->announce_create(rpdev);
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int rpmsg_dev_remove(struct device *dev)
|
||||
{
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
|
||||
int err = 0;
|
||||
|
||||
if (rpdev->ops->announce_destroy)
|
||||
err = rpdev->ops->announce_destroy(rpdev);
|
||||
|
||||
rpdrv->remove(rpdev);
|
||||
|
||||
rpmsg_destroy_ept(rpdev->ept);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct bus_type rpmsg_bus = {
|
||||
.name = "rpmsg",
|
||||
.match = rpmsg_dev_match,
|
||||
.dev_attrs = rpmsg_dev_attrs,
|
||||
.uevent = rpmsg_uevent,
|
||||
.probe = rpmsg_dev_probe,
|
||||
.remove = rpmsg_dev_remove,
|
||||
};
|
||||
|
||||
static void rpmsg_release_device(struct device *dev)
|
||||
{
|
||||
struct rpmsg_device *rpdev = to_rpmsg_device(dev);
|
||||
|
||||
kfree(rpdev);
|
||||
}
|
||||
|
||||
int rpmsg_register_device(struct rpmsg_device *rpdev)
|
||||
{
|
||||
struct device *dev = &rpdev->dev;
|
||||
int ret;
|
||||
|
||||
dev_set_name(&rpdev->dev, "%s:%s",
|
||||
dev_name(dev->parent), rpdev->id.name);
|
||||
|
||||
rpdev->dev.bus = &rpmsg_bus;
|
||||
rpdev->dev.release = rpmsg_release_device;
|
||||
|
||||
ret = device_register(&rpdev->dev);
|
||||
if (ret) {
|
||||
dev_err(dev, "device_register failed: %d\n", ret);
|
||||
put_device(&rpdev->dev);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_register_device);
|
||||
|
||||
/*
|
||||
* find an existing channel using its name + address properties,
|
||||
* and destroy it
|
||||
*/
|
||||
int rpmsg_unregister_device(struct device *parent,
|
||||
struct rpmsg_channel_info *chinfo)
|
||||
{
|
||||
struct device *dev;
|
||||
|
||||
dev = rpmsg_find_device(parent, chinfo);
|
||||
if (!dev)
|
||||
return -EINVAL;
|
||||
|
||||
device_unregister(dev);
|
||||
|
||||
put_device(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(rpmsg_unregister_device);
|
||||
|
||||
/**
|
||||
* __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
|
||||
* @rpdrv: pointer to a struct rpmsg_driver
|
||||
* @owner: owning module/driver
|
||||
*
|
||||
* Returns 0 on success, and an appropriate error value on failure.
|
||||
*/
|
||||
int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner)
|
||||
{
|
||||
rpdrv->drv.bus = &rpmsg_bus;
|
||||
rpdrv->drv.owner = owner;
|
||||
return driver_register(&rpdrv->drv);
|
||||
}
|
||||
EXPORT_SYMBOL(__register_rpmsg_driver);
|
||||
|
||||
/**
|
||||
* unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus
|
||||
* @rpdrv: pointer to a struct rpmsg_driver
|
||||
*
|
||||
* Returns 0 on success, and an appropriate error value on failure.
|
||||
*/
|
||||
void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv)
|
||||
{
|
||||
driver_unregister(&rpdrv->drv);
|
||||
}
|
||||
EXPORT_SYMBOL(unregister_rpmsg_driver);
|
||||
|
||||
|
||||
static int __init rpmsg_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = bus_register(&rpmsg_bus);
|
||||
if (ret)
|
||||
pr_err("failed to register rpmsg bus: %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
postcore_initcall(rpmsg_init);
|
||||
|
||||
static void __exit rpmsg_fini(void)
|
||||
{
|
||||
bus_unregister(&rpmsg_bus);
|
||||
}
|
||||
module_exit(rpmsg_fini);
|
||||
|
||||
MODULE_DESCRIPTION("remote processor messaging bus");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* remote processor messaging bus internals
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __RPMSG_INTERNAL_H__
|
||||
#define __RPMSG_INTERNAL_H__
|
||||
|
||||
#include <linux/rpmsg.h>
|
||||
|
||||
#define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev)
|
||||
#define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv)
|
||||
|
||||
/**
|
||||
* struct rpmsg_device_ops - indirection table for the rpmsg_device operations
|
||||
* @create_ept: create backend-specific endpoint, requried
|
||||
* @announce_create: announce presence of new channel, optional
|
||||
* @announce_destroy: announce destruction of channel, optional
|
||||
*
|
||||
* Indirection table for the operations that a rpmsg backend should implement.
|
||||
* @announce_create and @announce_destroy are optional as the backend might
|
||||
* advertise new channels implicitly by creating the endpoints.
|
||||
*/
|
||||
struct rpmsg_device_ops {
|
||||
struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,
|
||||
rpmsg_rx_cb_t cb, void *priv,
|
||||
struct rpmsg_channel_info chinfo);
|
||||
|
||||
int (*announce_create)(struct rpmsg_device *ept);
|
||||
int (*announce_destroy)(struct rpmsg_device *ept);
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rpmsg_endpoint_ops - indirection table for rpmsg_endpoint operations
|
||||
* @destroy_ept: destroy the given endpoint, required
|
||||
* @send: see @rpmsg_send(), required
|
||||
* @sendto: see @rpmsg_sendto(), optional
|
||||
* @send_offchannel: see @rpmsg_send_offchannel(), optional
|
||||
* @trysend: see @rpmsg_trysend(), required
|
||||
* @trysendto: see @rpmsg_trysendto(), optional
|
||||
* @trysend_offchannel: see @rpmsg_trysend_offchannel(), optional
|
||||
*
|
||||
* Indirection table for the operations that a rpmsg backend should implement.
|
||||
* In addition to @destroy_ept, the backend must at least implement @send and
|
||||
* @trysend, while the variants sending data off-channel are optional.
|
||||
*/
|
||||
struct rpmsg_endpoint_ops {
|
||||
void (*destroy_ept)(struct rpmsg_endpoint *ept);
|
||||
|
||||
int (*send)(struct rpmsg_endpoint *ept, void *data, int len);
|
||||
int (*sendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
|
||||
int (*send_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
||||
void *data, int len);
|
||||
|
||||
int (*trysend)(struct rpmsg_endpoint *ept, void *data, int len);
|
||||
int (*trysendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
|
||||
int (*trysend_offchannel)(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
||||
void *data, int len);
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
+216
-323
File diff suppressed because it is too large
Load Diff
+40
-218
@@ -41,65 +41,27 @@
|
||||
#include <linux/kref.h>
|
||||
#include <linux/mutex.h>
|
||||
|
||||
/* The feature bitmap for virtio rpmsg */
|
||||
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
|
||||
|
||||
/**
|
||||
* struct rpmsg_hdr - common header for all rpmsg messages
|
||||
* @src: source address
|
||||
* @dst: destination address
|
||||
* @reserved: reserved for future use
|
||||
* @len: length of payload (in bytes)
|
||||
* @flags: message flags
|
||||
* @data: @len bytes of message payload data
|
||||
*
|
||||
* Every message sent(/received) on the rpmsg bus begins with this header.
|
||||
*/
|
||||
struct rpmsg_hdr {
|
||||
u32 src;
|
||||
u32 dst;
|
||||
u32 reserved;
|
||||
u16 len;
|
||||
u16 flags;
|
||||
u8 data[0];
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* struct rpmsg_ns_msg - dynamic name service announcement message
|
||||
* @name: name of remote service that is published
|
||||
* @addr: address of remote service that is published
|
||||
* @flags: indicates whether service is created or destroyed
|
||||
*
|
||||
* This message is sent across to publish a new service, or announce
|
||||
* about its removal. When we receive these messages, an appropriate
|
||||
* rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe()
|
||||
* or ->remove() handler of the appropriate rpmsg driver will be invoked
|
||||
* (if/as-soon-as one is registered).
|
||||
*/
|
||||
struct rpmsg_ns_msg {
|
||||
char name[RPMSG_NAME_SIZE];
|
||||
u32 addr;
|
||||
u32 flags;
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
* enum rpmsg_ns_flags - dynamic name service announcement flags
|
||||
*
|
||||
* @RPMSG_NS_CREATE: a new remote service was just created
|
||||
* @RPMSG_NS_DESTROY: a known remote service was just destroyed
|
||||
*/
|
||||
enum rpmsg_ns_flags {
|
||||
RPMSG_NS_CREATE = 0,
|
||||
RPMSG_NS_DESTROY = 1,
|
||||
};
|
||||
|
||||
#define RPMSG_ADDR_ANY 0xFFFFFFFF
|
||||
|
||||
struct virtproc_info;
|
||||
struct rpmsg_device;
|
||||
struct rpmsg_endpoint;
|
||||
struct rpmsg_device_ops;
|
||||
struct rpmsg_endpoint_ops;
|
||||
|
||||
/**
|
||||
* rpmsg_channel - devices that belong to the rpmsg bus are called channels
|
||||
* @vrp: the remote processor this channel belongs to
|
||||
* struct rpmsg_channel_info - channel info representation
|
||||
* @name: name of service
|
||||
* @src: local address
|
||||
* @dst: destination address
|
||||
*/
|
||||
struct rpmsg_channel_info {
|
||||
char name[RPMSG_NAME_SIZE];
|
||||
u32 src;
|
||||
u32 dst;
|
||||
};
|
||||
|
||||
/**
|
||||
* rpmsg_device - device that belong to the rpmsg bus
|
||||
* @dev: the device struct
|
||||
* @id: device id (used to match between rpmsg drivers and devices)
|
||||
* @src: local address
|
||||
@@ -107,17 +69,18 @@ struct virtproc_info;
|
||||
* @ept: the rpmsg endpoint of this channel
|
||||
* @announce: if set, rpmsg will announce the creation/removal of this channel
|
||||
*/
|
||||
struct rpmsg_channel {
|
||||
struct virtproc_info *vrp;
|
||||
struct rpmsg_device {
|
||||
struct device dev;
|
||||
struct rpmsg_device_id id;
|
||||
u32 src;
|
||||
u32 dst;
|
||||
struct rpmsg_endpoint *ept;
|
||||
bool announce;
|
||||
|
||||
const struct rpmsg_device_ops *ops;
|
||||
};
|
||||
|
||||
typedef void (*rpmsg_rx_cb_t)(struct rpmsg_channel *, void *, int, void *, u32);
|
||||
typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
|
||||
|
||||
/**
|
||||
* struct rpmsg_endpoint - binds a local rpmsg address to its user
|
||||
@@ -143,12 +106,14 @@ typedef void (*rpmsg_rx_cb_t)(struct rpmsg_channel *, void *, int, void *, u32);
|
||||
* create additional endpoints by themselves (see rpmsg_create_ept()).
|
||||
*/
|
||||
struct rpmsg_endpoint {
|
||||
struct rpmsg_channel *rpdev;
|
||||
struct rpmsg_device *rpdev;
|
||||
struct kref refcount;
|
||||
rpmsg_rx_cb_t cb;
|
||||
struct mutex cb_lock;
|
||||
u32 addr;
|
||||
void *priv;
|
||||
|
||||
const struct rpmsg_endpoint_ops *ops;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -162,20 +127,19 @@ struct rpmsg_endpoint {
|
||||
struct rpmsg_driver {
|
||||
struct device_driver drv;
|
||||
const struct rpmsg_device_id *id_table;
|
||||
int (*probe)(struct rpmsg_channel *dev);
|
||||
void (*remove)(struct rpmsg_channel *dev);
|
||||
void (*callback)(struct rpmsg_channel *, void *, int, void *, u32);
|
||||
int (*probe)(struct rpmsg_device *dev);
|
||||
void (*remove)(struct rpmsg_device *dev);
|
||||
int (*callback)(struct rpmsg_device *, void *, int, void *, u32);
|
||||
};
|
||||
|
||||
int register_rpmsg_device(struct rpmsg_channel *dev);
|
||||
void unregister_rpmsg_device(struct rpmsg_channel *dev);
|
||||
int register_rpmsg_device(struct rpmsg_device *dev);
|
||||
void unregister_rpmsg_device(struct rpmsg_device *dev);
|
||||
int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
|
||||
void unregister_rpmsg_driver(struct rpmsg_driver *drv);
|
||||
void rpmsg_destroy_ept(struct rpmsg_endpoint *);
|
||||
struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *,
|
||||
rpmsg_rx_cb_t cb, void *priv, u32 addr);
|
||||
int
|
||||
rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool);
|
||||
struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *,
|
||||
rpmsg_rx_cb_t cb, void *priv,
|
||||
struct rpmsg_channel_info chinfo);
|
||||
|
||||
/* use a macro to avoid include chaining to get THIS_MODULE */
|
||||
#define register_rpmsg_driver(drv) \
|
||||
@@ -193,156 +157,14 @@ rpmsg_send_offchannel_raw(struct rpmsg_channel *, u32, u32, void *, int, bool);
|
||||
module_driver(__rpmsg_driver, register_rpmsg_driver, \
|
||||
unregister_rpmsg_driver)
|
||||
|
||||
/**
|
||||
* rpmsg_send() - send a message across to the remote processor
|
||||
* @rpdev: the rpmsg channel
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len on the @rpdev channel.
|
||||
* The message will be sent to the remote processor which the @rpdev
|
||||
* channel belongs to, using @rpdev's source and destination addresses.
|
||||
* In case there are no TX buffers available, the function will block until
|
||||
* one becomes available, or a timeout of 15 seconds elapses. When the latter
|
||||
* happens, -ERESTARTSYS is returned.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
static inline int rpmsg_send(struct rpmsg_channel *rpdev, void *data, int len)
|
||||
{
|
||||
u32 src = rpdev->src, dst = rpdev->dst;
|
||||
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
|
||||
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
|
||||
int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
||||
void *data, int len);
|
||||
|
||||
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* rpmsg_sendto() - send a message across to the remote processor, specify dst
|
||||
* @rpdev: the rpmsg channel
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
* @dst: destination address
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address.
|
||||
* The message will be sent to the remote processor which the @rpdev
|
||||
* channel belongs to, using @rpdev's source address.
|
||||
* In case there are no TX buffers available, the function will block until
|
||||
* one becomes available, or a timeout of 15 seconds elapses. When the latter
|
||||
* happens, -ERESTARTSYS is returned.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
static inline
|
||||
int rpmsg_sendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
|
||||
{
|
||||
u32 src = rpdev->src;
|
||||
|
||||
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
|
||||
* @rpdev: the rpmsg channel
|
||||
* @src: source address
|
||||
* @dst: destination address
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address,
|
||||
* and uses @src as the source address.
|
||||
* The message will be sent to the remote processor which the @rpdev
|
||||
* channel belongs to.
|
||||
* In case there are no TX buffers available, the function will block until
|
||||
* one becomes available, or a timeout of 15 seconds elapses. When the latter
|
||||
* happens, -ERESTARTSYS is returned.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
static inline
|
||||
int rpmsg_send_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
|
||||
void *data, int len)
|
||||
{
|
||||
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* rpmsg_send() - send a message across to the remote processor
|
||||
* @rpdev: the rpmsg channel
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len on the @rpdev channel.
|
||||
* The message will be sent to the remote processor which the @rpdev
|
||||
* channel belongs to, using @rpdev's source and destination addresses.
|
||||
* In case there are no TX buffers available, the function will immediately
|
||||
* return -ENOMEM without waiting until one becomes available.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
static inline
|
||||
int rpmsg_trysend(struct rpmsg_channel *rpdev, void *data, int len)
|
||||
{
|
||||
u32 src = rpdev->src, dst = rpdev->dst;
|
||||
|
||||
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* rpmsg_sendto() - send a message across to the remote processor, specify dst
|
||||
* @rpdev: the rpmsg channel
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
* @dst: destination address
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address.
|
||||
* The message will be sent to the remote processor which the @rpdev
|
||||
* channel belongs to, using @rpdev's source address.
|
||||
* In case there are no TX buffers available, the function will immediately
|
||||
* return -ENOMEM without waiting until one becomes available.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
static inline
|
||||
int rpmsg_trysendto(struct rpmsg_channel *rpdev, void *data, int len, u32 dst)
|
||||
{
|
||||
u32 src = rpdev->src;
|
||||
|
||||
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* rpmsg_send_offchannel() - send a message using explicit src/dst addresses
|
||||
* @rpdev: the rpmsg channel
|
||||
* @src: source address
|
||||
* @dst: destination address
|
||||
* @data: payload of message
|
||||
* @len: length of payload
|
||||
*
|
||||
* This function sends @data of length @len to the remote @dst address,
|
||||
* and uses @src as the source address.
|
||||
* The message will be sent to the remote processor which the @rpdev
|
||||
* channel belongs to.
|
||||
* In case there are no TX buffers available, the function will immediately
|
||||
* return -ENOMEM without waiting until one becomes available.
|
||||
*
|
||||
* Can only be called from process context (for now).
|
||||
*
|
||||
* Returns 0 on success and an appropriate error value on failure.
|
||||
*/
|
||||
static inline
|
||||
int rpmsg_trysend_offchannel(struct rpmsg_channel *rpdev, u32 src, u32 dst,
|
||||
void *data, int len)
|
||||
{
|
||||
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
|
||||
}
|
||||
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
|
||||
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
|
||||
int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
||||
void *data, int len);
|
||||
|
||||
#endif /* _LINUX_RPMSG_H */
|
||||
|
||||
@@ -24,38 +24,52 @@
|
||||
#define MSG "hello world!"
|
||||
#define MSG_LIMIT 100
|
||||
|
||||
static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
|
||||
struct instance_data {
|
||||
int rx_count;
|
||||
};
|
||||
|
||||
static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
|
||||
void *priv, u32 src)
|
||||
{
|
||||
int ret;
|
||||
static int rx_count;
|
||||
struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
|
||||
|
||||
dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n", ++rx_count, src);
|
||||
dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
|
||||
++idata->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) {
|
||||
if (idata->rx_count >= MSG_LIMIT) {
|
||||
dev_info(&rpdev->dev, "goodbye!\n");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* send a new message now */
|
||||
ret = rpmsg_send(rpdev, MSG, strlen(MSG));
|
||||
ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
|
||||
if (ret)
|
||||
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
|
||||
static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
|
||||
{
|
||||
int ret;
|
||||
struct instance_data *idata;
|
||||
|
||||
dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
|
||||
rpdev->src, rpdev->dst);
|
||||
|
||||
idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
|
||||
if (!idata)
|
||||
return -ENOMEM;
|
||||
|
||||
dev_set_drvdata(&rpdev->dev, idata);
|
||||
|
||||
/* send a message to our remote processor */
|
||||
ret = rpmsg_send(rpdev, MSG, strlen(MSG));
|
||||
ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
|
||||
if (ret) {
|
||||
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
|
||||
return ret;
|
||||
@@ -64,7 +78,7 @@ static int rpmsg_sample_probe(struct rpmsg_channel *rpdev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rpmsg_sample_remove(struct rpmsg_channel *rpdev)
|
||||
static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
|
||||
{
|
||||
dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user