cmpxchg-llsc.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_CMPXCHG_LLSC_H
  3. #define __ASM_SH_CMPXCHG_LLSC_H
  4. static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
  5. {
  6. unsigned long retval;
  7. unsigned long tmp;
  8. __asm__ __volatile__ (
  9. "1: \n\t"
  10. "movli.l @%2, %0 ! xchg_u32 \n\t"
  11. "mov %0, %1 \n\t"
  12. "mov %3, %0 \n\t"
  13. "movco.l %0, @%2 \n\t"
  14. "bf 1b \n\t"
  15. "synco \n\t"
  16. : "=&z"(tmp), "=&r" (retval)
  17. : "r" (m), "r" (val)
  18. : "t", "memory"
  19. );
  20. return retval;
  21. }
  22. static inline unsigned long
  23. __cmpxchg_u32(volatile u32 *m, unsigned long old, unsigned long new)
  24. {
  25. unsigned long retval;
  26. unsigned long tmp;
  27. __asm__ __volatile__ (
  28. "1: \n\t"
  29. "movli.l @%2, %0 ! __cmpxchg_u32 \n\t"
  30. "mov %0, %1 \n\t"
  31. "cmp/eq %1, %3 \n\t"
  32. "bf 2f \n\t"
  33. "mov %4, %0 \n\t"
  34. "2: \n\t"
  35. "movco.l %0, @%2 \n\t"
  36. "bf 1b \n\t"
  37. "synco \n\t"
  38. : "=&z" (tmp), "=&r" (retval)
  39. : "r" (m), "r" (old), "r" (new)
  40. : "t", "memory"
  41. );
  42. return retval;
  43. }
  44. #include <asm/cmpxchg-xchg.h>
  45. #endif /* __ASM_SH_CMPXCHG_LLSC_H */