system.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #include <asm/cmpxchg.h>
  22. struct task_struct;
  23. /* context switching is now performed out-of-line in switch_to.S */
  24. extern struct task_struct *__switch_to(struct task_struct *,
  25. struct task_struct *);
  26. #define switch_to(prev, next, last) \
  27. do { \
  28. ((last) = __switch_to((prev), (next))); \
  29. } while (0)
  30. #define arch_align_stack(x) (x)
  31. #define nop() asm volatile ("nop")
  32. #endif /* !__ASSEMBLY__ */
  33. /*
  34. * Force strict CPU ordering.
  35. * And yes, this is required on UP too when we're talking
  36. * to devices.
  37. *
  38. * This implementation only contains a compiler barrier.
  39. */
  40. #define mb() asm volatile ("": : :"memory")
  41. #define rmb() mb()
  42. #define wmb() asm volatile ("": : :"memory")
  43. #ifdef CONFIG_SMP
  44. #define smp_mb() mb()
  45. #define smp_rmb() rmb()
  46. #define smp_wmb() wmb()
  47. #else
  48. #define smp_mb() barrier()
  49. #define smp_rmb() barrier()
  50. #define smp_wmb() barrier()
  51. #endif
  52. #define set_mb(var, value) do { var = value; mb(); } while (0)
  53. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  54. #define read_barrier_depends() do {} while (0)
  55. #define smp_read_barrier_depends() do {} while (0)
  56. /*
  57. * we make sure local_irq_enable() doesn't cause priority inversion
  58. */
  59. #ifndef __ASSEMBLY__
  60. /* This function doesn't exist, so you'll get a linker error
  61. * if something tries to do an invalid xchg(). */
  62. extern void __xchg_called_with_bad_pointer(void);
  63. static inline
  64. unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  65. {
  66. unsigned long ret, flags;
  67. switch (size) {
  68. case 1:
  69. #ifdef __xchg_u8
  70. return __xchg_u8(x, ptr);
  71. #else
  72. local_irq_save(flags);
  73. ret = *(volatile u8 *)ptr;
  74. *(volatile u8 *)ptr = x;
  75. local_irq_restore(flags);
  76. return ret;
  77. #endif /* __xchg_u8 */
  78. case 2:
  79. #ifdef __xchg_u16
  80. return __xchg_u16(x, ptr);
  81. #else
  82. local_irq_save(flags);
  83. ret = *(volatile u16 *)ptr;
  84. *(volatile u16 *)ptr = x;
  85. local_irq_restore(flags);
  86. return ret;
  87. #endif /* __xchg_u16 */
  88. case 4:
  89. #ifdef __xchg_u32
  90. return __xchg_u32(x, ptr);
  91. #else
  92. local_irq_save(flags);
  93. ret = *(volatile u32 *)ptr;
  94. *(volatile u32 *)ptr = x;
  95. local_irq_restore(flags);
  96. return ret;
  97. #endif /* __xchg_u32 */
  98. #ifdef CONFIG_64BIT
  99. case 8:
  100. #ifdef __xchg_u64
  101. return __xchg_u64(x, ptr);
  102. #else
  103. local_irq_save(flags);
  104. ret = *(volatile u64 *)ptr;
  105. *(volatile u64 *)ptr = x;
  106. local_irq_restore(flags);
  107. return ret;
  108. #endif /* __xchg_u64 */
  109. #endif /* CONFIG_64BIT */
  110. default:
  111. __xchg_called_with_bad_pointer();
  112. return x;
  113. }
  114. }
  115. #define xchg(ptr, x) \
  116. ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
  117. #endif /* !__ASSEMBLY__ */
  118. #endif /* __KERNEL__ */
  119. #endif /* __ASM_GENERIC_SYSTEM_H */