system_32.h 8.2 KB

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