system.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright IBM Corp. 1999, 2009
  3. *
  4. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  5. */
  6. #ifndef __ASM_SYSTEM_H
  7. #define __ASM_SYSTEM_H
  8. #include <linux/kernel.h>
  9. #include <linux/errno.h>
  10. #include <asm/types.h>
  11. #include <asm/ptrace.h>
  12. #include <asm/setup.h>
  13. #include <asm/processor.h>
  14. #include <asm/lowcore.h>
  15. #include <asm/cmpxchg.h>
  16. #ifdef __KERNEL__
  17. struct task_struct;
  18. extern struct task_struct *__switch_to(void *, void *);
  19. extern void update_per_regs(struct task_struct *task);
  20. static inline void save_fp_regs(s390_fp_regs *fpregs)
  21. {
  22. asm volatile(
  23. " std 0,%O0+8(%R0)\n"
  24. " std 2,%O0+24(%R0)\n"
  25. " std 4,%O0+40(%R0)\n"
  26. " std 6,%O0+56(%R0)"
  27. : "=Q" (*fpregs) : "Q" (*fpregs));
  28. if (!MACHINE_HAS_IEEE)
  29. return;
  30. asm volatile(
  31. " stfpc %0\n"
  32. " std 1,%O0+16(%R0)\n"
  33. " std 3,%O0+32(%R0)\n"
  34. " std 5,%O0+48(%R0)\n"
  35. " std 7,%O0+64(%R0)\n"
  36. " std 8,%O0+72(%R0)\n"
  37. " std 9,%O0+80(%R0)\n"
  38. " std 10,%O0+88(%R0)\n"
  39. " std 11,%O0+96(%R0)\n"
  40. " std 12,%O0+104(%R0)\n"
  41. " std 13,%O0+112(%R0)\n"
  42. " std 14,%O0+120(%R0)\n"
  43. " std 15,%O0+128(%R0)\n"
  44. : "=Q" (*fpregs) : "Q" (*fpregs));
  45. }
  46. static inline void restore_fp_regs(s390_fp_regs *fpregs)
  47. {
  48. asm volatile(
  49. " ld 0,%O0+8(%R0)\n"
  50. " ld 2,%O0+24(%R0)\n"
  51. " ld 4,%O0+40(%R0)\n"
  52. " ld 6,%O0+56(%R0)"
  53. : : "Q" (*fpregs));
  54. if (!MACHINE_HAS_IEEE)
  55. return;
  56. asm volatile(
  57. " lfpc %0\n"
  58. " ld 1,%O0+16(%R0)\n"
  59. " ld 3,%O0+32(%R0)\n"
  60. " ld 5,%O0+48(%R0)\n"
  61. " ld 7,%O0+64(%R0)\n"
  62. " ld 8,%O0+72(%R0)\n"
  63. " ld 9,%O0+80(%R0)\n"
  64. " ld 10,%O0+88(%R0)\n"
  65. " ld 11,%O0+96(%R0)\n"
  66. " ld 12,%O0+104(%R0)\n"
  67. " ld 13,%O0+112(%R0)\n"
  68. " ld 14,%O0+120(%R0)\n"
  69. " ld 15,%O0+128(%R0)\n"
  70. : : "Q" (*fpregs));
  71. }
  72. static inline void save_access_regs(unsigned int *acrs)
  73. {
  74. asm volatile("stam 0,15,%0" : "=Q" (*acrs));
  75. }
  76. static inline void restore_access_regs(unsigned int *acrs)
  77. {
  78. asm volatile("lam 0,15,%0" : : "Q" (*acrs));
  79. }
  80. #define switch_to(prev,next,last) do { \
  81. if (prev->mm) { \
  82. save_fp_regs(&prev->thread.fp_regs); \
  83. save_access_regs(&prev->thread.acrs[0]); \
  84. } \
  85. if (next->mm) { \
  86. restore_fp_regs(&next->thread.fp_regs); \
  87. restore_access_regs(&next->thread.acrs[0]); \
  88. update_per_regs(next); \
  89. } \
  90. prev = __switch_to(prev,next); \
  91. } while (0)
  92. extern void account_vtime(struct task_struct *, struct task_struct *);
  93. extern void account_tick_vtime(struct task_struct *);
  94. #ifdef CONFIG_PFAULT
  95. extern int pfault_init(void);
  96. extern void pfault_fini(void);
  97. #else /* CONFIG_PFAULT */
  98. #define pfault_init() ({-1;})
  99. #define pfault_fini() do { } while (0)
  100. #endif /* CONFIG_PFAULT */
  101. extern void cmma_init(void);
  102. extern int memcpy_real(void *, void *, size_t);
  103. #define finish_arch_switch(prev) do { \
  104. set_fs(current->thread.mm_segment); \
  105. account_vtime(prev, current); \
  106. } while (0)
  107. #define nop() asm volatile("nop")
  108. /*
  109. * Force strict CPU ordering.
  110. * And yes, this is required on UP too when we're talking
  111. * to devices.
  112. *
  113. * This is very similar to the ppc eieio/sync instruction in that is
  114. * does a checkpoint syncronisation & makes sure that
  115. * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
  116. */
  117. #define eieio() asm volatile("bcr 15,0" : : : "memory")
  118. #define SYNC_OTHER_CORES(x) eieio()
  119. #define mb() eieio()
  120. #define rmb() eieio()
  121. #define wmb() eieio()
  122. #define read_barrier_depends() do { } while(0)
  123. #define smp_mb() mb()
  124. #define smp_rmb() rmb()
  125. #define smp_wmb() wmb()
  126. #define smp_read_barrier_depends() read_barrier_depends()
  127. #define smp_mb__before_clear_bit() smp_mb()
  128. #define smp_mb__after_clear_bit() smp_mb()
  129. #define set_mb(var, value) do { var = value; mb(); } while (0)
  130. #ifdef __s390x__
  131. #define __ctl_load(array, low, high) ({ \
  132. typedef struct { char _[sizeof(array)]; } addrtype; \
  133. asm volatile( \
  134. " lctlg %1,%2,%0\n" \
  135. : : "Q" (*(addrtype *)(&array)), \
  136. "i" (low), "i" (high)); \
  137. })
  138. #define __ctl_store(array, low, high) ({ \
  139. typedef struct { char _[sizeof(array)]; } addrtype; \
  140. asm volatile( \
  141. " stctg %1,%2,%0\n" \
  142. : "=Q" (*(addrtype *)(&array)) \
  143. : "i" (low), "i" (high)); \
  144. })
  145. #else /* __s390x__ */
  146. #define __ctl_load(array, low, high) ({ \
  147. typedef struct { char _[sizeof(array)]; } addrtype; \
  148. asm volatile( \
  149. " lctl %1,%2,%0\n" \
  150. : : "Q" (*(addrtype *)(&array)), \
  151. "i" (low), "i" (high)); \
  152. })
  153. #define __ctl_store(array, low, high) ({ \
  154. typedef struct { char _[sizeof(array)]; } addrtype; \
  155. asm volatile( \
  156. " stctl %1,%2,%0\n" \
  157. : "=Q" (*(addrtype *)(&array)) \
  158. : "i" (low), "i" (high)); \
  159. })
  160. #endif /* __s390x__ */
  161. #define __ctl_set_bit(cr, bit) ({ \
  162. unsigned long __dummy; \
  163. __ctl_store(__dummy, cr, cr); \
  164. __dummy |= 1UL << (bit); \
  165. __ctl_load(__dummy, cr, cr); \
  166. })
  167. #define __ctl_clear_bit(cr, bit) ({ \
  168. unsigned long __dummy; \
  169. __ctl_store(__dummy, cr, cr); \
  170. __dummy &= ~(1UL << (bit)); \
  171. __ctl_load(__dummy, cr, cr); \
  172. })
  173. /*
  174. * Use to set psw mask except for the first byte which
  175. * won't be changed by this function.
  176. */
  177. static inline void
  178. __set_psw_mask(unsigned long mask)
  179. {
  180. __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8)));
  181. }
  182. #define local_mcck_enable() __set_psw_mask(psw_kernel_bits)
  183. #define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK)
  184. #ifdef CONFIG_SMP
  185. extern void smp_ctl_set_bit(int cr, int bit);
  186. extern void smp_ctl_clear_bit(int cr, int bit);
  187. #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
  188. #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
  189. #else
  190. #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
  191. #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
  192. #endif /* CONFIG_SMP */
  193. #define MAX_FACILITY_BIT (256*8) /* stfle_fac_list has 256 bytes */
  194. /*
  195. * The test_facility function uses the bit odering where the MSB is bit 0.
  196. * That makes it easier to query facility bits with the bit number as
  197. * documented in the Principles of Operation.
  198. */
  199. static inline int test_facility(unsigned long nr)
  200. {
  201. unsigned char *ptr;
  202. if (nr >= MAX_FACILITY_BIT)
  203. return 0;
  204. ptr = (unsigned char *) &S390_lowcore.stfle_fac_list + (nr >> 3);
  205. return (*ptr & (0x80 >> (nr & 7))) != 0;
  206. }
  207. static inline unsigned short stap(void)
  208. {
  209. unsigned short cpu_address;
  210. asm volatile("stap %0" : "=m" (cpu_address));
  211. return cpu_address;
  212. }
  213. extern void (*_machine_restart)(char *command);
  214. extern void (*_machine_halt)(void);
  215. extern void (*_machine_power_off)(void);
  216. extern unsigned long arch_align_stack(unsigned long sp);
  217. static inline int tprot(unsigned long addr)
  218. {
  219. int rc = -EFAULT;
  220. asm volatile(
  221. " tprot 0(%1),0\n"
  222. "0: ipm %0\n"
  223. " srl %0,28\n"
  224. "1:\n"
  225. EX_TABLE(0b,1b)
  226. : "+d" (rc) : "a" (addr) : "cc");
  227. return rc;
  228. }
  229. #endif /* __KERNEL__ */
  230. #endif