mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-30 08:04:13 +08:00
cc97ab235f
MIPS has up until now had 3 different ways for a task's floating point context to be initialized: - If the task's first use of FP involves it gaining ownership of an FPU then _init_fpu() is used to initialize the FPU's registers such that they all contain ~0, and the FPU registers will be stored to struct thread_info later (eg. when context switching). - If the task first uses FP on a CPU without an associated FPU then fpu_emulator_init_fpu() initializes the task's floating point register state in struct thread_info such that all floating point register contain the bit pattern 0x7ff800007ff80000, different to the _init_fpu() behaviour. - If a task's floating point context is first accessed via ptrace then init_fp_ctx() initializes the floating point register state in struct thread_info to ~0, giving equivalent state to _init_fpu(). The _init_fpu() path has 2 separate implementations - one for r2k/r3k style systems & one for r4k style systems. The _init_fpu() path also requires that we be careful to clear & restore the value of the Config5.FRE bit on modern systems in order to avoid inadvertently triggering floating point exceptions. None of this code is in a performance critical hot path - it runs only the first time a task uses floating point. As such it doesn't seem to warrant the complications of maintaining the _init_fpu() path. Remove _init_fpu() & fpu_emulator_init_fpu(), instead using init_fp_ctx() consistently to initialize floating point register state in struct thread_info. Upon a task's first use of floating point this will typically mean that we initialize state in memory & then load it into FPU registers using _restore_fp() just as we would on a context switch. For other paths such as __compute_return_epc_for_insn() or mipsr2_decoder() this results in a significant simplification of the work to be done. Signed-off-by: Paul Burton <paul.burton@mips.com> Patchwork: https://patchwork.linux-mips.org/patch/21002/ Cc: linux-mips@linux-mips.org
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
/*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
* Copyright (C) 2014 Lemote Corporation.
|
|
* written by Huacai Chen <chenhc@lemote.com>
|
|
*
|
|
* based on arch/mips/cavium-octeon/cpu.c
|
|
* Copyright (C) 2009 Wind River Systems,
|
|
* written by Ralf Baechle <ralf@linux-mips.org>
|
|
*/
|
|
#include <linux/init.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <asm/fpu.h>
|
|
#include <asm/cop2.h>
|
|
#include <asm/current.h>
|
|
#include <asm/mipsregs.h>
|
|
|
|
static int loongson_cu2_call(struct notifier_block *nfb, unsigned long action,
|
|
void *data)
|
|
{
|
|
int fpu_owned;
|
|
int fr = !test_thread_flag(TIF_32BIT_FPREGS);
|
|
|
|
switch (action) {
|
|
case CU2_EXCEPTION:
|
|
preempt_disable();
|
|
fpu_owned = __is_fpu_owner();
|
|
if (!fr)
|
|
set_c0_status(ST0_CU1 | ST0_CU2);
|
|
else
|
|
set_c0_status(ST0_CU1 | ST0_CU2 | ST0_FR);
|
|
enable_fpu_hazard();
|
|
KSTK_STATUS(current) |= (ST0_CU1 | ST0_CU2);
|
|
if (fr)
|
|
KSTK_STATUS(current) |= ST0_FR;
|
|
else
|
|
KSTK_STATUS(current) &= ~ST0_FR;
|
|
/* If FPU is owned, we needn't init or restore fp */
|
|
if (!fpu_owned) {
|
|
set_thread_flag(TIF_USEDFPU);
|
|
init_fp_ctx(current);
|
|
_restore_fp(current);
|
|
}
|
|
preempt_enable();
|
|
|
|
return NOTIFY_STOP; /* Don't call default notifier */
|
|
}
|
|
|
|
return NOTIFY_OK; /* Let default notifier send signals */
|
|
}
|
|
|
|
static int __init loongson_cu2_setup(void)
|
|
{
|
|
return cu2_notifier(loongson_cu2_call, 0);
|
|
}
|
|
early_initcall(loongson_cu2_setup);
|