system.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * include/asm-s390/system.h
  3. *
  4. * S390 version
  5. * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7. *
  8. * Derived from "include/asm-i386/system.h"
  9. */
  10. #ifndef __ASM_SYSTEM_H
  11. #define __ASM_SYSTEM_H
  12. #include <linux/kernel.h>
  13. #include <asm/types.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/setup.h>
  16. #include <asm/processor.h>
  17. #ifdef __KERNEL__
  18. struct task_struct;
  19. extern struct task_struct *__switch_to(void *, void *);
  20. static inline void save_fp_regs(s390_fp_regs *fpregs)
  21. {
  22. asm volatile(
  23. " std 0,8(%1)\n"
  24. " std 2,24(%1)\n"
  25. " std 4,40(%1)\n"
  26. " std 6,56(%1)"
  27. : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory");
  28. if (!MACHINE_HAS_IEEE)
  29. return;
  30. asm volatile(
  31. " stfpc 0(%1)\n"
  32. " std 1,16(%1)\n"
  33. " std 3,32(%1)\n"
  34. " std 5,48(%1)\n"
  35. " std 7,64(%1)\n"
  36. " std 8,72(%1)\n"
  37. " std 9,80(%1)\n"
  38. " std 10,88(%1)\n"
  39. " std 11,96(%1)\n"
  40. " std 12,104(%1)\n"
  41. " std 13,112(%1)\n"
  42. " std 14,120(%1)\n"
  43. " std 15,128(%1)\n"
  44. : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory");
  45. }
  46. static inline void restore_fp_regs(s390_fp_regs *fpregs)
  47. {
  48. asm volatile(
  49. " ld 0,8(%0)\n"
  50. " ld 2,24(%0)\n"
  51. " ld 4,40(%0)\n"
  52. " ld 6,56(%0)"
  53. : : "a" (fpregs), "m" (*fpregs));
  54. if (!MACHINE_HAS_IEEE)
  55. return;
  56. asm volatile(
  57. " lfpc 0(%0)\n"
  58. " ld 1,16(%0)\n"
  59. " ld 3,32(%0)\n"
  60. " ld 5,48(%0)\n"
  61. " ld 7,64(%0)\n"
  62. " ld 8,72(%0)\n"
  63. " ld 9,80(%0)\n"
  64. " ld 10,88(%0)\n"
  65. " ld 11,96(%0)\n"
  66. " ld 12,104(%0)\n"
  67. " ld 13,112(%0)\n"
  68. " ld 14,120(%0)\n"
  69. " ld 15,128(%0)\n"
  70. : : "a" (fpregs), "m" (*fpregs));
  71. }
  72. static inline void save_access_regs(unsigned int *acrs)
  73. {
  74. asm volatile("stam 0,15,0(%0)" : : "a" (acrs) : "memory");
  75. }
  76. static inline void restore_access_regs(unsigned int *acrs)
  77. {
  78. asm volatile("lam 0,15,0(%0)" : : "a" (acrs));
  79. }
  80. #define switch_to(prev,next,last) do { \
  81. if (prev == next) \
  82. break; \
  83. save_fp_regs(&prev->thread.fp_regs); \
  84. restore_fp_regs(&next->thread.fp_regs); \
  85. save_access_regs(&prev->thread.acrs[0]); \
  86. restore_access_regs(&next->thread.acrs[0]); \
  87. prev = __switch_to(prev,next); \
  88. } while (0)
  89. /*
  90. * On SMP systems, when the scheduler does migration-cost autodetection,
  91. * it needs a way to flush as much of the CPU's caches as possible.
  92. *
  93. * TODO: fill this in!
  94. */
  95. static inline void sched_cacheflush(void)
  96. {
  97. }
  98. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  99. extern void account_vtime(struct task_struct *);
  100. extern void account_tick_vtime(struct task_struct *);
  101. extern void account_system_vtime(struct task_struct *);
  102. #else
  103. #define account_vtime(x) do { /* empty */ } while (0)
  104. #endif
  105. #ifdef CONFIG_PFAULT
  106. extern void pfault_irq_init(void);
  107. extern int pfault_init(void);
  108. extern void pfault_fini(void);
  109. #else /* CONFIG_PFAULT */
  110. #define pfault_irq_init() do { } while (0)
  111. #define pfault_init() ({-1;})
  112. #define pfault_fini() do { } while (0)
  113. #endif /* CONFIG_PFAULT */
  114. #define finish_arch_switch(prev) do { \
  115. set_fs(current->thread.mm_segment); \
  116. account_vtime(prev); \
  117. } while (0)
  118. #define nop() asm volatile("nop")
  119. #define xchg(ptr,x) \
  120. ({ \
  121. __typeof__(*(ptr)) __ret; \
  122. __ret = (__typeof__(*(ptr))) \
  123. __xchg((unsigned long)(x), (void *)(ptr),sizeof(*(ptr))); \
  124. __ret; \
  125. })
  126. static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
  127. {
  128. unsigned long addr, old;
  129. int shift;
  130. switch (size) {
  131. case 1:
  132. addr = (unsigned long) ptr;
  133. shift = (3 ^ (addr & 3)) << 3;
  134. addr ^= addr & 3;
  135. asm volatile(
  136. " l %0,0(%4)\n"
  137. "0: lr 0,%0\n"
  138. " nr 0,%3\n"
  139. " or 0,%2\n"
  140. " cs %0,0,0(%4)\n"
  141. " jl 0b\n"
  142. : "=&d" (old), "=m" (*(int *) addr)
  143. : "d" (x << shift), "d" (~(255 << shift)), "a" (addr),
  144. "m" (*(int *) addr) : "memory", "cc", "0");
  145. x = old >> shift;
  146. break;
  147. case 2:
  148. addr = (unsigned long) ptr;
  149. shift = (2 ^ (addr & 2)) << 3;
  150. addr ^= addr & 2;
  151. asm volatile(
  152. " l %0,0(%4)\n"
  153. "0: lr 0,%0\n"
  154. " nr 0,%3\n"
  155. " or 0,%2\n"
  156. " cs %0,0,0(%4)\n"
  157. " jl 0b\n"
  158. : "=&d" (old), "=m" (*(int *) addr)
  159. : "d" (x << shift), "d" (~(65535 << shift)), "a" (addr),
  160. "m" (*(int *) addr) : "memory", "cc", "0");
  161. x = old >> shift;
  162. break;
  163. case 4:
  164. asm volatile(
  165. " l %0,0(%3)\n"
  166. "0: cs %0,%2,0(%3)\n"
  167. " jl 0b\n"
  168. : "=&d" (old), "=m" (*(int *) ptr)
  169. : "d" (x), "a" (ptr), "m" (*(int *) ptr)
  170. : "memory", "cc");
  171. x = old;
  172. break;
  173. #ifdef __s390x__
  174. case 8:
  175. asm volatile(
  176. " lg %0,0(%3)\n"
  177. "0: csg %0,%2,0(%3)\n"
  178. " jl 0b\n"
  179. : "=&d" (old), "=m" (*(long *) ptr)
  180. : "d" (x), "a" (ptr), "m" (*(long *) ptr)
  181. : "memory", "cc");
  182. x = old;
  183. break;
  184. #endif /* __s390x__ */
  185. }
  186. return x;
  187. }
  188. /*
  189. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  190. * store NEW in MEM. Return the initial value in MEM. Success is
  191. * indicated by comparing RETURN with OLD.
  192. */
  193. #define __HAVE_ARCH_CMPXCHG 1
  194. #define cmpxchg(ptr,o,n)\
  195. ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
  196. (unsigned long)(n),sizeof(*(ptr))))
  197. static inline unsigned long
  198. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  199. {
  200. unsigned long addr, prev, tmp;
  201. int shift;
  202. switch (size) {
  203. case 1:
  204. addr = (unsigned long) ptr;
  205. shift = (3 ^ (addr & 3)) << 3;
  206. addr ^= addr & 3;
  207. asm volatile(
  208. " l %0,0(%4)\n"
  209. "0: nr %0,%5\n"
  210. " lr %1,%0\n"
  211. " or %0,%2\n"
  212. " or %1,%3\n"
  213. " cs %0,%1,0(%4)\n"
  214. " jnl 1f\n"
  215. " xr %1,%0\n"
  216. " nr %1,%5\n"
  217. " jnz 0b\n"
  218. "1:"
  219. : "=&d" (prev), "=&d" (tmp)
  220. : "d" (old << shift), "d" (new << shift), "a" (ptr),
  221. "d" (~(255 << shift))
  222. : "memory", "cc");
  223. return prev >> shift;
  224. case 2:
  225. addr = (unsigned long) ptr;
  226. shift = (2 ^ (addr & 2)) << 3;
  227. addr ^= addr & 2;
  228. asm volatile(
  229. " l %0,0(%4)\n"
  230. "0: nr %0,%5\n"
  231. " lr %1,%0\n"
  232. " or %0,%2\n"
  233. " or %1,%3\n"
  234. " cs %0,%1,0(%4)\n"
  235. " jnl 1f\n"
  236. " xr %1,%0\n"
  237. " nr %1,%5\n"
  238. " jnz 0b\n"
  239. "1:"
  240. : "=&d" (prev), "=&d" (tmp)
  241. : "d" (old << shift), "d" (new << shift), "a" (ptr),
  242. "d" (~(65535 << shift))
  243. : "memory", "cc");
  244. return prev >> shift;
  245. case 4:
  246. asm volatile(
  247. " cs %0,%2,0(%3)\n"
  248. : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
  249. : "memory", "cc");
  250. return prev;
  251. #ifdef __s390x__
  252. case 8:
  253. asm volatile(
  254. " csg %0,%2,0(%3)\n"
  255. : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
  256. : "memory", "cc");
  257. return prev;
  258. #endif /* __s390x__ */
  259. }
  260. return old;
  261. }
  262. /*
  263. * Force strict CPU ordering.
  264. * And yes, this is required on UP too when we're talking
  265. * to devices.
  266. *
  267. * This is very similar to the ppc eieio/sync instruction in that is
  268. * does a checkpoint syncronisation & makes sure that
  269. * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
  270. */
  271. #define eieio() asm volatile("bcr 15,0" : : : "memory")
  272. #define SYNC_OTHER_CORES(x) eieio()
  273. #define mb() eieio()
  274. #define rmb() eieio()
  275. #define wmb() eieio()
  276. #define read_barrier_depends() do { } while(0)
  277. #define smp_mb() mb()
  278. #define smp_rmb() rmb()
  279. #define smp_wmb() wmb()
  280. #define smp_read_barrier_depends() read_barrier_depends()
  281. #define smp_mb__before_clear_bit() smp_mb()
  282. #define smp_mb__after_clear_bit() smp_mb()
  283. #define set_mb(var, value) do { var = value; mb(); } while (0)
  284. #ifdef __s390x__
  285. #define __ctl_load(array, low, high) ({ \
  286. typedef struct { char _[sizeof(array)]; } addrtype; \
  287. asm volatile( \
  288. " lctlg %1,%2,0(%0)\n" \
  289. : : "a" (&array), "i" (low), "i" (high), \
  290. "m" (*(addrtype *)(array))); \
  291. })
  292. #define __ctl_store(array, low, high) ({ \
  293. typedef struct { char _[sizeof(array)]; } addrtype; \
  294. asm volatile( \
  295. " stctg %2,%3,0(%1)\n" \
  296. : "=m" (*(addrtype *)(array)) \
  297. : "a" (&array), "i" (low), "i" (high)); \
  298. })
  299. #else /* __s390x__ */
  300. #define __ctl_load(array, low, high) ({ \
  301. typedef struct { char _[sizeof(array)]; } addrtype; \
  302. asm volatile( \
  303. " lctl %1,%2,0(%0)\n" \
  304. : : "a" (&array), "i" (low), "i" (high), \
  305. "m" (*(addrtype *)(array))); \
  306. })
  307. #define __ctl_store(array, low, high) ({ \
  308. typedef struct { char _[sizeof(array)]; } addrtype; \
  309. asm volatile( \
  310. " stctl %2,%3,0(%1)\n" \
  311. : "=m" (*(addrtype *)(array)) \
  312. : "a" (&array), "i" (low), "i" (high)); \
  313. })
  314. #endif /* __s390x__ */
  315. #define __ctl_set_bit(cr, bit) ({ \
  316. unsigned long __dummy; \
  317. __ctl_store(__dummy, cr, cr); \
  318. __dummy |= 1UL << (bit); \
  319. __ctl_load(__dummy, cr, cr); \
  320. })
  321. #define __ctl_clear_bit(cr, bit) ({ \
  322. unsigned long __dummy; \
  323. __ctl_store(__dummy, cr, cr); \
  324. __dummy &= ~(1UL << (bit)); \
  325. __ctl_load(__dummy, cr, cr); \
  326. })
  327. #include <linux/irqflags.h>
  328. /*
  329. * Use to set psw mask except for the first byte which
  330. * won't be changed by this function.
  331. */
  332. static inline void
  333. __set_psw_mask(unsigned long mask)
  334. {
  335. __load_psw_mask(mask | (__raw_local_irq_stosm(0x00) & ~(-1UL >> 8)));
  336. }
  337. #define local_mcck_enable() __set_psw_mask(psw_kernel_bits)
  338. #define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK)
  339. #ifdef CONFIG_SMP
  340. extern void smp_ctl_set_bit(int cr, int bit);
  341. extern void smp_ctl_clear_bit(int cr, int bit);
  342. #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
  343. #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
  344. #else
  345. #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
  346. #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
  347. #endif /* CONFIG_SMP */
  348. extern void (*_machine_restart)(char *command);
  349. extern void (*_machine_halt)(void);
  350. extern void (*_machine_power_off)(void);
  351. #define arch_align_stack(x) (x)
  352. #endif /* __KERNEL__ */
  353. #endif