[Bionic][PATCH 06/18] powerpc/io: Add __raw_writeq_be() __raw_rm_writeq_be()

Jose Ricardo Ziviani joserz at linux.ibm.com
Wed Oct 31 15:09:19 UTC 2018

From: Michael Ellerman <mpe at ellerman.id.au>

BugLink: https://bugs.launchpad.net/qemu-kvm/+bug/1800649

Add byte-swapping versions of __raw_writeq() and __raw_rm_writeq().

This allows us to avoid sparse warnings caused by passing __be64 to
__raw_writeq(), which takes unsigned long:

  warning: incorrect type in argument 1 (different base types)
      expected unsigned long [unsigned] v
      got restricted __be64 [usertype] <noident>

It's also generally preferable to use a byte-swapping accessor rather
than doing it by hand in the code, which is more bug prone.

Signed-off-by: Michael Ellerman <mpe at ellerman.id.au>
Reviewed-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
(cherry picked from commit 8056fe28d04607106e7d418bd9ee2e63562def50)
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.ibm.com>
 arch/powerpc/include/asm/io.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index 422f99cf9924..5bd703cda859 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -369,6 +369,11 @@ static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
 	*(volatile unsigned long __force *)PCI_FIX_ADDR(addr) = v;
+static inline void __raw_writeq_be(unsigned long v, volatile void __iomem *addr)
+	__raw_writeq((__force unsigned long)cpu_to_be64(v), addr);
  * Real mode versions of the above. Those instructions are only supposed
  * to be used in hypervisor real mode as per the architecture spec.
@@ -397,6 +402,11 @@ static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
 		: : "r" (val), "r" (paddr) : "memory");
+static inline void __raw_rm_writeq_be(u64 val, volatile void __iomem *paddr)
+	__raw_rm_writeq((__force u64)cpu_to_be64(val), paddr);
 static inline u8 __raw_rm_readb(volatile void __iomem *paddr)
 	u8 ret;

More information about the kernel-team mailing list