Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright IBM Corp. 1999, 2009 |
| 4 | * |
| 5 | * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 6 | */ |
| 7 | |
| 8 | #ifndef __ASM_SWITCH_TO_H |
| 9 | #define __ASM_SWITCH_TO_H |
| 10 | |
| 11 | #include <linux/thread_info.h> |
Hendrik Brueckner | b075390 | 2015-10-06 12:25:59 +0200 | [diff] [blame] | 12 | #include <asm/fpu/api.h> |
Heiko Carstens | bee5c28 | 2013-08-20 10:24:12 +0200 | [diff] [blame] | 13 | #include <asm/ptrace.h> |
Martin Schwidefsky | 916cda1 | 2016-01-26 14:10:34 +0100 | [diff] [blame] | 14 | #include <asm/guarded_storage.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 15 | |
| 16 | extern struct task_struct *__switch_to(void *, void *); |
Michael Mueller | 64597f9 | 2013-07-02 22:58:26 +0200 | [diff] [blame] | 17 | extern void update_cr_regs(struct task_struct *task); |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 18 | |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 19 | static inline void save_access_regs(unsigned int *acrs) |
| 20 | { |
Heiko Carstens | bee5c28 | 2013-08-20 10:24:12 +0200 | [diff] [blame] | 21 | typedef struct { int _[NUM_ACRS]; } acrstype; |
| 22 | |
| 23 | asm volatile("stam 0,15,%0" : "=Q" (*(acrstype *)acrs)); |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static inline void restore_access_regs(unsigned int *acrs) |
| 27 | { |
Heiko Carstens | bee5c28 | 2013-08-20 10:24:12 +0200 | [diff] [blame] | 28 | typedef struct { int _[NUM_ACRS]; } acrstype; |
| 29 | |
| 30 | asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs)); |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 31 | } |
| 32 | |
Heiko Carstens | fbbd7f1 | 2017-11-20 12:38:44 +0100 | [diff] [blame] | 33 | #define switch_to(prev, next, last) do { \ |
| 34 | /* save_fpu_regs() sets the CIF_FPU flag, which enforces \ |
| 35 | * a restore of the floating point / vector registers as \ |
| 36 | * soon as the next task returns to user space \ |
| 37 | */ \ |
| 38 | save_fpu_regs(); \ |
| 39 | save_access_regs(&prev->thread.acrs[0]); \ |
| 40 | save_ri_cb(prev->thread.ri_cb); \ |
| 41 | save_gs_cb(prev->thread.gs_cb); \ |
Heiko Carstens | a1c5bef | 2017-11-09 12:29:34 +0100 | [diff] [blame] | 42 | update_cr_regs(next); \ |
Heiko Carstens | fbbd7f1 | 2017-11-20 12:38:44 +0100 | [diff] [blame] | 43 | restore_access_regs(&next->thread.acrs[0]); \ |
| 44 | restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \ |
| 45 | restore_gs_cb(next->thread.gs_cb); \ |
| 46 | prev = __switch_to(prev, next); \ |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 47 | } while (0) |
| 48 | |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 49 | #endif /* __ASM_SWITCH_TO_H */ |