bitops.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef BITOPS_H
  2. #define BITOPS_H
  3. #include "wm_osal.h"
  4. /*
  5. * These functions are the basis of our bit ops.
  6. *
  7. * First, the atomic bitops. These use native endian.
  8. */
  9. static __inline void set_bit(unsigned int bit, volatile unsigned long *p)
  10. {
  11. u32 cpu_sr;
  12. unsigned long mask = 1 << (bit & 31);
  13. p += bit >> 5;
  14. cpu_sr = tls_os_set_critical();
  15. *p |= mask;
  16. tls_os_release_critical(cpu_sr);
  17. }
  18. static __inline void clear_bit(unsigned int bit, volatile unsigned long *p)
  19. {
  20. u32 cpu_sr;
  21. unsigned long mask = 1 << (bit & 31);
  22. p += bit >> 5;
  23. cpu_sr = tls_os_set_critical();
  24. *p &= ~mask;
  25. tls_os_release_critical(cpu_sr);
  26. }
  27. static __inline void change_bit(unsigned int bit, volatile unsigned long *p)
  28. {
  29. u32 cpu_sr;
  30. unsigned long mask = 1 << (bit & 31);
  31. p += bit >> 5;
  32. cpu_sr = tls_os_set_critical();
  33. *p ^= mask;
  34. tls_os_release_critical(cpu_sr);
  35. }
  36. static __inline int
  37. test_and_set_bit(unsigned int bit, volatile unsigned long *p)
  38. {
  39. u32 cpu_sr;
  40. unsigned int res;
  41. unsigned long mask = 1 << (bit & 31);
  42. p += bit >> 5;
  43. cpu_sr = tls_os_set_critical();
  44. res = *p;
  45. *p = res | mask;
  46. tls_os_release_critical(cpu_sr);
  47. return res & mask;
  48. }
  49. static __inline int
  50. test_and_clear_bit(unsigned int bit, volatile unsigned long *p)
  51. {
  52. u32 cpu_sr;
  53. unsigned int res;
  54. unsigned long mask = 1 << (bit & 31);
  55. p += bit >> 5;
  56. cpu_sr = tls_os_set_critical();
  57. res = *p;
  58. *p = res & ~mask;
  59. tls_os_release_critical(cpu_sr);
  60. return res & mask;
  61. }
  62. static __inline int
  63. test_bit(unsigned int bit, volatile unsigned long *p)
  64. {
  65. u32 cpu_sr;
  66. unsigned int res;
  67. unsigned long mask = 1 << (bit & 31);
  68. p += bit >> 5;
  69. cpu_sr = tls_os_set_critical();
  70. res = *p;
  71. tls_os_release_critical(cpu_sr);
  72. return res & mask;
  73. }
  74. static __inline int
  75. test_and_change_bit(unsigned int bit, volatile unsigned long *p)
  76. {
  77. u32 cpu_sr;
  78. unsigned int res;
  79. unsigned long mask = 1 << (bit & 31);
  80. p += bit >> 5;
  81. cpu_sr = tls_os_set_critical();
  82. res = *p;
  83. *p = res ^ mask;
  84. tls_os_release_critical(cpu_sr);
  85. return res & mask;
  86. }
  87. #endif /* BITOPS_H */