system.h 7.9 KB

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