rwlock.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Helpers used by both rw spinlocks and rw semaphores.
  3. *
  4. * Based in part on code from semaphore.h and
  5. * spinlock.h Copyright 1996 Linus Torvalds.
  6. *
  7. * Copyright 1999 Red Hat, Inc.
  8. *
  9. * Written by Benjamin LaHaise.
  10. *
  11. * Modified by Matsushita Electric Industrial Co., Ltd.
  12. * Modifications:
  13. * 13-Nov-2006 MEI Temporarily delete lock functions for SMP support.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the Free
  17. * Software Foundation; either version 2 of the License, or (at your option)
  18. * any later version.
  19. */
  20. #ifndef _ASM_RWLOCK_H
  21. #define _ASM_RWLOCK_H
  22. #define RW_LOCK_BIAS 0x01000000
  23. #ifndef CONFIG_SMP
  24. typedef struct { unsigned long a[100]; } __dummy_lock_t;
  25. #define __dummy_lock(lock) (*(__dummy_lock_t *)(lock))
  26. #define RW_LOCK_BIAS_STR "0x01000000"
  27. #define __build_read_lock_ptr(rw, helper) \
  28. do { \
  29. asm volatile( \
  30. " mov (%0),d3 \n" \
  31. " sub 1,d3 \n" \
  32. " mov d3,(%0) \n" \
  33. " blt 1f \n" \
  34. " bra 2f \n" \
  35. "1: jmp 3f \n" \
  36. "2: \n" \
  37. " .section .text.lock,\"ax\" \n" \
  38. "3: call "helper"[],0 \n" \
  39. " jmp 2b \n" \
  40. " .previous" \
  41. : \
  42. : "d" (rw) \
  43. : "memory", "d3", "cc"); \
  44. } while (0)
  45. #define __build_read_lock_const(rw, helper) \
  46. do { \
  47. asm volatile( \
  48. " mov (%0),d3 \n" \
  49. " sub 1,d3 \n" \
  50. " mov d3,(%0) \n" \
  51. " blt 1f \n" \
  52. " bra 2f \n" \
  53. "1: jmp 3f \n" \
  54. "2: \n" \
  55. " .section .text.lock,\"ax\" \n" \
  56. "3: call "helper"[],0 \n" \
  57. " jmp 2b \n" \
  58. " .previous" \
  59. : \
  60. : "d" (rw) \
  61. : "memory", "d3", "cc"); \
  62. } while (0)
  63. #define __build_read_lock(rw, helper) \
  64. do { \
  65. if (__builtin_constant_p(rw)) \
  66. __build_read_lock_const(rw, helper); \
  67. else \
  68. __build_read_lock_ptr(rw, helper); \
  69. } while (0)
  70. #define __build_write_lock_ptr(rw, helper) \
  71. do { \
  72. asm volatile( \
  73. " mov (%0),d3 \n" \
  74. " sub 1,d3 \n" \
  75. " mov d3,(%0) \n" \
  76. " blt 1f \n" \
  77. " bra 2f \n" \
  78. "1: jmp 3f \n" \
  79. "2: \n" \
  80. " .section .text.lock,\"ax\" \n" \
  81. "3: call "helper"[],0 \n" \
  82. " jmp 2b \n" \
  83. " .previous" \
  84. : \
  85. : "d" (rw) \
  86. : "memory", "d3", "cc"); \
  87. } while (0)
  88. #define __build_write_lock_const(rw, helper) \
  89. do { \
  90. asm volatile( \
  91. " mov (%0),d3 \n" \
  92. " sub 1,d3 \n" \
  93. " mov d3,(%0) \n" \
  94. " blt 1f \n" \
  95. " bra 2f \n" \
  96. "1: jmp 3f \n" \
  97. "2: \n" \
  98. " .section .text.lock,\"ax\" \n" \
  99. "3: call "helper"[],0 \n" \
  100. " jmp 2b \n" \
  101. " .previous" \
  102. : \
  103. : "d" (rw) \
  104. : "memory", "d3", "cc"); \
  105. } while (0)
  106. #define __build_write_lock(rw, helper) \
  107. do { \
  108. if (__builtin_constant_p(rw)) \
  109. __build_write_lock_const(rw, helper); \
  110. else \
  111. __build_write_lock_ptr(rw, helper); \
  112. } while (0)
  113. #endif /* CONFIG_SMP */
  114. #endif /* _ASM_RWLOCK_H */