riscv: use generic relaxed MMIO accessors
PATCH v3 1/1 riscv: use generic relaxed MMIO accessors
The relaxed MMIO accessors duplicate the generic implementation, as noted by their FIXME comment. Remove those definitions and their empty barrier hooks so asm-generic/io.h supplies them through the existing asm/io.h include path.
The M-mode timer uses the lightweight asm/mmio.h header before the generic relaxed accessors are available. Use readl_cpu() and readq_cpu() there, which perform the same accesses and endian conversion as the existing relaxed accessors.
---
v3: don't touch asm-generic, and preserve custom __raw_* helpers.
v2: split asm-generic/io.h to fix M-mode build
https://lore.kernel.org/linux-riscv/[email protected]/
v1: https://lore.kernel.org/linux-riscv/[email protected]/
--- arch/riscv/include/asm/mmio.h | 27 --------------------------- arch/riscv/include/asm/timex.h | 6 +++--- 2 files changed, 3 insertions(+), 30 deletions(-)
arch/riscv/include/asm/mmio.h +0 -27
@@ -98,33 +98,6 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)#define writeq_cpu (v, c) ((void)__raw_writeq((__force u64)cpu_to_le64(v), (c)))#endif -/* -* Relaxed I/O memory access primitives. These follow the Device memory -* ordering rules but do not guarantee any ordering relative to Normal memory -* accesses. These are defined to order the indicated access (either a read or -* write) with all other I/O memory accesses to the same peripheral. Since the -* platform specification defines that all I/O regions are strongly ordered on -* channel 0, no explicit fences are required to enforce this ordering. -*/ -/* FIXME: These are now the same as asm-generic */ -#define __io_rbr () do {} while (0) -#define __io_rar () do {} while (0) -#define __io_rbw () do {} while (0) -#define __io_raw () do {} while (0) - -#define readb_relaxed (c) ({ u8 __v; __io_rbr(); __v = readb_cpu(c); __io_rar(); __v; }) -#define readw_relaxed (c) ({ u16 __v; __io_rbr(); __v = readw_cpu(c); __io_rar(); __v; }) -#define readl_relaxed (c) ({ u32 __v; __io_rbr(); __v = readl_cpu(c); __io_rar(); __v; }) - -#define writeb_relaxed (v, c) ({ __io_rbw(); writeb_cpu((v), (c)); __io_raw(); }) -#define writew_relaxed (v, c) ({ __io_rbw(); writew_cpu((v), (c)); __io_raw(); }) -#define writel_relaxed (v, c) ({ __io_rbw(); writel_cpu((v), (c)); __io_raw(); }) - -#ifdef CONFIG_64BIT -#define readq_relaxed (c) ({ u64 __v; __io_rbr(); __v = readq_cpu(c); __io_rar(); __v; }) -#define writeq_relaxed (v, c) ({ __io_rbw(); writeq_cpu((v), (c)); __io_raw(); }) -#endif -/* * I/O memory access primitives. Reads are ordered relative to any following * Normal memory read and delay() loop. Writes are ordered relative to any
arch/riscv/include/asm/timex.h +3 -3
@@ -17,18 +17,18 @@ typedef unsigned long cycles_t;#ifdef CONFIG_64BIT static inline cycles_t get_cycles (void ) { -return readq_relaxed (clint_time_val); +return readq_cpu (clint_time_val); }#else /* !CONFIG_64BIT */ static inline u32 get_cycles (void ) { -return readl_relaxed (((u32 __iomem *)clint_time_val)); +return readl_cpu (((u32 __iomem *)clint_time_val)); }#define get_cycles get_cyclesstatic inline u32 get_cycles_hi (void ) { -return readl_relaxed (((u32 __iomem *)clint_time_val) +1 ); +return readl_cpu (((u32 __iomem *)clint_time_val) +1 ); }#define get_cycles_hi get_cycles_hi#endif /* CONFIG_64BIT */
Signature · 1 line
2.43.0
Quoted 4 lines · Qingfang Deng
The relaxed MMIO accessors duplicate the generic implementation, as noted by their FIXME comment. Remove those definitions and their empty barrier hooks so
asm-generic/io.hsupplies them through the existingasm/io.hinclude path.
This seems fine.
Quoted 9 lines
The M-mode timer uses the lightweight
asm/mmio.hheader before the generic relaxed accessors are available. Usereadl_cpu()andreadq_cpu()there, which perform the same accesses and endian conversion as the existing relaxed accessors.arch/riscv/include/asm/timex.h +0
-0@@ -17,18 +17,18 @@ typedef unsigned long cycles_t;#ifdef CONFIG_64BIT static inline cycles_t get_cycles (void ) {
arch/riscv/include/asm/timex.h typedef unsigned long cycles_t; · line 27
Quoted 10 lines
arch/riscv/include/asm/timex.h +2
-2- return readq_relaxed(clint_time_val); + return readq_cpu(clint_time_val); }#else /* !CONFIG_64BIT */ static inline u32 get_cycles (void ) { -return readl_relaxed (((u32 __iomem *)clint_time_val)); +return readl_cpu (((u32 __iomem *)clint_time_val)); }#define get_cycles get_cycles
I don't understand this bit: Why should these not keep using the portable accessors? As far as I can tell, the readl_cpu() helpers are just an implementation detail in riscv and could be removed along with the custom readl_relaxed() variant, but with your patch that becomes harder.
Arnd