public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
Cc: git@amd.com, michal.simek@amd.com, alexandre.belloni@bootlin.com,
	robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	pgaj@cadence.com, wsa+renesas@sang-engineering.com,
	tommaso.merciai.xr@bp.renesas.com, arnd@arndb.de,
	quic_msavaliy@quicinc.com, Shyam-sundar.S-k@amd.com,
	sakari.ailus@linux.intel.com, billy_tsai@aspeedtech.com,
	kees@kernel.org, gustavoars@kernel.org,
	jarkko.nikula@linux.intel.com, jorge.marques@analog.com,
	linux-i3c@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-hardening@vger.kernel.org, radhey.shyam.pandey@amd.com,
	srinivas.goud@amd.com, shubhrajyoti.datta@amd.com,
	manion05gk@gmail.com
Subject: Re: [PATCH V7 2/4] asm-generic/io.h: Add big-endian MMIO accessors
Date: Tue, 23 Sep 2025 14:43:55 -0400	[thread overview]
Message-ID: <aNLqa4poPkkvASbq@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20250923154551.2112388-3-manikanta.guntupalli@amd.com>

On Tue, Sep 23, 2025 at 09:15:49PM +0530, Manikanta Guntupalli wrote:
> Add MMIO accessors to support big-endian memory operations. These helpers
> include {read, write}{w, l, q}_be() and {read, write}s{w, l, q}_be(),
> which allows to access big-endian memory regions while returning
> the results in the CPU’s native endianness.
>
> This provides a consistent interface to interact with hardware using
> big-endian register layouts.
>
> Signed-off-by: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> Changes since V7:
> This patch introduced in V7.
> ---
>  include/asm-generic/io.h | 202 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 202 insertions(+)
>
> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> index 11abad6c87e1..d18a8ca6c06c 100644
> --- a/include/asm-generic/io.h
> +++ b/include/asm-generic/io.h
> @@ -295,6 +295,96 @@ static inline void writeq(u64 value, volatile void __iomem *addr)
>  #endif
>  #endif /* CONFIG_64BIT */
>
> +/*
> + * {read,write}{w,l,q}_be() access big endian memory and return result
> + * in native endianness.
> + */
> +
> +#ifndef readw_be
> +#define readw_be readw_be
> +static inline u16 readw_be(const volatile void __iomem *addr)
> +{
> +	u16 val;
> +
> +	log_read_mmio(16, addr, _THIS_IP_, _RET_IP_);
> +	__io_br();
> +	val = __be16_to_cpu((__be16 __force)__raw_readw(addr));
> +	__io_ar(val);
> +	log_post_read_mmio(val, 16, addr, _THIS_IP_, _RET_IP_);
> +	return val;
> +}
> +#endif
> +
> +#ifndef readl_be
> +#define readl_be readl_be
> +static inline u32 readl_be(const volatile void __iomem *addr)
> +{
> +	u32 val;
> +
> +	log_read_mmio(32, addr, _THIS_IP_, _RET_IP_);
> +	__io_br();
> +	val = __be32_to_cpu((__be32 __force)__raw_readl(addr));
> +	__io_ar(val);
> +	log_post_read_mmio(val, 32, addr, _THIS_IP_, _RET_IP_);
> +	return val;
> +}
> +#endif
> +
> +#ifdef CONFIG_64BIT
> +#ifndef readq_be
> +#define readq_be readq_be
> +static inline u64 readq_be(const volatile void __iomem *addr)
> +{
> +	u64 val;
> +
> +	log_read_mmio(64, addr, _THIS_IP_, _RET_IP_);
> +	__io_br();
> +	val = __be64_to_cpu((__be64 __force)__raw_readq(addr));
> +	__io_ar(val);
> +	log_post_read_mmio(val, 64, addr, _THIS_IP_, _RET_IP_);
> +	return val;
> +}
> +#endif
> +#endif /* CONFIG_64BIT */
> +
> +#ifndef writew_be
> +#define writew_be writew_be
> +static inline void writew_be(u16 value, volatile void __iomem *addr)
> +{
> +	log_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
> +	__io_bw();
> +	__raw_writew((u16 __force)__cpu_to_be16(value), addr);
> +	__io_aw();
> +	log_post_write_mmio(value, 16, addr, _THIS_IP_, _RET_IP_);
> +}
> +#endif
> +
> +#ifndef writel_be
> +#define writel_be writel_be
> +static inline void writel_be(u32 value, volatile void __iomem *addr)
> +{
> +	log_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
> +	__io_bw();
> +	__raw_writel((u32 __force)__cpu_to_be32(value), addr);
> +	__io_aw();
> +	log_post_write_mmio(value, 32, addr, _THIS_IP_, _RET_IP_);
> +}
> +#endif
> +
> +#ifdef CONFIG_64BIT
> +#ifndef writeq_be
> +#define writeq_be writeq_be
> +static inline void writeq_be(u64 value, volatile void __iomem *addr)
> +{
> +	log_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
> +	__io_bw();
> +	__raw_writeq((u64 __force)__cpu_to_be64(value), addr);
> +	__io_aw();
> +	log_post_write_mmio(value, 64, addr, _THIS_IP_, _RET_IP_);
> +}
> +#endif
> +#endif /* CONFIG_64BIT */
> +
>  /*
>   * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
>   * are not guaranteed to provide ordering against spinlocks or memory
> @@ -524,6 +614,118 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
>  #endif
>  #endif /* CONFIG_64BIT */
>
> +/*
> + * {read,write}s{w,l,q}_be() repeatedly access the same memory address
> + * in big endianness in 16-, 32- or 64-bit chunks (@count times) and
> + * return result in native endianness.
> + */
> +
> +#ifndef readsw_be
> +#define readsw_be readsw_be
> +static inline void readsw_be(const volatile void __iomem *addr,
> +			     void *buffer,
> +			     unsigned int count)
> +{
> +	if (count) {
> +		u16 *buf = buffer;
> +
> +		do {
> +			u16 x = __be16_to_cpu((__be16 __force)__raw_readw(addr));
> +			*buf++ = x;
> +		} while (--count);
> +	}
> +}
> +#endif
> +
> +#ifndef readsl_be
> +#define readsl_be readsl_be
> +static inline void readsl_be(const volatile void __iomem *addr,
> +			     void *buffer,
> +			     unsigned int count)
> +{
> +	if (count) {
> +		u32 *buf = buffer;
> +
> +		do {
> +			u32 x = __be32_to_cpu((__be32 __force)__raw_readl(addr));
> +			*buf++ = x;
> +		} while (--count);
> +	}
> +}
> +#endif
> +
> +#ifdef CONFIG_64BIT
> +#ifndef readsq_be
> +#define readsq_be readsq_be
> +static inline void readsq_be(const volatile void __iomem *addr,
> +			     void *buffer,
> +			     unsigned int count)
> +{
> +	if (count) {
> +		u64 *buf = buffer;
> +
> +		do {
> +			u64 x = __be64_to_cpu((__be64 __force)__raw_readq(addr));
> +			*buf++ = x;
> +		} while (--count);
> +	}
> +}
> +#endif
> +#endif /* CONFIG_64BIT */
> +
> +#ifndef writesw_be
> +#define writesw_be writesw_be
> +static inline void writesw_be(volatile void __iomem *addr,
> +			      const void *buffer,
> +			      unsigned int count)
> +{
> +	if (count) {
> +		const u16 *buf = buffer;
> +
> +		do {
> +			__raw_writew((u16 __force)__cpu_to_be16(*buf), addr);
> +			buf++;
> +		} while (--count);
> +	}
> +}
> +#endif
> +
> +#ifndef writesl_be
> +#define writesl_be writesl_be
> +static inline void writesl_be(volatile void __iomem *addr,
> +			      const void *buffer,
> +			      unsigned int count)
> +{
> +	if (count) {
> +		const u32 *buf = buffer;
> +
> +		do {
> +			__raw_writel((u32 __force)__cpu_to_be32(*buf), addr);
> +			buf++;
> +		} while (--count);
> +	}
> +}
> +#endif
> +
> +#ifdef CONFIG_64BIT
> +#ifndef writesq_be
> +#define writesq_be writesq_be
> +static inline void writesq_be(volatile void __iomem *addr,
> +			      const void *buffer,
> +			      unsigned int count)
> +{
> +	if (count) {
> +		const u64 *buf = buffer;
> +
> +		do {
> +			__raw_writeq((u64 __force)__cpu_to_be64(*buf), addr);
> +			buf++;
> +		} while (--count);
> +	}
> +}
> +#endif
> +#endif /* CONFIG_64BIT */
> +
>  #ifndef PCI_IOBASE
>  #define PCI_IOBASE ((void __iomem *)0)
>  #endif
> --
> 2.34.1
>

  parent reply	other threads:[~2025-09-23 18:44 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 15:45 [PATCH V7 0/4] Add AMD I3C master controller driver and bindings Manikanta Guntupalli
2025-09-23 15:45 ` [PATCH V7 1/4] dt-bindings: i3c: Add AMD I3C master controller support Manikanta Guntupalli
2025-09-23 15:45 ` [PATCH V7 2/4] asm-generic/io.h: Add big-endian MMIO accessors Manikanta Guntupalli
2025-09-23 18:38   ` Arnd Bergmann
2025-09-24  8:59     ` Guntupalli, Manikanta
2025-09-24  9:46       ` Arnd Bergmann
2025-09-24 10:12         ` Guntupalli, Manikanta
2025-09-23 18:43   ` Frank Li [this message]
2025-09-24 20:34   ` kernel test robot
2025-09-25  6:15   ` kernel test robot
2025-09-23 15:45 ` [PATCH V7 3/4] i3c: master: Add endianness support for i3c_readl_fifo() and i3c_writel_fifo() Manikanta Guntupalli
2025-09-23 18:45   ` Frank Li
2025-09-23 18:51   ` Arnd Bergmann
2025-09-24  9:00     ` Guntupalli, Manikanta
2025-09-24 10:00       ` Arnd Bergmann
2025-09-24 12:22         ` Guntupalli, Manikanta
2025-09-24 14:05           ` Arnd Bergmann
2025-09-24 15:23             ` Guntupalli, Manikanta
2025-09-24 15:42               ` Arnd Bergmann
2025-09-25  9:26                 ` Guntupalli, Manikanta
2025-09-25 12:14                   ` Arnd Bergmann
2025-09-25 16:37                     ` Guntupalli, Manikanta
2025-09-25 16:50                       ` Frank Li
2025-09-25 12:22   ` kernel test robot
2025-09-23 15:45 ` [PATCH V7 4/4] i3c: master: Add AMD I3C bus controller driver Manikanta Guntupalli
2025-09-23 19:22   ` Frank Li
2025-09-25  5:42     ` Guntupalli, Manikanta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aNLqa4poPkkvASbq@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=arnd@arndb.de \
    --cc=billy_tsai@aspeedtech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=git@amd.com \
    --cc=gustavoars@kernel.org \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jorge.marques@analog.com \
    --cc=kees@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manikanta.guntupalli@amd.com \
    --cc=manion05gk@gmail.com \
    --cc=michal.simek@amd.com \
    --cc=pgaj@cadence.com \
    --cc=quic_msavaliy@quicinc.com \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=shubhrajyoti.datta@amd.com \
    --cc=srinivas.goud@amd.com \
    --cc=tommaso.merciai.xr@bp.renesas.com \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox