system.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __ASM_AVR32_SYSTEM_H
  9. #define __ASM_AVR32_SYSTEM_H
  10. #include <linux/compiler.h>
  11. #include <linux/types.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/sysreg.h>
  14. #define xchg(ptr,x) \
  15. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  16. #define nop() asm volatile("nop")
  17. #define mb() asm volatile("" : : : "memory")
  18. #define rmb() mb()
  19. #define wmb() asm volatile("sync 0" : : : "memory")
  20. #define read_barrier_depends() do { } while(0)
  21. #define set_mb(var, value) do { var = value; mb(); } while(0)
  22. /*
  23. * Help PathFinder and other Nexus-compliant debuggers keep track of
  24. * the current PID by emitting an Ownership Trace Message each time we
  25. * switch task.
  26. */
  27. #ifdef CONFIG_OWNERSHIP_TRACE
  28. #include <asm/ocd.h>
  29. #define finish_arch_switch(prev) \
  30. do { \
  31. __mtdr(DBGREG_PID, prev->pid); \
  32. __mtdr(DBGREG_PID, current->pid); \
  33. } while(0)
  34. #endif
  35. /*
  36. * switch_to(prev, next, last) should switch from task `prev' to task
  37. * `next'. `prev' will never be the same as `next'.
  38. *
  39. * We just delegate everything to the __switch_to assembly function,
  40. * which is implemented in arch/avr32/kernel/switch_to.S
  41. *
  42. * mb() tells GCC not to cache `current' across this call.
  43. */
  44. struct cpu_context;
  45. struct task_struct;
  46. extern struct task_struct *__switch_to(struct task_struct *,
  47. struct cpu_context *,
  48. struct cpu_context *);
  49. #define switch_to(prev, next, last) \
  50. do { \
  51. last = __switch_to(prev, &prev->thread.cpu_context + 1, \
  52. &next->thread.cpu_context); \
  53. } while (0)
  54. #ifdef CONFIG_SMP
  55. # error "The AVR32 port does not support SMP"
  56. #else
  57. # define smp_mb() barrier()
  58. # define smp_rmb() barrier()
  59. # define smp_wmb() barrier()
  60. # define smp_read_barrier_depends() do { } while(0)
  61. #endif
  62. #include <linux/irqflags.h>
  63. extern void __xchg_called_with_bad_pointer(void);
  64. #ifdef __CHECKER__
  65. extern unsigned long __builtin_xchg(void *ptr, unsigned long x);
  66. #endif
  67. #define xchg_u32(val, m) __builtin_xchg((void *)m, val)
  68. static inline unsigned long __xchg(unsigned long x,
  69. volatile void *ptr,
  70. int size)
  71. {
  72. switch(size) {
  73. case 4:
  74. return xchg_u32(x, ptr);
  75. default:
  76. __xchg_called_with_bad_pointer();
  77. return x;
  78. }
  79. }
  80. static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
  81. unsigned long new)
  82. {
  83. __u32 ret;
  84. asm volatile(
  85. "1: ssrf 5\n"
  86. " ld.w %[ret], %[m]\n"
  87. " cp.w %[ret], %[old]\n"
  88. " brne 2f\n"
  89. " stcond %[m], %[new]\n"
  90. " brne 1b\n"
  91. "2:\n"
  92. : [ret] "=&r"(ret), [m] "=m"(*m)
  93. : "m"(m), [old] "ir"(old), [new] "r"(new)
  94. : "memory", "cc");
  95. return ret;
  96. }
  97. extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
  98. volatile int * m, unsigned long old, unsigned long new);
  99. #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
  100. /* This function doesn't exist, so you'll get a linker error
  101. if something tries to do an invalid cmpxchg(). */
  102. extern void __cmpxchg_called_with_bad_pointer(void);
  103. #define __HAVE_ARCH_CMPXCHG 1
  104. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  105. unsigned long new, int size)
  106. {
  107. switch (size) {
  108. case 4:
  109. return __cmpxchg_u32(ptr, old, new);
  110. case 8:
  111. return __cmpxchg_u64(ptr, old, new);
  112. }
  113. __cmpxchg_called_with_bad_pointer();
  114. return old;
  115. }
  116. #define cmpxchg(ptr, old, new) \
  117. ((typeof(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), \
  118. (unsigned long)(new), \
  119. sizeof(*(ptr))))
  120. struct pt_regs;
  121. extern void __die(const char *, struct pt_regs *, unsigned long,
  122. const char *, const char *, unsigned long);
  123. extern void __die_if_kernel(const char *, struct pt_regs *, unsigned long,
  124. const char *, const char *, unsigned long);
  125. #define die(msg, regs, err) \
  126. __die(msg, regs, err, __FILE__ ":", __FUNCTION__, __LINE__)
  127. #define die_if_kernel(msg, regs, err) \
  128. __die_if_kernel(msg, regs, err, __FILE__ ":", __FUNCTION__, __LINE__)
  129. #define arch_align_stack(x) (x)
  130. #endif /* __ASM_AVR32_SYSTEM_H */