system.h 3.8 KB

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