162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Low-level task switching. This is based on information published in 462306a36Sopenharmony_ci * the Processor Abstraction Layer and the System Abstraction Layer 562306a36Sopenharmony_ci * manual. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (C) 1998-2003 Hewlett-Packard Co 862306a36Sopenharmony_ci * David Mosberger-Tang <davidm@hpl.hp.com> 962306a36Sopenharmony_ci * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com> 1062306a36Sopenharmony_ci * Copyright (C) 1999 Don Dugger <don.dugger@intel.com> 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci#ifndef _ASM_IA64_SWITCH_TO_H 1362306a36Sopenharmony_ci#define _ASM_IA64_SWITCH_TO_H 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/percpu.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct task_struct; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * Context switch from one thread to another. If the two threads have 2162306a36Sopenharmony_ci * different address spaces, schedule() has already taken care of 2262306a36Sopenharmony_ci * switching to the new address space by calling switch_mm(). 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * Disabling access to the fph partition and the debug-register 2562306a36Sopenharmony_ci * context switch MUST be done before calling ia64_switch_to() since a 2662306a36Sopenharmony_ci * newly created thread returns directly to 2762306a36Sopenharmony_ci * ia64_ret_from_syscall_clear_r8. 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ciextern struct task_struct *ia64_switch_to (void *next_task); 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciextern void ia64_save_extra (struct task_struct *task); 3262306a36Sopenharmony_ciextern void ia64_load_extra (struct task_struct *task); 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define IA64_HAS_EXTRA_STATE(t) \ 3562306a36Sopenharmony_ci ((t)->thread.flags & (IA64_THREAD_DBG_VALID|IA64_THREAD_PM_VALID)) 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define __switch_to(prev,next,last) do { \ 3862306a36Sopenharmony_ci if (IA64_HAS_EXTRA_STATE(prev)) \ 3962306a36Sopenharmony_ci ia64_save_extra(prev); \ 4062306a36Sopenharmony_ci if (IA64_HAS_EXTRA_STATE(next)) \ 4162306a36Sopenharmony_ci ia64_load_extra(next); \ 4262306a36Sopenharmony_ci ia64_psr(task_pt_regs(next))->dfh = !ia64_is_local_fpu_owner(next); \ 4362306a36Sopenharmony_ci (last) = ia64_switch_to((next)); \ 4462306a36Sopenharmony_ci} while (0) 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#ifdef CONFIG_SMP 4762306a36Sopenharmony_ci/* 4862306a36Sopenharmony_ci * In the SMP case, we save the fph state when context-switching away from a thread that 4962306a36Sopenharmony_ci * modified fph. This way, when the thread gets scheduled on another CPU, the CPU can 5062306a36Sopenharmony_ci * pick up the state from task->thread.fph, avoiding the complication of having to fetch 5162306a36Sopenharmony_ci * the latest fph state from another CPU. In other words: eager save, lazy restore. 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ci# define switch_to(prev,next,last) do { \ 5462306a36Sopenharmony_ci if (ia64_psr(task_pt_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) { \ 5562306a36Sopenharmony_ci ia64_psr(task_pt_regs(prev))->mfh = 0; \ 5662306a36Sopenharmony_ci (prev)->thread.flags |= IA64_THREAD_FPH_VALID; \ 5762306a36Sopenharmony_ci __ia64_save_fpu((prev)->thread.fph); \ 5862306a36Sopenharmony_ci } \ 5962306a36Sopenharmony_ci __switch_to(prev, next, last); \ 6062306a36Sopenharmony_ci /* "next" in old context is "current" in new context */ \ 6162306a36Sopenharmony_ci if (unlikely((current->thread.flags & IA64_THREAD_MIGRATION) && \ 6262306a36Sopenharmony_ci (task_cpu(current) != \ 6362306a36Sopenharmony_ci task_thread_info(current)->last_cpu))) { \ 6462306a36Sopenharmony_ci task_thread_info(current)->last_cpu = task_cpu(current); \ 6562306a36Sopenharmony_ci } \ 6662306a36Sopenharmony_ci} while (0) 6762306a36Sopenharmony_ci#else 6862306a36Sopenharmony_ci# define switch_to(prev,next,last) __switch_to(prev, next, last) 6962306a36Sopenharmony_ci#endif 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#endif /* _ASM_IA64_SWITCH_TO_H */ 72