cmpxchg.h 919 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_MICROBLAZE_CMPXCHG_H
  3. #define _ASM_MICROBLAZE_CMPXCHG_H
  4. #include <linux/irqflags.h>
  5. void __bad_xchg(volatile void *ptr, int size);
  6. static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
  7. int size)
  8. {
  9. unsigned long ret;
  10. unsigned long flags;
  11. switch (size) {
  12. case 1:
  13. local_irq_save(flags);
  14. ret = *(volatile unsigned char *)ptr;
  15. *(volatile unsigned char *)ptr = x;
  16. local_irq_restore(flags);
  17. break;
  18. case 4:
  19. local_irq_save(flags);
  20. ret = *(volatile unsigned long *)ptr;
  21. *(volatile unsigned long *)ptr = x;
  22. local_irq_restore(flags);
  23. break;
  24. default:
  25. __bad_xchg(ptr, size), ret = 0;
  26. break;
  27. }
  28. return ret;
  29. }
  30. #define xchg(ptr, x) \
  31. ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  32. #include <asm-generic/cmpxchg.h>
  33. #include <asm-generic/cmpxchg-local.h>
  34. #endif /* _ASM_MICROBLAZE_CMPXCHG_H */