processor.h 9.2 KB

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