system.h 12 KB

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