rpmsg: Make RPMSG name service modular
Mathieu Poirier
maintainerv2 cover rpmsg: Make RPMSG name service modular
Good afternoon,
This set starts by making the RPMSG protocol transport agnostic by moving the headers it uses to generic types and using those in the current implementation. From there it re-uses the work that Arnaud published[1] to make the name service modular.
Tested on stm32mp157 with the RPMSG client sample application. Applies cleanly on v5.9.
Thanks,
Mathieu
[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=338335
------
New for V2:
- Created new RPMSG types (Guennadi).
- Re-worked byte conversion functions(Guennadi).
- Added a single ->is_little_endian() operation (Arnaud).
- Fixed byte conversion before making name service modular.
Arnaud Pouliquen (4):
rpmsg: virtio: Rename rpmsg_create_channel
rpmsg: core: Add channel creation internal API
rpmsg: virtio: Add rpmsg channel device ops
rpmsg: Turn name service into a stand alone driver
Mathieu Poirier (5):
rpmsg: Move rpmsg_endpoint_ops to rpmsg.h
rpmsg: Introduce __rpmsg{16|32|64} types
rpmsg: virtio: Move from virtio to rpmsg byte conversion
rpmsg: Move rpmsg_hr and rpmsg_ns_msg to header file
rpmsg: Make rpmsg_{register|unregister}_device() public
drivers/rpmsg/Kconfig | 8 ++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_core.c | 44 +++++++ drivers/rpmsg/rpmsg_internal.h | 27 +--- drivers/rpmsg/rpmsg_ns.c | 110 +++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 206 ++++++++++--------------------- include/linux/rpmsg.h | 93 ++++++++++++-- include/linux/rpmsg_byteorder.h | 67 ++++++++++ include/linux/rpmsg_ns.h | 79 ++++++++++++ include/uapi/linux/rpmsg.h | 3 + include/uapi/linux/rpmsg_types.h | 11 ++ 11 files changed, 481 insertions(+), 168 deletions(-) create mode 100644 drivers/rpmsg/rpmsg_ns.c create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/linux/rpmsg_ns.h create mode 100644 include/uapi/linux/rpmsg_types.h
Signature · 1 line
2.25.1
Mathieu Poirier
maintainerPATCH v2 1/9 rpmsg: Move rpmsg_endpoint_ops to rpmsg.h
Move structure rpmsg_endpoint_ops to header rpmsg.h so that it can be used by other entities.
--- drivers/rpmsg/rpmsg_internal.h | 19 ------------------- include/linux/rpmsg.h | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 22 deletions(-)
drivers/rpmsg/rpmsg_internal.h +0 -19
@@ -18,25 +18,6 @@#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, required -* @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: see @rpmsg_destroy_ept(), required
include/linux/rpmsg.h +21 -3
@@ -22,7 +22,6 @@struct rpmsg_device ;struct rpmsg_endpoint ; -struct rpmsg_device_ops ;struct rpmsg_endpoint_ops ;/**
@@ -37,6 +36,27 @@ struct rpmsg_channel_info {u32 dst; }; +typedef int (*rpmsg_rx_cb_t )(struct rpmsg_device *,void *,int ,void *,u32 ); + +/** +* struct rpmsg_device_ops - indirection table for the rpmsg_device operations +* @create_ept: create backend-specific endpoint, required +* @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); +}; +/** * rpmsg_device - device that belong to the rpmsg bus * @dev: the device struct
@@ -59,8 +79,6 @@ struct rpmsg_device {const struct rpmsg_device_ops *ops; }; -typedef int (*rpmsg_rx_cb_t )(struct rpmsg_device *,void *,int ,void *,u32 ); -/** * struct rpmsg_endpoint - binds a local rpmsg address to its user * @rpdev: rpmsg channel device
Signature · 1 line
2.25.1
Re: [PATCH v2 1/9] rpmsg: Move rpmsg_endpoint_ops to rpmsg.h
Quoted 81 lines · Mathieu Poirier
Move structure
rpmsg_endpoint_opsto headerrpmsg.hso that it can be used by other entities.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/rpmsg_internal.h | 19 ------------------- include/linux/rpmsg.h | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 22 deletions(-)drivers/rpmsg/rpmsg_internal.h +0
-19@@ -18,25 +18,6 @@#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, required -* @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: see @rpmsg_destroy_ept(), required include/linux/rpmsg.h +21
-1@@ -22,7 +22,6 @@struct rpmsg_device ;struct rpmsg_endpoint ; -struct rpmsg_device_ops ;struct rpmsg_endpoint_ops ;/** @@ -37,6 +36,27 @@ struct rpmsg_channel_info {u32 dst; }; +typedef int (*rpmsg_rx_cb_t )(struct rpmsg_device *,void *,int ,void *,u32 ); + +/** +* struct rpmsg_device_ops - indirection table for the rpmsg_device operations +* @create_ept: create backend-specific endpoint, required +* @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); +}; +/** * rpmsg_device - device that belong to the rpmsg bus * @dev: the device struct
include/linux/rpmsg.h struct rpmsg_device { · line 84
Quoted 8 lines
include/linux/rpmsg.h +0
-2@@ -59,8 +79,6 @@ struct rpmsg_device {const struct rpmsg_device_ops *ops; }; -typedef int (*rpmsg_rx_cb_t )(struct rpmsg_device *,void *,int ,void *,u32 ); -/** * struct rpmsg_endpoint - binds a local rpmsg address to its user * @rpdev: rpmsg channel device
Thanks,
Arnaud
Mathieu Poirier
maintainerPATCH v2 2/9 rpmsg: Introduce __rpmsg{16|32|64} types
In reply to Mathieu PoirierIntroduce __rpmsg{16|32|64} types along with byte order conversion functions based on an rpmsg_device operation as a foundation to make RPMSG modular and transport agnostic.
--- include/linux/rpmsg.h | 51 ++++++++++++++++++++++++ include/linux/rpmsg_byteorder.h | 67 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg_types.h | 11 ++++++ 3 files changed, 129 insertions(+) create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/uapi/linux/rpmsg_types.h
include/linux/rpmsg.h +51 -0
@@ -17,6 +17,7 @@#include <linux/kref.h> #include <linux/mutex.h> #include <linux/poll.h> +#include <linux/rpmsg_byteorder.h> #define RPMSG_ADDR_ANY 0xFFFFFFFF
@@ -40,6 +41,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);/** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations +* @is_little_endian: returns true if using little endian byte ordering * @create_ept: create backend-specific endpoint, required * @announce_create: announce presence of new channel, optional * @announce_destroy: announce destruction of channel, optional
@@ -49,6 +51,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);* advertise new channels implicitly by creating the endpoints. */ struct rpmsg_device_ops { +bool (*is_little_endian)(struct rpmsg_device *rpdev);struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,rpmsg_rx_cb_t cb,void *priv,struct rpmsg_channel_info chinfo);
@@ -129,6 +132,54 @@ struct rpmsg_driver {int (*callback)(struct rpmsg_device *,void *,int ,void *,u32 ); }; +static inline u16 rpmsg16_to_cpu (struct rpmsg_device *rpdev,__rpmsg16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg16_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg16_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg16 cpu_to_rpmsg16 (struct rpmsg_device *rpdev,u16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg16 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg16 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u32 rpmsg32_to_cpu (struct rpmsg_device *rpdev,__rpmsg32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg32_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg32_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg32 cpu_to_rpmsg32 (struct rpmsg_device *rpdev,u32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg32 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg32 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u64 rpmsg64_to_cpu (struct rpmsg_device *rpdev,__rpmsg64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg64_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg64_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg64 cpu_to_rpmsg64 (struct rpmsg_device *rpdev,u64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg64 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg64 (rpdev->ops->is_little_endian (rpdev), val); +} +#if IS_ENABLED (CONFIG_RPMSG )int register_rpmsg_device (struct rpmsg_device *dev);
include/linux/rpmsg_byteorder.h new file +67 -0
67 lines not on this page · raw message
include/uapi/linux/rpmsg_types.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_RPMSG_TYPES_H +#define _UAPI_LINUX_RPMSG_TYPES_H + +#include <linux/types.h> + +typedef __u16 __bitwise __rpmsg16 ; +typedef __u32 __bitwise __rpmsg32 ; +typedef __u64 __bitwise __rpmsg64 ; + +#endif /* _UAPI_LINUX_RPMSG_TYPES_H */
Signature · 1 line
2.25.1
Re: [PATCH v2 2/9] rpmsg: Introduce __rpmsg{16|32|64} types
Hi Mathieu,
Quoted 110 lines · Mathieu Poirier
Introduce __rpmsg{16|32|64} types along with byte order conversion functions based on an
rpmsg_deviceoperation as a foundation to make RPMSG modular and transport agnostic.Suggested-by Guennadi Liakhovetski <[email protected]>Signed-off-by Mathieu Poirier <[email protected]>--- include/linux/rpmsg.h | 51 ++++++++++++++++++++++++ include/linux/rpmsg_byteorder.h | 67 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg_types.h | 11 ++++++ 3 files changed, 129 insertions(+) create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/uapi/linux/rpmsg_types.hinclude/linux/rpmsg.h +51
-0@@ -17,6 +17,7 @@#include <linux/kref.h> #include <linux/mutex.h> #include <linux/poll.h> +#include <linux/rpmsg_byteorder.h> #define RPMSG_ADDR_ANY 0xFFFFFFFF@@ -40,6 +41,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);/** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations +* @is_little_endian: returns true if using little endian byte ordering * @create_ept: create backend-specific endpoint, required * @announce_create: announce presence of new channel, optional * @announce_destroy: announce destruction of channel, optional @@ -49,6 +51,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);* advertise new channels implicitly by creating the endpoints. */ struct rpmsg_device_ops { +bool (*is_little_endian)(struct rpmsg_device *rpdev);struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,rpmsg_rx_cb_t cb,void *priv,struct rpmsg_channel_info chinfo);@@ -129,6 +132,54 @@ struct rpmsg_driver {int (*callback)(struct rpmsg_device *,void *,int ,void *,u32 ); }; +static inline u16 rpmsg16_to_cpu (struct rpmsg_device *rpdev,__rpmsg16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg16_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg16_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg16 cpu_to_rpmsg16 (struct rpmsg_device *rpdev,u16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg16 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg16 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u32 rpmsg32_to_cpu (struct rpmsg_device *rpdev,__rpmsg32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg32_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg32_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg32 cpu_to_rpmsg32 (struct rpmsg_device *rpdev,u32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg32 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg32 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u64 rpmsg64_to_cpu (struct rpmsg_device *rpdev,__rpmsg64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg64_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg64_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg64 cpu_to_rpmsg64 (struct rpmsg_device *rpdev,u64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg64 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg64 (rpdev->ops->is_little_endian (rpdev), val); +} +#if IS_ENABLED (CONFIG_RPMSG )int register_rpmsg_device (struct rpmsg_device *dev);include/linux/rpmsg_byteorder.h new file +7
-0@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Follows implementation found in linux/virtio_byteorder.h +*/ +#ifndef _LINUX_RPMSG_BYTEORDER_H +#define _LINUX_RPMSG_BYTEORDER_H +#include <linux/types.h>
include/linux/rpmsg_byteorder.h line 17
Quoted 10 lines
include/linux/rpmsg_byteorder.h new file +10
-0+#include <uapi/linux/rpmsg_types.h> + +static inline bool rpmsg_is_little_endian (void ) +{ +#ifdef __LITTLE_ENDIAN +return true; +#else +return false; +#endif +}
A suggestion:
static inline bool rpmsg_is_little_endian(void)
#if defined(__BYTE_ORDER)
# if __BYTE_ORDER == __BIG_ENDIAN
return true; # elif __BYTE_ORDER == __LITTLE_ENDIAN return false; # else # warning "unknown endianess, set to little by default" return true;
# endif
#endif
}
Otherwise
Thanks,
Arnaud
Quoted 68 lines
include/linux/rpmsg_byteorder.h new file +50
-0+ +static inline u16 __rpmsg16_to_cpu (bool little_endian,__rpmsg16 val) +{ +if (little_endian) +return le16_to_cpu ((__force __le16 )val); +else +return be16_to_cpu ((__force __be16 )val); +} + +static inline __rpmsg16 __cpu_to_rpmsg16 (bool little_endian,u16 val) +{ +if (little_endian) +return (__force __rpmsg16 )cpu_to_le16 (val); +else +return (__force __rpmsg16 )cpu_to_be16 (val); +} + +static inline u32 __rpmsg32_to_cpu (bool little_endian,__rpmsg32 val) +{ +if (little_endian) +return le32_to_cpu ((__force __le32 )val); +else +return be32_to_cpu ((__force __be32 )val); +} + +static inline __rpmsg32 __cpu_to_rpmsg32 (bool little_endian,u32 val) +{ +if (little_endian) +return (__force __rpmsg32 )cpu_to_le32 (val); +else +return (__force __rpmsg32 )cpu_to_be32 (val); +} + +static inline u64 __rpmsg64_to_cpu (bool little_endian,__rpmsg64 val) +{ +if (little_endian) +return le64_to_cpu ((__force __le64 )val); +else +return be64_to_cpu ((__force __be64 )val); +} + +static inline __rpmsg64 __cpu_to_rpmsg64 (bool little_endian,u64 val) +{ +if (little_endian) +return (__force __rpmsg64 )cpu_to_le64 (val); +else +return (__force __rpmsg64 )cpu_to_be64 (val); +} + +#endif /* _LINUX_RPMSG_BYTEORDER_H */ include/uapi/linux/rpmsg_types.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_RPMSG_TYPES_H +#define _UAPI_LINUX_RPMSG_TYPES_H + +#include <linux/types.h> + +typedef __u16 __bitwise __rpmsg16 ; +typedef __u32 __bitwise __rpmsg32 ; +typedef __u64 __bitwise __rpmsg64 ; + +#endif /* _UAPI_LINUX_RPMSG_TYPES_H */
Mathieu Poirier
maintainerRe: [PATCH v2 2/9] rpmsg: Introduce __rpmsg{16|32|64} types
Good day,
Quoted 135 lines · Arnaud POULIQUEN
Hi Mathieu,
Quoted 110 lines · Mathieu Poirier
Introduce __rpmsg{16|32|64} types along with byte order conversion functions based on an
rpmsg_deviceoperation as a foundation to make RPMSG modular and transport agnostic.Suggested-by Guennadi Liakhovetski <[email protected]>Signed-off-by Mathieu Poirier <[email protected]>--- include/linux/rpmsg.h | 51 ++++++++++++++++++++++++ include/linux/rpmsg_byteorder.h | 67 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg_types.h | 11 ++++++ 3 files changed, 129 insertions(+) create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/uapi/linux/rpmsg_types.hinclude/linux/rpmsg.h +51
-0@@ -17,6 +17,7 @@#include <linux/kref.h> #include <linux/mutex.h> #include <linux/poll.h> +#include <linux/rpmsg_byteorder.h> #define RPMSG_ADDR_ANY 0xFFFFFFFF@@ -40,6 +41,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);/** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations +* @is_little_endian: returns true if using little endian byte ordering * @create_ept: create backend-specific endpoint, required * @announce_create: announce presence of new channel, optional * @announce_destroy: announce destruction of channel, optional @@ -49,6 +51,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);* advertise new channels implicitly by creating the endpoints. */ struct rpmsg_device_ops { +bool (*is_little_endian)(struct rpmsg_device *rpdev);struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,rpmsg_rx_cb_t cb,void *priv,struct rpmsg_channel_info chinfo);@@ -129,6 +132,54 @@ struct rpmsg_driver {int (*callback)(struct rpmsg_device *,void *,int ,void *,u32 ); }; +static inline u16 rpmsg16_to_cpu (struct rpmsg_device *rpdev,__rpmsg16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg16_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg16_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg16 cpu_to_rpmsg16 (struct rpmsg_device *rpdev,u16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg16 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg16 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u32 rpmsg32_to_cpu (struct rpmsg_device *rpdev,__rpmsg32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg32_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg32_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg32 cpu_to_rpmsg32 (struct rpmsg_device *rpdev,u32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg32 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg32 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u64 rpmsg64_to_cpu (struct rpmsg_device *rpdev,__rpmsg64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg64_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg64_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg64 cpu_to_rpmsg64 (struct rpmsg_device *rpdev,u64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg64 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg64 (rpdev->ops->is_little_endian (rpdev), val); +} +#if IS_ENABLED (CONFIG_RPMSG )int register_rpmsg_device (struct rpmsg_device *dev);include/linux/rpmsg_byteorder.h new file +7
-0@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Follows implementation found in linux/virtio_byteorder.h +*/ +#ifndef _LINUX_RPMSG_BYTEORDER_H +#define _LINUX_RPMSG_BYTEORDER_H +#include <linux/types.h> include/linux/rpmsg_byteorder.h line 17
Quoted 10 lines
include/linux/rpmsg_byteorder.h new file +10
-0+#include <uapi/linux/rpmsg_types.h> + +static inline bool rpmsg_is_little_endian (void ) +{ +#ifdef __LITTLE_ENDIAN +return true; +#else +return false; +#endif +}A suggestion:
static inline bool
rpmsg_is_little_endian(void)
#ifdefined(__BYTE_ORDER)
# if__BYTE_ORDER==__BIG_ENDIANreturn true; # elif __BYTE_ORDER == __LITTLE_ENDIAN return false; # else # warning "unknown endianess, set to little by default" return true;
Quoted 3 lines
# endif
#endif
}
I found that __BYTE_ORDER is not defined stm32mp157 - have you used it before?
Quoted 76 lines
Otherwise
Reviewed-by Arnaud Pouliquen <[email protected]>Thanks,
ArnaudQuoted 68 lines
include/linux/rpmsg_byteorder.h new file +50
-0+ +static inline u16 __rpmsg16_to_cpu (bool little_endian,__rpmsg16 val) +{ +if (little_endian) +return le16_to_cpu ((__force __le16 )val); +else +return be16_to_cpu ((__force __be16 )val); +} + +static inline __rpmsg16 __cpu_to_rpmsg16 (bool little_endian,u16 val) +{ +if (little_endian) +return (__force __rpmsg16 )cpu_to_le16 (val); +else +return (__force __rpmsg16 )cpu_to_be16 (val); +} + +static inline u32 __rpmsg32_to_cpu (bool little_endian,__rpmsg32 val) +{ +if (little_endian) +return le32_to_cpu ((__force __le32 )val); +else +return be32_to_cpu ((__force __be32 )val); +} + +static inline __rpmsg32 __cpu_to_rpmsg32 (bool little_endian,u32 val) +{ +if (little_endian) +return (__force __rpmsg32 )cpu_to_le32 (val); +else +return (__force __rpmsg32 )cpu_to_be32 (val); +} + +static inline u64 __rpmsg64_to_cpu (bool little_endian,__rpmsg64 val) +{ +if (little_endian) +return le64_to_cpu ((__force __le64 )val); +else +return be64_to_cpu ((__force __be64 )val); +} + +static inline __rpmsg64 __cpu_to_rpmsg64 (bool little_endian,u64 val) +{ +if (little_endian) +return (__force __rpmsg64 )cpu_to_le64 (val); +else +return (__force __rpmsg64 )cpu_to_be64 (val); +} + +#endif /* _LINUX_RPMSG_BYTEORDER_H */ include/uapi/linux/rpmsg_types.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_RPMSG_TYPES_H +#define _UAPI_LINUX_RPMSG_TYPES_H + +#include <linux/types.h> + +typedef __u16 __bitwise __rpmsg16 ; +typedef __u32 __bitwise __rpmsg32 ; +typedef __u64 __bitwise __rpmsg64 ; + +#endif /* _UAPI_LINUX_RPMSG_TYPES_H */
Re: [PATCH v2 2/9] rpmsg: Introduce __rpmsg{16|32|64} types
Quoted 142 lines · Mathieu Poirier
Good day,
Quoted 135 lines · Arnaud POULIQUEN
Hi Mathieu,
Quoted 110 lines · Mathieu Poirier
Introduce __rpmsg{16|32|64} types along with byte order conversion functions based on an
rpmsg_deviceoperation as a foundation to make RPMSG modular and transport agnostic.Suggested-by Guennadi Liakhovetski <[email protected]>Signed-off-by Mathieu Poirier <[email protected]>--- include/linux/rpmsg.h | 51 ++++++++++++++++++++++++ include/linux/rpmsg_byteorder.h | 67 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg_types.h | 11 ++++++ 3 files changed, 129 insertions(+) create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/uapi/linux/rpmsg_types.hinclude/linux/rpmsg.h +51
-0@@ -17,6 +17,7 @@#include <linux/kref.h> #include <linux/mutex.h> #include <linux/poll.h> +#include <linux/rpmsg_byteorder.h> #define RPMSG_ADDR_ANY 0xFFFFFFFF@@ -40,6 +41,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);/** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations +* @is_little_endian: returns true if using little endian byte ordering * @create_ept: create backend-specific endpoint, required * @announce_create: announce presence of new channel, optional * @announce_destroy: announce destruction of channel, optional @@ -49,6 +51,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);* advertise new channels implicitly by creating the endpoints. */ struct rpmsg_device_ops { +bool (*is_little_endian)(struct rpmsg_device *rpdev);struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev,rpmsg_rx_cb_t cb,void *priv,struct rpmsg_channel_info chinfo);@@ -129,6 +132,54 @@ struct rpmsg_driver {int (*callback)(struct rpmsg_device *,void *,int ,void *,u32 ); }; +static inline u16 rpmsg16_to_cpu (struct rpmsg_device *rpdev,__rpmsg16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg16_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg16_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg16 cpu_to_rpmsg16 (struct rpmsg_device *rpdev,u16 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg16 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg16 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u32 rpmsg32_to_cpu (struct rpmsg_device *rpdev,__rpmsg32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg32_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg32_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg32 cpu_to_rpmsg32 (struct rpmsg_device *rpdev,u32 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg32 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg32 (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline u64 rpmsg64_to_cpu (struct rpmsg_device *rpdev,__rpmsg64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __rpmsg64_to_cpu (rpmsg_is_little_endian (), val); +else +return __rpmsg64_to_cpu (rpdev->ops->is_little_endian (rpdev), val); +} + +static inline __rpmsg64 cpu_to_rpmsg64 (struct rpmsg_device *rpdev,u64 val) +{ +if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) +return __cpu_to_rpmsg64 (rpmsg_is_little_endian (), val); +else +return __cpu_to_rpmsg64 (rpdev->ops->is_little_endian (rpdev), val); +} +#if IS_ENABLED (CONFIG_RPMSG )int register_rpmsg_device (struct rpmsg_device *dev);include/linux/rpmsg_byteorder.h new file +7
-0@@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Follows implementation found in linux/virtio_byteorder.h +*/ +#ifndef _LINUX_RPMSG_BYTEORDER_H +#define _LINUX_RPMSG_BYTEORDER_H +#include <linux/types.h> include/linux/rpmsg_byteorder.h line 17
Quoted 10 lines
include/linux/rpmsg_byteorder.h new file +10
-0+#include <uapi/linux/rpmsg_types.h> + +static inline bool rpmsg_is_little_endian (void ) +{ +#ifdef __LITTLE_ENDIAN +return true; +#else +return false; +#endif +}A suggestion:
static inline bool
rpmsg_is_little_endian(void)
#ifdefined(__BYTE_ORDER)
# if__BYTE_ORDER==__BIG_ENDIANreturn true; # elif __BYTE_ORDER == __LITTLE_ENDIAN return false; # else # warning "unknown endianess, set to little by default" return true;Quoted 3 lines
# endif
#endif
}
Quoted 1 line
I found that
__BYTE_ORDERis not defined stm32mp157 - have you used it before?
Good point! it seems not defined for some architectures...something strange is that it is used in some generic code (e.g.[1]) but it works considering little by default...
I saw this implementation in Linux kernel code, for instance [2]. that's said, __LITTLE_ENDIAN or __BIG_ENDIAN seems always defined regarding [3]. So just forget this suggestion...
[1]https://elixir.bootlin.com/linux/latest/source/include/math-emu/double.h#L59 [2]https://elixir.bootlin.com/linux/latest/source/tools/lib/bpf/btf.c#L506 [3]https://elixir.bootlin.com/linux/latest/source/include/linux/kconfig.h#L12
Quoted 77 lines
Quoted 77 lines
Otherwise
Reviewed-by Arnaud Pouliquen <[email protected]>Thanks,
ArnaudQuoted 68 lines
include/linux/rpmsg_byteorder.h new file +50
-0+ +static inline u16 __rpmsg16_to_cpu (bool little_endian,__rpmsg16 val) +{ +if (little_endian) +return le16_to_cpu ((__force __le16 )val); +else +return be16_to_cpu ((__force __be16 )val); +} + +static inline __rpmsg16 __cpu_to_rpmsg16 (bool little_endian,u16 val) +{ +if (little_endian) +return (__force __rpmsg16 )cpu_to_le16 (val); +else +return (__force __rpmsg16 )cpu_to_be16 (val); +} + +static inline u32 __rpmsg32_to_cpu (bool little_endian,__rpmsg32 val) +{ +if (little_endian) +return le32_to_cpu ((__force __le32 )val); +else +return be32_to_cpu ((__force __be32 )val); +} + +static inline __rpmsg32 __cpu_to_rpmsg32 (bool little_endian,u32 val) +{ +if (little_endian) +return (__force __rpmsg32 )cpu_to_le32 (val); +else +return (__force __rpmsg32 )cpu_to_be32 (val); +} + +static inline u64 __rpmsg64_to_cpu (bool little_endian,__rpmsg64 val) +{ +if (little_endian) +return le64_to_cpu ((__force __le64 )val); +else +return be64_to_cpu ((__force __be64 )val); +} + +static inline __rpmsg64 __cpu_to_rpmsg64 (bool little_endian,u64 val) +{ +if (little_endian) +return (__force __rpmsg64 )cpu_to_le64 (val); +else +return (__force __rpmsg64 )cpu_to_be64 (val); +} + +#endif /* _LINUX_RPMSG_BYTEORDER_H */ include/uapi/linux/rpmsg_types.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_RPMSG_TYPES_H +#define _UAPI_LINUX_RPMSG_TYPES_H + +#include <linux/types.h> + +typedef __u16 __bitwise __rpmsg16 ; +typedef __u32 __bitwise __rpmsg32 ; +typedef __u64 __bitwise __rpmsg64 ; + +#endif /* _UAPI_LINUX_RPMSG_TYPES_H */
Mathieu Poirier
maintainerPATCH v2 3/9 rpmsg: virtio: Move from virtio to rpmsg byte conversion
In reply to Mathieu PoirierUse rpmsg byte conversion functions in order for the RPMSG headers and generic functions to be used by external entities.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 60 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 25 deletions(-)
drivers/rpmsg/virtio_rpmsg_bus.c +35 -25
@@ -19,11 +19,11 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> +#include <linux/rpmsg_byteorder.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/virtio.h> -#include <linux/virtio_byteorder.h> #include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h>
@@ -85,11 +85,11 @@ struct virtproc_info {* Every message sent(/received) on the rpmsg bus begins with this header. */ struct rpmsg_hdr { -__virtio32 src; -__virtio32 dst; -__virtio32 reserved; -__virtio16 len; -__virtio16 flags; +__rpmsg32 src; +__rpmsg32 dst; +__rpmsg32 reserved; +__rpmsg16 len; +__rpmsg16 flags;u8 data[]; } __packed;
@@ -107,8 +107,8 @@ struct rpmsg_hdr {*/ struct rpmsg_ns_msg {char name[RPMSG_NAME_SIZE ]; -__virtio32 addr; -__virtio32 flags; +__rpmsg32 addr; +__rpmsg32 flags; } __packed;/**
@@ -280,6 +280,14 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,return NULL ; } +static bool virtio_rpmsg_is_little_endian (struct rpmsg_device *rpdev) +{ +struct virtio_rpmsg_channel *vch =to_virtio_rpmsg_channel (rpdev); +struct virtproc_info *vrp = vch->vrp; + +return virtio_is_little_endian (vrp->vdev); +} + static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv,
@@ -336,8 +344,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)struct rpmsg_ns_msg nsm;strncpy (nsm.name, rpdev->id.name,RPMSG_NAME_SIZE ); - nsm.addr =cpu_to_virtio32 (vrp->vdev, rpdev->ept->addr); - nsm.flags =cpu_to_virtio32 (vrp->vdev,RPMSG_NS_CREATE ); + nsm.addr =cpu_to_rpmsg32 (rpdev, rpdev->ept->addr); + nsm.flags =cpu_to_rpmsg32 (rpdev,RPMSG_NS_CREATE ); err =rpmsg_sendto (rpdev->ept, &nsm,sizeof (nsm),RPMSG_NS_ADDR );if (err)
@@ -360,8 +368,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)struct rpmsg_ns_msg nsm;strncpy (nsm.name, rpdev->id.name,RPMSG_NAME_SIZE ); - nsm.addr =cpu_to_virtio32 (vrp->vdev, rpdev->ept->addr); - nsm.flags =cpu_to_virtio32 (vrp->vdev,RPMSG_NS_DESTROY ); + nsm.addr =cpu_to_rpmsg32 (rpdev, rpdev->ept->addr); + nsm.flags =cpu_to_rpmsg32 (rpdev,RPMSG_NS_DESTROY ); err =rpmsg_sendto (rpdev->ept, &nsm,sizeof (nsm),RPMSG_NS_ADDR );if (err)
@@ -372,6 +380,7 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) }static const struct rpmsg_device_ops virtio_rpmsg_ops = { + .is_little_endian = virtio_rpmsg_is_little_endian, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy,
@@ -613,10 +622,10 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, } } - msg->len =cpu_to_virtio16 (vrp->vdev, len); + msg->len =cpu_to_rpmsg16 (rpdev, len); msg->flags =0 ; - msg->src =cpu_to_virtio32 (vrp->vdev, src); - msg->dst =cpu_to_virtio32 (vrp->vdev, dst); + msg->src =cpu_to_rpmsg32 (rpdev, src); + msg->dst =cpu_to_rpmsg32 (rpdev, dst); msg->reserved =0 ;memcpy (msg->data, data, len);
@@ -705,14 +714,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, {struct rpmsg_endpoint *ept;struct scatterlist sg; -unsigned int msg_len =virtio16_to_cpu (vrp->vdev, msg->len); +bool little_endian =rpmsg_is_little_endian (); +unsigned int msg_len =__rpmsg16_to_cpu (little_endian, msg->len);int err;dev_dbg (dev,"From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n" , -virtio32_to_cpu (vrp->vdev, msg->src), -virtio32_to_cpu (vrp->vdev, msg->dst), msg_len, -virtio16_to_cpu (vrp->vdev, msg->flags), -virtio32_to_cpu (vrp->vdev, msg->reserved)); +__rpmsg32_to_cpu (little_endian, msg->src), +__rpmsg32_to_cpu (little_endian, msg->dst), msg_len, +__rpmsg16_to_cpu (little_endian, msg->flags), +__rpmsg32_to_cpu (little_endian, msg->reserved));#if defined(CONFIG_DYNAMIC_DEBUG )dynamic_hex_dump ("rpmsg_virtio RX: " ,DUMP_PREFIX_NONE ,16 ,1 , msg,sizeof (*msg) + msg_len, true);
@@ -731,7 +741,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,/* use the dst addr to fetch the callback of the appropriate user */ mutex_lock (&vrp->endpoints_lock); - ept =idr_find (&vrp->endpoints,virtio32_to_cpu (vrp->vdev, msg->dst)); + ept =idr_find (&vrp->endpoints,__rpmsg32_to_cpu (little_endian, msg->dst));/* let's make sure no one deallocates ept while we use it */ if (ept)
@@ -745,7 +755,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,if (ept->cb) ept->cb (ept->rpdev, msg->data, msg_len, ept->priv, -virtio32_to_cpu (vrp->vdev, msg->src)); +__rpmsg32_to_cpu (little_endian, msg->src));mutex_unlock (&ept->cb_lock);
@@ -853,13 +863,13 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,strncpy (chinfo.name, msg->name,sizeof (chinfo.name)); chinfo.src =RPMSG_ADDR_ANY ; - chinfo.dst =virtio32_to_cpu (vrp->vdev, msg->addr); + chinfo.dst =rpmsg32_to_cpu (rpdev, msg->addr);dev_info (dev,"%sing channel %s addr 0x%x\n" , -virtio32_to_cpu (vrp->vdev, msg->flags) &RPMSG_NS_DESTROY ? +rpmsg32_to_cpu (rpdev, msg->flags) &RPMSG_NS_DESTROY ?"destroy" :"creat" , msg->name, chinfo.dst); -if (virtio32_to_cpu (vrp->vdev, msg->flags) &RPMSG_NS_DESTROY ) { +if (rpmsg32_to_cpu (rpdev, msg->flags) &RPMSG_NS_DESTROY ) { ret =rpmsg_unregister_device (&vrp->vdev->dev, &chinfo);if (ret)dev_err (dev,"rpmsg_destroy_channel failed: %d\n" , ret);
Signature · 1 line
2.25.1
Re: [PATCH v2 3/9] rpmsg: virtio: Move from virtio to rpmsg byte conversion
Quoted 54 lines · Mathieu Poirier
Use rpmsg byte conversion functions in order for the RPMSG headers and generic functions to be used by external entities.
Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 60 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 25 deletions(-)drivers/rpmsg/virtio_rpmsg_bus.c +8
-8@@ -19,11 +19,11 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> +#include <linux/rpmsg_byteorder.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/virtio.h> -#include <linux/virtio_byteorder.h> #include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h> @@ -85,11 +85,11 @@ struct virtproc_info {* Every message sent(/received) on the rpmsg bus begins with this header. */ struct rpmsg_hdr { -__virtio32 src; -__virtio32 dst; -__virtio32 reserved; -__virtio16 len; -__virtio16 flags; +__rpmsg32 src; +__rpmsg32 dst; +__rpmsg32 reserved; +__rpmsg16 len; +__rpmsg16 flags;u8 data[]; } __packed;@@ -107,8 +107,8 @@ struct rpmsg_hdr {*/ struct rpmsg_ns_msg {char name[RPMSG_NAME_SIZE ]; -__virtio32 addr; -__virtio32 flags; +__rpmsg32 addr; +__rpmsg32 flags; } __packed;/**
drivers/rpmsg/virtio_rpmsg_bus.c static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp, · line 289
Quoted 10 lines
drivers/rpmsg/virtio_rpmsg_bus.c +7
-0@@ -280,6 +280,14 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,return NULL ; } +static bool virtio_rpmsg_is_little_endian (struct rpmsg_device *rpdev) +{ +struct virtio_rpmsg_channel *vch =to_virtio_rpmsg_channel (rpdev); +struct virtproc_info *vrp = vch->vrp; + +return virtio_is_little_endian (vrp->vdev); +}
Regarding this i wonder if the endianess could not be a rpmsg_device field that would be set on __rpmsg_create_channel?
I don't think that the endianess could change, so perhaps no need to call ops for each conversion using interface implemented in rpmsg.h...
But perhaps I missed something?
Quoted 56 lines
drivers/rpmsg/virtio_rpmsg_bus.c +11
-8+ static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv,@@ -336,8 +344,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)struct rpmsg_ns_msg nsm;strncpy (nsm.name, rpdev->id.name,RPMSG_NAME_SIZE ); - nsm.addr =cpu_to_virtio32 (vrp->vdev, rpdev->ept->addr); - nsm.flags =cpu_to_virtio32 (vrp->vdev,RPMSG_NS_CREATE ); + nsm.addr =cpu_to_rpmsg32 (rpdev, rpdev->ept->addr); + nsm.flags =cpu_to_rpmsg32 (rpdev,RPMSG_NS_CREATE ); err =rpmsg_sendto (rpdev->ept, &nsm,sizeof (nsm),RPMSG_NS_ADDR );if (err)@@ -360,8 +368,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)struct rpmsg_ns_msg nsm;strncpy (nsm.name, rpdev->id.name,RPMSG_NAME_SIZE ); - nsm.addr =cpu_to_virtio32 (vrp->vdev, rpdev->ept->addr); - nsm.flags =cpu_to_virtio32 (vrp->vdev,RPMSG_NS_DESTROY ); + nsm.addr =cpu_to_rpmsg32 (rpdev, rpdev->ept->addr); + nsm.flags =cpu_to_rpmsg32 (rpdev,RPMSG_NS_DESTROY ); err =rpmsg_sendto (rpdev->ept, &nsm,sizeof (nsm),RPMSG_NS_ADDR );if (err)@@ -372,6 +380,7 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) }static const struct rpmsg_device_ops virtio_rpmsg_ops = { + .is_little_endian = virtio_rpmsg_is_little_endian, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy,@@ -613,10 +622,10 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, } } - msg->len =cpu_to_virtio16 (vrp->vdev, len); + msg->len =cpu_to_rpmsg16 (rpdev, len); msg->flags =0 ; - msg->src =cpu_to_virtio32 (vrp->vdev, src); - msg->dst =cpu_to_virtio32 (vrp->vdev, dst); + msg->src =cpu_to_rpmsg32 (rpdev, src); + msg->dst =cpu_to_rpmsg32 (rpdev, dst); msg->reserved =0 ;memcpy (msg->data, data, len);@@ -705,14 +714,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, {struct rpmsg_endpoint *ept;struct scatterlist sg; -unsigned int msg_len =virtio16_to_cpu (vrp->vdev, msg->len); +bool little_endian =rpmsg_is_little_endian (); +unsigned int msg_len =__rpmsg16_to_cpu (little_endian, msg->len);int err;
drivers/rpmsg/virtio_rpmsg_bus.c static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, · line 725
Quoted 10 lines
drivers/rpmsg/virtio_rpmsg_bus.c +4
-4dev_dbg (dev,"From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n" , -virtio32_to_cpu (vrp->vdev, msg->src), -virtio32_to_cpu (vrp->vdev, msg->dst), msg_len, -virtio16_to_cpu (vrp->vdev, msg->flags), -virtio32_to_cpu (vrp->vdev, msg->reserved)); +__rpmsg32_to_cpu (little_endian, msg->src), +__rpmsg32_to_cpu (little_endian, msg->dst), msg_len, +__rpmsg16_to_cpu (little_endian, msg->flags), +__rpmsg32_to_cpu (little_endian, msg->reserved));
Nitpicking: sometime rpmsgXX_to_cpu is used, sometime __rpmsgXX_to_cpu, Perhaps only one API should be used... But i don't see any blocking point to use both...:)
Thanks,
Arnaud
Quoted 39 lines
drivers/rpmsg/virtio_rpmsg_bus.c +5
-5#if defined(CONFIG_DYNAMIC_DEBUG )dynamic_hex_dump ("rpmsg_virtio RX: " ,DUMP_PREFIX_NONE ,16 ,1 , msg,sizeof (*msg) + msg_len, true);@@ -731,7 +741,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,/* use the dst addr to fetch the callback of the appropriate user */ mutex_lock (&vrp->endpoints_lock); - ept =idr_find (&vrp->endpoints,virtio32_to_cpu (vrp->vdev, msg->dst)); + ept =idr_find (&vrp->endpoints,__rpmsg32_to_cpu (little_endian, msg->dst));/* let's make sure no one deallocates ept while we use it */ if (ept)@@ -745,7 +755,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,if (ept->cb) ept->cb (ept->rpdev, msg->data, msg_len, ept->priv, -virtio32_to_cpu (vrp->vdev, msg->src)); +__rpmsg32_to_cpu (little_endian, msg->src));mutex_unlock (&ept->cb_lock);@@ -853,13 +863,13 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,strncpy (chinfo.name, msg->name,sizeof (chinfo.name)); chinfo.src =RPMSG_ADDR_ANY ; - chinfo.dst =virtio32_to_cpu (vrp->vdev, msg->addr); + chinfo.dst =rpmsg32_to_cpu (rpdev, msg->addr);dev_info (dev,"%sing channel %s addr 0x%x\n" , -virtio32_to_cpu (vrp->vdev, msg->flags) &RPMSG_NS_DESTROY ? +rpmsg32_to_cpu (rpdev, msg->flags) &RPMSG_NS_DESTROY ?"destroy" :"creat" , msg->name, chinfo.dst); -if (virtio32_to_cpu (vrp->vdev, msg->flags) &RPMSG_NS_DESTROY ) { +if (rpmsg32_to_cpu (rpdev, msg->flags) &RPMSG_NS_DESTROY ) { ret =rpmsg_unregister_device (&vrp->vdev->dev, &chinfo);if (ret)dev_err (dev,"rpmsg_destroy_channel failed: %d\n" , ret);
Mathieu Poirier
maintainerRe: [PATCH v2 3/9] rpmsg: virtio: Move from virtio to rpmsg byte conversion
Quoted 60 lines · Arnaud POULIQUEN
Quoted 57 lines · Mathieu Poirier
Use rpmsg byte conversion functions in order for the RPMSG headers and generic functions to be used by external entities.
Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 60 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 25 deletions(-)drivers/rpmsg/virtio_rpmsg_bus.c +8
-8@@ -19,11 +19,11 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> +#include <linux/rpmsg_byteorder.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/virtio.h> -#include <linux/virtio_byteorder.h> #include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h> @@ -85,11 +85,11 @@ struct virtproc_info {* Every message sent(/received) on the rpmsg bus begins with this header. */ struct rpmsg_hdr { -__virtio32 src; -__virtio32 dst; -__virtio32 reserved; -__virtio16 len; -__virtio16 flags; +__rpmsg32 src; +__rpmsg32 dst; +__rpmsg32 reserved; +__rpmsg16 len; +__rpmsg16 flags;u8 data[]; } __packed;@@ -107,8 +107,8 @@ struct rpmsg_hdr {*/ struct rpmsg_ns_msg {char name[RPMSG_NAME_SIZE ]; -__virtio32 addr; -__virtio32 flags; +__rpmsg32 addr; +__rpmsg32 flags; } __packed;/** @@ -280,6 +280,14 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,return NULL ; }
Quoted 12 lines
drivers/rpmsg/virtio_rpmsg_bus.c static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp, · line 289
Quoted 7 lines
drivers/rpmsg/virtio_rpmsg_bus.c +7
-0+static bool virtio_rpmsg_is_little_endian (struct rpmsg_device *rpdev) +{ +struct virtio_rpmsg_channel *vch =to_virtio_rpmsg_channel (rpdev); +struct virtproc_info *vrp = vch->vrp; + +return virtio_is_little_endian (vrp->vdev); +}Regarding this i wonder if the endianess could not be a
rpmsg_devicefield that would be set on__rpmsg_create_channel?
I don't think that the endianess could change, so perhaps no need to call ops for each conversion using interface implemented inrpmsg.h...
That's a valid point - I certainly don't expect the endianness to change dynamically.
Quoted 59 lines
But perhaps I missed something?
Quoted 57 lines
drivers/rpmsg/virtio_rpmsg_bus.c +11
-8+ static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv,@@ -336,8 +344,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)struct rpmsg_ns_msg nsm;strncpy (nsm.name, rpdev->id.name,RPMSG_NAME_SIZE ); - nsm.addr =cpu_to_virtio32 (vrp->vdev, rpdev->ept->addr); - nsm.flags =cpu_to_virtio32 (vrp->vdev,RPMSG_NS_CREATE ); + nsm.addr =cpu_to_rpmsg32 (rpdev, rpdev->ept->addr); + nsm.flags =cpu_to_rpmsg32 (rpdev,RPMSG_NS_CREATE ); err =rpmsg_sendto (rpdev->ept, &nsm,sizeof (nsm),RPMSG_NS_ADDR );if (err)@@ -360,8 +368,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)struct rpmsg_ns_msg nsm;strncpy (nsm.name, rpdev->id.name,RPMSG_NAME_SIZE ); - nsm.addr =cpu_to_virtio32 (vrp->vdev, rpdev->ept->addr); - nsm.flags =cpu_to_virtio32 (vrp->vdev,RPMSG_NS_DESTROY ); + nsm.addr =cpu_to_rpmsg32 (rpdev, rpdev->ept->addr); + nsm.flags =cpu_to_rpmsg32 (rpdev,RPMSG_NS_DESTROY ); err =rpmsg_sendto (rpdev->ept, &nsm,sizeof (nsm),RPMSG_NS_ADDR );if (err)@@ -372,6 +380,7 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) }static const struct rpmsg_device_ops virtio_rpmsg_ops = { + .is_little_endian = virtio_rpmsg_is_little_endian, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy,@@ -613,10 +622,10 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, } } - msg->len =cpu_to_virtio16 (vrp->vdev, len); + msg->len =cpu_to_rpmsg16 (rpdev, len); msg->flags =0 ; - msg->src =cpu_to_virtio32 (vrp->vdev, src); - msg->dst =cpu_to_virtio32 (vrp->vdev, dst); + msg->src =cpu_to_rpmsg32 (rpdev, src); + msg->dst =cpu_to_rpmsg32 (rpdev, dst); msg->reserved =0 ;memcpy (msg->data, data, len);@@ -705,14 +714,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, {struct rpmsg_endpoint *ept;struct scatterlist sg; -unsigned int msg_len =virtio16_to_cpu (vrp->vdev, msg->len); +bool little_endian =rpmsg_is_little_endian (); +unsigned int msg_len =__rpmsg16_to_cpu (little_endian, msg->len);int err;
Quoted 12 lines
drivers/rpmsg/virtio_rpmsg_bus.c static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, · line 725
Quoted 9 lines
drivers/rpmsg/virtio_rpmsg_bus.c +4
-4dev_dbg (dev,"From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n" , -virtio32_to_cpu (vrp->vdev, msg->src), -virtio32_to_cpu (vrp->vdev, msg->dst), msg_len, -virtio16_to_cpu (vrp->vdev, msg->flags), -virtio32_to_cpu (vrp->vdev, msg->reserved)); +__rpmsg32_to_cpu (little_endian, msg->src), +__rpmsg32_to_cpu (little_endian, msg->dst), msg_len, +__rpmsg16_to_cpu (little_endian, msg->flags), +__rpmsg32_to_cpu (little_endian, msg->reserved));Nitpicking: sometime
rpmsgXX_to_cpuis used, sometime__rpmsgXX_to_cpu, Perhaps only one API should be used... But i don't see any blocking point to use both...:)
Here we have to use __rpmsgXX_to_CPU() because the rpmsg_device is not available. It could be fixed but would require a serious amount of refactoring for little value. Moreover since this rpmsg_recv_single() is specific to the virtIO implementation the end result is the same.
Quoted 43 lines
Thanks,
ArnaudQuoted 39 lines
drivers/rpmsg/virtio_rpmsg_bus.c +5
-5#if defined(CONFIG_DYNAMIC_DEBUG )dynamic_hex_dump ("rpmsg_virtio RX: " ,DUMP_PREFIX_NONE ,16 ,1 , msg,sizeof (*msg) + msg_len, true);@@ -731,7 +741,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,/* use the dst addr to fetch the callback of the appropriate user */ mutex_lock (&vrp->endpoints_lock); - ept =idr_find (&vrp->endpoints,virtio32_to_cpu (vrp->vdev, msg->dst)); + ept =idr_find (&vrp->endpoints,__rpmsg32_to_cpu (little_endian, msg->dst));/* let's make sure no one deallocates ept while we use it */ if (ept)@@ -745,7 +755,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,if (ept->cb) ept->cb (ept->rpdev, msg->data, msg_len, ept->priv, -virtio32_to_cpu (vrp->vdev, msg->src)); +__rpmsg32_to_cpu (little_endian, msg->src));mutex_unlock (&ept->cb_lock);@@ -853,13 +863,13 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,strncpy (chinfo.name, msg->name,sizeof (chinfo.name)); chinfo.src =RPMSG_ADDR_ANY ; - chinfo.dst =virtio32_to_cpu (vrp->vdev, msg->addr); + chinfo.dst =rpmsg32_to_cpu (rpdev, msg->addr);dev_info (dev,"%sing channel %s addr 0x%x\n" , -virtio32_to_cpu (vrp->vdev, msg->flags) &RPMSG_NS_DESTROY ? +rpmsg32_to_cpu (rpdev, msg->flags) &RPMSG_NS_DESTROY ?"destroy" :"creat" , msg->name, chinfo.dst); -if (virtio32_to_cpu (vrp->vdev, msg->flags) &RPMSG_NS_DESTROY ) { +if (rpmsg32_to_cpu (rpdev, msg->flags) &RPMSG_NS_DESTROY ) { ret =rpmsg_unregister_device (&vrp->vdev->dev, &chinfo);if (ret)dev_err (dev,"rpmsg_destroy_channel failed: %d\n" , ret);
Mathieu Poirier
maintainerPATCH v2 4/9 rpmsg: Move rpmsg_hr and rpmsg_ns_msg to header file
In reply to Mathieu PoirierMove structures rpmsg_hdr and rpmsg_ns_msg to their own header file so that they can be used by other entities.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 58 ++---------------------------- include/linux/rpmsg_ns.h | 62 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg.h | 3 ++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 include/linux/rpmsg_ns.h
drivers/rpmsg/virtio_rpmsg_bus.c +2 -56
@@ -19,7 +19,7 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> -#include <linux/rpmsg_byteorder.h> +#include <linux/rpmsg_ns.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h>
@@ -27,6 +27,7 @@#include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h> +#include <uapi/linux/rpmsg.h> #include "rpmsg_internal.h"
@@ -70,58 +71,6 @@ struct virtproc_info {struct rpmsg_endpoint *ns_ept; }; -/* 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 { -__rpmsg32 src; -__rpmsg32 dst; -__rpmsg32 reserved; -__rpmsg16 len; -__rpmsg16 flags; -u8 data[]; -} __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 ]; -__rpmsg32 addr; -__rpmsg32 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 , -}; -/** * @vrp: the remote processor this channel belongs to */
@@ -162,9 +111,6 @@ struct virtio_rpmsg_channel {*/ #define RPMSG_RESERVED_ADDRESSES (1024) -/* Address 53 is reserved for advertising remote services */ -#define RPMSG_NS_ADDR (53) -static void virtio_rpmsg_destroy_ept (struct rpmsg_endpoint *ept);static int virtio_rpmsg_send (struct rpmsg_endpoint *ept,void *data,int len); static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
include/linux/rpmsg_ns.h new file +62 -0
62 lines not on this page · raw message
include/uapi/linux/rpmsg.h +3 -0
@@ -24,4 +24,7 @@ struct rpmsg_endpoint_info {#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info)#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2) +/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0/* RP supports name service notifications */ +#endif
Signature · 1 line
2.25.1
Re: [PATCH v2 4/9] rpmsg: Move rpmsg_hr and rpmsg_ns_msg to header file
Hi Mathieu,
Quoted 125 lines · Mathieu Poirier
Move structures
rpmsg_hdrandrpmsg_ns_msgto their own header file so that they can be used by other entities.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 58 ++---------------------------- include/linux/rpmsg_ns.h | 62 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg.h | 3 ++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 include/linux/rpmsg_ns.hdrivers/rpmsg/virtio_rpmsg_bus.c +2
-56@@ -19,7 +19,7 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> -#include <linux/rpmsg_byteorder.h> +#include <linux/rpmsg_ns.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h> @@ -27,6 +27,7 @@#include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h> +#include <uapi/linux/rpmsg.h> #include "rpmsg_internal.h" @@ -70,58 +71,6 @@ struct virtproc_info {struct rpmsg_endpoint *ns_ept; }; -/* 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 { -__rpmsg32 src; -__rpmsg32 dst; -__rpmsg32 reserved; -__rpmsg16 len; -__rpmsg16 flags; -u8 data[]; -} __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 ]; -__rpmsg32 addr; -__rpmsg32 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 , -}; -/** * @vrp: the remote processor this channel belongs to */ @@ -162,9 +111,6 @@ struct virtio_rpmsg_channel {*/ #define RPMSG_RESERVED_ADDRESSES (1024) -/* Address 53 is reserved for advertising remote services */ -#define RPMSG_NS_ADDR (53) -static void virtio_rpmsg_destroy_ept (struct rpmsg_endpoint *ept);static int virtio_rpmsg_send (struct rpmsg_endpoint *ept,void *data,int len); static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,include/linux/rpmsg_ns.h new file +18
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_RPMSG_NS_H +#define _LINUX_RPMSG_NS_H + +#include <linux/mod_devicetable.h> +#include <linux/types.h> +#include <linux/rpmsg_byteorder.h> + +/** +* 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 +*
include/linux/rpmsg_ns.h line 28
Quoted 10 lines
include/linux/rpmsg_ns.h new file +10
-0+* Every message sent(/received) on the rpmsg bus begins with this header. +*/ +struct rpmsg_hdr { +__rpmsg32 src; +__rpmsg32 dst; +__rpmsg32 reserved; +__rpmsg16 len; +__rpmsg16 flags; +u8 data[]; +} __packed;
This structure is not related to the rpmsg ns service but to the rpmsg bus. If this structure has to be exposed to rpmsg client should be in rpmsg.h, but Is there a need to expose it for now?
I suppose that it is for vhost...As the need will depends on the implementation, I would suggest leaving it internally and expose only if needed, in the related series.
Quoted 22 lines
include/linux/rpmsg_ns.h new file +22
-0+ +/** +* 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 ]; +__rpmsg32 addr; +__rpmsg32 flags; +} __packed; + +/** +* enum rpmsg_ns_flags - dynamic name service announcement flags +*
include/linux/rpmsg_ns.h line 60
Quoted 10 lines
include/linux/rpmsg_ns.h new file +10
-0+* @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 , +}; + +/* Address 53 is reserved for advertising remote services */ +#define RPMSG_NS_ADDR (53)
What about my proposal [1] to put this in rpmsg.h, to create a list of reserved Address
include/uapi/linux/rpmsg.h struct rpmsg_endpoint_info { · line 29
Quoted 13 lines
include/linux/rpmsg_ns.h new file +2
-0+ +#endif include/uapi/linux/rpmsg.h +3
-0@@ -24,4 +24,7 @@ struct rpmsg_endpoint_info {#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info)#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2) +/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0/* RP supports name service notifications */ +
Same suggestion here,i would drop this from this series
Thanks,
Arnaud
Quoted 2 lines
include/uapi/linux/rpmsg.h +0
-0#endif
Mathieu Poirier
maintainerRe: [PATCH v2 4/9] rpmsg: Move rpmsg_hr and rpmsg_ns_msg to header file
Quoted 137 lines · Arnaud POULIQUEN
Hi Mathieu,
Quoted 134 lines · Mathieu Poirier
Move structures
rpmsg_hdrandrpmsg_ns_msgto their own header file so that they can be used by other entities.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 58 ++---------------------------- include/linux/rpmsg_ns.h | 62 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg.h | 3 ++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 include/linux/rpmsg_ns.hdrivers/rpmsg/virtio_rpmsg_bus.c +2
-56@@ -19,7 +19,7 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> -#include <linux/rpmsg_byteorder.h> +#include <linux/rpmsg_ns.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h> @@ -27,6 +27,7 @@#include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h> +#include <uapi/linux/rpmsg.h> #include "rpmsg_internal.h" @@ -70,58 +71,6 @@ struct virtproc_info {struct rpmsg_endpoint *ns_ept; }; -/* 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 { -__rpmsg32 src; -__rpmsg32 dst; -__rpmsg32 reserved; -__rpmsg16 len; -__rpmsg16 flags; -u8 data[]; -} __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 ]; -__rpmsg32 addr; -__rpmsg32 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 , -}; -/** * @vrp: the remote processor this channel belongs to */ @@ -162,9 +111,6 @@ struct virtio_rpmsg_channel {*/ #define RPMSG_RESERVED_ADDRESSES (1024) -/* Address 53 is reserved for advertising remote services */ -#define RPMSG_NS_ADDR (53) -static void virtio_rpmsg_destroy_ept (struct rpmsg_endpoint *ept);static int virtio_rpmsg_send (struct rpmsg_endpoint *ept,void *data,int len); static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,include/linux/rpmsg_ns.h new file +27
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_RPMSG_NS_H +#define _LINUX_RPMSG_NS_H + +#include <linux/mod_devicetable.h> +#include <linux/types.h> +#include <linux/rpmsg_byteorder.h> + +/** + * 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 { + __rpmsg32 src; + __rpmsg32 dst; + __rpmsg32 reserved; + __rpmsg16 len; + __rpmsg16 flags; + u8 data[];
Quoted 9 lines
include/linux/rpmsg_ns.h line 28
Quoted 1 line
include/linux/rpmsg_ns.h new file +1
-0+} __packed;This structure is not related to the rpmsg ns service but to the rpmsg bus. If this structure has to be exposed to rpmsg client should be in
rpmsg.h, but Is there a need to expose it for now?
I suppose that it is for vhost...As the need will depends on the implementation, I would suggest leaving it internally and expose only if needed, in the related series.
I also thought about moving rpmsg_hdr to rpmsg.h but decided against because in most cases using the name space service usually means that a message header will be required. I also thought it would be easier to use, i.e include one header rather than two. That too is a little thin because anyone using a name service will also need to get access to rpmsg_device, which is in rpmsg.h.
I'm definitely not strongly opinionated on where it should go, or I can leave it in virtio_rpmsg_bus.c too...
Quoted 27 lines
Quoted 27 lines
include/linux/rpmsg_ns.h new file +27
-0+ +/** +* 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 ]; +__rpmsg32 addr; +__rpmsg32 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 ,
Quoted 8 lines
include/linux/rpmsg_ns.h line 60
Quoted 5 lines
include/linux/rpmsg_ns.h new file +5
-0+ RPMSG_NS_DESTROY = 1, +}; + +/* Address 53 is reserved for advertising remote services */ +#define RPMSG_NS_ADDR (53)What about my proposal [1] to put this in
rpmsg.h, to create a list of reserved Address
That too is a grey area... Moving RPMSG_NS_ADDR to rpmsg.h means we have a name service #define in rpmsg.h. I think that one should stay in rpmsg_ns.h.
Quoted 13 lines
[1] https://lkml.org/lkml/2020/7/31/442
Quoted 10 lines
include/linux/rpmsg_ns.h new file +2
-0+ +#endif include/uapi/linux/rpmsg.h +0
-0@@ -24,4 +24,7 @@ struct rpmsg_endpoint_info {#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info)#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2)
Quoted 5 lines
include/uapi/linux/rpmsg.h struct rpmsg_endpoint_info { · line 29
Quoted 3 lines
include/uapi/linux/rpmsg.h +3
-0+/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0/* RP supports name service notifications */ +Same suggestion here,i would drop this from this series
Will do.
Thanks for the feedback,
Mathieu
Quoted 6 lines
Thanks,
ArnaudQuoted 2 lines
include/uapi/linux/rpmsg.h +0
-0#endif
Re: [PATCH v2 4/9] rpmsg: Move rpmsg_hr and rpmsg_ns_msg to header file
Quoted 148 lines · Mathieu Poirier
Quoted 137 lines · Arnaud POULIQUEN
Hi Mathieu,
Quoted 134 lines · Mathieu Poirier
Move structures
rpmsg_hdrandrpmsg_ns_msgto their own header file so that they can be used by other entities.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 58 ++---------------------------- include/linux/rpmsg_ns.h | 62 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg.h | 3 ++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 include/linux/rpmsg_ns.hdrivers/rpmsg/virtio_rpmsg_bus.c +2
-56@@ -19,7 +19,7 @@#include <linux/mutex.h> #include <linux/of_device.h> #include <linux/rpmsg.h> -#include <linux/rpmsg_byteorder.h> +#include <linux/rpmsg_ns.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/sched.h> @@ -27,6 +27,7 @@#include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/wait.h> +#include <uapi/linux/rpmsg.h> #include "rpmsg_internal.h" @@ -70,58 +71,6 @@ struct virtproc_info {struct rpmsg_endpoint *ns_ept; }; -/* 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 { -__rpmsg32 src; -__rpmsg32 dst; -__rpmsg32 reserved; -__rpmsg16 len; -__rpmsg16 flags; -u8 data[]; -} __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 ]; -__rpmsg32 addr; -__rpmsg32 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 , -}; -/** * @vrp: the remote processor this channel belongs to */ @@ -162,9 +111,6 @@ struct virtio_rpmsg_channel {*/ #define RPMSG_RESERVED_ADDRESSES (1024) -/* Address 53 is reserved for advertising remote services */ -#define RPMSG_NS_ADDR (53) -static void virtio_rpmsg_destroy_ept (struct rpmsg_endpoint *ept);static int virtio_rpmsg_send (struct rpmsg_endpoint *ept,void *data,int len); static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,include/linux/rpmsg_ns.h new file +27
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_RPMSG_NS_H +#define _LINUX_RPMSG_NS_H + +#include <linux/mod_devicetable.h> +#include <linux/types.h> +#include <linux/rpmsg_byteorder.h> + +/** + * 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 { + __rpmsg32 src; + __rpmsg32 dst; + __rpmsg32 reserved; + __rpmsg16 len; + __rpmsg16 flags; + u8 data[];Quoted 9 lines
include/linux/rpmsg_ns.h line 28
Quoted 1 line
include/linux/rpmsg_ns.h new file +1
-0+} __packed;This structure is not related to the rpmsg ns service but to the rpmsg bus. If this structure has to be exposed to rpmsg client should be in
rpmsg.h, but Is there a need to expose it for now?
I suppose that it is for vhost...As the need will depends on the implementation, I would suggest leaving it internally and expose only if needed, in the related series.
Quoted 8 lines
I also thought about moving
rpmsg_hdrtorpmsg.hbut decided against because in most cases using the name space service usually means that a message header will be required. I also thought it would be easier to use, i.e include one header rather than two. That too is a little thin because anyone using a name service will also need to get access torpmsg_device, which is inrpmsg.h.I'm definitely not strongly opinionated on where it should go, or I can leave it in
virtio_rpmsg_bus.ctoo...
The rpmsg_ns service does not use this structure. So seems to me not at the good place
The virtio_rpmsg.c does, and a vhost_rpmsg.c should do it as well. I would be in favor of moving it to rpmsg_internal.h to expose it to the rpmg_buses (e.g. rpmsg_vhost) as a generic message header. Leaving it in virtio_rpmsg_bus.c also seems also a good alternative.
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
include/linux/rpmsg_ns.h new file +27
-0+ +/** +* 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 ]; +__rpmsg32 addr; +__rpmsg32 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 ,Quoted 8 lines
include/linux/rpmsg_ns.h line 60
Quoted 5 lines
include/linux/rpmsg_ns.h new file +5
-0+ RPMSG_NS_DESTROY = 1, +}; + +/* Address 53 is reserved for advertising remote services */ +#define RPMSG_NS_ADDR (53)What about my proposal [1] to put this in
rpmsg.h, to create a list of reserved Address
Quoted 2 lines
That too is a grey area... Moving
RPMSG_NS_ADDRtorpmsg.hmeans we have a name service #define inrpmsg.h. I think that one should stay inrpmsg_ns.h.
That seems reasonable, very simple to change this in future if needed.
Regards
Arnaud
Quoted 31 lines
Quoted 14 lines
[1] https://lkml.org/lkml/2020/7/31/442
Quoted 10 lines
include/linux/rpmsg_ns.h new file +2
-0+ +#endif include/uapi/linux/rpmsg.h +0
-0@@ -24,4 +24,7 @@ struct rpmsg_endpoint_info {#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info)#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2)Quoted 5 lines
include/uapi/linux/rpmsg.h struct rpmsg_endpoint_info { · line 29
Quoted 3 lines
include/uapi/linux/rpmsg.h +3
-0+/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0/* RP supports name service notifications */ +Same suggestion here,i would drop this from this series
Will do.
Thanks for the feedback,
MathieuQuoted 6 lines
Thanks,
ArnaudQuoted 2 lines
include/uapi/linux/rpmsg.h +0
-0#endif
Mathieu Poirier
maintainerPATCH v2 5/9 rpmsg: virtio: Rename rpmsg_create_channel
In reply to Mathieu PoirierFrom: Arnaud Pouliquen <[email protected]>
Rename the internal function as it is internal, and as the name will be used in rpmsg_core.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/rpmsg/virtio_rpmsg_bus.c +3 -3
@@ -345,8 +345,8 @@ static void virtio_rpmsg_release_device(struct device *dev)* this function will be used to create both static and dynamic * channels. */ -static struct rpmsg_device *rpmsg_create_channel (struct virtproc_info *vrp, -struct rpmsg_channel_info *chinfo) +static struct rpmsg_device *__rpmsg_create_channel (struct virtproc_info *vrp, +struct rpmsg_channel_info *chinfo) {struct virtio_rpmsg_channel *vch;struct rpmsg_device *rpdev;
@@ -820,7 +820,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,if (ret)dev_err (dev,"rpmsg_destroy_channel failed: %d\n" , ret); }else { - newch =rpmsg_create_channel (vrp, &chinfo); + newch =__rpmsg_create_channel (vrp, &chinfo);if (!newch)dev_err (dev,"rpmsg_create_channel failed\n" ); }
Signature · 1 line
2.25.1
Mathieu Poirier
maintainerPATCH v2 6/9 rpmsg: core: Add channel creation internal API
In reply to Mathieu PoirierFrom: Arnaud Pouliquen <[email protected]>
Add the channel creation API as a first step to be able to define the name service announcement as a rpmsg driver independent from the RPMsg virtio bus.
--- drivers/rpmsg/rpmsg_core.c | 44 ++++++++++++++++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 4 ++++ include/linux/rpmsg.h | 6 +++++ 3 files changed, 54 insertions(+)
drivers/rpmsg/rpmsg_core.c +44 -0
@@ -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
drivers/rpmsg/rpmsg_internal.h +4 -0
@@ -56,6 +56,10 @@ int rpmsg_unregister_device(struct device *parent,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
include/linux/rpmsg.h +6 -0
@@ -42,6 +42,8 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);/** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations * @is_little_endian: returns true if using little endian byte ordering +* @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
@@ -52,6 +54,10 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);*/ struct rpmsg_device_ops {bool (*is_little_endian)(struct rpmsg_device *rpdev); +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);
Signature · 1 line
2.25.1
Mathieu Poirier
maintainerPATCH v2 7/9 rpmsg: virtio: Add rpmsg channel device ops
In reply to Mathieu PoirierFrom: Arnaud Pouliquen <[email protected]>
Implement the create and release of the RPMsg channel for the RPMsg virtio bus.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/rpmsg/virtio_rpmsg_bus.c +22 -0
@@ -122,6 +122,8 @@ static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);static int virtio_rpmsg_trysend_offchannel (struct rpmsg_endpoint *ept,u32 src,u32 dst,void *data,int len); +static struct rpmsg_device *__rpmsg_create_channel (struct virtproc_info *vrp, +struct rpmsg_channel_info *chinfo);static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .destroy_ept = virtio_rpmsg_destroy_ept,
@@ -234,6 +236,24 @@ static bool virtio_rpmsg_is_little_endian(struct rpmsg_device *rpdev)return virtio_is_little_endian (vrp->vdev); } +static struct rpmsg_device *virtio_rpmsg_create_channel (struct rpmsg_device *rpdev, +struct rpmsg_channel_info *chinfo) +{ +struct virtio_rpmsg_channel *vch =to_virtio_rpmsg_channel (rpdev); +struct virtproc_info *vrp = vch->vrp; + +return __rpmsg_create_channel (vrp, chinfo); +} + +static int virtio_rpmsg_release_channel (struct rpmsg_device *rpdev, +struct rpmsg_channel_info *chinfo) +{ +struct virtio_rpmsg_channel *vch =to_virtio_rpmsg_channel (rpdev); +struct virtproc_info *vrp = vch->vrp; + +return rpmsg_unregister_device (&vrp->vdev->dev, chinfo); +} + static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv,
@@ -327,6 +347,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)static const struct rpmsg_device_ops virtio_rpmsg_ops = { .is_little_endian = virtio_rpmsg_is_little_endian, + .create_channel = virtio_rpmsg_create_channel, + .release_channel = virtio_rpmsg_release_channel, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy,
Signature · 1 line
2.25.1
Mathieu Poirier
maintainerPATCH v2 8/9 rpmsg: Make rpmsg_{register|unregister}_device() public
In reply to Mathieu PoirierMake function rpmsg_register_device() and rpmsg_unregister_device() functions public so that they can be used by other clients. While doing so get rid of two obsolete function, i.e register_rpmsg_device() and unregister_rpmsg_device(), to prevent confusion.
--- drivers/rpmsg/rpmsg_internal.h | 4 ---- include/linux/rpmsg.h | 12 ++++++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/rpmsg/rpmsg_internal.h +0 -4
@@ -49,10 +49,6 @@ 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);
include/linux/rpmsg.h +8 -4
@@ -188,8 +188,9 @@ static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val)#if IS_ENABLED (CONFIG_RPMSG ) -int register_rpmsg_device (struct rpmsg_device *dev); -void unregister_rpmsg_device (struct rpmsg_device *dev); +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 *);
@@ -212,15 +213,18 @@ __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,#else -static inline int register_rpmsg_device (struct rpmsg_device *dev) +static inline int rpmsg_register_device (struct rpmsg_device *rpdev) {return -ENXIO ; } -static inline void unregister_rpmsg_device (struct rpmsg_device *dev) +static inline int rpmsg_unregister_device (struct device *parent, +struct rpmsg_channel_info *chinfo) {/* This shouldn't be possible */ WARN_ON (1 ); + +return -ENXIO ; } static inline int __register_rpmsg_driver(struct rpmsg_driver *drv,
Signature · 1 line
2.25.1
Re: [PATCH v2 8/9] rpmsg: Make rpmsg_{register|unregister}_device() public
Quoted 54 lines · Mathieu Poirier
Make function
rpmsg_register_device()andrpmsg_unregister_device()functions public so that they can be used by other clients. While doing so get rid of two obsolete function, i.eregister_rpmsg_device()andunregister_rpmsg_device(), to prevent confusion.Signed-off-by Mathieu Poirier <[email protected]>--- drivers/rpmsg/rpmsg_internal.h | 4 ---- include/linux/rpmsg.h | 12 ++++++++---- 2 files changed, 8 insertions(+), 8 deletions(-)drivers/rpmsg/rpmsg_internal.h +0
-4@@ -49,10 +49,6 @@ 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);include/linux/rpmsg.h +4
-4@@ -188,8 +188,9 @@ static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val)#if IS_ENABLED (CONFIG_RPMSG ) -int register_rpmsg_device (struct rpmsg_device *dev); -void unregister_rpmsg_device (struct rpmsg_device *dev); +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 *);@@ -212,15 +213,18 @@ __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,#else -static inline int register_rpmsg_device (struct rpmsg_device *dev) +static inline int rpmsg_register_device (struct rpmsg_device *rpdev) {return -ENXIO ; } -static inline void unregister_rpmsg_device (struct rpmsg_device *dev)
include/linux/rpmsg.h __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, · line 230
Quoted 10 lines
include/linux/rpmsg.h +4
-0+static inline int rpmsg_unregister_device (struct device *parent, +struct rpmsg_channel_info *chinfo) {/* This shouldn't be possible */ WARN_ON (1 ); + +return -ENXIO ; } static inline int __register_rpmsg_driver(struct rpmsg_driver *drv,
Thanks,
Arnaud
Mathieu Poirier
maintainerPATCH v2 9/9 rpmsg: Turn name service into a stand alone driver
In reply to Mathieu PoirierFrom: Arnaud Pouliquen <[email protected]>
Make the RPMSG name service announcement a stand alone driver so that it can be reused by other subsystems. It is also the first step in making the functionatlity transport independent, i.e that is not tied to virtIO.
--- drivers/rpmsg/Kconfig | 8 +++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_ns.c | 110 +++++++++++++++++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 84 +++++------------------ include/linux/rpmsg_ns.h | 17 +++++ 5 files changed, 154 insertions(+), 66 deletions(-) create mode 100644 drivers/rpmsg/rpmsg_ns.c
drivers/rpmsg/Kconfig +8 -0
@@ -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
drivers/rpmsg/Makefile +1 -0
@@ -1,6 +1,7 @@ # 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
drivers/rpmsg/rpmsg_ns.c new file +110 -0
110 lines not on this page · raw message
drivers/rpmsg/virtio_rpmsg_bus.c +18 -66
123 lines not on this page · raw message
include/linux/rpmsg_ns.h +17 -0
@@ -59,4 +59,21 @@ enum rpmsg_ns_flags {/* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR (53) +/** +* 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. +*/ +static inline 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); +} +#endif
Signature · 1 line
2.25.1
Quoted 9 lines · Mathieu Poirier
Good afternoon,
This set starts by making the RPMSG protocol transport agnostic by moving the headers it uses to generic types and using those in the current implementation. From there it re-uses the work that Arnaud published[1] to make the name service modular.
Tested on stm32mp157 with the RPMSG client sample application. Applies cleanly on v5.9.
Thanks
Guennadi
Quoted 46 lines
Thanks,
Mathieu[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=338335
------
New for V2:
- Created new RPMSG types (Guennadi).
- Re-worked byte conversion functions(Guennadi).
- Added a single ->is_little_endian() operation (Arnaud).
- Fixed byte conversion before making name service modular.Arnaud Pouliquen (4):
rpmsg: virtio: Renamerpmsg_create_channel
rpmsg: core: Add channel creation internal API
rpmsg: virtio: Add rpmsg channel device ops
rpmsg: Turn name service into a stand alone driverMathieu Poirier (5):
rpmsg: Moverpmsg_endpoint_opstorpmsg.h
rpmsg: Introduce __rpmsg{16|32|64} types
rpmsg: virtio: Move from virtio to rpmsg byte conversion
rpmsg: Moverpmsg_hrandrpmsg_ns_msgto header file
rpmsg: Make rpmsg_{register|unregister}_device() publicdrivers/rpmsg/Kconfig | 8 ++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_core.c | 44 +++++++ drivers/rpmsg/rpmsg_internal.h | 27 +--- drivers/rpmsg/rpmsg_ns.c | 110 +++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 206 ++++++++++--------------------- include/linux/rpmsg.h | 93 ++++++++++++-- include/linux/rpmsg_byteorder.h | 67 ++++++++++ include/linux/rpmsg_ns.h | 79 ++++++++++++ include/uapi/linux/rpmsg.h | 3 + include/uapi/linux/rpmsg_types.h | 11 ++ 11 files changed, 481 insertions(+), 168 deletions(-) create mode 100644 drivers/rpmsg/rpmsg_ns.c create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/linux/rpmsg_ns.h create mode 100644 include/uapi/linux/rpmsg_types.hSignature · 1 line
2.25.1