blob: b16c3d0a1b9fc180bee2846ba5e057bd6cd40983 [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 Schwidefskyd3a73ac2014-04-15 12:55:07 +020021
Heiko Carstens92778b92015-10-06 16:23:39 +020022#define _CIF_MCCK_PENDING _BITUL(CIF_MCCK_PENDING)
23#define _CIF_ASCE _BITUL(CIF_ASCE)
24#define _CIF_NOHZ_DELAY _BITUL(CIF_NOHZ_DELAY)
25#define _CIF_FPU _BITUL(CIF_FPU)
26#define _CIF_IGNORE_IRQ _BITUL(CIF_IGNORE_IRQ)
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020027
Heiko Carstenseb608fb2012-09-05 13:26:11 +020028#ifndef __ASSEMBLY__
29
Heiko Carstensedd53782008-12-25 13:39:16 +010030#include <linux/linkage.h>
David Howellsa0616cd2012-03-28 18:30:02 +010031#include <linux/irqflags.h>
Heiko Carstense86a6ed2009-09-11 10:29:04 +020032#include <asm/cpu.h>
Christian Ehrhardt25097bf2009-04-14 15:36:16 +020033#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/ptrace.h>
Christian Ehrhardt25097bf2009-04-14 15:36:16 +020035#include <asm/setup.h>
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020036#include <asm/runtime_instr.h>
Hendrik Bruecknerb0753902015-10-06 12:25:59 +020037#include <asm/fpu/types.h>
38#include <asm/fpu/internal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020040static inline void set_cpu_flag(int flag)
41{
Heiko Carstensac25e792015-10-06 16:23:29 +020042 S390_lowcore.cpu_flags |= (1UL << flag);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020043}
44
45static inline void clear_cpu_flag(int flag)
46{
Heiko Carstensac25e792015-10-06 16:23:29 +020047 S390_lowcore.cpu_flags &= ~(1UL << flag);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020048}
49
50static inline int test_cpu_flag(int flag)
51{
Heiko Carstensac25e792015-10-06 16:23:29 +020052 return !!(S390_lowcore.cpu_flags & (1UL << flag));
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020053}
54
Martin Schwidefskyfe0f4972014-09-30 17:37:52 +020055#define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY)
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Default implementation of macro that returns current
59 * instruction pointer ("program counter").
60 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020061#define current_text_addr() ({ void *pc; asm("basr %0,0" : "=a" (pc)); pc; })
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Heiko Carstense86a6ed2009-09-11 10:29:04 +020063static inline void get_cpu_id(struct cpuid *ptr)
Michael Holzheu72960a02007-02-21 10:55:18 +010064{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010065 asm volatile("stidp %0" : "=Q" (*ptr));
Michael Holzheu72960a02007-02-21 10:55:18 +010066}
67
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +010068extern void s390_adjust_jiffies(void);
Martin Schwidefsky638ad342011-10-30 15:17:13 +010069extern const struct seq_operations cpuinfo_op;
70extern int sysctl_ieee_emulation_warnings;
Al Viro65f22a92012-09-06 15:48:11 -040071extern void execve_tail(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/*
Martin Schwidefskyf481bfa2009-03-18 13:27:36 +010074 * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Martin Schwidefskyf481bfa2009-03-18 13:27:36 +010077#define TASK_SIZE_OF(tsk) ((tsk)->mm->context.asce_limit)
Martin Schwidefsky5a216a22008-02-09 18:24:36 +010078#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
79 (1UL << 30) : (1UL << 41))
80#define TASK_SIZE TASK_SIZE_OF(current)
Martin Schwidefskyee6ee552013-07-26 15:04:03 +020081#define TASK_MAX_SIZE (1UL << 53)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Martin Schwidefsky6252d702008-02-09 18:24:37 +010083#define STACK_TOP (1UL << (test_thread_flag(TIF_31BIT) ? 31:42))
84#define STACK_TOP_MAX (1UL << 42)
David Howells922a70d2008-02-08 04:19:26 -080085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define HAVE_ARCH_PICK_MMAP_LAYOUT
87
88typedef struct {
89 __u32 ar4;
90} mm_segment_t;
91
92/*
93 * Thread structure
94 */
95struct thread_struct {
Hendrik Brueckner904818e2015-06-11 15:33:54 +020096 struct fpu fpu; /* FP and VX register save area */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 unsigned int acrs[NUM_ACRS];
98 unsigned long ksp; /* kernel stack pointer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 mm_segment_t mm_segment;
Martin Schwidefskye5992f22011-07-24 10:48:20 +0200100 unsigned long gmap_addr; /* address of last gmap fault. */
Dominik Dingel24eb3a82013-06-17 16:25:18 +0200101 unsigned int gmap_pfault; /* signal of a pending guest pfault */
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100102 struct per_regs per_user; /* User specified PER registers */
103 struct per_event per_event; /* Cause of the last PER trap */
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200104 unsigned long per_flags; /* Flags to control debug behavior */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* pfault_wait is used to block the process on a pfault event */
106 unsigned long pfault_wait;
Heiko Carstensf2db2e62011-05-23 10:24:34 +0200107 struct list_head list;
Jan Glaubere4b8b3f2012-07-31 10:52:05 +0200108 /* cpu runtime instrumentation */
109 struct runtime_instr_cb *ri_cb;
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200110 unsigned char trap_tdb[256]; /* Transaction abort diagnose block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
Michael Mueller64597f92013-07-02 22:58:26 +0200113/* Flag to disable transactions. */
114#define PER_FLAG_NO_TE 1UL
115/* Flag to enable random transaction aborts. */
116#define PER_FLAG_TE_ABORT_RAND 2UL
117/* Flag to specify random transaction abort mode:
118 * - abort each transaction at a random instruction before TEND if set.
119 * - abort random transactions at a random instruction if cleared.
120 */
121#define PER_FLAG_TE_ABORT_RAND_TEND 4UL
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123typedef struct thread_struct thread_struct;
124
125/*
126 * Stack layout of a C stack frame.
127 */
128#ifndef __PACK_STACK
129struct stack_frame {
130 unsigned long back_chain;
131 unsigned long empty1[5];
132 unsigned long gprs[10];
133 unsigned int empty2[8];
134};
135#else
136struct stack_frame {
137 unsigned long empty1[5];
138 unsigned int empty2[8];
139 unsigned long gprs[10];
140 unsigned long back_chain;
141};
142#endif
143
144#define ARCH_MIN_TASKALIGN 8
145
Hendrik Brueckner0ac27772015-09-29 17:53:22 +0200146extern __vector128 init_task_fpu_regs[__NUM_VXRS];
Martin Schwidefsky6f3fa3f2007-10-22 12:52:45 +0200147#define INIT_THREAD { \
148 .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \
Hendrik Brueckner0ac27772015-09-29 17:53:22 +0200149 .fpu.regs = (void *)&init_task_fpu_regs, \
Martin Schwidefsky6f3fa3f2007-10-22 12:52:45 +0200150}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/*
153 * Do necessary setup to start up a new thread.
154 */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100155#define start_thread(regs, new_psw, new_stackp) do { \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200156 regs->psw.mask = PSW_USER_BITS | PSW_MASK_EA | PSW_MASK_BA; \
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100157 regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
158 regs->gprs[15] = new_stackp; \
Al Viro65f22a92012-09-06 15:48:11 -0400159 execve_tail(); \
Martin Schwidefsky63506c42008-07-14 09:58:54 +0200160} while (0)
161
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100162#define start_thread31(regs, new_psw, new_stackp) do { \
Martin Schwidefskye258d712013-09-24 09:14:56 +0200163 regs->psw.mask = PSW_USER_BITS | PSW_MASK_BA; \
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100164 regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
165 regs->gprs[15] = new_stackp; \
166 crst_table_downgrade(current->mm, 1UL << 31); \
Al Viro65f22a92012-09-06 15:48:11 -0400167 execve_tail(); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168} while (0)
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/* Forward declaration, a strange C thing */
171struct task_struct;
172struct mm_struct;
Eric W. Biedermandf5f8312008-02-08 04:18:33 -0800173struct seq_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Heiko Carstens5a798592015-02-12 13:08:27 +0100175void show_cacheinfo(struct seq_file *m);
Heiko Carstens66680222012-08-29 14:12:20 +0200176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/* Free all resources held by a thread. */
178extern void release_thread(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/*
181 * Return saved PC of a blocked thread.
182 */
183extern unsigned long thread_saved_pc(struct task_struct *t);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185unsigned long get_wchan(struct task_struct *p);
Al Viroc7584fb2006-01-12 01:05:49 -0800186#define task_pt_regs(tsk) ((struct pt_regs *) \
Al Viro30af7122006-01-12 01:05:50 -0800187 (task_stack_page(tsk) + THREAD_SIZE) - 1)
Al Viroc7584fb2006-01-12 01:05:49 -0800188#define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
189#define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Heiko Carstens5ebf2502013-10-16 09:58:01 +0200191/* Has task runtime instrumentation enabled ? */
192#define is_ri_task(tsk) (!!(tsk)->thread.ri_cb)
193
David Howellsa0616cd2012-03-28 18:30:02 +0100194static inline unsigned short stap(void)
195{
196 unsigned short cpu_address;
197
198 asm volatile("stap %0" : "=m" (cpu_address));
199 return cpu_address;
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/*
203 * Give up the time slice of the virtual PU.
204 */
Heiko Carstens4d92f502015-01-28 07:43:56 +0100205void cpu_relax(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Davidlohr Bueso3a6bfbc2014-06-29 15:09:33 -0700207#define cpu_relax_lowlatency() barrier()
Heiko Carstens083986e2013-09-28 11:23:59 +0200208
Heiko Carstensdc74d7f2007-06-19 13:10:06 +0200209static inline void psw_set_key(unsigned int key)
210{
211 asm volatile("spka 0(%0)" : : "d" (key));
212}
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/*
Heiko Carstens77fa2242005-06-25 14:55:30 -0700215 * Set PSW to specified value.
216 */
217static inline void __load_psw(psw_t psw)
218{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100219 asm volatile("lpswe %0" : : "Q" (psw) : "cc");
Heiko Carstens77fa2242005-06-25 14:55:30 -0700220}
221
222/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 * Set PSW mask to specified value, while leaving the
224 * PSW addr pointing to the next instruction.
225 */
Heiko Carstensecbafda2015-10-12 11:54:03 +0200226static inline void __load_psw_mask(unsigned long mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 psw_t psw;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 psw.mask = mask;
232
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200233 asm volatile(
234 " larl %0,1f\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100235 " stg %0,%O1+8(%R1)\n"
236 " lpswe %1\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 "1:"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100238 : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100240
241/*
Martin Schwidefsky22362a02015-07-08 10:20:04 +0200242 * Extract current PSW mask
243 */
244static inline unsigned long __extract_psw(void)
245{
246 unsigned int reg1, reg2;
247
248 asm volatile("epsw %0,%1" : "=d" (reg1), "=a" (reg2));
249 return (((unsigned long) reg1) << 32) | ((unsigned long) reg2);
250}
251
Heiko Carstensecbafda2015-10-12 11:54:03 +0200252static inline void local_mcck_enable(void)
253{
254 __load_psw_mask(__extract_psw() | PSW_MASK_MCHECK);
255}
256
257static inline void local_mcck_disable(void)
258{
259 __load_psw_mask(__extract_psw() & ~PSW_MASK_MCHECK);
260}
261
Martin Schwidefsky22362a02015-07-08 10:20:04 +0200262/*
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100263 * Rewind PSW instruction address by specified number of bytes.
264 */
265static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
266{
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100267 unsigned long mask;
268
269 mask = (psw.mask & PSW_MASK_EA) ? -1UL :
270 (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 :
271 (1UL << 24) - 1;
272 return (psw.addr - ilc) & mask;
Martin Schwidefskyccf45ca2011-10-30 15:16:48 +0100273}
Martin Schwidefskyb5f87f12014-10-01 10:57:57 +0200274
275/*
276 * Function to stop a processor until the next interrupt occurs
277 */
278void enabled_wait(void);
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 * Function to drop a processor into disabled wait state
282 */
Joe Perchesff2d8b12012-01-12 17:17:21 -0800283static inline void __noreturn disabled_wait(unsigned long code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Heiko Carstensf9e6edf2015-10-12 12:28:28 +0200285 psw_t psw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Heiko Carstensf9e6edf2015-10-12 12:28:28 +0200287 psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA;
288 psw.addr = code;
289 __load_psw(psw);
Heiko Carstensedd53782008-12-25 13:39:16 +0100290 while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293/*
Heiko Carstensab14de62007-02-05 21:18:37 +0100294 * Basic Machine Check/Program Check Handler.
295 */
296
297extern void s390_base_mcck_handler(void);
298extern void s390_base_pgm_handler(void);
299extern void s390_base_ext_handler(void);
300
301extern void (*s390_base_mcck_handler_fn)(void);
302extern void (*s390_base_pgm_handler_fn)(void);
303extern void (*s390_base_ext_handler_fn)(void);
304
Heiko Carstensdfd54cb2006-09-25 23:31:33 -0700305#define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
306
Heiko Carstensfbe76562012-06-05 09:59:52 +0200307extern int memcpy_real(void *, void *, size_t);
308extern void memcpy_absolute(void *, void *, size_t);
309
310#define mem_assign_absolute(dest, val) { \
311 __typeof__(dest) __tmp = (val); \
312 \
313 BUILD_BUG_ON(sizeof(__tmp) != sizeof(val)); \
314 memcpy_absolute(&(dest), &__tmp, sizeof(__tmp)); \
315}
316
Heiko Carstenseb608fb2012-09-05 13:26:11 +0200317#endif /* __ASSEMBLY__ */
318
319#endif /* __ASM_S390_PROCESSOR_H */