cmpxchg.h 880 B

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