system_32.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #ifndef __SPARC_SYSTEM_H
  2. #define __SPARC_SYSTEM_H
  3. #include <linux/kernel.h>
  4. #include <linux/threads.h> /* NR_CPUS */
  5. #include <linux/thread_info.h>
  6. #include <asm/page.h>
  7. #include <asm/psr.h>
  8. #include <asm/ptrace.h>
  9. #include <asm/btfixup.h>
  10. #include <asm/smp.h>
  11. #ifndef __ASSEMBLY__
  12. #include <linux/irqflags.h>
  13. static inline unsigned int probe_irq_mask(unsigned long val)
  14. {
  15. return 0;
  16. }
  17. /*
  18. * Sparc (general) CPU types
  19. */
  20. enum sparc_cpu {
  21. sun4 = 0x00,
  22. sun4c = 0x01,
  23. sun4m = 0x02,
  24. sun4d = 0x03,
  25. sun4e = 0x04,
  26. sun4u = 0x05, /* V8 ploos ploos */
  27. sun_unknown = 0x06,
  28. ap1000 = 0x07, /* almost a sun4m */
  29. };
  30. /* Really, userland should not be looking at any of this... */
  31. #ifdef __KERNEL__
  32. extern enum sparc_cpu sparc_cpu_model;
  33. #define ARCH_SUN4C (sparc_cpu_model==sun4c)
  34. #define SUN4M_NCPUS 4 /* Architectural limit of sun4m. */
  35. extern char reboot_command[];
  36. extern struct thread_info *current_set[NR_CPUS];
  37. extern unsigned long empty_bad_page;
  38. extern unsigned long empty_bad_page_table;
  39. extern unsigned long empty_zero_page;
  40. extern void sun_do_break(void);
  41. extern int serial_console;
  42. extern int stop_a_enabled;
  43. extern int scons_pwroff;
  44. static inline int con_is_present(void)
  45. {
  46. return serial_console ? 0 : 1;
  47. }
  48. /* When a context switch happens we must flush all user windows so that
  49. * the windows of the current process are flushed onto its stack. This
  50. * way the windows are all clean for the next process and the stack
  51. * frames are up to date.
  52. */
  53. extern void flush_user_windows(void);
  54. extern void kill_user_windows(void);
  55. extern void synchronize_user_stack(void);
  56. extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
  57. void *fpqueue, unsigned long *fpqdepth);
  58. #ifdef CONFIG_SMP
  59. #define SWITCH_ENTER(prv) \
  60. do { \
  61. if (test_tsk_thread_flag(prv, TIF_USEDFPU)) { \
  62. put_psr(get_psr() | PSR_EF); \
  63. fpsave(&(prv)->thread.float_regs[0], &(prv)->thread.fsr, \
  64. &(prv)->thread.fpqueue[0], &(prv)->thread.fpqdepth); \
  65. clear_tsk_thread_flag(prv, TIF_USEDFPU); \
  66. (prv)->thread.kregs->psr &= ~PSR_EF; \
  67. } \
  68. } while(0)
  69. #define SWITCH_DO_LAZY_FPU(next) /* */
  70. #else
  71. #define SWITCH_ENTER(prv) /* */
  72. #define SWITCH_DO_LAZY_FPU(nxt) \
  73. do { \
  74. if (last_task_used_math != (nxt)) \
  75. (nxt)->thread.kregs->psr&=~PSR_EF; \
  76. } while(0)
  77. #endif
  78. extern void flushw_all(void);
  79. /*
  80. * Flush windows so that the VM switch which follows
  81. * would not pull the stack from under us.
  82. *
  83. * SWITCH_ENTER and SWITH_DO_LAZY_FPU do not work yet (e.g. SMP does not work)
  84. * XXX WTF is the above comment? Found in late teen 2.4.x.
  85. */
  86. #define prepare_arch_switch(next) do { \
  87. __asm__ __volatile__( \
  88. ".globl\tflush_patch_switch\nflush_patch_switch:\n\t" \
  89. "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
  90. "save %sp, -0x40, %sp; save %sp, -0x40, %sp; save %sp, -0x40, %sp\n\t" \
  91. "save %sp, -0x40, %sp\n\t" \
  92. "restore; restore; restore; restore; restore; restore; restore"); \
  93. } while(0)
  94. /* Much care has gone into this code, do not touch it.
  95. *
  96. * We need to loadup regs l0/l1 for the newly forked child
  97. * case because the trap return path relies on those registers
  98. * holding certain values, gcc is told that they are clobbered.
  99. * Gcc needs registers for 3 values in and 1 value out, so we
  100. * clobber every non-fixed-usage register besides l2/l3/o4/o5. -DaveM
  101. *
  102. * Hey Dave, that do not touch sign is too much of an incentive
  103. * - Anton & Pete
  104. */
  105. #define switch_to(prev, next, last) do { \
  106. SWITCH_ENTER(prev); \
  107. SWITCH_DO_LAZY_FPU(next); \
  108. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next->active_mm)); \
  109. __asm__ __volatile__( \
  110. "sethi %%hi(here - 0x8), %%o7\n\t" \
  111. "mov %%g6, %%g3\n\t" \
  112. "or %%o7, %%lo(here - 0x8), %%o7\n\t" \
  113. "rd %%psr, %%g4\n\t" \
  114. "std %%sp, [%%g6 + %4]\n\t" \
  115. "rd %%wim, %%g5\n\t" \
  116. "wr %%g4, 0x20, %%psr\n\t" \
  117. "nop\n\t" \
  118. "std %%g4, [%%g6 + %3]\n\t" \
  119. "ldd [%2 + %3], %%g4\n\t" \
  120. "mov %2, %%g6\n\t" \
  121. ".globl patchme_store_new_current\n" \
  122. "patchme_store_new_current:\n\t" \
  123. "st %2, [%1]\n\t" \
  124. "wr %%g4, 0x20, %%psr\n\t" \
  125. "nop\n\t" \
  126. "nop\n\t" \
  127. "nop\n\t" /* LEON needs all 3 nops: load to %sp depends on CWP. */ \
  128. "ldd [%%g6 + %4], %%sp\n\t" \
  129. "wr %%g5, 0x0, %%wim\n\t" \
  130. "ldd [%%sp + 0x00], %%l0\n\t" \
  131. "ldd [%%sp + 0x38], %%i6\n\t" \
  132. "wr %%g4, 0x0, %%psr\n\t" \
  133. "nop\n\t" \
  134. "nop\n\t" \
  135. "jmpl %%o7 + 0x8, %%g0\n\t" \
  136. " ld [%%g3 + %5], %0\n\t" \
  137. "here:\n" \
  138. : "=&r" (last) \
  139. : "r" (&(current_set[hard_smp_processor_id()])), \
  140. "r" (task_thread_info(next)), \
  141. "i" (TI_KPSR), \
  142. "i" (TI_KSP), \
  143. "i" (TI_TASK) \
  144. : "g1", "g2", "g3", "g4", "g5", "g7", \
  145. "l0", "l1", "l3", "l4", "l5", "l6", "l7", \
  146. "i0", "i1", "i2", "i3", "i4", "i5", \
  147. "o0", "o1", "o2", "o3", "o7"); \
  148. } while(0)
  149. /* XXX Change this if we ever use a PSO mode kernel. */
  150. #define mb() __asm__ __volatile__ ("" : : : "memory")
  151. #define rmb() mb()
  152. #define wmb() mb()
  153. #define read_barrier_depends() do { } while(0)
  154. #define set_mb(__var, __value) do { __var = __value; mb(); } while(0)
  155. #define smp_mb() __asm__ __volatile__("":::"memory")
  156. #define smp_rmb() __asm__ __volatile__("":::"memory")
  157. #define smp_wmb() __asm__ __volatile__("":::"memory")
  158. #define smp_read_barrier_depends() do { } while(0)
  159. #define nop() __asm__ __volatile__ ("nop")
  160. /* This has special calling conventions */
  161. #ifndef CONFIG_SMP
  162. BTFIXUPDEF_CALL(void, ___xchg32, void)
  163. #endif
  164. static inline unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val)
  165. {
  166. #ifdef CONFIG_SMP
  167. __asm__ __volatile__("swap [%2], %0"
  168. : "=&r" (val)
  169. : "0" (val), "r" (m)
  170. : "memory");
  171. return val;
  172. #else
  173. register unsigned long *ptr asm("g1");
  174. register unsigned long ret asm("g2");
  175. ptr = (unsigned long *) m;
  176. ret = val;
  177. /* Note: this is magic and the nop there is
  178. really needed. */
  179. __asm__ __volatile__(
  180. "mov %%o7, %%g4\n\t"
  181. "call ___f____xchg32\n\t"
  182. " nop\n\t"
  183. : "=&r" (ret)
  184. : "0" (ret), "r" (ptr)
  185. : "g3", "g4", "g7", "memory", "cc");
  186. return ret;
  187. #endif
  188. }
  189. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  190. extern void __xchg_called_with_bad_pointer(void);
  191. static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
  192. {
  193. switch (size) {
  194. case 4:
  195. return xchg_u32(ptr, x);
  196. };
  197. __xchg_called_with_bad_pointer();
  198. return x;
  199. }
  200. /* Emulate cmpxchg() the same way we emulate atomics,
  201. * by hashing the object address and indexing into an array
  202. * of spinlocks to get a bit of performance...
  203. *
  204. * See arch/sparc/lib/atomic32.c for implementation.
  205. *
  206. * Cribbed from <asm-parisc/atomic.h>
  207. */
  208. #define __HAVE_ARCH_CMPXCHG 1
  209. /* bug catcher for when unsupported size is used - won't link */
  210. extern void __cmpxchg_called_with_bad_pointer(void);
  211. /* we only need to support cmpxchg of a u32 on sparc */
  212. extern unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
  213. /* don't worry...optimizer will get rid of most of this */
  214. static inline unsigned long
  215. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
  216. {
  217. switch (size) {
  218. case 4:
  219. return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
  220. default:
  221. __cmpxchg_called_with_bad_pointer();
  222. break;
  223. }
  224. return old;
  225. }
  226. #define cmpxchg(ptr, o, n) \
  227. ({ \
  228. __typeof__(*(ptr)) _o_ = (o); \
  229. __typeof__(*(ptr)) _n_ = (n); \
  230. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  231. (unsigned long)_n_, sizeof(*(ptr))); \
  232. })
  233. #include <asm-generic/cmpxchg-local.h>
  234. /*
  235. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  236. * them available.
  237. */
  238. #define cmpxchg_local(ptr, o, n) \
  239. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  240. (unsigned long)(n), sizeof(*(ptr))))
  241. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  242. extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noreturn));
  243. #endif /* __KERNEL__ */
  244. #endif /* __ASSEMBLY__ */
  245. #define arch_align_stack(x) (x)
  246. #endif /* !(__SPARC_SYSTEM_H) */