system.h 3.9 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/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. ocd_write(PID, prev->pid); \
  33. ocd_write(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. static inline unsigned long xchg_u32(u32 val, volatile u32 *m)
  66. {
  67. u32 ret;
  68. asm volatile("xchg %[ret], %[m], %[val]"
  69. : [ret] "=&r"(ret), "=m"(*m)
  70. : "m"(*m), [m] "r"(m), [val] "r"(val)
  71. : "memory");
  72. return ret;
  73. }
  74. static inline unsigned long __xchg(unsigned long x,
  75. volatile void *ptr,
  76. int size)
  77. {
  78. switch(size) {
  79. case 4:
  80. return xchg_u32(x, ptr);
  81. default:
  82. __xchg_called_with_bad_pointer();
  83. return x;
  84. }
  85. }
  86. static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
  87. unsigned long new)
  88. {
  89. __u32 ret;
  90. asm volatile(
  91. "1: ssrf 5\n"
  92. " ld.w %[ret], %[m]\n"
  93. " cp.w %[ret], %[old]\n"
  94. " brne 2f\n"
  95. " stcond %[m], %[new]\n"
  96. " brne 1b\n"
  97. "2:\n"
  98. : [ret] "=&r"(ret), [m] "=m"(*m)
  99. : "m"(m), [old] "ir"(old), [new] "r"(new)
  100. : "memory", "cc");
  101. return ret;
  102. }
  103. extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
  104. volatile int * m, unsigned long old, unsigned long new);
  105. #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
  106. /* This function doesn't exist, so you'll get a linker error
  107. if something tries to do an invalid cmpxchg(). */
  108. extern void __cmpxchg_called_with_bad_pointer(void);
  109. #define __HAVE_ARCH_CMPXCHG 1
  110. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  111. unsigned long new, int size)
  112. {
  113. switch (size) {
  114. case 4:
  115. return __cmpxchg_u32(ptr, old, new);
  116. case 8:
  117. return __cmpxchg_u64(ptr, old, new);
  118. }
  119. __cmpxchg_called_with_bad_pointer();
  120. return old;
  121. }
  122. #define cmpxchg(ptr, old, new) \
  123. ((typeof(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), \
  124. (unsigned long)(new), \
  125. sizeof(*(ptr))))
  126. struct pt_regs;
  127. void NORET_TYPE die(const char *str, struct pt_regs *regs, long err);
  128. void _exception(long signr, struct pt_regs *regs, int code,
  129. unsigned long addr);
  130. #define arch_align_stack(x) (x)
  131. #endif /* __ASM_AVR32_SYSTEM_H */