system.h 6.9 KB

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