Skip to content

Commit 83d8b38

Browse files
xen0nchenhuacai
authored andcommitted
LoongArch: Simplify the invtlb wrappers
The invtlb instruction has been supported by upstream LoongArch toolchains from day one, so ditch the raw opcode trickery and just use plain inline asm for it. While at it, also make the invtlb asm statements barriers, for proper modeling of the side effects. The functions are also marked as __always_inline instead of just "inline", because they cannot work at all if not inlined: the op argument will not be compile-time const in that case, thus failing to satisfy the "i" constraint. The signature of the other more specific invtlb wrappers contain unused arguments right now, but these are not removed right away in order for the patch to be focused. In the meantime, assertions are added to ensure no accidental misuse happens before the refactor. (The more specific wrappers cannot re-use the generic invtlb wrapper, because the ISA manual says $zero shall be used in case a particular op does not take the respective argument: re-using the generic wrapper would mean losing control over the register usage.) Signed-off-by: WANG Xuerui <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 53a4858 commit 83d8b38

File tree

1 file changed

+19
-24
lines changed
  • arch/loongarch/include/asm

1 file changed

+19
-24
lines changed

arch/loongarch/include/asm/tlb.h

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,52 +88,47 @@ enum invtlb_ops {
8888
INVTLB_GID_ADDR = 0x16,
8989
};
9090

91-
/*
92-
* invtlb op info addr
93-
* (0x1 << 26) | (0x24 << 20) | (0x13 << 15) |
94-
* (addr << 10) | (info << 5) | op
95-
*/
96-
static inline void invtlb(u32 op, u32 info, u64 addr)
91+
static __always_inline void invtlb(u32 op, u32 info, u64 addr)
9792
{
9893
__asm__ __volatile__(
99-
"parse_r addr,%0\n\t"
100-
"parse_r info,%1\n\t"
101-
".word ((0x6498000) | (addr << 10) | (info << 5) | %2)\n\t"
102-
:
103-
: "r"(addr), "r"(info), "i"(op)
94+
"invtlb %0, %1, %2\n\t"
10495
:
96+
: "i"(op), "r"(info), "r"(addr)
97+
: "memory"
10598
);
10699
}
107100

108-
static inline void invtlb_addr(u32 op, u32 info, u64 addr)
101+
static __always_inline void invtlb_addr(u32 op, u32 info, u64 addr)
109102
{
103+
BUILD_BUG_ON(!__builtin_constant_p(info) || info != 0);
110104
__asm__ __volatile__(
111-
"parse_r addr,%0\n\t"
112-
".word ((0x6498000) | (addr << 10) | (0 << 5) | %1)\n\t"
113-
:
114-
: "r"(addr), "i"(op)
105+
"invtlb %0, $zero, %1\n\t"
115106
:
107+
: "i"(op), "r"(addr)
108+
: "memory"
116109
);
117110
}
118111

119-
static inline void invtlb_info(u32 op, u32 info, u64 addr)
112+
static __always_inline void invtlb_info(u32 op, u32 info, u64 addr)
120113
{
114+
BUILD_BUG_ON(!__builtin_constant_p(addr) || addr != 0);
121115
__asm__ __volatile__(
122-
"parse_r info,%0\n\t"
123-
".word ((0x6498000) | (0 << 10) | (info << 5) | %1)\n\t"
124-
:
125-
: "r"(info), "i"(op)
116+
"invtlb %0, %1, $zero\n\t"
126117
:
118+
: "i"(op), "r"(info)
119+
: "memory"
127120
);
128121
}
129122

130-
static inline void invtlb_all(u32 op, u32 info, u64 addr)
123+
static __always_inline void invtlb_all(u32 op, u32 info, u64 addr)
131124
{
125+
BUILD_BUG_ON(!__builtin_constant_p(info) || info != 0);
126+
BUILD_BUG_ON(!__builtin_constant_p(addr) || addr != 0);
132127
__asm__ __volatile__(
133-
".word ((0x6498000) | (0 << 10) | (0 << 5) | %0)\n\t"
128+
"invtlb %0, $zero, $zero\n\t"
134129
:
135130
: "i"(op)
136-
:
131+
: "memory"
137132
);
138133
}
139134

0 commit comments

Comments
 (0)