diff mbox series

[08/10] rpmsg: core: Add RPMSG byte conversion operations

Message ID 20200922001000.899956-9-mathieu.poirier@linaro.org (mailing list archive)
State Superseded
Headers show
Series rpmsg: Make RPMSG name service modular | expand

Commit Message

Mathieu Poirier Sept. 22, 2020, 12:09 a.m. UTC
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(+)

Comments

Randy Dunlap Sept. 22, 2020, 1:07 a.m. UTC | #1
On 9/21/20 5:09 PM, Mathieu Poirier wrote:
> +/**

Hi,
This block is not in kernel-doc format, so the comment block should not
begin with /**.

> + * 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)
> +{


thanks.
Arnaud POULIQUEN Sept. 22, 2020, 2:34 p.m. UTC | #2
On 9/22/20 2:09 AM, 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)
> +{
> +	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;

Alternative could be to choice the processor endianness ( it was the case
before the virtio patch to set the endianness

> +
> +	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);

This trigg me a suggestion. Perhaps it would be simpler to have only on ops
to get the endianness.

Regards
Arnaud

>  	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
>
Mathieu Poirier Sept. 22, 2020, 7:46 p.m. UTC | #3
On Tue, Sep 22, 2020 at 04:34:53PM +0200, Arnaud POULIQUEN wrote:
> 
> 
> On 9/22/20 2:09 AM, 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)
> > +{
> > +	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;
> 
> Alternative could be to choice the processor endianness ( it was the case
> before the virtio patch to set the endianness

That's a good idea.

> 
> > +
> > +	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);
> 
> This trigg me a suggestion. Perhaps it would be simpler to have only on ops
> to get the endianness.
> 

Another good idea, I'll look into it.

Thanks for the comments,
Mathieu

> Regards
> Arnaud
> 
> >  	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
> >
Dan Carpenter Sept. 23, 2020, 11:56 a.m. UTC | #4
Hi Mathieu,

url:    https://github.com/0day-ci/linux/commits/Mathieu-Poirier/rpmsg-Make-RPMSG-name-service-modular/20200922-081745
base:    b10b8ad862118bf42c28a98b0f067619aadcfb23
config: i386-randconfig-m021-20200923 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/rpmsg/rpmsg_core.c:33 rpmsg16_to_cpu() warn: signedness bug returning '(-22)'
drivers/rpmsg/rpmsg_core.c:44 cpu_to_rpmsg16() warn: signedness bug returning '(-22)'

# https://github.com/0day-ci/linux/commit/547ad00c50065bf914ac4090882d0ac692f5452d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mathieu-Poirier/rpmsg-Make-RPMSG-name-service-modular/20200922-081745
git checkout 547ad00c50065bf914ac4090882d0ac692f5452d
vim +33 drivers/rpmsg/rpmsg_core.c

547ad00c50065bf Mathieu Poirier 2020-09-21  30  u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, u16 val)
                                                ^^^

547ad00c50065bf Mathieu Poirier 2020-09-21  31  {
547ad00c50065bf Mathieu Poirier 2020-09-21  32  	if (WARN_ON(!rpdev))
547ad00c50065bf Mathieu Poirier 2020-09-21 @33  		return -EINVAL;
                                                                ^^^^^^^^^^^^^^
All the negative returns get truncated to a high u16 value.

547ad00c50065bf Mathieu Poirier 2020-09-21  34  	if (!rpdev->ops || !rpdev->ops->transport16_to_cpu)
547ad00c50065bf Mathieu Poirier 2020-09-21  35  		return -EPERM;
                                                                ^^^^^^^^^^^^^^
547ad00c50065bf Mathieu Poirier 2020-09-21  36  
547ad00c50065bf Mathieu Poirier 2020-09-21  37  	return rpdev->ops->transport16_to_cpu(rpdev, val);
547ad00c50065bf Mathieu Poirier 2020-09-21  38  }
547ad00c50065bf Mathieu Poirier 2020-09-21  39  EXPORT_SYMBOL(rpmsg16_to_cpu);
547ad00c50065bf Mathieu Poirier 2020-09-21  40  
547ad00c50065bf Mathieu Poirier 2020-09-21  41  u16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val)
547ad00c50065bf Mathieu Poirier 2020-09-21  42  {
547ad00c50065bf Mathieu Poirier 2020-09-21  43  	if (WARN_ON(!rpdev))
547ad00c50065bf Mathieu Poirier 2020-09-21 @44  		return -EINVAL;
                                                                ^^^^^^^^^^^^^^
547ad00c50065bf Mathieu Poirier 2020-09-21  45  	if (!rpdev->ops || !rpdev->ops->cpu_to_transport16)
547ad00c50065bf Mathieu Poirier 2020-09-21  46  		return -EPERM;
                                                                ^^^^^^^^^^^^^
547ad00c50065bf Mathieu Poirier 2020-09-21  47  
547ad00c50065bf Mathieu Poirier 2020-09-21  48  	return rpdev->ops->cpu_to_transport16(rpdev, val);
547ad00c50065bf Mathieu Poirier 2020-09-21  49  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Guennadi Liakhovetski Sept. 30, 2020, 7:11 a.m. UTC | #5
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
>
diff mbox series

Patch

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)
+{
+	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