Skip to content

Commit c85688e

Browse files
ericchancfpalmer-dabbelt
authored andcommitted
riscv/barrier: Consolidate fence definitions
Disparate fence implementations are consolidated into fence.h. Also introduce RISCV_FENCE_ASM to make fence macro more reusable. Signed-off-by: Eric Chan <ericchancf@google.com> Reviewed-by: Andrea Parri <parri.andrea@gmail.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Link: https://lore.kernel.org/r/20240217131316.3668927-1-ericchancf@google.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent b3c8064 commit c85688e

File tree

7 files changed

+16
-14
lines changed

7 files changed

+16
-14
lines changed

arch/riscv/include/asm/atomic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#endif
1818

1919
#include <asm/cmpxchg.h>
20-
#include <asm/barrier.h>
2120

2221
#define __atomic_acquire_fence() \
2322
__asm__ __volatile__(RISCV_ACQUIRE_BARRIER "" ::: "memory")

arch/riscv/include/asm/barrier.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
#define _ASM_RISCV_BARRIER_H
1212

1313
#ifndef __ASSEMBLY__
14+
#include <asm/fence.h>
1415

1516
#define nop() __asm__ __volatile__ ("nop")
1617
#define __nops(n) ".rept " #n "\nnop\n.endr\n"
1718
#define nops(n) __asm__ __volatile__ (__nops(n))
1819

19-
#define RISCV_FENCE(p, s) \
20-
__asm__ __volatile__ ("fence " #p "," #s : : : "memory")
2120

2221
/* These barriers need to enforce ordering on both devices or memory. */
2322
#define __mb() RISCV_FENCE(iorw, iorw)

arch/riscv/include/asm/cmpxchg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <linux/bug.h>
1010

11-
#include <asm/barrier.h>
1211
#include <asm/fence.h>
1312

1413
#define __xchg_relaxed(ptr, new, size) \

arch/riscv/include/asm/fence.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#ifndef _ASM_RISCV_FENCE_H
22
#define _ASM_RISCV_FENCE_H
33

4+
#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n"
5+
#define RISCV_FENCE(p, s) \
6+
({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); })
7+
48
#ifdef CONFIG_SMP
5-
#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n"
6-
#define RISCV_RELEASE_BARRIER "\tfence rw, w\n"
7-
#define RISCV_FULL_BARRIER "\tfence rw, rw\n"
9+
#define RISCV_ACQUIRE_BARRIER RISCV_FENCE_ASM(r, rw)
10+
#define RISCV_RELEASE_BARRIER RISCV_FENCE_ASM(rw, w)
11+
#define RISCV_FULL_BARRIER RISCV_FENCE_ASM(rw, rw)
812
#else
913
#define RISCV_ACQUIRE_BARRIER
1014
#define RISCV_RELEASE_BARRIER

arch/riscv/include/asm/io.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
* sufficient to ensure this works sanely on controllers that support I/O
4848
* writes.
4949
*/
50-
#define __io_pbr() __asm__ __volatile__ ("fence io,i" : : : "memory");
51-
#define __io_par(v) __asm__ __volatile__ ("fence i,ior" : : : "memory");
52-
#define __io_pbw() __asm__ __volatile__ ("fence iow,o" : : : "memory");
53-
#define __io_paw() __asm__ __volatile__ ("fence o,io" : : : "memory");
50+
#define __io_pbr() RISCV_FENCE(io, i)
51+
#define __io_par(v) RISCV_FENCE(i, ior)
52+
#define __io_pbw() RISCV_FENCE(iow, o)
53+
#define __io_paw() RISCV_FENCE(o, io)
5454

5555
/*
5656
* Accesses from a single hart to a single I/O address must be ordered. This

arch/riscv/include/asm/mmio.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define _ASM_RISCV_MMIO_H
1313

1414
#include <linux/types.h>
15+
#include <asm/fence.h>
1516
#include <asm/mmiowb.h>
1617

1718
/* Generic IO read/write. These perform native-endian accesses. */
@@ -131,8 +132,8 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
131132
* doesn't define any ordering between the memory space and the I/O space.
132133
*/
133134
#define __io_br() do {} while (0)
134-
#define __io_ar(v) ({ __asm__ __volatile__ ("fence i,ir" : : : "memory"); })
135-
#define __io_bw() ({ __asm__ __volatile__ ("fence w,o" : : : "memory"); })
135+
#define __io_ar(v) RISCV_FENCE(i, ir)
136+
#define __io_bw() RISCV_FENCE(w, o)
136137
#define __io_aw() mmiowb_set_pending()
137138

138139
#define readb(c) ({ u8 __v; __io_br(); __v = readb_cpu(c); __io_ar(__v); __v; })

arch/riscv/include/asm/mmiowb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* "o,w" is sufficient to ensure that all writes to the device have completed
88
* before the write to the spinlock is allowed to commit.
99
*/
10-
#define mmiowb() __asm__ __volatile__ ("fence o,w" : : : "memory");
10+
#define mmiowb() RISCV_FENCE(o, w)
1111

1212
#include <linux/smp.h>
1313
#include <asm-generic/mmiowb.h>

0 commit comments

Comments
 (0)