processor.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * S390 version
  4. * Copyright IBM Corp. 1999
  5. * Author(s): Hartmut Penner ([email protected]),
  6. * Martin Schwidefsky ([email protected])
  7. *
  8. * Derived from "include/asm-i386/processor.h"
  9. * Copyright (C) 1994, Linus Torvalds
  10. */
  11. #ifndef __ASM_S390_PROCESSOR_H
  12. #define __ASM_S390_PROCESSOR_H
  13. #include <linux/bits.h>
  14. #define CIF_NOHZ_DELAY 2 /* delay HZ disable for a tick */
  15. #define CIF_FPU 3 /* restore FPU registers */
  16. #define CIF_ENABLED_WAIT 5 /* in enabled wait state */
  17. #define CIF_MCCK_GUEST 6 /* machine check happening in guest */
  18. #define CIF_DEDICATED_CPU 7 /* this CPU is dedicated */
  19. #define _CIF_NOHZ_DELAY BIT(CIF_NOHZ_DELAY)
  20. #define _CIF_FPU BIT(CIF_FPU)
  21. #define _CIF_ENABLED_WAIT BIT(CIF_ENABLED_WAIT)
  22. #define _CIF_MCCK_GUEST BIT(CIF_MCCK_GUEST)
  23. #define _CIF_DEDICATED_CPU BIT(CIF_DEDICATED_CPU)
  24. #define RESTART_FLAG_CTLREGS _AC(1 << 0, U)
  25. #ifndef __ASSEMBLY__
  26. #include <linux/cpumask.h>
  27. #include <linux/linkage.h>
  28. #include <linux/irqflags.h>
  29. #include <asm/cpu.h>
  30. #include <asm/page.h>
  31. #include <asm/ptrace.h>
  32. #include <asm/setup.h>
  33. #include <asm/runtime_instr.h>
  34. #include <asm/fpu/types.h>
  35. #include <asm/fpu/internal.h>
  36. #include <asm/irqflags.h>
  37. typedef long (*sys_call_ptr_t)(struct pt_regs *regs);
  38. static inline void set_cpu_flag(int flag)
  39. {
  40. S390_lowcore.cpu_flags |= (1UL << flag);
  41. }
  42. static inline void clear_cpu_flag(int flag)
  43. {
  44. S390_lowcore.cpu_flags &= ~(1UL << flag);
  45. }
  46. static inline int test_cpu_flag(int flag)
  47. {
  48. return !!(S390_lowcore.cpu_flags & (1UL << flag));
  49. }
  50. /*
  51. * Test CIF flag of another CPU. The caller needs to ensure that
  52. * CPU hotplug can not happen, e.g. by disabling preemption.
  53. */
  54. static inline int test_cpu_flag_of(int flag, int cpu)
  55. {
  56. struct lowcore *lc = lowcore_ptr[cpu];
  57. return !!(lc->cpu_flags & (1UL << flag));
  58. }
  59. #define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY)
  60. static inline void get_cpu_id(struct cpuid *ptr)
  61. {
  62. asm volatile("stidp %0" : "=Q" (*ptr));
  63. }
  64. void s390_adjust_jiffies(void);
  65. void s390_update_cpu_mhz(void);
  66. void cpu_detect_mhz_feature(void);
  67. extern const struct seq_operations cpuinfo_op;
  68. extern void execve_tail(void);
  69. extern void __bpon(void);
  70. unsigned long vdso_size(void);
  71. /*
  72. * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
  73. */
  74. #define TASK_SIZE (test_thread_flag(TIF_31BIT) ? \
  75. _REGION3_SIZE : TASK_SIZE_MAX)
  76. #define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
  77. (_REGION3_SIZE >> 1) : (_REGION2_SIZE >> 1))
  78. #define TASK_SIZE_MAX (-PAGE_SIZE)
  79. #define VDSO_BASE (STACK_TOP + PAGE_SIZE)
  80. #define VDSO_LIMIT (test_thread_flag(TIF_31BIT) ? _REGION3_SIZE : _REGION2_SIZE)
  81. #define STACK_TOP (VDSO_LIMIT - vdso_size() - PAGE_SIZE)
  82. #define STACK_TOP_MAX (_REGION2_SIZE - vdso_size() - PAGE_SIZE)
  83. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  84. /*
  85. * Thread structure
  86. */
  87. struct thread_struct {
  88. unsigned int acrs[NUM_ACRS];
  89. unsigned long ksp; /* kernel stack pointer */
  90. unsigned long user_timer; /* task cputime in user space */
  91. unsigned long guest_timer; /* task cputime in kvm guest */
  92. unsigned long system_timer; /* task cputime in kernel space */
  93. unsigned long hardirq_timer; /* task cputime in hardirq context */
  94. unsigned long softirq_timer; /* task cputime in softirq context */
  95. const sys_call_ptr_t *sys_call_table; /* system call table address */
  96. unsigned long gmap_addr; /* address of last gmap fault. */
  97. unsigned int gmap_write_flag; /* gmap fault write indication */
  98. unsigned int gmap_int_code; /* int code of last gmap fault */
  99. unsigned int gmap_pfault; /* signal of a pending guest pfault */
  100. /* Per-thread information related to debugging */
  101. struct per_regs per_user; /* User specified PER registers */
  102. struct per_event per_event; /* Cause of the last PER trap */
  103. unsigned long per_flags; /* Flags to control debug behavior */
  104. unsigned int system_call; /* system call number in signal */
  105. unsigned long last_break; /* last breaking-event-address. */
  106. /* pfault_wait is used to block the process on a pfault event */
  107. unsigned long pfault_wait;
  108. struct list_head list;
  109. /* cpu runtime instrumentation */
  110. struct runtime_instr_cb *ri_cb;
  111. struct gs_cb *gs_cb; /* Current guarded storage cb */
  112. struct gs_cb *gs_bc_cb; /* Broadcast guarded storage cb */
  113. struct pgm_tdb trap_tdb; /* Transaction abort diagnose block */
  114. /*
  115. * Warning: 'fpu' is dynamically-sized. It *MUST* be at
  116. * the end.
  117. */
  118. struct fpu fpu; /* FP and VX register save area */
  119. };
  120. /* Flag to disable transactions. */
  121. #define PER_FLAG_NO_TE 1UL
  122. /* Flag to enable random transaction aborts. */
  123. #define PER_FLAG_TE_ABORT_RAND 2UL
  124. /* Flag to specify random transaction abort mode:
  125. * - abort each transaction at a random instruction before TEND if set.
  126. * - abort random transactions at a random instruction if cleared.
  127. */
  128. #define PER_FLAG_TE_ABORT_RAND_TEND 4UL
  129. typedef struct thread_struct thread_struct;
  130. #define ARCH_MIN_TASKALIGN 8
  131. #define INIT_THREAD { \
  132. .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \
  133. .fpu.regs = (void *) init_task.thread.fpu.fprs, \
  134. .last_break = 1, \
  135. }
  136. /*
  137. * Do necessary setup to start up a new thread.
  138. */
  139. #define start_thread(regs, new_psw, new_stackp) do { \
  140. regs->psw.mask = PSW_USER_BITS | PSW_MASK_EA | PSW_MASK_BA; \
  141. regs->psw.addr = new_psw; \
  142. regs->gprs[15] = new_stackp; \
  143. execve_tail(); \
  144. } while (0)
  145. #define start_thread31(regs, new_psw, new_stackp) do { \
  146. regs->psw.mask = PSW_USER_BITS | PSW_MASK_BA; \
  147. regs->psw.addr = new_psw; \
  148. regs->gprs[15] = new_stackp; \
  149. execve_tail(); \
  150. } while (0)
  151. /* Forward declaration, a strange C thing */
  152. struct task_struct;
  153. struct mm_struct;
  154. struct seq_file;
  155. struct pt_regs;
  156. void show_registers(struct pt_regs *regs);
  157. void show_cacheinfo(struct seq_file *m);
  158. /* Free guarded storage control block */
  159. void guarded_storage_release(struct task_struct *tsk);
  160. void gs_load_bc_cb(struct pt_regs *regs);
  161. unsigned long __get_wchan(struct task_struct *p);
  162. #define task_pt_regs(tsk) ((struct pt_regs *) \
  163. (task_stack_page(tsk) + THREAD_SIZE) - 1)
  164. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
  165. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
  166. /* Has task runtime instrumentation enabled ? */
  167. #define is_ri_task(tsk) (!!(tsk)->thread.ri_cb)
  168. /* avoid using global register due to gcc bug in versions < 8.4 */
  169. #define current_stack_pointer (__current_stack_pointer())
  170. static __always_inline unsigned long __current_stack_pointer(void)
  171. {
  172. unsigned long sp;
  173. asm volatile("lgr %0,15" : "=d" (sp));
  174. return sp;
  175. }
  176. static __always_inline unsigned short stap(void)
  177. {
  178. unsigned short cpu_address;
  179. asm volatile("stap %0" : "=Q" (cpu_address));
  180. return cpu_address;
  181. }
  182. #define cpu_relax() barrier()
  183. #define ECAG_CACHE_ATTRIBUTE 0
  184. #define ECAG_CPU_ATTRIBUTE 1
  185. static inline unsigned long __ecag(unsigned int asi, unsigned char parm)
  186. {
  187. unsigned long val;
  188. asm volatile("ecag %0,0,0(%1)" : "=d" (val) : "a" (asi << 8 | parm));
  189. return val;
  190. }
  191. static inline void psw_set_key(unsigned int key)
  192. {
  193. asm volatile("spka 0(%0)" : : "d" (key));
  194. }
  195. /*
  196. * Set PSW to specified value.
  197. */
  198. static inline void __load_psw(psw_t psw)
  199. {
  200. asm volatile("lpswe %0" : : "Q" (psw) : "cc");
  201. }
  202. /*
  203. * Set PSW mask to specified value, while leaving the
  204. * PSW addr pointing to the next instruction.
  205. */
  206. static __always_inline void __load_psw_mask(unsigned long mask)
  207. {
  208. unsigned long addr;
  209. psw_t psw;
  210. psw.mask = mask;
  211. asm volatile(
  212. " larl %0,1f\n"
  213. " stg %0,%1\n"
  214. " lpswe %2\n"
  215. "1:"
  216. : "=&d" (addr), "=Q" (psw.addr) : "Q" (psw) : "memory", "cc");
  217. }
  218. /*
  219. * Extract current PSW mask
  220. */
  221. static inline unsigned long __extract_psw(void)
  222. {
  223. unsigned int reg1, reg2;
  224. asm volatile("epsw %0,%1" : "=d" (reg1), "=a" (reg2));
  225. return (((unsigned long) reg1) << 32) | ((unsigned long) reg2);
  226. }
  227. static inline void local_mcck_enable(void)
  228. {
  229. __load_psw_mask(__extract_psw() | PSW_MASK_MCHECK);
  230. }
  231. static inline void local_mcck_disable(void)
  232. {
  233. __load_psw_mask(__extract_psw() & ~PSW_MASK_MCHECK);
  234. }
  235. /*
  236. * Rewind PSW instruction address by specified number of bytes.
  237. */
  238. static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
  239. {
  240. unsigned long mask;
  241. mask = (psw.mask & PSW_MASK_EA) ? -1UL :
  242. (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 :
  243. (1UL << 24) - 1;
  244. return (psw.addr - ilc) & mask;
  245. }
  246. /*
  247. * Function to drop a processor into disabled wait state
  248. */
  249. static __always_inline void __noreturn disabled_wait(void)
  250. {
  251. psw_t psw;
  252. psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA;
  253. psw.addr = _THIS_IP_;
  254. __load_psw(psw);
  255. while (1);
  256. }
  257. #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
  258. extern int s390_isolate_bp(void);
  259. extern int s390_isolate_bp_guest(void);
  260. static __always_inline bool regs_irqs_disabled(struct pt_regs *regs)
  261. {
  262. return arch_irqs_disabled_flags(regs->psw.mask);
  263. }
  264. #endif /* __ASSEMBLY__ */
  265. #endif /* __ASM_S390_PROCESSOR_H */