Skip to content

Commit d9708b1

Browse files
guoren83Alexandre Ghiti
authored andcommitted
riscv: Implement smp_cond_load8/16() with Zawrs
RISC-V code uses the queued spinlock implementation, which calls the macros smp_cond_load_acquire for one byte. So, complement the implementation of byte and halfword versions. Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Guo Ren <[email protected]> Cc: Andrew Jones <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Ghiti <[email protected]>
1 parent d9be2b9 commit d9708b1

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

arch/riscv/include/asm/cmpxchg.h

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,48 @@ static __always_inline void __cmpwait(volatile void *ptr,
365365
{
366366
unsigned long tmp;
367367

368+
u32 *__ptr32b;
369+
ulong __s, __val, __mask;
370+
368371
asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop",
369372
0, RISCV_ISA_EXT_ZAWRS, 1)
370373
: : : : no_zawrs);
371374

372375
switch (size) {
373376
case 1:
374-
fallthrough;
377+
__ptr32b = (u32 *)((ulong)(ptr) & ~0x3);
378+
__s = ((ulong)(ptr) & 0x3) * BITS_PER_BYTE;
379+
__val = val << __s;
380+
__mask = 0xff << __s;
381+
382+
asm volatile(
383+
" lr.w %0, %1\n"
384+
" and %0, %0, %3\n"
385+
" xor %0, %0, %2\n"
386+
" bnez %0, 1f\n"
387+
ZAWRS_WRS_NTO "\n"
388+
"1:"
389+
: "=&r" (tmp), "+A" (*(__ptr32b))
390+
: "r" (__val), "r" (__mask)
391+
: "memory");
392+
break;
375393
case 2:
376-
/* RISC-V doesn't have lr instructions on byte and half-word. */
377-
goto no_zawrs;
394+
__ptr32b = (u32 *)((ulong)(ptr) & ~0x3);
395+
__s = ((ulong)(ptr) & 0x2) * BITS_PER_BYTE;
396+
__val = val << __s;
397+
__mask = 0xffff << __s;
398+
399+
asm volatile(
400+
" lr.w %0, %1\n"
401+
" and %0, %0, %3\n"
402+
" xor %0, %0, %2\n"
403+
" bnez %0, 1f\n"
404+
ZAWRS_WRS_NTO "\n"
405+
"1:"
406+
: "=&r" (tmp), "+A" (*(__ptr32b))
407+
: "r" (__val), "r" (__mask)
408+
: "memory");
409+
break;
378410
case 4:
379411
asm volatile(
380412
" lr.w %0, %1\n"

0 commit comments

Comments
 (0)