processor.h 9.4 KB

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