Release 4.14 arch/mips/include/asm/fpu.h
/*
* Copyright (C) 2002 MontaVista Software Inc.
* Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#ifndef _ASM_FPU_H
#define _ASM_FPU_H
#include <linux/sched.h>
#include <linux/sched/task_stack.h>
#include <linux/ptrace.h>
#include <linux/thread_info.h>
#include <linux/bitops.h>
#include <asm/mipsregs.h>
#include <asm/cpu.h>
#include <asm/cpu-features.h>
#include <asm/fpu_emulator.h>
#include <asm/hazards.h>
#include <asm/ptrace.h>
#include <asm/processor.h>
#include <asm/current.h>
#include <asm/msa.h>
#ifdef CONFIG_MIPS_MT_FPAFF
#include <asm/mips_mt.h>
#endif
struct sigcontext;
struct sigcontext32;
extern void _init_fpu(unsigned int);
extern void _save_fp(struct task_struct *);
extern void _restore_fp(struct task_struct *);
/*
* This enum specifies a mode in which we want the FPU to operate, for cores
* which implement the Status.FR bit. Note that the bottom bit of the value
* purposefully matches the desired value of the Status.FR bit.
*/
enum fpu_mode {
FPU_32BIT = 0, /* FR = 0 */
FPU_64BIT, /* FR = 1, FRE = 0 */
FPU_AS_IS,
FPU_HYBRID, /* FR = 1, FRE = 1 */
#define FPU_FR_MASK 0x1
};
#define __disable_fpu() \
do { \
clear_c0_status(ST0_CU1); \
disable_fpu_hazard(); \
} while (0)
static inline int __enable_fpu(enum fpu_mode mode)
{
int fr;
switch (mode) {
case FPU_AS_IS:
/* just enable the FPU in its current mode */
set_c0_status(ST0_CU1);
enable_fpu_hazard();
return 0;
case FPU_HYBRID:
if (!cpu_has_fre)
return SIGFPE;
/* set FRE */
set_c0_config5(MIPS_CONF5_FRE);
goto fr_common;
case FPU_64BIT:
#if !(defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) \
|| defined(CONFIG_64BIT))
/* we only have a 32-bit FPU */
return SIGFPE;
#endif
/* fall through */
case FPU_32BIT:
if (cpu_has_fre) {
/* clear FRE */
clear_c0_config5(MIPS_CONF5_FRE);
}
fr_common:
/* set CU1 & change FR appropriately */
fr = (int)mode & FPU_FR_MASK;
change_c0_status(ST0_CU1 | ST0_FR, ST0_CU1 | (fr ? ST0_FR : 0));
enable_fpu_hazard();
/* check FR has the desired value */
if (!!(read_c0_status() & ST0_FR) == !!fr)
return 0;
/* unsupported FR value */
__disable_fpu();
return SIGFPE;
default:
BUG();
}
return SIGFPE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Burton | 145 | 87.88% | 3 | 30.00% |
Ralf Bächle | 9 | 5.45% | 3 | 30.00% |
Markos Chandras | 7 | 4.24% | 2 | 20.00% |
Aaro Koskinen | 3 | 1.82% | 1 | 10.00% |
Paul Bolle | 1 | 0.61% | 1 | 10.00% |
Total | 165 | 100.00% | 10 | 100.00% |
#define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU)
static inline int __is_fpu_owner(void)
{
return test_thread_flag(TIF_USEDFPU);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 15 | 100.00% | 2 | 100.00% |
Total | 15 | 100.00% | 2 | 100.00% |
static inline int is_fpu_owner(void)
{
return cpu_has_fpu && __is_fpu_owner();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 15 | 100.00% | 1 | 100.00% |
Total | 15 | 100.00% | 1 | 100.00% |
static inline int __own_fpu(void)
{
enum fpu_mode mode;
int ret;
if (test_thread_flag(TIF_HYBRID_FPREGS))
mode = FPU_HYBRID;
else
mode = !test_thread_flag(TIF_32BIT_FPREGS);
ret = __enable_fpu(mode);
if (ret)
return ret;
KSTK_STATUS(current) |= ST0_CU1;
if (mode == FPU_64BIT || mode == FPU_HYBRID)
KSTK_STATUS(current) |= ST0_FR;
else /* mode == FPU_32BIT */
KSTK_STATUS(current) &= ~ST0_FR;
set_thread_flag(TIF_USEDFPU);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Burton | 70 | 76.09% | 2 | 50.00% |
Ralf Bächle | 21 | 22.83% | 1 | 25.00% |
Atsushi Nemoto | 1 | 1.09% | 1 | 25.00% |
Total | 92 | 100.00% | 4 | 100.00% |
static inline int own_fpu_inatomic(int restore)
{
int ret = 0;
if (cpu_has_fpu && !__is_fpu_owner()) {
ret = __own_fpu();
if (restore && !ret)
_restore_fp(current);
}
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Atsushi Nemoto | 31 | 68.89% | 2 | 66.67% |
Paul Burton | 14 | 31.11% | 1 | 33.33% |
Total | 45 | 100.00% | 3 | 100.00% |
static inline int own_fpu(int restore)
{
int ret;
preempt_disable();
ret = own_fpu_inatomic(restore);
preempt_enable();
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Atsushi Nemoto | 19 | 65.52% | 2 | 50.00% |
Paul Burton | 9 | 31.03% | 1 | 25.00% |
Ralf Bächle | 1 | 3.45% | 1 | 25.00% |
Total | 29 | 100.00% | 4 | 100.00% |
static inline void lose_fpu_inatomic(int save, struct task_struct *tsk)
{
if (is_msa_enabled()) {
if (save) {
save_msa(tsk);
tsk->thread.fpu.fcr31 =
read_32bit_cp1_register(CP1_STATUS);
}
disable_msa();
clear_tsk_thread_flag(tsk, TIF_USEDMSA);
__disable_fpu();
} else if (is_fpu_owner()) {
if (save)
_save_fp(tsk);
__disable_fpu();
} else {
/* FPU should not have been left enabled with no owner */
WARN(read_c0_status() & ST0_CU1,
"Orphaned FPU left enabled");
}
KSTK_STATUS(tsk) &= ~ST0_CU1;
clear_tsk_thread_flag(tsk, TIF_USEDFPU);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Burton | 46 | 42.59% | 2 | 28.57% |
Ralf Bächle | 21 | 19.44% | 1 | 14.29% |
James Hogan | 17 | 15.74% | 2 | 28.57% |
Atsushi Nemoto | 12 | 11.11% | 1 | 14.29% |
Manuel Lauss | 12 | 11.11% | 1 | 14.29% |
Total | 108 | 100.00% | 7 | 100.00% |
static inline void lose_fpu(int save)
{
preempt_disable();
lose_fpu_inatomic(save, current);
preempt_enable();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Burton | 19 | 82.61% | 1 | 33.33% |
Atsushi Nemoto | 3 | 13.04% | 1 | 33.33% |
Ralf Bächle | 1 | 4.35% | 1 | 33.33% |
Total | 23 | 100.00% | 3 | 100.00% |
static inline int init_fpu(void)
{
unsigned int fcr31 = current->thread.fpu.fcr31;
int ret = 0;
if (cpu_has_fpu) {
unsigned int config5;
ret = __own_fpu();
if (ret)
return ret;
if (!cpu_has_fre) {
_init_fpu(fcr31);
return 0;
}
/*
* Ensure FRE is clear whilst running _init_fpu, since
* single precision FP instructions are used. If FRE
* was set then we'll just end up initialising all 32
* 64b registers.
*/
config5 = clear_c0_config5(MIPS_CONF5_FRE);
enable_fpu_hazard();
_init_fpu(fcr31);
/* Restore FRE */
write_c0_config5(config5);
enable_fpu_hazard();
} else
fpu_emulator_init_fpu();
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 40 | 42.11% | 3 | 42.86% |
Paul Burton | 34 | 35.79% | 2 | 28.57% |
Maciej W. Rozycki | 18 | 18.95% | 1 | 14.29% |
Atsushi Nemoto | 3 | 3.16% | 1 | 14.29% |
Total | 95 | 100.00% | 7 | 100.00% |
static inline void save_fp(struct task_struct *tsk)
{
if (cpu_has_fpu)
_save_fp(tsk);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 21 | 100.00% | 1 | 100.00% |
Total | 21 | 100.00% | 1 | 100.00% |
static inline void restore_fp(struct task_struct *tsk)
{
if (cpu_has_fpu)
_restore_fp(tsk);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 21 | 100.00% | 1 | 100.00% |
Total | 21 | 100.00% | 1 | 100.00% |
static inline union fpureg *get_fpu_regs(struct task_struct *tsk)
{
if (tsk == current) {
preempt_disable();
if (is_fpu_owner())
_save_fp(current);
preempt_enable();
}
return tsk->thread.fpu.fpr;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Ralf Bächle | 35 | 74.47% | 2 | 50.00% |
Atsushi Nemoto | 10 | 21.28% | 1 | 25.00% |
Paul Burton | 2 | 4.26% | 1 | 25.00% |
Total | 47 | 100.00% | 4 | 100.00% |
#endif /* _ASM_FPU_H */
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paul Burton | 371 | 46.26% | 6 | 20.00% |
Ralf Bächle | 274 | 34.16% | 7 | 23.33% |
Atsushi Nemoto | 79 | 9.85% | 3 | 10.00% |
James Hogan | 20 | 2.49% | 3 | 10.00% |
Maciej W. Rozycki | 20 | 2.49% | 1 | 3.33% |
Manuel Lauss | 12 | 1.50% | 1 | 3.33% |
Markos Chandras | 7 | 0.87% | 2 | 6.67% |
Jiri Slaby | 5 | 0.62% | 1 | 3.33% |
Aaro Koskinen | 3 | 0.37% | 1 | 3.33% |
Ingo Molnar | 3 | 0.37% | 1 | 3.33% |
Arnd Bergmann | 3 | 0.37% | 1 | 3.33% |
Chris Dearman | 2 | 0.25% | 1 | 3.33% |
Andrew Morton | 2 | 0.25% | 1 | 3.33% |
Paul Bolle | 1 | 0.12% | 1 | 3.33% |
Total | 802 | 100.00% | 30 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.