system.h 3.2 KB

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