]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/mips/loongson64/loongson-3/cop2-ex.c
Merge remote-tracking branches 'spi/topic/devprop', 'spi/topic/fsl', 'spi/topic/fsl...
[mirror_ubuntu-bionic-kernel.git] / arch / mips / loongson64 / loongson-3 / cop2-ex.c
CommitLineData
ef2f826c
HC
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2014 Lemote Corporation.
7 * written by Huacai Chen <chenhc@lemote.com>
8 *
9 * based on arch/mips/cavium-octeon/cpu.c
10 * Copyright (C) 2009 Wind River Systems,
11 * written by Ralf Baechle <ralf@linux-mips.org>
12 */
13#include <linux/init.h>
14#include <linux/sched.h>
15#include <linux/notifier.h>
fc69910f 16#include <linux/ptrace.h>
ef2f826c
HC
17
18#include <asm/fpu.h>
19#include <asm/cop2.h>
20#include <asm/current.h>
21#include <asm/mipsregs.h>
22
23static int loongson_cu2_call(struct notifier_block *nfb, unsigned long action,
24 void *data)
25{
bfcdf130 26 int fpu_owned;
ef2f826c
HC
27 int fr = !test_thread_flag(TIF_32BIT_FPREGS);
28
29 switch (action) {
30 case CU2_EXCEPTION:
31 preempt_disable();
bfcdf130 32 fpu_owned = __is_fpu_owner();
ef2f826c
HC
33 if (!fr)
34 set_c0_status(ST0_CU1 | ST0_CU2);
35 else
36 set_c0_status(ST0_CU1 | ST0_CU2 | ST0_FR);
37 enable_fpu_hazard();
38 KSTK_STATUS(current) |= (ST0_CU1 | ST0_CU2);
39 if (fr)
40 KSTK_STATUS(current) |= ST0_FR;
41 else
42 KSTK_STATUS(current) &= ~ST0_FR;
bfcdf130
HC
43 /* If FPU is owned, we needn't init or restore fp */
44 if (!fpu_owned) {
ef2f826c
HC
45 set_thread_flag(TIF_USEDFPU);
46 if (!used_math()) {
9b26616c 47 _init_fpu(current->thread.fpu.fcr31);
ef2f826c
HC
48 set_used_math();
49 } else
50 _restore_fp(current);
51 }
52 preempt_enable();
53
54 return NOTIFY_STOP; /* Don't call default notifier */
55 }
56
57 return NOTIFY_OK; /* Let default notifier send signals */
58}
59
60static int __init loongson_cu2_setup(void)
61{
62 return cu2_notifier(loongson_cu2_call, 0);
63}
64early_initcall(loongson_cu2_setup);