lkml.org 
[lkml]   [2020]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 08/10] rpmsg: core: Add RPMSG byte conversion operations
On Mon, Sep 21, 2020 at 06:09:58PM -0600, Mathieu Poirier wrote:
> Add RPMSG device specific byte conversion operations as a first
> step to separate the RPMSG name space service from the virtIO
> transport layer.
>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> ---
> drivers/rpmsg/rpmsg_core.c | 51 ++++++++++++++++++++++++++++++++++
> drivers/rpmsg/rpmsg_internal.h | 12 ++++++++
> 2 files changed, 63 insertions(+)
>
> diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
> index 50a835eaf1ba..66ad5b5f1e87 100644
> --- a/drivers/rpmsg/rpmsg_core.c
> +++ b/drivers/rpmsg/rpmsg_core.c
> @@ -20,6 +20,57 @@
>
> #include "rpmsg_internal.h"
>
> +/**
> + * rpmsg{16|32}_to_cpu()
> + * cpu_to_rpmsg[16|32}() - rpmsg device specific byte conversion functions to
> + * perform byte conversion between rpmsg device and the
> + * transport layer it is operating on.
> + */
> +
> +u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, u16 val)

All the endianness conversions are great as long as they compile to
NOPs where no conversion is needed. Can we come up with a solution
to keep it that way?

Thanks
Guennadi

> +{
> + if (WARN_ON(!rpdev))
> + return -EINVAL;
> + if (!rpdev->ops || !rpdev->ops->transport16_to_cpu)
> + return -EPERM;
> +
> + return rpdev->ops->transport16_to_cpu(rpdev, val);
> +}
> +EXPORT_SYMBOL(rpmsg16_to_cpu);
> +
> +u16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val)
> +{
> + if (WARN_ON(!rpdev))
> + return -EINVAL;
> + if (!rpdev->ops || !rpdev->ops->cpu_to_transport16)
> + return -EPERM;
> +
> + return rpdev->ops->cpu_to_transport16(rpdev, val);
> +}
> +EXPORT_SYMBOL(cpu_to_rpmsg16);
> +
> +u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, u32 val)
> +{
> + if (WARN_ON(!rpdev))
> + return -EINVAL;
> + if (!rpdev->ops || !rpdev->ops->transport32_to_cpu)
> + return -EPERM;
> +
> + return rpdev->ops->transport32_to_cpu(rpdev, val);
> +}
> +EXPORT_SYMBOL(rpmsg32_to_cpu);
> +
> +u32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val)
> +{
> + if (WARN_ON(!rpdev))
> + return -EINVAL;
> + if (!rpdev->ops || !rpdev->ops->cpu_to_transport32)
> + return -EPERM;
> +
> + return rpdev->ops->cpu_to_transport32(rpdev, val);
> +}
> +EXPORT_SYMBOL(cpu_to_rpmsg32);
> +
> /**
> * rpmsg_create_channel() - create a new rpmsg channel
> * using its name and address info.
> diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h
> index 2e65386f191e..2f0ad1a52698 100644
> --- a/drivers/rpmsg/rpmsg_internal.h
> +++ b/drivers/rpmsg/rpmsg_internal.h
> @@ -81,6 +81,8 @@ struct virtio_rpmsg_channel {
>
> /**
> * struct rpmsg_device_ops - indirection table for the rpmsg_device operations
> + * @transport{16|32}_to_cpu: byte conversion from rpmsg device to transport layer
> + * @cpu_to_transport{16|32}: byte conversion from transport layer to rpmsg device
> * @create_channel: create backend-specific channel, optional
> * @release_channel: release backend-specific channel, optional
> * @create_ept: create backend-specific endpoint, required
> @@ -92,6 +94,10 @@ struct virtio_rpmsg_channel {
> * advertise new channels implicitly by creating the endpoints.
> */
> struct rpmsg_device_ops {
> + u16 (*transport16_to_cpu)(struct rpmsg_device *rpdev, u16 val);
> + u16 (*cpu_to_transport16)(struct rpmsg_device *rpdev, u16 val);
> + u32 (*transport32_to_cpu)(struct rpmsg_device *rpdev, u32 val);
> + u32 (*cpu_to_transport32)(struct rpmsg_device *rpdev, u32 val);
> struct rpmsg_device *(*create_channel)(struct rpmsg_device *rpdev,
> struct rpmsg_channel_info *chinfo);
> int (*release_channel)(struct rpmsg_device *rpdev,
> @@ -148,6 +154,12 @@ 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);
> +
> +u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, u16 val);
> +u16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val);
> +u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, u32 val);
> +u32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val);
> +
> /**
> * rpmsg_chrdev_register_device() - register chrdev device based on rpdev
> * @rpdev: prepared rpdev to be used for creating endpoints
> --
> 2.25.1
>

\
 
 \ /
  Last update: 2020-09-30 09:13    [W:0.224 / U:1.816 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site