1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Low-level task switching. This is based on information published in 4*4882a593Smuzhiyun * the Processor Abstraction Layer and the System Abstraction Layer 5*4882a593Smuzhiyun * manual. 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * Copyright (C) 1998-2003 Hewlett-Packard Co 8*4882a593Smuzhiyun * David Mosberger-Tang <davidm@hpl.hp.com> 9*4882a593Smuzhiyun * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com> 10*4882a593Smuzhiyun * Copyright (C) 1999 Don Dugger <don.dugger@intel.com> 11*4882a593Smuzhiyun */ 12*4882a593Smuzhiyun #ifndef _ASM_IA64_SWITCH_TO_H 13*4882a593Smuzhiyun #define _ASM_IA64_SWITCH_TO_H 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun #include <linux/percpu.h> 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun struct task_struct; 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun /* 20*4882a593Smuzhiyun * Context switch from one thread to another. If the two threads have 21*4882a593Smuzhiyun * different address spaces, schedule() has already taken care of 22*4882a593Smuzhiyun * switching to the new address space by calling switch_mm(). 23*4882a593Smuzhiyun * 24*4882a593Smuzhiyun * Disabling access to the fph partition and the debug-register 25*4882a593Smuzhiyun * context switch MUST be done before calling ia64_switch_to() since a 26*4882a593Smuzhiyun * newly created thread returns directly to 27*4882a593Smuzhiyun * ia64_ret_from_syscall_clear_r8. 28*4882a593Smuzhiyun */ 29*4882a593Smuzhiyun extern struct task_struct *ia64_switch_to (void *next_task); 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun extern void ia64_save_extra (struct task_struct *task); 32*4882a593Smuzhiyun extern void ia64_load_extra (struct task_struct *task); 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun #define IA64_HAS_EXTRA_STATE(t) \ 35*4882a593Smuzhiyun ((t)->thread.flags & (IA64_THREAD_DBG_VALID|IA64_THREAD_PM_VALID)) 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun #define __switch_to(prev,next,last) do { \ 38*4882a593Smuzhiyun if (IA64_HAS_EXTRA_STATE(prev)) \ 39*4882a593Smuzhiyun ia64_save_extra(prev); \ 40*4882a593Smuzhiyun if (IA64_HAS_EXTRA_STATE(next)) \ 41*4882a593Smuzhiyun ia64_load_extra(next); \ 42*4882a593Smuzhiyun ia64_psr(task_pt_regs(next))->dfh = !ia64_is_local_fpu_owner(next); \ 43*4882a593Smuzhiyun (last) = ia64_switch_to((next)); \ 44*4882a593Smuzhiyun } while (0) 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun #ifdef CONFIG_SMP 47*4882a593Smuzhiyun /* 48*4882a593Smuzhiyun * In the SMP case, we save the fph state when context-switching away from a thread that 49*4882a593Smuzhiyun * modified fph. This way, when the thread gets scheduled on another CPU, the CPU can 50*4882a593Smuzhiyun * pick up the state from task->thread.fph, avoiding the complication of having to fetch 51*4882a593Smuzhiyun * the latest fph state from another CPU. In other words: eager save, lazy restore. 52*4882a593Smuzhiyun */ 53*4882a593Smuzhiyun # define switch_to(prev,next,last) do { \ 54*4882a593Smuzhiyun if (ia64_psr(task_pt_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) { \ 55*4882a593Smuzhiyun ia64_psr(task_pt_regs(prev))->mfh = 0; \ 56*4882a593Smuzhiyun (prev)->thread.flags |= IA64_THREAD_FPH_VALID; \ 57*4882a593Smuzhiyun __ia64_save_fpu((prev)->thread.fph); \ 58*4882a593Smuzhiyun } \ 59*4882a593Smuzhiyun __switch_to(prev, next, last); \ 60*4882a593Smuzhiyun /* "next" in old context is "current" in new context */ \ 61*4882a593Smuzhiyun if (unlikely((current->thread.flags & IA64_THREAD_MIGRATION) && \ 62*4882a593Smuzhiyun (task_cpu(current) != \ 63*4882a593Smuzhiyun task_thread_info(current)->last_cpu))) { \ 64*4882a593Smuzhiyun task_thread_info(current)->last_cpu = task_cpu(current); \ 65*4882a593Smuzhiyun } \ 66*4882a593Smuzhiyun } while (0) 67*4882a593Smuzhiyun #else 68*4882a593Smuzhiyun # define switch_to(prev,next,last) __switch_to(prev, next, last) 69*4882a593Smuzhiyun #endif 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun #endif /* _ASM_IA64_SWITCH_TO_H */ 72