processor.h 10 KB

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