diff options
Diffstat (limited to 'include/linux/rpmsg.h')
| -rw-r--r-- | include/linux/rpmsg.h | 436 |
1 files changed, 217 insertions, 219 deletions
diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 82a673905edb..fb7ab9165645 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -1,35 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ /* * Remote processor messaging * * Copyright (C) 2011 Texas Instruments, Inc. * Copyright (C) 2011 Google, Inc. * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name Texas Instruments nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _LINUX_RPMSG_H @@ -37,93 +12,66 @@ #include <linux/types.h> #include <linux/device.h> +#include <linux/err.h> #include <linux/mod_devicetable.h> #include <linux/kref.h> #include <linux/mutex.h> +#include <linux/poll.h> +#include <linux/rpmsg/byteorder.h> +#include <uapi/linux/rpmsg.h> -/* The feature bitmap for virtio rpmsg */ -#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +struct rpmsg_device; +struct rpmsg_endpoint; +struct rpmsg_device_ops; +struct rpmsg_endpoint_ops; /** - * struct rpmsg_hdr - common header for all rpmsg messages - * @src: source address + * struct rpmsg_channel_info - channel info representation + * @name: name of service + * @src: local 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 { +struct rpmsg_channel_info { + char name[RPMSG_NAME_SIZE]; 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; - /** - * rpmsg_channel - devices that belong to the rpmsg bus are called channels - * @vrp: the remote processor this channel belongs to + * rpmsg_device - device that belong to the rpmsg bus * @dev: the device struct * @id: device id (used to match between rpmsg drivers and devices) + * @driver_override: driver name to force a match; do not set directly, + * because core frees it; use driver_set_override() to + * set or clear it. * @src: local address * @dst: destination address * @ept: the rpmsg endpoint of this channel * @announce: if set, rpmsg will announce the creation/removal of this channel + * @little_endian: True if transport is using little endian byte representation */ -struct rpmsg_channel { - struct virtproc_info *vrp; +struct rpmsg_device { struct device dev; struct rpmsg_device_id id; + const char *driver_override; u32 src; u32 dst; struct rpmsg_endpoint *ept; bool announce; + bool little_endian; + + 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); +typedef int (*rpmsg_flowcontrol_cb_t)(struct rpmsg_device *, void *, bool); /** * struct rpmsg_endpoint - binds a local rpmsg address to its user * @rpdev: rpmsg channel device * @refcount: when this drops to zero, the ept is deallocated * @cb: rx callback handler + * @flow_cb: remote flow control callback handler * @cb_lock: must be taken before accessing/changing @cb * @addr: local rpmsg address * @priv: private data for the driver's use @@ -143,12 +91,15 @@ 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; + rpmsg_flowcontrol_cb_t flow_cb; struct mutex cb_lock; u32 addr; void *priv; + + const struct rpmsg_endpoint_ops *ops; }; /** @@ -158,175 +109,222 @@ struct rpmsg_endpoint { * @probe: invoked when a matching rpmsg channel (i.e. device) is found * @remove: invoked when the rpmsg channel is removed * @callback: invoked when an inbound message is received on the channel + * @flowcontrol: invoked when remote side flow control request is received */ 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 (*flowcontrol)(struct rpmsg_device *, void *, bool); }; -int register_rpmsg_device(struct rpmsg_channel *dev); -void unregister_rpmsg_device(struct rpmsg_channel *dev); -int register_rpmsg_driver(struct rpmsg_driver *drv); +static inline u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, __rpmsg16 val) +{ + if (!rpdev) + return __rpmsg16_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg16_to_cpu(rpdev->little_endian, val); +} + +static inline __rpmsg16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val) +{ + if (!rpdev) + return __cpu_to_rpmsg16(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg16(rpdev->little_endian, val); +} + +static inline u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, __rpmsg32 val) +{ + if (!rpdev) + return __rpmsg32_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg32_to_cpu(rpdev->little_endian, val); +} + +static inline __rpmsg32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val) +{ + if (!rpdev) + return __cpu_to_rpmsg32(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg32(rpdev->little_endian, val); +} + +static inline u64 rpmsg64_to_cpu(struct rpmsg_device *rpdev, __rpmsg64 val) +{ + if (!rpdev) + return __rpmsg64_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg64_to_cpu(rpdev->little_endian, val); +} + +static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val) +{ + if (!rpdev) + return __cpu_to_rpmsg64(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg64(rpdev->little_endian, val); +} + +#if IS_ENABLED(CONFIG_RPMSG) + +int rpmsg_register_device_override(struct rpmsg_device *rpdev, + const char *driver_override); +int rpmsg_register_device(struct rpmsg_device *rpdev); +int rpmsg_unregister_device(struct device *parent, + struct rpmsg_channel_info *chinfo); +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); -/** - * 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) +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_trysend(struct rpmsg_endpoint *ept, void *data, int len); +int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); + +__poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, + poll_table *wait); + +ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept); + +int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool pause, u32 dst); + +#else + +static inline int rpmsg_register_device_override(struct rpmsg_device *rpdev, + const char *driver_override) { - u32 src = rpdev->src, dst = rpdev->dst; + return -ENXIO; +} - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); +static inline int rpmsg_register_device(struct rpmsg_device *rpdev) +{ + return -ENXIO; } -/** - * 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) +static inline int rpmsg_unregister_device(struct device *parent, + struct rpmsg_channel_info *chinfo) { - u32 src = rpdev->src; + /* This shouldn't be possible */ + WARN_ON(1); - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); + return -ENXIO; } -/** - * 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) +static inline int __register_rpmsg_driver(struct rpmsg_driver *drv, + struct module *owner) { - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; } -/** - * 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) +static inline void unregister_rpmsg_driver(struct rpmsg_driver *drv) { - u32 src = rpdev->src, dst = rpdev->dst; + /* This shouldn't be possible */ + WARN_ON(1); +} - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); +static inline void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) +{ + /* This shouldn't be possible */ + WARN_ON(1); } -/** - * 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) +static inline struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, + rpmsg_rx_cb_t cb, + void *priv, + struct rpmsg_channel_info chinfo) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return NULL; +} + +static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) { - u32 src = rpdev->src; + /* This shouldn't be possible */ + WARN_ON(1); - return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); + return -ENXIO; } +static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, + u32 dst) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; + +} + +static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} + +static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, + int len, u32 dst) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} + +static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, + struct file *filp, poll_table *wait) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return 0; +} + +static inline ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} + +static inline int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool pause, u32 dst) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} + +#endif /* IS_ENABLED(CONFIG_RPMSG) */ + +/* use a macro to avoid include chaining to get THIS_MODULE */ +#define register_rpmsg_driver(drv) \ + __register_rpmsg_driver(drv, THIS_MODULE) + /** - * 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. + * module_rpmsg_driver() - Helper macro for registering an rpmsg driver + * @__rpmsg_driver: rpmsg_driver struct * - * Can only be called from process context (for now). - * - * Returns 0 on success and an appropriate error value on failure. + * Helper macro for rpmsg drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate. Each module may only + * use this macro once, and calling it replaces module_init() and module_exit() */ -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); -} +#define module_rpmsg_driver(__rpmsg_driver) \ + module_driver(__rpmsg_driver, register_rpmsg_driver, \ + unregister_rpmsg_driver) #endif /* _LINUX_RPMSG_H */ |
