percpu.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef __ARCH_S390_PERCPU__
  2. #define __ARCH_S390_PERCPU__
  3. #include <linux/preempt.h>
  4. #include <asm/cmpxchg.h>
  5. /*
  6. * s390 uses its own implementation for per cpu data, the offset of
  7. * the cpu local data area is cached in the cpu's lowcore memory.
  8. */
  9. #define __my_cpu_offset S390_lowcore.percpu_offset
  10. /*
  11. * For 64 bit module code, the module may be more than 4G above the
  12. * per cpu area, use weak definitions to force the compiler to
  13. * generate external references.
  14. */
  15. #if defined(CONFIG_SMP) && defined(__s390x__) && defined(MODULE)
  16. #define ARCH_NEEDS_WEAK_PER_CPU
  17. #endif
  18. #define arch_this_cpu_to_op(pcp, val, op) \
  19. do { \
  20. typedef typeof(pcp) pcp_op_T__; \
  21. pcp_op_T__ old__, new__, prev__; \
  22. pcp_op_T__ *ptr__; \
  23. preempt_disable(); \
  24. ptr__ = __this_cpu_ptr(&(pcp)); \
  25. prev__ = *ptr__; \
  26. do { \
  27. old__ = prev__; \
  28. new__ = old__ op (val); \
  29. switch (sizeof(*ptr__)) { \
  30. case 8: \
  31. prev__ = cmpxchg64(ptr__, old__, new__); \
  32. break; \
  33. default: \
  34. prev__ = cmpxchg(ptr__, old__, new__); \
  35. } \
  36. } while (prev__ != old__); \
  37. preempt_enable(); \
  38. } while (0)
  39. #define this_cpu_add_1(pcp, val) arch_this_cpu_to_op(pcp, val, +)
  40. #define this_cpu_add_2(pcp, val) arch_this_cpu_to_op(pcp, val, +)
  41. #define this_cpu_add_4(pcp, val) arch_this_cpu_to_op(pcp, val, +)
  42. #define this_cpu_add_8(pcp, val) arch_this_cpu_to_op(pcp, val, +)
  43. #define this_cpu_and_1(pcp, val) arch_this_cpu_to_op(pcp, val, &)
  44. #define this_cpu_and_2(pcp, val) arch_this_cpu_to_op(pcp, val, &)
  45. #define this_cpu_and_4(pcp, val) arch_this_cpu_to_op(pcp, val, &)
  46. #define this_cpu_and_8(pcp, val) arch_this_cpu_to_op(pcp, val, &)
  47. #define this_cpu_or_1(pcp, val) arch_this_cpu_to_op(pcp, val, |)
  48. #define this_cpu_or_2(pcp, val) arch_this_cpu_to_op(pcp, val, |)
  49. #define this_cpu_or_4(pcp, val) arch_this_cpu_to_op(pcp, val, |)
  50. #define this_cpu_or_8(pcp, val) arch_this_cpu_to_op(pcp, val, |)
  51. #define this_cpu_xor_1(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
  52. #define this_cpu_xor_2(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
  53. #define this_cpu_xor_4(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
  54. #define this_cpu_xor_8(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
  55. #define arch_this_cpu_cmpxchg(pcp, oval, nval) \
  56. ({ \
  57. typedef typeof(pcp) pcp_op_T__; \
  58. pcp_op_T__ ret__; \
  59. pcp_op_T__ *ptr__; \
  60. preempt_disable(); \
  61. ptr__ = __this_cpu_ptr(&(pcp)); \
  62. switch (sizeof(*ptr__)) { \
  63. case 8: \
  64. ret__ = cmpxchg64(ptr__, oval, nval); \
  65. break; \
  66. default: \
  67. ret__ = cmpxchg(ptr__, oval, nval); \
  68. } \
  69. preempt_enable(); \
  70. ret__; \
  71. })
  72. #define this_cpu_cmpxchg_1(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
  73. #define this_cpu_cmpxchg_2(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
  74. #define this_cpu_cmpxchg_4(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
  75. #define this_cpu_cmpxchg_8(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
  76. #include <asm-generic/percpu.h>
  77. #endif /* __ARCH_S390_PERCPU__ */