system.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. extern void copy_to_absolute_zero(void *dest, void *src, size_t count);
  104. #define finish_arch_switch(prev) do { \
  105. set_fs(current->thread.mm_segment); \
  106. account_vtime(prev, current); \
  107. } while (0)
  108. #define nop() asm volatile("nop")
  109. /*
  110. * Force strict CPU ordering.
  111. * And yes, this is required on UP too when we're talking
  112. * to devices.
  113. *
  114. * This is very similar to the ppc eieio/sync instruction in that is
  115. * does a checkpoint syncronisation & makes sure that
  116. * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
  117. */
  118. #define eieio() asm volatile("bcr 15,0" : : : "memory")
  119. #define SYNC_OTHER_CORES(x) eieio()
  120. #define mb() eieio()
  121. #define rmb() eieio()
  122. #define wmb() eieio()
  123. #define read_barrier_depends() do { } while(0)
  124. #define smp_mb() mb()
  125. #define smp_rmb() rmb()
  126. #define smp_wmb() wmb()
  127. #define smp_read_barrier_depends() read_barrier_depends()
  128. #define smp_mb__before_clear_bit() smp_mb()
  129. #define smp_mb__after_clear_bit() smp_mb()
  130. #define set_mb(var, value) do { var = value; mb(); } while (0)
  131. #ifdef __s390x__
  132. #define __ctl_load(array, low, high) ({ \
  133. typedef struct { char _[sizeof(array)]; } addrtype; \
  134. asm volatile( \
  135. " lctlg %1,%2,%0\n" \
  136. : : "Q" (*(addrtype *)(&array)), \
  137. "i" (low), "i" (high)); \
  138. })
  139. #define __ctl_store(array, low, high) ({ \
  140. typedef struct { char _[sizeof(array)]; } addrtype; \
  141. asm volatile( \
  142. " stctg %1,%2,%0\n" \
  143. : "=Q" (*(addrtype *)(&array)) \
  144. : "i" (low), "i" (high)); \
  145. })
  146. #else /* __s390x__ */
  147. #define __ctl_load(array, low, high) ({ \
  148. typedef struct { char _[sizeof(array)]; } addrtype; \
  149. asm volatile( \
  150. " lctl %1,%2,%0\n" \
  151. : : "Q" (*(addrtype *)(&array)), \
  152. "i" (low), "i" (high)); \
  153. })
  154. #define __ctl_store(array, low, high) ({ \
  155. typedef struct { char _[sizeof(array)]; } addrtype; \
  156. asm volatile( \
  157. " stctl %1,%2,%0\n" \
  158. : "=Q" (*(addrtype *)(&array)) \
  159. : "i" (low), "i" (high)); \
  160. })
  161. #endif /* __s390x__ */
  162. #define __ctl_set_bit(cr, bit) ({ \
  163. unsigned long __dummy; \
  164. __ctl_store(__dummy, cr, cr); \
  165. __dummy |= 1UL << (bit); \
  166. __ctl_load(__dummy, cr, cr); \
  167. })
  168. #define __ctl_clear_bit(cr, bit) ({ \
  169. unsigned long __dummy; \
  170. __ctl_store(__dummy, cr, cr); \
  171. __dummy &= ~(1UL << (bit)); \
  172. __ctl_load(__dummy, cr, cr); \
  173. })
  174. /*
  175. * Use to set psw mask except for the first byte which
  176. * won't be changed by this function.
  177. */
  178. static inline void
  179. __set_psw_mask(unsigned long mask)
  180. {
  181. __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8)));
  182. }
  183. #define local_mcck_enable() __set_psw_mask(psw_kernel_bits)
  184. #define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK)
  185. #ifdef CONFIG_SMP
  186. extern void smp_ctl_set_bit(int cr, int bit);
  187. extern void smp_ctl_clear_bit(int cr, int bit);
  188. #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
  189. #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
  190. #else
  191. #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
  192. #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
  193. #endif /* CONFIG_SMP */
  194. #define MAX_FACILITY_BIT (256*8) /* stfle_fac_list has 256 bytes */
  195. /*
  196. * The test_facility function uses the bit odering where the MSB is bit 0.
  197. * That makes it easier to query facility bits with the bit number as
  198. * documented in the Principles of Operation.
  199. */
  200. static inline int test_facility(unsigned long nr)
  201. {
  202. unsigned char *ptr;
  203. if (nr >= MAX_FACILITY_BIT)
  204. return 0;
  205. ptr = (unsigned char *) &S390_lowcore.stfle_fac_list + (nr >> 3);
  206. return (*ptr & (0x80 >> (nr & 7))) != 0;
  207. }
  208. static inline unsigned short stap(void)
  209. {
  210. unsigned short cpu_address;
  211. asm volatile("stap %0" : "=m" (cpu_address));
  212. return cpu_address;
  213. }
  214. extern void (*_machine_restart)(char *command);
  215. extern void (*_machine_halt)(void);
  216. extern void (*_machine_power_off)(void);
  217. extern unsigned long arch_align_stack(unsigned long sp);
  218. static inline int tprot(unsigned long addr)
  219. {
  220. int rc = -EFAULT;
  221. asm volatile(
  222. " tprot 0(%1),0\n"
  223. "0: ipm %0\n"
  224. " srl %0,28\n"
  225. "1:\n"
  226. EX_TABLE(0b,1b)
  227. : "+d" (rc) : "a" (addr) : "cc");
  228. return rc;
  229. }
  230. #endif /* __KERNEL__ */
  231. #endif