Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * S390 version |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 12 | #ifndef __ASM_S390_PROCESSOR_H |
| 13 | #define __ASM_S390_PROCESSOR_H |
| 14 | |
Heiko Carstens | 92778b9 | 2015-10-06 16:23:39 +0200 | [diff] [blame] | 15 | #include <linux/const.h> |
| 16 | |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 17 | #define CIF_MCCK_PENDING 0 /* machine check handling is pending */ |
Heiko Carstens | 606aa4a | 2017-02-17 08:12:30 +0100 | [diff] [blame] | 18 | #define CIF_ASCE_PRIMARY 1 /* primary asce needs fixup / uaccess */ |
Heiko Carstens | b5a882f | 2017-02-17 08:13:28 +0100 | [diff] [blame] | 19 | #define CIF_ASCE_SECONDARY 2 /* secondary asce needs fixup / uaccess */ |
| 20 | #define CIF_NOHZ_DELAY 3 /* delay HZ disable for a tick */ |
| 21 | #define CIF_FPU 4 /* restore FPU registers */ |
| 22 | #define CIF_IGNORE_IRQ 5 /* ignore interrupt (for udelay) */ |
| 23 | #define CIF_ENABLED_WAIT 6 /* in enabled wait state */ |
QingFeng Hao | c929500 | 2017-06-07 11:30:42 +0200 | [diff] [blame] | 24 | #define CIF_MCCK_GUEST 7 /* machine check happening in guest */ |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 25 | |
Heiko Carstens | 92778b9 | 2015-10-06 16:23:39 +0200 | [diff] [blame] | 26 | #define _CIF_MCCK_PENDING _BITUL(CIF_MCCK_PENDING) |
Heiko Carstens | 606aa4a | 2017-02-17 08:12:30 +0100 | [diff] [blame] | 27 | #define _CIF_ASCE_PRIMARY _BITUL(CIF_ASCE_PRIMARY) |
Heiko Carstens | b5a882f | 2017-02-17 08:13:28 +0100 | [diff] [blame] | 28 | #define _CIF_ASCE_SECONDARY _BITUL(CIF_ASCE_SECONDARY) |
Heiko Carstens | 92778b9 | 2015-10-06 16:23:39 +0200 | [diff] [blame] | 29 | #define _CIF_NOHZ_DELAY _BITUL(CIF_NOHZ_DELAY) |
| 30 | #define _CIF_FPU _BITUL(CIF_FPU) |
| 31 | #define _CIF_IGNORE_IRQ _BITUL(CIF_IGNORE_IRQ) |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 32 | #define _CIF_ENABLED_WAIT _BITUL(CIF_ENABLED_WAIT) |
QingFeng Hao | c929500 | 2017-06-07 11:30:42 +0200 | [diff] [blame] | 33 | #define _CIF_MCCK_GUEST _BITUL(CIF_MCCK_GUEST) |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 34 | |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 35 | #ifndef __ASSEMBLY__ |
| 36 | |
Heiko Carstens | edd5378 | 2008-12-25 13:39:16 +0100 | [diff] [blame] | 37 | #include <linux/linkage.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 38 | #include <linux/irqflags.h> |
Heiko Carstens | e86a6ed | 2009-09-11 10:29:04 +0200 | [diff] [blame] | 39 | #include <asm/cpu.h> |
Christian Ehrhardt | 25097bf | 2009-04-14 15:36:16 +0200 | [diff] [blame] | 40 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/ptrace.h> |
Christian Ehrhardt | 25097bf | 2009-04-14 15:36:16 +0200 | [diff] [blame] | 42 | #include <asm/setup.h> |
Jan Glauber | e4b8b3f | 2012-07-31 10:52:05 +0200 | [diff] [blame] | 43 | #include <asm/runtime_instr.h> |
Hendrik Brueckner | b075390 | 2015-10-06 12:25:59 +0200 | [diff] [blame] | 44 | #include <asm/fpu/types.h> |
| 45 | #include <asm/fpu/internal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 47 | static inline void set_cpu_flag(int flag) |
| 48 | { |
Heiko Carstens | ac25e79 | 2015-10-06 16:23:29 +0200 | [diff] [blame] | 49 | S390_lowcore.cpu_flags |= (1UL << flag); |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static inline void clear_cpu_flag(int flag) |
| 53 | { |
Heiko Carstens | ac25e79 | 2015-10-06 16:23:29 +0200 | [diff] [blame] | 54 | S390_lowcore.cpu_flags &= ~(1UL << flag); |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static inline int test_cpu_flag(int flag) |
| 58 | { |
Heiko Carstens | ac25e79 | 2015-10-06 16:23:29 +0200 | [diff] [blame] | 59 | return !!(S390_lowcore.cpu_flags & (1UL << flag)); |
Martin Schwidefsky | d3a73ac | 2014-04-15 12:55:07 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 62 | /* |
| 63 | * Test CIF flag of another CPU. The caller needs to ensure that |
| 64 | * CPU hotplug can not happen, e.g. by disabling preemption. |
| 65 | */ |
| 66 | static inline int test_cpu_flag_of(int flag, int cpu) |
| 67 | { |
Heiko Carstens | c667aea | 2015-12-31 10:29:00 +0100 | [diff] [blame] | 68 | struct lowcore *lc = lowcore_ptr[cpu]; |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 69 | return !!(lc->cpu_flags & (1UL << flag)); |
| 70 | } |
| 71 | |
Martin Schwidefsky | fe0f497 | 2014-09-30 17:37:52 +0200 | [diff] [blame] | 72 | #define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY) |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* |
| 75 | * Default implementation of macro that returns current |
| 76 | * instruction pointer ("program counter"). |
| 77 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 78 | #define current_text_addr() ({ void *pc; asm("basr %0,0" : "=a" (pc)); pc; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Heiko Carstens | e86a6ed | 2009-09-11 10:29:04 +0200 | [diff] [blame] | 80 | static inline void get_cpu_id(struct cpuid *ptr) |
Michael Holzheu | 72960a0 | 2007-02-21 10:55:18 +0100 | [diff] [blame] | 81 | { |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 82 | asm volatile("stidp %0" : "=Q" (*ptr)); |
Michael Holzheu | 72960a0 | 2007-02-21 10:55:18 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Heiko Carstens | 097a116 | 2016-04-14 12:35:22 +0200 | [diff] [blame] | 85 | void s390_adjust_jiffies(void); |
| 86 | void s390_update_cpu_mhz(void); |
| 87 | void cpu_detect_mhz_feature(void); |
| 88 | |
Martin Schwidefsky | 638ad34 | 2011-10-30 15:17:13 +0100 | [diff] [blame] | 89 | extern const struct seq_operations cpuinfo_op; |
| 90 | extern int sysctl_ieee_emulation_warnings; |
Al Viro | 65f22a9 | 2012-09-06 15:48:11 -0400 | [diff] [blame] | 91 | extern void execve_tail(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* |
Martin Schwidefsky | f481bfa | 2009-03-18 13:27:36 +0100 | [diff] [blame] | 94 | * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Martin Schwidefsky | ee71d16 | 2017-04-20 14:43:51 +0200 | [diff] [blame] | 97 | #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_31BIT) ? \ |
Martin Schwidefsky | 1aea9b3 | 2017-04-24 18:19:10 +0200 | [diff] [blame] | 98 | (1UL << 31) : -PAGE_SIZE) |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 99 | #define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \ |
| 100 | (1UL << 30) : (1UL << 41)) |
| 101 | #define TASK_SIZE TASK_SIZE_OF(current) |
Martin Schwidefsky | 1aea9b3 | 2017-04-24 18:19:10 +0200 | [diff] [blame] | 102 | #define TASK_SIZE_MAX (-PAGE_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Martin Schwidefsky | ee71d16 | 2017-04-20 14:43:51 +0200 | [diff] [blame] | 104 | #define STACK_TOP (test_thread_flag(TIF_31BIT) ? \ |
| 105 | (1UL << 31) : (1UL << 42)) |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 106 | #define STACK_TOP_MAX (1UL << 42) |
David Howells | 922a70d | 2008-02-08 04:19:26 -0800 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define HAVE_ARCH_PICK_MMAP_LAYOUT |
| 109 | |
| 110 | typedef struct { |
| 111 | __u32 ar4; |
| 112 | } mm_segment_t; |
| 113 | |
| 114 | /* |
| 115 | * Thread structure |
| 116 | */ |
| 117 | struct thread_struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | unsigned int acrs[NUM_ACRS]; |
| 119 | unsigned long ksp; /* kernel stack pointer */ |
Martin Schwidefsky | 90c53e6 | 2016-11-08 12:15:59 +0100 | [diff] [blame] | 120 | unsigned long user_timer; /* task cputime in user space */ |
Martin Schwidefsky | b7394a5 | 2017-01-05 18:11:49 +0100 | [diff] [blame] | 121 | unsigned long guest_timer; /* task cputime in kvm guest */ |
Martin Schwidefsky | 90c53e6 | 2016-11-08 12:15:59 +0100 | [diff] [blame] | 122 | unsigned long system_timer; /* task cputime in kernel space */ |
Martin Schwidefsky | b7394a5 | 2017-01-05 18:11:49 +0100 | [diff] [blame] | 123 | unsigned long hardirq_timer; /* task cputime in hardirq context */ |
| 124 | unsigned long softirq_timer; /* task cputime in softirq context */ |
Martin Schwidefsky | ef280c8 | 2016-11-08 12:33:38 +0100 | [diff] [blame] | 125 | unsigned long sys_call_table; /* system call table address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | mm_segment_t mm_segment; |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 127 | unsigned long gmap_addr; /* address of last gmap fault. */ |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 128 | unsigned int gmap_write_flag; /* gmap fault write indication */ |
David Hildenbrand | 4a49443 | 2016-03-08 12:31:52 +0100 | [diff] [blame] | 129 | unsigned int gmap_int_code; /* int code of last gmap fault */ |
Dominik Dingel | 24eb3a8 | 2013-06-17 16:25:18 +0200 | [diff] [blame] | 130 | unsigned int gmap_pfault; /* signal of a pending guest pfault */ |
Martin Schwidefsky | f8fc82b | 2016-11-08 11:11:02 +0100 | [diff] [blame] | 131 | /* Per-thread information related to debugging */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 132 | struct per_regs per_user; /* User specified PER registers */ |
| 133 | struct per_event per_event; /* Cause of the last PER trap */ |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 134 | unsigned long per_flags; /* Flags to control debug behavior */ |
Martin Schwidefsky | f8fc82b | 2016-11-08 11:11:02 +0100 | [diff] [blame] | 135 | unsigned int system_call; /* system call number in signal */ |
Martin Schwidefsky | ef280c8 | 2016-11-08 12:33:38 +0100 | [diff] [blame] | 136 | unsigned long last_break; /* last breaking-event-address. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* pfault_wait is used to block the process on a pfault event */ |
| 138 | unsigned long pfault_wait; |
Heiko Carstens | f2db2e6 | 2011-05-23 10:24:34 +0200 | [diff] [blame] | 139 | struct list_head list; |
Jan Glauber | e4b8b3f | 2012-07-31 10:52:05 +0200 | [diff] [blame] | 140 | /* cpu runtime instrumentation */ |
| 141 | struct runtime_instr_cb *ri_cb; |
Martin Schwidefsky | 916cda1 | 2016-01-26 14:10:34 +0100 | [diff] [blame] | 142 | struct gs_cb *gs_cb; /* Current guarded storage cb */ |
| 143 | struct gs_cb *gs_bc_cb; /* Broadcast guarded storage cb */ |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 144 | unsigned char trap_tdb[256]; /* Transaction abort diagnose block */ |
Martin Schwidefsky | 3f6813b | 2016-04-01 15:42:15 +0200 | [diff] [blame] | 145 | /* |
| 146 | * Warning: 'fpu' is dynamically-sized. It *MUST* be at |
| 147 | * the end. |
| 148 | */ |
| 149 | struct fpu fpu; /* FP and VX register save area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 152 | /* Flag to disable transactions. */ |
| 153 | #define PER_FLAG_NO_TE 1UL |
| 154 | /* Flag to enable random transaction aborts. */ |
| 155 | #define PER_FLAG_TE_ABORT_RAND 2UL |
| 156 | /* Flag to specify random transaction abort mode: |
| 157 | * - abort each transaction at a random instruction before TEND if set. |
| 158 | * - abort random transactions at a random instruction if cleared. |
| 159 | */ |
| 160 | #define PER_FLAG_TE_ABORT_RAND_TEND 4UL |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | typedef struct thread_struct thread_struct; |
| 163 | |
| 164 | /* |
| 165 | * Stack layout of a C stack frame. |
| 166 | */ |
| 167 | #ifndef __PACK_STACK |
| 168 | struct stack_frame { |
| 169 | unsigned long back_chain; |
| 170 | unsigned long empty1[5]; |
| 171 | unsigned long gprs[10]; |
| 172 | unsigned int empty2[8]; |
| 173 | }; |
| 174 | #else |
| 175 | struct stack_frame { |
| 176 | unsigned long empty1[5]; |
| 177 | unsigned int empty2[8]; |
| 178 | unsigned long gprs[10]; |
| 179 | unsigned long back_chain; |
| 180 | }; |
| 181 | #endif |
| 182 | |
| 183 | #define ARCH_MIN_TASKALIGN 8 |
| 184 | |
Martin Schwidefsky | 6f3fa3f | 2007-10-22 12:52:45 +0200 | [diff] [blame] | 185 | #define INIT_THREAD { \ |
| 186 | .ksp = sizeof(init_stack) + (unsigned long) &init_stack, \ |
Martin Schwidefsky | 3f6813b | 2016-04-01 15:42:15 +0200 | [diff] [blame] | 187 | .fpu.regs = (void *) init_task.thread.fpu.fprs, \ |
Martin Schwidefsky | 6f3fa3f | 2007-10-22 12:52:45 +0200 | [diff] [blame] | 188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * Do necessary setup to start up a new thread. |
| 192 | */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 193 | #define start_thread(regs, new_psw, new_stackp) do { \ |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 194 | regs->psw.mask = PSW_USER_BITS | PSW_MASK_EA | PSW_MASK_BA; \ |
Heiko Carstens | fecc868a | 2016-01-18 12:49:44 +0100 | [diff] [blame] | 195 | regs->psw.addr = new_psw; \ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 196 | regs->gprs[15] = new_stackp; \ |
Al Viro | 65f22a9 | 2012-09-06 15:48:11 -0400 | [diff] [blame] | 197 | execve_tail(); \ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 198 | } while (0) |
| 199 | |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 200 | #define start_thread31(regs, new_psw, new_stackp) do { \ |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 201 | regs->psw.mask = PSW_USER_BITS | PSW_MASK_BA; \ |
Heiko Carstens | fecc868a | 2016-01-18 12:49:44 +0100 | [diff] [blame] | 202 | regs->psw.addr = new_psw; \ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 203 | regs->gprs[15] = new_stackp; \ |
Gerald Schaefer | 723cacb | 2016-04-15 16:38:40 +0200 | [diff] [blame] | 204 | crst_table_downgrade(current->mm); \ |
Al Viro | 65f22a9 | 2012-09-06 15:48:11 -0400 | [diff] [blame] | 205 | execve_tail(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } while (0) |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* Forward declaration, a strange C thing */ |
| 209 | struct task_struct; |
| 210 | struct mm_struct; |
Eric W. Biederman | df5f831 | 2008-02-08 04:18:33 -0800 | [diff] [blame] | 211 | struct seq_file; |
Heiko Carstens | b5a882f | 2017-02-17 08:13:28 +0100 | [diff] [blame] | 212 | struct pt_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Heiko Carstens | d020863 | 2016-10-17 11:08:31 +0200 | [diff] [blame] | 214 | typedef int (*dump_trace_func_t)(void *data, unsigned long address, int reliable); |
Heiko Carstens | 758d39e | 2016-02-09 12:58:54 +0100 | [diff] [blame] | 215 | void dump_trace(dump_trace_func_t func, void *data, |
| 216 | struct task_struct *task, unsigned long sp); |
Heiko Carstens | b5a882f | 2017-02-17 08:13:28 +0100 | [diff] [blame] | 217 | void show_registers(struct pt_regs *regs); |
Heiko Carstens | 758d39e | 2016-02-09 12:58:54 +0100 | [diff] [blame] | 218 | |
Heiko Carstens | 5a79859 | 2015-02-12 13:08:27 +0100 | [diff] [blame] | 219 | void show_cacheinfo(struct seq_file *m); |
Heiko Carstens | 6668022 | 2012-08-29 14:12:20 +0200 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /* Free all resources held by a thread. */ |
| 222 | extern void release_thread(struct task_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Martin Schwidefsky | 916cda1 | 2016-01-26 14:10:34 +0100 | [diff] [blame] | 224 | /* Free guarded storage control block for current */ |
| 225 | void exit_thread_gs(void); |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | unsigned long get_wchan(struct task_struct *p); |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 228 | #define task_pt_regs(tsk) ((struct pt_regs *) \ |
Al Viro | 30af712 | 2006-01-12 01:05:50 -0800 | [diff] [blame] | 229 | (task_stack_page(tsk) + THREAD_SIZE) - 1) |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 230 | #define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr) |
| 231 | #define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Heiko Carstens | 5ebf250 | 2013-10-16 09:58:01 +0200 | [diff] [blame] | 233 | /* Has task runtime instrumentation enabled ? */ |
| 234 | #define is_ri_task(tsk) (!!(tsk)->thread.ri_cb) |
| 235 | |
Heiko Carstens | 76737ce | 2016-01-31 17:06:16 +0100 | [diff] [blame] | 236 | static inline unsigned long current_stack_pointer(void) |
| 237 | { |
| 238 | unsigned long sp; |
| 239 | |
| 240 | asm volatile("la %0,0(15)" : "=a" (sp)); |
| 241 | return sp; |
| 242 | } |
| 243 | |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 244 | static inline unsigned short stap(void) |
| 245 | { |
| 246 | unsigned short cpu_address; |
| 247 | |
| 248 | asm volatile("stap %0" : "=m" (cpu_address)); |
| 249 | return cpu_address; |
| 250 | } |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Give up the time slice of the virtual PU. |
| 254 | */ |
Christian Borntraeger | 6d0d287 | 2016-11-16 13:23:05 +0100 | [diff] [blame] | 255 | #define cpu_relax_yield cpu_relax_yield |
Christian Borntraeger | 79ab11c | 2016-10-25 11:03:11 +0200 | [diff] [blame] | 256 | void cpu_relax_yield(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Christian Borntraeger | 22b6430 | 2016-10-25 11:03:13 +0200 | [diff] [blame] | 258 | #define cpu_relax() barrier() |
Heiko Carstens | 083986e | 2013-09-28 11:23:59 +0200 | [diff] [blame] | 259 | |
Heiko Carstens | 097a116 | 2016-04-14 12:35:22 +0200 | [diff] [blame] | 260 | #define ECAG_CACHE_ATTRIBUTE 0 |
| 261 | #define ECAG_CPU_ATTRIBUTE 1 |
| 262 | |
| 263 | static inline unsigned long __ecag(unsigned int asi, unsigned char parm) |
| 264 | { |
| 265 | unsigned long val; |
| 266 | |
| 267 | asm volatile(".insn rsy,0xeb000000004c,%0,0,0(%1)" /* ecag */ |
| 268 | : "=d" (val) : "a" (asi << 8 | parm)); |
| 269 | return val; |
| 270 | } |
| 271 | |
Heiko Carstens | dc74d7f | 2007-06-19 13:10:06 +0200 | [diff] [blame] | 272 | static inline void psw_set_key(unsigned int key) |
| 273 | { |
| 274 | asm volatile("spka 0(%0)" : : "d" (key)); |
| 275 | } |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 278 | * Set PSW to specified value. |
| 279 | */ |
| 280 | static inline void __load_psw(psw_t psw) |
| 281 | { |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 282 | asm volatile("lpswe %0" : : "Q" (psw) : "cc"); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | * Set PSW mask to specified value, while leaving the |
| 287 | * PSW addr pointing to the next instruction. |
| 288 | */ |
Heiko Carstens | ecbafda | 2015-10-12 11:54:03 +0200 | [diff] [blame] | 289 | static inline void __load_psw_mask(unsigned long mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | unsigned long addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | psw_t psw; |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | psw.mask = mask; |
| 295 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 296 | asm volatile( |
| 297 | " larl %0,1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 298 | " stg %0,%O1+8(%R1)\n" |
| 299 | " lpswe %1\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | "1:" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 301 | : "=&d" (addr), "=Q" (psw) : "Q" (psw) : "memory", "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
Martin Schwidefsky | ccf45ca | 2011-10-30 15:16:48 +0100 | [diff] [blame] | 303 | |
| 304 | /* |
Martin Schwidefsky | 22362a0 | 2015-07-08 10:20:04 +0200 | [diff] [blame] | 305 | * Extract current PSW mask |
| 306 | */ |
| 307 | static inline unsigned long __extract_psw(void) |
| 308 | { |
| 309 | unsigned int reg1, reg2; |
| 310 | |
| 311 | asm volatile("epsw %0,%1" : "=d" (reg1), "=a" (reg2)); |
| 312 | return (((unsigned long) reg1) << 32) | ((unsigned long) reg2); |
| 313 | } |
| 314 | |
Heiko Carstens | ecbafda | 2015-10-12 11:54:03 +0200 | [diff] [blame] | 315 | static inline void local_mcck_enable(void) |
| 316 | { |
| 317 | __load_psw_mask(__extract_psw() | PSW_MASK_MCHECK); |
| 318 | } |
| 319 | |
| 320 | static inline void local_mcck_disable(void) |
| 321 | { |
| 322 | __load_psw_mask(__extract_psw() & ~PSW_MASK_MCHECK); |
| 323 | } |
| 324 | |
Martin Schwidefsky | 22362a0 | 2015-07-08 10:20:04 +0200 | [diff] [blame] | 325 | /* |
Martin Schwidefsky | ccf45ca | 2011-10-30 15:16:48 +0100 | [diff] [blame] | 326 | * Rewind PSW instruction address by specified number of bytes. |
| 327 | */ |
| 328 | static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc) |
| 329 | { |
Martin Schwidefsky | ccf45ca | 2011-10-30 15:16:48 +0100 | [diff] [blame] | 330 | unsigned long mask; |
| 331 | |
| 332 | mask = (psw.mask & PSW_MASK_EA) ? -1UL : |
| 333 | (psw.mask & PSW_MASK_BA) ? (1UL << 31) - 1 : |
| 334 | (1UL << 24) - 1; |
| 335 | return (psw.addr - ilc) & mask; |
Martin Schwidefsky | ccf45ca | 2011-10-30 15:16:48 +0100 | [diff] [blame] | 336 | } |
Martin Schwidefsky | b5f87f1 | 2014-10-01 10:57:57 +0200 | [diff] [blame] | 337 | |
| 338 | /* |
| 339 | * Function to stop a processor until the next interrupt occurs |
| 340 | */ |
| 341 | void enabled_wait(void); |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | * Function to drop a processor into disabled wait state |
| 345 | */ |
Joe Perches | ff2d8b1 | 2012-01-12 17:17:21 -0800 | [diff] [blame] | 346 | static inline void __noreturn disabled_wait(unsigned long code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Heiko Carstens | f9e6edf | 2015-10-12 12:28:28 +0200 | [diff] [blame] | 348 | psw_t psw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Heiko Carstens | f9e6edf | 2015-10-12 12:28:28 +0200 | [diff] [blame] | 350 | psw.mask = PSW_MASK_BASE | PSW_MASK_WAIT | PSW_MASK_BA | PSW_MASK_EA; |
| 351 | psw.addr = code; |
| 352 | __load_psw(psw); |
Heiko Carstens | edd5378 | 2008-12-25 13:39:16 +0100 | [diff] [blame] | 353 | while (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 357 | * Basic Machine Check/Program Check Handler. |
| 358 | */ |
| 359 | |
| 360 | extern void s390_base_mcck_handler(void); |
| 361 | extern void s390_base_pgm_handler(void); |
| 362 | extern void s390_base_ext_handler(void); |
| 363 | |
| 364 | extern void (*s390_base_mcck_handler_fn)(void); |
| 365 | extern void (*s390_base_pgm_handler_fn)(void); |
| 366 | extern void (*s390_base_ext_handler_fn)(void); |
| 367 | |
Heiko Carstens | dfd54cb | 2006-09-25 23:31:33 -0700 | [diff] [blame] | 368 | #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL |
| 369 | |
Heiko Carstens | fbe7656 | 2012-06-05 09:59:52 +0200 | [diff] [blame] | 370 | extern int memcpy_real(void *, void *, size_t); |
| 371 | extern void memcpy_absolute(void *, void *, size_t); |
| 372 | |
Heiko Carstens | 1228f7b | 2017-02-16 10:41:52 +0100 | [diff] [blame] | 373 | #define mem_assign_absolute(dest, val) do { \ |
Heiko Carstens | fbe7656 | 2012-06-05 09:59:52 +0200 | [diff] [blame] | 374 | __typeof__(dest) __tmp = (val); \ |
| 375 | \ |
| 376 | BUILD_BUG_ON(sizeof(__tmp) != sizeof(val)); \ |
| 377 | memcpy_absolute(&(dest), &__tmp, sizeof(__tmp)); \ |
Heiko Carstens | 1228f7b | 2017-02-16 10:41:52 +0100 | [diff] [blame] | 378 | } while (0) |
Heiko Carstens | fbe7656 | 2012-06-05 09:59:52 +0200 | [diff] [blame] | 379 | |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 380 | #endif /* __ASSEMBLY__ */ |
| 381 | |
| 382 | #endif /* __ASM_S390_PROCESSOR_H */ |