blob: 9c00351f1545808c1f9e9ec9dd21fd5aa46d0184 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02003 * Copyright IBM Corp. 1999
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
11#ifndef __ASM_S390_PROCESSOR_H
12#define __ASM_S390_PROCESSOR_H
13
Heiko Carstens92778b92015-10-06 16:23:39 +020014#include <linux/const.h>
15
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020016#define CIF_MCCK_PENDING 0 /* machine check handling is pending */
17#define CIF_ASCE 1 /* user asce needs fixup / uaccess */
Martin Schwidefskyfe0f4972014-09-30 17:37:52 +020018#define CIF_NOHZ_DELAY 2 /* delay HZ disable for a tick */
Hendrik Bruecknerb0753902015-10-06 12:25:59 +020019#define CIF_FPU 3 /* restore FPU registers */
Heiko Carstensdb7e0072015-08-15 11:42:21 +020020#define CIF_IGNORE_IRQ 4 /* ignore interrupt (for udelay) */
Martin Schwidefsky419123f2015-11-19 11:09:45 +010021#define CIF_ENABLED_WAIT 5 /* in enabled wait state */
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020022
Heiko Carstens92778b92015-10-06 16:23:39 +020023#define _CIF_MCCK_PENDING _BITUL(CIF_MCCK_PENDING)
24#define _CIF_ASCE _BITUL(CIF_ASCE)
25#define _CIF_NOHZ_DELAY _BITUL(CIF_NOHZ_DELAY)
26#define _CIF_FPU _BITUL(CIF_FPU)
27#define _CIF_IGNORE_IRQ _BITUL(CIF_IGNORE_IRQ)
Martin Schwidefsky419123f2015-11-19 11:09:45 +010028#define _CIF_ENABLED_WAIT _BITUL(CIF_ENABLED_WAIT)
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020029
Heiko Carstenseb608fb2012-09-05 13:26:11 +020030#ifndef __ASSEMBLY__
31
Heiko Carstensedd53782008-12-25 13:39:16 +010032#include <linux/linkage.h>
David Howellsa0616cd2012-03-28 18:30:02 +010033#include <linux/irqflags.h>
Heiko Carstense86a6ed2009-09-11 10:29:04 +020034#include <asm/cpu.h>
Christian Ehrhardt25097bf2009-04-14 15:36:16 +020035#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/ptrace.h>
Christian Ehrhardt25097bf2009-04-14 15:36:16 +020037#include <asm/setup.h>
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020038#include <asm/runtime_instr.h>
Hendrik Bruecknerb0753902015-10-06 12:25:59 +020039#include <asm/fpu/types.h>
40#include <asm/fpu/internal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020042static inline void set_cpu_flag(int flag)
43{
Heiko Carstensac25e792015-10-06 16:23:29 +020044 S390_lowcore.cpu_flags |= (1UL << flag);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020045}
46
47static inline void clear_cpu_flag(int flag)
48{
Heiko Carstensac25e792015-10-06 16:23:29 +020049 S390_lowcore.cpu_flags &= ~(1UL << flag);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020050}
51
52static inline int test_cpu_flag(int flag)
53{
Heiko Carstensac25e792015-10-06 16:23:29 +020054 return !!(S390_lowcore.cpu_flags & (1UL << flag));
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020055}
56
Martin Schwidefsky419123f2015-11-19 11:09:45 +010057/*
58 * Test CIF flag of another CPU. The caller needs to ensure that
59 * CPU hotplug can not happen, e.g. by disabling preemption.
60 */
61static inline int test_cpu_flag_of(int flag, int cpu)
62{
Heiko Carstensc667aea2015-12-31 10:29:00 +010063 struct lowcore *lc = lowcore_ptr[cpu];
Martin Schwidefsky419123f2015-11-19 11:09:45 +010064 return !!(lc->cpu_flags & (1UL << flag));
65}
66
Martin Schwidefskyfe0f4972014-09-30 17:37:52 +020067#define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY)
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/*
70 * Default implementation of macro that returns current
71 * instruction pointer ("program counter").
72 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020073#define current_text_addr() ({ void *pc; asm("basr %0,0" : "=a" (pc)); pc; })
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Heiko Carstense86a6ed2009-09-11 10:29:04 +020075static inline void get_cpu_id(struct cpuid *ptr)
Michael Holzheu72960a02007-02-21 10:55:18 +010076{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010077 asm volatile("stidp %0" : "=Q" (*ptr));
Michael Holzheu72960a02007-02-21 10:55:18 +010078}
79
Heiko Carstens097a1162016-04-14 12:35:22 +020080void s390_adjust_jiffies(void);
81void s390_update_cpu_mhz(void);
82void cpu_detect_mhz_feature(void);
83
Martin Schwidefsky638ad342011-10-30 15:17:13 +010084extern const struct seq_operations cpuinfo_op;
85extern int sysctl_ieee_emulation_warnings;
Al Viro65f22a92012-09-06 15:48:11 -040086extern void execve_tail(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/*
Martin Schwidefskyf481bfa2009-03-18 13:27:36 +010089 * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Martin Schwidefskyf481bfa2009-03-18 13:27:36 +010092#define TASK_SIZE_OF(tsk) ((tsk)->mm->context.asce_limit)
Martin Schwidefsky5a216a22008-02-09 18:24:36 +010093#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
94 (1UL << 30) : (1UL << 41))
95#define TASK_SIZE TASK_SIZE_OF(current)
Martin Schwidefskyee6ee552013-07-26 15:04:03 +020096#define TASK_MAX_SIZE (1UL << 53)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Martin Schwidefsky6252d702008-02-09 18:24:37 +010098#define STACK_TOP (1UL << (test_thread_flag(TIF_31BIT) ? 31:42))
99#define STACK_TOP_MAX (1UL << 42)
David Howells922a70d2008-02-08 04:19:26 -0800100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define HAVE_ARCH_PICK_MMAP_LAYOUT
102
103typedef struct {
104 __u32 ar4;
105} mm_segment_t;
106
107/*
108 * Thread structure
109 */
110struct thread_struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 unsigned int acrs[NUM_ACRS];
112 unsigned long ksp; /* kernel stack pointer */
Martin Schwidefsky90c53e62016-11-08 12:15:59 +0100113 unsigned long user_timer; /* task cputime in user space */
114 unsigned long system_timer; /* task cputime in kernel space */
Martin Schwidefskyef280c82016-11-08 12:33:38 +0100115 unsigned long sys_call_table; /* system call table address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 mm_segment_t mm_segment;
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200117 unsigned long gmap_addr; /* address of last gmap fault. */
Martin Schwidefsky4be130a2016-03-08 12:12:18 +0100118 unsigned int gmap_write_flag; /* gmap fault write indication */
David Hildenbrand4a494432016-03-08 12:31:52 +0100119 unsigned int gmap_int_code; /* int code of last gmap fault */
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200120 unsigned int gmap_pfault; /* signal of a pending guest pfault */
Martin Schwidefskyf8fc82b2016-11-08 11:11:02 +0100121 /* Per-thread information related to debugging */
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100122 struct per_regs per_user; /* User specified PER registers */
123 struct per_event per_event; /* Cause of the last PER trap */
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200124 unsigned long per_flags; /* Flags to control debug behavior */
Martin Schwidefskyf8fc82b2016-11-08 11:11:02 +0100125 unsigned int system_call; /* system call number in signal */
Martin Schwidefskyef280c82016-11-08 12:33:38 +0100126 unsigned long last_break; /* last breaking-event-address. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* pfault_wait is used to block the process on a pfault event */
128 unsigned long pfault_wait;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200129 struct list_head list;
Jan Glaubere4b8b3f2012-07-31 10:52:05 +0200130 /* cpu runtime instrumentation */
131 struct runtime_instr_cb *ri_cb;
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200132 unsigned char trap_tdb[256]; /* Transaction abort diagnose block */
Martin Schwidefsky3f6813b2016-04-01 15:42:15 +0200133 /*
134 * Warning: 'fpu' is dynamically-sized. It *MUST* be at
135 * the end.
136 */
137 struct fpu fpu; /* FP and VX register save area */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
Michael Mueller64597f92013-07-02 22:58:26 +0200140/* Flag to disable transactions. */
141#define PER_FLAG_NO_TE 1UL
142/* Flag to enable random transaction aborts. */
143#define PER_FLAG_TE_ABORT_RAND 2UL
144/* Flag to specify random transaction abort mode:
145 * - abort each transaction at a random instruction before TEND if set.
146 * - abort random transactions at a random instruction if cleared.
147 */
148#define PER_FLAG_TE_ABORT_RAND_TEND 4UL
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150typedef struct thread_struct thread_struct;
151
152/*
153 * Stack layout of a C stack frame.
154 */
155#ifndef __PACK_STACK
156struct stack_frame {
157 unsigned long back_chain;
158 unsigned long empty1[5];
159 unsigned long gprs[10];
160 unsigned int empty2[8];
161};
162#else
163struct stack_frame {
164 unsigned long empty1[5];
165 unsigned int empty2[8];
166 unsigned long gprs[10];
167 unsigned long back_chain;
168};
169#endif
170
171#define ARCH_MIN_TASKALIGN 8
172
Martin Schwidefsky6f3fa3f2007-10-22 12:52:45 +0200173#define INIT_THREAD { \
174 .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \
Martin Schwidefsky3f6813b2016-04-01 15:42:15 +0200175 .fpu.regs = (void *) init_task.thread.fpu.fprs, \
Martin Schwidefsky6f3fa3f2007-10-22 12:52:45 +0200176}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/*
179 * Do necessary setup to start up a new thread.
180 */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100181#define start_thread(regs, new_psw, new_stackp) do { \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200182 regs->psw.mask = PSW_USER_BITS | PSW_MASK_EA | PSW_MASK_BA; \
Heiko Carstensfecc868a2016-01-18 12:49:44 +0100183 regs->psw.addr = new_psw; \
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100184 regs->gprs[15] = new_stackp; \
Al Viro65f22a92012-09-06 15:48:11 -0400185 execve_tail(); \
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200186} while (0)
187
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100188#define start_thread31(regs, new_psw, new_stackp) do { \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200189 regs->psw.mask = PSW_USER_BITS | PSW_MASK_BA; \
Heiko Carstensfecc868a2016-01-18 12:49:44 +0100190 regs->psw.addr = new_psw; \
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100191 regs->gprs[15] = new_stackp; \
Gerald Schaefer723cacb2016-04-15 16:38:40 +0200192 crst_table_downgrade(current->mm); \
Al Viro65f22a92012-09-06 15:48:11 -0400193 execve_tail(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194} while (0)
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/* Forward declaration, a strange C thing */
197struct task_struct;
198struct mm_struct;
Eric W. Biedermandf5f8312008-02-08 04:18:33 -0800199struct seq_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Heiko Carstensd0208632016-10-17 11:08:31 +0200201typedef int (*dump_trace_func_t)(void *data, unsigned long address, int reliable);
Heiko Carstens758d39e2016-02-09 12:58:54 +0100202void dump_trace(dump_trace_func_t func, void *data,
203 struct task_struct *task, unsigned long sp);
204
Heiko Carstens5a798592015-02-12 13:08:27 +0100205void show_cacheinfo(struct seq_file *m);
Heiko Carstens66680222012-08-29 14:12:20 +0200206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/* Free all resources held by a thread. */
208extern void release_thread(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/*
211 * Return saved PC of a blocked thread.
212 */
213extern unsigned long thread_saved_pc(struct task_struct *t);
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215unsigned long get_wchan(struct task_struct *p);
Al Viroc7584fb2006-01-12 01:05:49 -0800216#define task_pt_regs(tsk) ((struct pt_regs *) \
Al Viro30af7122006-01-12 01:05:50 -0800217 (task_stack_page(tsk) + THREAD_SIZE) - 1)
Al Viroc7584fb2006-01-12 01:05:49 -0800218#define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
219#define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Heiko Carstens5ebf2502013-10-16 09:58:01 +0200221/* Has task runtime instrumentation enabled ? */
222#define is_ri_task(tsk) (!!(tsk)->thread.ri_cb)
223
Heiko Carstens76737ce2016-01-31 17:06:16 +0100224static inline unsigned long current_stack_pointer(void)
225{
226 unsigned long sp;
227
228 asm volatile("la %0,0(15)" : "=a" (sp));
229 return sp;
230}
231
David Howellsa0616cd2012-03-28 18:30:02 +0100232static inline unsigned short stap(void)
233{
234 unsigned short cpu_address;
235
236 asm volatile("stap %0" : "=m" (cpu_address));
237 return cpu_address;
238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/*
241 * Give up the time slice of the virtual PU.
242 */
Heiko Carstens4d92f502015-01-28 07:43:56 +0100243void cpu_relax(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Davidlohr Bueso3a6bfbc2014-06-29 15:09:33 -0700245#define cpu_relax_lowlatency() barrier()
Heiko Carstens083986e2013-09-28 11:23:59 +0200246
Heiko Carstens097a1162016-04-14 12:35:22 +0200247#define ECAG_CACHE_ATTRIBUTE 0
248#define ECAG_CPU_ATTRIBUTE 1
249
250static inline unsigned long __ecag(unsigned int asi, unsigned char parm)
251{
252 unsigned long val;
253
254 asm volatile(".insn rsy,0xeb000000004c,%0,0,0(%1)" /* ecag */
255 : "=d" (val) : "a" (asi << 8 | parm));
256 return val;
257}
258
Heiko Carstensdc74d7f2007-06-19 13:10:06 +0200259static inline void psw_set_key(unsigned int key)
260{
261 asm volatile("spka 0(%0)" : : "d" (key));
262}
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264/*
Heiko Carstens77fa2242005-06-25 14:55:30 -0700265 * Set PSW to specified value.
266 */
267static inline void __load_psw(psw_t psw)
268{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100269 asm volatile("lpswe %0" : : "Q" (psw) : "cc");
Heiko Carstens77fa2242005-06-25 14:55:30 -0700270}
271
272/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 * Set PSW mask to specified value, while leaving the
274 * PSW addr pointing to the next instruction.
275 */
Heiko Carstensecbafda2015-10-12 11:54:03 +0200276static inline void __load_psw_mask(unsigned long mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 psw_t psw;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 psw.mask = mask;
282
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200283 asm volatile(
284 " larl %0,1f\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100285 " stg %0,%O1+8(%R1)\n"
286 " lpswe %1\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 "1:"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100288 : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100290
291/*
Martin Schwidefsky22362a02015-07-08 10:20:04 +0200292 * Extract current PSW mask
293 */
294static inline unsigned long __extract_psw(void)
295{
296 unsigned int reg1, reg2;
297
298 asm volatile("epsw %0,%1" : "=d" (reg1), "=a" (reg2));
299 return (((unsigned long) reg1) << 32) | ((unsigned long) reg2);
300}
301
Heiko Carstensecbafda2015-10-12 11:54:03 +0200302static inline void local_mcck_enable(void)
303{
304 __load_psw_mask(__extract_psw() | PSW_MASK_MCHECK);
305}
306
307static inline void local_mcck_disable(void)
308{
309 __load_psw_mask(__extract_psw() & ~PSW_MASK_MCHECK);
310}
311
Martin Schwidefsky22362a02015-07-08 10:20:04 +0200312/*
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100313 * Rewind PSW instruction address by specified number of bytes.
314 */
315static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
316{
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100317 unsigned long mask;
318
319 mask = (psw.mask & PSW_MASK_EA) ? -1UL :
320 (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 :
321 (1UL << 24) - 1;
322 return (psw.addr - ilc) & mask;
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100323}
Martin Schwidefskyb5f87f12014-10-01 10:57:57 +0200324
325/*
326 * Function to stop a processor until the next interrupt occurs
327 */
328void enabled_wait(void);
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 * Function to drop a processor into disabled wait state
332 */
Joe Perchesff2d8b12012-01-12 17:17:21 -0800333static inline void __noreturn disabled_wait(unsigned long code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Heiko Carstensf9e6edf2015-10-12 12:28:28 +0200335 psw_t psw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Heiko Carstensf9e6edf2015-10-12 12:28:28 +0200337 psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA;
338 psw.addr = code;
339 __load_psw(psw);
Heiko Carstensedd53782008-12-25 13:39:16 +0100340 while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
343/*
Heiko Carstensab14de62007-02-05 21:18:37 +0100344 * Basic Machine Check/Program Check Handler.
345 */
346
347extern void s390_base_mcck_handler(void);
348extern void s390_base_pgm_handler(void);
349extern void s390_base_ext_handler(void);
350
351extern void (*s390_base_mcck_handler_fn)(void);
352extern void (*s390_base_pgm_handler_fn)(void);
353extern void (*s390_base_ext_handler_fn)(void);
354
Heiko Carstensdfd54cb2006-09-25 23:31:33 -0700355#define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
356
Heiko Carstensfbe76562012-06-05 09:59:52 +0200357extern int memcpy_real(void *, void *, size_t);
358extern void memcpy_absolute(void *, void *, size_t);
359
360#define mem_assign_absolute(dest, val) { \
361 __typeof__(dest) __tmp = (val); \
362 \
363 BUILD_BUG_ON(sizeof(__tmp) != sizeof(val)); \
364 memcpy_absolute(&(dest), &__tmp, sizeof(__tmp)); \
365}
366
Heiko Carstenseb608fb2012-09-05 13:26:11 +0200367#endif /* __ASSEMBLY__ */
368
369#endif /* __ASM_S390_PROCESSOR_H */