system.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Generic system definitions, based on MN10300 definitions.
  2. *
  3. * It should be possible to use these on really simple architectures,
  4. * but it serves more as a starting point for new ports.
  5. *
  6. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  7. * Written by David Howells (dhowells@redhat.com)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public Licence
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the Licence, or (at your option) any later version.
  13. */
  14. #ifndef __ASM_GENERIC_SYSTEM_H
  15. #define __ASM_GENERIC_SYSTEM_H
  16. #ifdef __KERNEL__
  17. #ifndef __ASSEMBLY__
  18. #include <linux/types.h>
  19. #include <linux/irqflags.h>
  20. #include <asm/cmpxchg-local.h>
  21. struct task_struct;
  22. /* context switching is now performed out-of-line in switch_to.S */
  23. extern struct task_struct *__switch_to(struct task_struct *,
  24. struct task_struct *);
  25. #define switch_to(prev, next, last) \
  26. do { \
  27. ((last) = __switch_to((prev), (next))); \
  28. } while (0)
  29. #define arch_align_stack(x) (x)
  30. #define nop() asm volatile ("nop")
  31. #endif /* !__ASSEMBLY__ */
  32. /*
  33. * Force strict CPU ordering.
  34. * And yes, this is required on UP too when we're talking
  35. * to devices.
  36. *
  37. * This implementation only contains a compiler barrier.
  38. */
  39. #define mb() asm volatile ("": : :"memory")
  40. #define rmb() mb()
  41. #define wmb() asm volatile ("": : :"memory")
  42. #ifdef CONFIG_SMP
  43. #define smp_mb() mb()
  44. #define smp_rmb() rmb()
  45. #define smp_wmb() wmb()
  46. #else
  47. #define smp_mb() barrier()
  48. #define smp_rmb() barrier()
  49. #define smp_wmb() barrier()
  50. #endif
  51. #define set_mb(var, value) do { var = value; mb(); } while (0)
  52. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  53. #define read_barrier_depends() do {} while (0)
  54. #define smp_read_barrier_depends() do {} while (0)
  55. /*
  56. * we make sure local_irq_enable() doesn't cause priority inversion
  57. */
  58. #ifndef __ASSEMBLY__
  59. /* This function doesn't exist, so you'll get a linker error
  60. * if something tries to do an invalid xchg(). */
  61. extern void __xchg_called_with_bad_pointer(void);
  62. static inline
  63. unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  64. {
  65. unsigned long ret, flags;
  66. switch (size) {
  67. case 1:
  68. #ifdef __xchg_u8
  69. return __xchg_u8(x, ptr);
  70. #else
  71. local_irq_save(flags);
  72. ret = *(volatile u8 *)ptr;
  73. *(volatile u8 *)ptr = x;
  74. local_irq_restore(flags);
  75. return ret;
  76. #endif /* __xchg_u8 */
  77. case 2:
  78. #ifdef __xchg_u16
  79. return __xchg_u16(x, ptr);
  80. #else
  81. local_irq_save(flags);
  82. ret = *(volatile u16 *)ptr;
  83. *(volatile u16 *)ptr = x;
  84. local_irq_restore(flags);
  85. return ret;
  86. #endif /* __xchg_u16 */
  87. case 4:
  88. #ifdef __xchg_u32
  89. return __xchg_u32(x, ptr);
  90. #else
  91. local_irq_save(flags);
  92. ret = *(volatile u32 *)ptr;
  93. *(volatile u32 *)ptr = x;
  94. local_irq_restore(flags);
  95. return ret;
  96. #endif /* __xchg_u32 */
  97. #ifdef CONFIG_64BIT
  98. case 8:
  99. #ifdef __xchg_u64
  100. return __xchg_u64(x, ptr);
  101. #else
  102. local_irq_save(flags);
  103. ret = *(volatile u64 *)ptr;
  104. *(volatile u64 *)ptr = x;
  105. local_irq_restore(flags);
  106. return ret;
  107. #endif /* __xchg_u64 */
  108. #endif /* CONFIG_64BIT */
  109. default:
  110. __xchg_called_with_bad_pointer();
  111. return x;
  112. }
  113. }
  114. #define xchg(ptr, x) \
  115. ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  116. static inline unsigned long __cmpxchg(volatile unsigned long *m,
  117. unsigned long old, unsigned long new)
  118. {
  119. unsigned long retval;
  120. unsigned long flags;
  121. local_irq_save(flags);
  122. retval = *m;
  123. if (retval == old)
  124. *m = new;
  125. local_irq_restore(flags);
  126. return retval;
  127. }
  128. #define cmpxchg(ptr, o, n) \
  129. ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
  130. (unsigned long)(o), \
  131. (unsigned long)(n)))
  132. #endif /* !__ASSEMBLY__ */
  133. #endif /* __KERNEL__ */
  134. #endif /* __ASM_GENERIC_SYSTEM_H */