system.h 6.9 KB

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