MIPS: Loongson-3: Enable the COP2 usage
PATCH v4 1/1 MIPS: Loongson-3: Enable the COP2 usage
Loongson-3 has some specific instructions (MMI/SIMD) in coprocessor 2. COP2 isn't independent because it share COP1 (FPU)'s registers. This patch enable the COP2 usage so user-space programs can use the MMI/SIMD instructions. When COP2 exception happens, we enable both COP1 (FPU) and COP2, only in this way the fp context can be saved and restored correctly.
V4: Make it work fine in preemptible kernel.
--- arch/mips/include/asm/cop2.h | 8 ++++ arch/mips/loongson/loongson-3/Makefile | 2 +- arch/mips/loongson/loongson-3/cop2-ex.c | 63 +++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletions(-) create mode 100644 arch/mips/loongson/loongson-3/cop2-ex.c
arch/mips/include/asm/cop2.h +8 -0
@@ -32,6 +32,14 @@ extern void nlm_cop2_restore(struct nlm_cop2_state *);#define cop2_present 1#define cop2_lazy_restore 0 +#elif defined(CONFIG_CPU_LOONGSON3 ) + +#define cop2_save (r) +#define cop2_restore (r) + +#define cop2_present 1 +#define cop2_lazy_restore 1 +#else #define cop2_present 0
arch/mips/loongson/loongson-3/Makefile +1 -1
@@ -1,7 +1,7 @@ # # Makefile for Loongson-3 family machines # -obj-y += irq.o +obj-y += irq.o cop2-ex.o obj-$(CONFIG_SMP) += smp.o
arch/mips/loongson/loongson-3/cop2-ex.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.7.3
Hi, Ralf,
I found that the V3 of Loongson's patchset has been merged into mips-for-linux-next. But the 7th patch (this one) should be updated for preemptible kernel. The reason is nearly the same as
http://www.linux-mips.org/archives/linux-mips/2014-07/msg00237.html.
Thanks.
Huacai
Quoted 121 lines · Huacai Chen
Loongson-3 has some specific instructions (MMI/SIMD) in coprocessor 2. COP2 isn't independent because it share COP1 (FPU)'s registers. This patch enable the COP2 usage so user-space programs can use the MMI/SIMD instructions. When COP2 exception happens, we enable both COP1 (FPU) and COP2, only in this way the fp context can be saved and restored correctly.
V4: Make it work fine in preemptible kernel.
Signed-off-by Huacai Chen <[email protected]>--- arch/mips/include/asm/cop2.h | 8 ++++ arch/mips/loongson/loongson-3/Makefile | 2 +- arch/mips/loongson/loongson-3/cop2-ex.c | 63 +++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletions(-) create mode 100644 arch/mips/loongson/loongson-3/cop2-ex.carch/mips/include/asm/cop2.h +8
-0@@ -32,6 +32,14 @@ extern void nlm_cop2_restore(struct nlm_cop2_state *);#define cop2_present 1#define cop2_lazy_restore 0 +#elif defined(CONFIG_CPU_LOONGSON3 ) + +#define cop2_save (r) +#define cop2_restore (r) + +#define cop2_present 1 +#define cop2_lazy_restore 1 +#else #define cop2_present 0arch/mips/loongson/loongson-3/Makefile +1
-1@@ -1,7 +1,7 @@ # # Makefile for Loongson-3 family machines # -obj-y += irq.o +obj-y += irq.o cop2-ex.o obj-$(CONFIG_SMP) += smp.oarch/mips/loongson/loongson-3/cop2-ex.c new file +63
-1@@ -0,0 +1,63 @@ +/* +* 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 <[email protected]> +* +* based on arch/mips/cavium-octeon/cpu.c +* Copyright (C) 2009 Wind River Systems, +* written by Ralf Baechle <[email protected]> +*/ +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/notifier.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 ); +if (!used_math ()) { +_init_fpu (); +set_used_math (); + }else +_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); --1.7.7.3
Quoted 6 lines · Huacai Chen
I found that the V3 of Loongson's patchset has been merged into mips-for-linux-next. But the 7th patch (this one) should be updated for preemptible kernel. The reason is nearly the same as
http://www.linux-mips.org/archives/linux-mips/2014-07/msg00237.html.
Thanks.
I'm marking this one as rejected because V3 plus
https://patchwork.linux-mips.org/patch/7515/ which are already applied are identical.
Thanks,
Ralf