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