spinlock.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #ifndef __BFIN_SPINLOCK_H
  7. #define __BFIN_SPINLOCK_H
  8. #ifndef CONFIG_SMP
  9. # include <asm-generic/spinlock.h>
  10. #else
  11. #include <linux/atomic.h>
  12. #include <asm/processor.h>
  13. #include <asm/barrier.h>
  14. asmlinkage int __raw_spin_is_locked_asm(volatile int *ptr);
  15. asmlinkage void __raw_spin_lock_asm(volatile int *ptr);
  16. asmlinkage int __raw_spin_trylock_asm(volatile int *ptr);
  17. asmlinkage void __raw_spin_unlock_asm(volatile int *ptr);
  18. asmlinkage void __raw_read_lock_asm(volatile int *ptr);
  19. asmlinkage int __raw_read_trylock_asm(volatile int *ptr);
  20. asmlinkage void __raw_read_unlock_asm(volatile int *ptr);
  21. asmlinkage void __raw_write_lock_asm(volatile int *ptr);
  22. asmlinkage int __raw_write_trylock_asm(volatile int *ptr);
  23. asmlinkage void __raw_write_unlock_asm(volatile int *ptr);
  24. static inline int arch_spin_is_locked(arch_spinlock_t *lock)
  25. {
  26. return __raw_spin_is_locked_asm(&lock->lock);
  27. }
  28. static inline void arch_spin_lock(arch_spinlock_t *lock)
  29. {
  30. __raw_spin_lock_asm(&lock->lock);
  31. }
  32. #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
  33. static inline int arch_spin_trylock(arch_spinlock_t *lock)
  34. {
  35. return __raw_spin_trylock_asm(&lock->lock);
  36. }
  37. static inline void arch_spin_unlock(arch_spinlock_t *lock)
  38. {
  39. __raw_spin_unlock_asm(&lock->lock);
  40. }
  41. static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
  42. {
  43. smp_cond_load_acquire(&lock->lock, !VAL);
  44. }
  45. static inline int arch_read_can_lock(arch_rwlock_t *rw)
  46. {
  47. return __raw_uncached_fetch_asm(&rw->lock) > 0;
  48. }
  49. static inline int arch_write_can_lock(arch_rwlock_t *rw)
  50. {
  51. return __raw_uncached_fetch_asm(&rw->lock) == RW_LOCK_BIAS;
  52. }
  53. static inline void arch_read_lock(arch_rwlock_t *rw)
  54. {
  55. __raw_read_lock_asm(&rw->lock);
  56. }
  57. #define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
  58. static inline int arch_read_trylock(arch_rwlock_t *rw)
  59. {
  60. return __raw_read_trylock_asm(&rw->lock);
  61. }
  62. static inline void arch_read_unlock(arch_rwlock_t *rw)
  63. {
  64. __raw_read_unlock_asm(&rw->lock);
  65. }
  66. static inline void arch_write_lock(arch_rwlock_t *rw)
  67. {
  68. __raw_write_lock_asm(&rw->lock);
  69. }
  70. #define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
  71. static inline int arch_write_trylock(arch_rwlock_t *rw)
  72. {
  73. return __raw_write_trylock_asm(&rw->lock);
  74. }
  75. static inline void arch_write_unlock(arch_rwlock_t *rw)
  76. {
  77. __raw_write_unlock_asm(&rw->lock);
  78. }
  79. #define arch_spin_relax(lock) cpu_relax()
  80. #define arch_read_relax(lock) cpu_relax()
  81. #define arch_write_relax(lock) cpu_relax()
  82. #endif
  83. #endif /* !__BFIN_SPINLOCK_H */