1*b2441318SGreg 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 #ifdef CONFIG_PERFMON 35c140d879SDavid Howells DECLARE_PER_CPU(unsigned long, pfm_syst_info); 366065a244SChristoph Lameter # define PERFMON_IS_SYSWIDE() (__this_cpu_read(pfm_syst_info) & 0x1) 37c140d879SDavid Howells #else 38c140d879SDavid Howells # define PERFMON_IS_SYSWIDE() (0) 39c140d879SDavid Howells #endif 40c140d879SDavid Howells 41c140d879SDavid Howells #define IA64_HAS_EXTRA_STATE(t) \ 42c140d879SDavid Howells ((t)->thread.flags & (IA64_THREAD_DBG_VALID|IA64_THREAD_PM_VALID) \ 43c140d879SDavid Howells || PERFMON_IS_SYSWIDE()) 44c140d879SDavid Howells 45c140d879SDavid Howells #define __switch_to(prev,next,last) do { \ 46c140d879SDavid Howells if (IA64_HAS_EXTRA_STATE(prev)) \ 47c140d879SDavid Howells ia64_save_extra(prev); \ 48c140d879SDavid Howells if (IA64_HAS_EXTRA_STATE(next)) \ 49c140d879SDavid Howells ia64_load_extra(next); \ 50c140d879SDavid Howells ia64_psr(task_pt_regs(next))->dfh = !ia64_is_local_fpu_owner(next); \ 51c140d879SDavid Howells (last) = ia64_switch_to((next)); \ 52c140d879SDavid Howells } while (0) 53c140d879SDavid Howells 54c140d879SDavid Howells #ifdef CONFIG_SMP 55c140d879SDavid Howells /* 56c140d879SDavid Howells * In the SMP case, we save the fph state when context-switching away from a thread that 57c140d879SDavid Howells * modified fph. This way, when the thread gets scheduled on another CPU, the CPU can 58c140d879SDavid Howells * pick up the state from task->thread.fph, avoiding the complication of having to fetch 59c140d879SDavid Howells * the latest fph state from another CPU. In other words: eager save, lazy restore. 60c140d879SDavid Howells */ 61c140d879SDavid Howells # define switch_to(prev,next,last) do { \ 62c140d879SDavid Howells if (ia64_psr(task_pt_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) { \ 63c140d879SDavid Howells ia64_psr(task_pt_regs(prev))->mfh = 0; \ 64c140d879SDavid Howells (prev)->thread.flags |= IA64_THREAD_FPH_VALID; \ 65c140d879SDavid Howells __ia64_save_fpu((prev)->thread.fph); \ 66c140d879SDavid Howells } \ 67c140d879SDavid Howells __switch_to(prev, next, last); \ 68c140d879SDavid Howells /* "next" in old context is "current" in new context */ \ 69c140d879SDavid Howells if (unlikely((current->thread.flags & IA64_THREAD_MIGRATION) && \ 70c140d879SDavid Howells (task_cpu(current) != \ 71c140d879SDavid Howells task_thread_info(current)->last_cpu))) { \ 72c140d879SDavid Howells platform_migrate(current); \ 73c140d879SDavid Howells task_thread_info(current)->last_cpu = task_cpu(current); \ 74c140d879SDavid Howells } \ 75c140d879SDavid Howells } while (0) 76c140d879SDavid Howells #else 77c140d879SDavid Howells # define switch_to(prev,next,last) __switch_to(prev, next, last) 78c140d879SDavid Howells #endif 79c140d879SDavid Howells 80c140d879SDavid Howells #endif /* _ASM_IA64_SWITCH_TO_H */ 81