blob: eefe543f84c9264d69dfd40474833f4c38a12fcd [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
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020014#define CIF_MCCK_PENDING 0 /* machine check handling is pending */
15#define CIF_ASCE 1 /* user asce needs fixup / uaccess */
Martin Schwidefskyfe0f4972014-09-30 17:37:52 +020016#define CIF_NOHZ_DELAY 2 /* delay HZ disable for a tick */
Hendrik Brueckner9977e882015-06-10 12:53:42 +020017#define CIF_FPU 3 /* restore vector registers */
Heiko Carstensdb7e0072015-08-15 11:42:21 +020018#define CIF_IGNORE_IRQ 4 /* ignore interrupt (for udelay) */
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020019
20#define _CIF_MCCK_PENDING (1<<CIF_MCCK_PENDING)
21#define _CIF_ASCE (1<<CIF_ASCE)
Martin Schwidefskyfe0f4972014-09-30 17:37:52 +020022#define _CIF_NOHZ_DELAY (1<<CIF_NOHZ_DELAY)
Hendrik Brueckner9977e882015-06-10 12:53:42 +020023#define _CIF_FPU (1<<CIF_FPU)
Heiko Carstensdb7e0072015-08-15 11:42:21 +020024#define _CIF_IGNORE_IRQ (1<<CIF_IGNORE_IRQ)
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020025
Heiko Carstenseb608fb2012-09-05 13:26:11 +020026#ifndef __ASSEMBLY__
27
Heiko Carstensedd53782008-12-25 13:39:16 +010028#include <linux/linkage.h>
David Howellsa0616cd2012-03-28 18:30:02 +010029#include <linux/irqflags.h>
Heiko Carstense86a6ed2009-09-11 10:29:04 +020030#include <asm/cpu.h>
Christian Ehrhardt25097bf2009-04-14 15:36:16 +020031#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/ptrace.h>
Christian Ehrhardt25097bf2009-04-14 15:36:16 +020033#include <asm/setup.h>
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020034#include <asm/runtime_instr.h>
Hendrik Brueckner904818e2015-06-11 15:33:54 +020035#include <asm/fpu-internal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020037static inline void set_cpu_flag(int flag)
38{
Heiko Carstensac25e792015-10-06 16:23:29 +020039 S390_lowcore.cpu_flags |= (1UL << flag);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020040}
41
42static inline void clear_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 int test_cpu_flag(int flag)
48{
Heiko Carstensac25e792015-10-06 16:23:29 +020049 return !!(S390_lowcore.cpu_flags & (1UL << flag));
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020050}
51
Martin Schwidefskyfe0f4972014-09-30 17:37:52 +020052#define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY)
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/*
55 * Default implementation of macro that returns current
56 * instruction pointer ("program counter").
57 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020058#define current_text_addr() ({ void *pc; asm("basr %0,0" : "=a" (pc)); pc; })
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Heiko Carstense86a6ed2009-09-11 10:29:04 +020060static inline void get_cpu_id(struct cpuid *ptr)
Michael Holzheu72960a02007-02-21 10:55:18 +010061{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010062 asm volatile("stidp %0" : "=Q" (*ptr));
Michael Holzheu72960a02007-02-21 10:55:18 +010063}
64
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +010065extern void s390_adjust_jiffies(void);
Martin Schwidefsky638ad342011-10-30 15:17:13 +010066extern const struct seq_operations cpuinfo_op;
67extern int sysctl_ieee_emulation_warnings;
Al Viro65f22a92012-09-06 15:48:11 -040068extern void execve_tail(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
Martin Schwidefskyf481bfa2009-03-18 13:27:36 +010071 * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Martin Schwidefskyf481bfa2009-03-18 13:27:36 +010074#define TASK_SIZE_OF(tsk) ((tsk)->mm->context.asce_limit)
Martin Schwidefsky5a216a22008-02-09 18:24:36 +010075#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
76 (1UL << 30) : (1UL << 41))
77#define TASK_SIZE TASK_SIZE_OF(current)
Martin Schwidefskyee6ee552013-07-26 15:04:03 +020078#define TASK_MAX_SIZE (1UL << 53)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Martin Schwidefsky6252d702008-02-09 18:24:37 +010080#define STACK_TOP (1UL << (test_thread_flag(TIF_31BIT) ? 31:42))
81#define STACK_TOP_MAX (1UL << 42)
David Howells922a70d2008-02-08 04:19:26 -080082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define HAVE_ARCH_PICK_MMAP_LAYOUT
84
85typedef struct {
86 __u32 ar4;
87} mm_segment_t;
88
89/*
90 * Thread structure
91 */
92struct thread_struct {
Hendrik Brueckner904818e2015-06-11 15:33:54 +020093 struct fpu fpu; /* FP and VX register save area */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned int acrs[NUM_ACRS];
95 unsigned long ksp; /* kernel stack pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 mm_segment_t mm_segment;
Martin Schwidefskye5992f22011-07-24 10:48:20 +020097 unsigned long gmap_addr; /* address of last gmap fault. */
Dominik Dingel24eb3a82013-06-17 16:25:18 +020098 unsigned int gmap_pfault; /* signal of a pending guest pfault */
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +010099 struct per_regs per_user; /* User specified PER registers */
100 struct per_event per_event; /* Cause of the last PER trap */
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200101 unsigned long per_flags; /* Flags to control debug behavior */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /* pfault_wait is used to block the process on a pfault event */
103 unsigned long pfault_wait;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200104 struct list_head list;
Jan Glaubere4b8b3f2012-07-31 10:52:05 +0200105 /* cpu runtime instrumentation */
106 struct runtime_instr_cb *ri_cb;
107 int ri_signum;
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200108 unsigned char trap_tdb[256]; /* Transaction abort diagnose block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
Michael Mueller64597f92013-07-02 22:58:26 +0200111/* Flag to disable transactions. */
112#define PER_FLAG_NO_TE 1UL
113/* Flag to enable random transaction aborts. */
114#define PER_FLAG_TE_ABORT_RAND 2UL
115/* Flag to specify random transaction abort mode:
116 * - abort each transaction at a random instruction before TEND if set.
117 * - abort random transactions at a random instruction if cleared.
118 */
119#define PER_FLAG_TE_ABORT_RAND_TEND 4UL
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121typedef struct thread_struct thread_struct;
122
123/*
124 * Stack layout of a C stack frame.
125 */
126#ifndef __PACK_STACK
127struct stack_frame {
128 unsigned long back_chain;
129 unsigned long empty1[5];
130 unsigned long gprs[10];
131 unsigned int empty2[8];
132};
133#else
134struct stack_frame {
135 unsigned long empty1[5];
136 unsigned int empty2[8];
137 unsigned long gprs[10];
138 unsigned long back_chain;
139};
140#endif
141
142#define ARCH_MIN_TASKALIGN 8
143
Hendrik Brueckner0ac27772015-09-29 17:53:22 +0200144extern __vector128 init_task_fpu_regs[__NUM_VXRS];
Martin Schwidefsky6f3fa3f2007-10-22 12:52:45 +0200145#define INIT_THREAD { \
146 .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \
Hendrik Brueckner0ac27772015-09-29 17:53:22 +0200147 .fpu.regs = (void *)&init_task_fpu_regs, \
Martin Schwidefsky6f3fa3f2007-10-22 12:52:45 +0200148}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/*
151 * Do necessary setup to start up a new thread.
152 */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100153#define start_thread(regs, new_psw, new_stackp) do { \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200154 regs->psw.mask = PSW_USER_BITS | PSW_MASK_EA | PSW_MASK_BA; \
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100155 regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
156 regs->gprs[15] = new_stackp; \
Al Viro65f22a92012-09-06 15:48:11 -0400157 execve_tail(); \
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200158} while (0)
159
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100160#define start_thread31(regs, new_psw, new_stackp) do { \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200161 regs->psw.mask = PSW_USER_BITS | PSW_MASK_BA; \
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100162 regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
163 regs->gprs[15] = new_stackp; \
164 crst_table_downgrade(current->mm, 1UL << 31); \
Al Viro65f22a92012-09-06 15:48:11 -0400165 execve_tail(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166} while (0)
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/* Forward declaration, a strange C thing */
169struct task_struct;
170struct mm_struct;
Eric W. Biedermandf5f8312008-02-08 04:18:33 -0800171struct seq_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Heiko Carstens5a798592015-02-12 13:08:27 +0100173void show_cacheinfo(struct seq_file *m);
Heiko Carstens66680222012-08-29 14:12:20 +0200174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/* Free all resources held by a thread. */
176extern void release_thread(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/*
179 * Return saved PC of a blocked thread.
180 */
181extern unsigned long thread_saved_pc(struct task_struct *t);
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183unsigned long get_wchan(struct task_struct *p);
Al Viroc7584fb2006-01-12 01:05:49 -0800184#define task_pt_regs(tsk) ((struct pt_regs *) \
Al Viro30af7122006-01-12 01:05:50 -0800185 (task_stack_page(tsk) + THREAD_SIZE) - 1)
Al Viroc7584fb2006-01-12 01:05:49 -0800186#define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
187#define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Heiko Carstens5ebf2502013-10-16 09:58:01 +0200189/* Has task runtime instrumentation enabled ? */
190#define is_ri_task(tsk) (!!(tsk)->thread.ri_cb)
191
David Howellsa0616cd2012-03-28 18:30:02 +0100192static inline unsigned short stap(void)
193{
194 unsigned short cpu_address;
195
196 asm volatile("stap %0" : "=m" (cpu_address));
197 return cpu_address;
198}
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200/*
201 * Give up the time slice of the virtual PU.
202 */
Heiko Carstens4d92f502015-01-28 07:43:56 +0100203void cpu_relax(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Davidlohr Bueso3a6bfbc2014-06-29 15:09:33 -0700205#define cpu_relax_lowlatency() barrier()
Heiko Carstens083986e2013-09-28 11:23:59 +0200206
Heiko Carstensdc74d7f2007-06-19 13:10:06 +0200207static inline void psw_set_key(unsigned int key)
208{
209 asm volatile("spka 0(%0)" : : "d" (key));
210}
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/*
Heiko Carstens77fa2242005-06-25 14:55:30 -0700213 * Set PSW to specified value.
214 */
215static inline void __load_psw(psw_t psw)
216{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100217 asm volatile("lpswe %0" : : "Q" (psw) : "cc");
Heiko Carstens77fa2242005-06-25 14:55:30 -0700218}
219
220/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 * Set PSW mask to specified value, while leaving the
222 * PSW addr pointing to the next instruction.
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static inline void __load_psw_mask (unsigned long mask)
225{
226 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 psw_t psw;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 psw.mask = mask;
230
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200231 asm volatile(
232 " larl %0,1f\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100233 " stg %0,%O1+8(%R1)\n"
234 " lpswe %1\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 "1:"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100236 : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100238
239/*
Martin Schwidefsky22362a02015-07-08 10:20:04 +0200240 * Extract current PSW mask
241 */
242static inline unsigned long __extract_psw(void)
243{
244 unsigned int reg1, reg2;
245
246 asm volatile("epsw %0,%1" : "=d" (reg1), "=a" (reg2));
247 return (((unsigned long) reg1) << 32) | ((unsigned long) reg2);
248}
249
250/*
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100251 * Rewind PSW instruction address by specified number of bytes.
252 */
253static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
254{
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100255 unsigned long mask;
256
257 mask = (psw.mask & PSW_MASK_EA) ? -1UL :
258 (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 :
259 (1UL << 24) - 1;
260 return (psw.addr - ilc) & mask;
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100261}
Martin Schwidefskyb5f87f12014-10-01 10:57:57 +0200262
263/*
264 * Function to stop a processor until the next interrupt occurs
265 */
266void enabled_wait(void);
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 * Function to drop a processor into disabled wait state
270 */
Joe Perchesff2d8b12012-01-12 17:17:21 -0800271static inline void __noreturn disabled_wait(unsigned long code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 unsigned long ctl_buf;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700274 psw_t dw_psw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100276 dw_psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700277 dw_psw.addr = code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /*
279 * Store status and then load disabled wait psw,
280 * the processor is dead afterwards
281 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200282 asm volatile(
283 " stctg 0,0,0(%2)\n"
284 " ni 4(%2),0xef\n" /* switch off protection */
285 " lctlg 0,0,0(%2)\n"
286 " lghi 1,0x1000\n"
287 " stpt 0x328(1)\n" /* store timer */
288 " stckc 0x330(1)\n" /* store clock comparator */
289 " stpx 0x318(1)\n" /* store prefix register */
290 " stam 0,15,0x340(1)\n"/* store access registers */
291 " stfpc 0x31c(1)\n" /* store fpu control */
292 " std 0,0x200(1)\n" /* store f0 */
293 " std 1,0x208(1)\n" /* store f1 */
294 " std 2,0x210(1)\n" /* store f2 */
295 " std 3,0x218(1)\n" /* store f3 */
296 " std 4,0x220(1)\n" /* store f4 */
297 " std 5,0x228(1)\n" /* store f5 */
298 " std 6,0x230(1)\n" /* store f6 */
299 " std 7,0x238(1)\n" /* store f7 */
300 " std 8,0x240(1)\n" /* store f8 */
301 " std 9,0x248(1)\n" /* store f9 */
302 " std 10,0x250(1)\n" /* store f10 */
303 " std 11,0x258(1)\n" /* store f11 */
304 " std 12,0x260(1)\n" /* store f12 */
305 " std 13,0x268(1)\n" /* store f13 */
306 " std 14,0x270(1)\n" /* store f14 */
307 " std 15,0x278(1)\n" /* store f15 */
308 " stmg 0,15,0x280(1)\n"/* store general registers */
309 " stctg 0,15,0x380(1)\n"/* store control registers */
310 " oi 0x384(1),0x10\n"/* fake protection bit */
311 " lpswe 0(%1)"
312 : "=m" (ctl_buf)
Heiko Carstensbdd42b22009-09-22 22:58:47 +0200313 : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc", "0", "1");
Heiko Carstensedd53782008-12-25 13:39:16 +0100314 while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317/*
David Howellsa0616cd2012-03-28 18:30:02 +0100318 * Use to set psw mask except for the first byte which
319 * won't be changed by this function.
320 */
321static inline void
322__set_psw_mask(unsigned long mask)
323{
324 __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8)));
325}
326
327#define local_mcck_enable() \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200328 __set_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT | PSW_MASK_MCHECK)
David Howellsa0616cd2012-03-28 18:30:02 +0100329#define local_mcck_disable() \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200330 __set_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT)
David Howellsa0616cd2012-03-28 18:30:02 +0100331
332/*
Heiko Carstensab14de62007-02-05 21:18:37 +0100333 * Basic Machine Check/Program Check Handler.
334 */
335
336extern void s390_base_mcck_handler(void);
337extern void s390_base_pgm_handler(void);
338extern void s390_base_ext_handler(void);
339
340extern void (*s390_base_mcck_handler_fn)(void);
341extern void (*s390_base_pgm_handler_fn)(void);
342extern void (*s390_base_ext_handler_fn)(void);
343
Heiko Carstensdfd54cb2006-09-25 23:31:33 -0700344#define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
345
Heiko Carstensfbe76562012-06-05 09:59:52 +0200346extern int memcpy_real(void *, void *, size_t);
347extern void memcpy_absolute(void *, void *, size_t);
348
349#define mem_assign_absolute(dest, val) { \
350 __typeof__(dest) __tmp = (val); \
351 \
352 BUILD_BUG_ON(sizeof(__tmp) != sizeof(val)); \
353 memcpy_absolute(&(dest), &__tmp, sizeof(__tmp)); \
354}
355
Heiko Carstenseb608fb2012-09-05 13:26:11 +0200356#endif /* __ASSEMBLY__ */
357
358#endif /* __ASM_S390_PROCESSOR_H */