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
6 * Copyright (C) 2013 Broadcom Corporation.
8 * based on arch/mips/cavium-octeon/cpu.c
9 * Copyright (C) 2009 Wind River Systems,
10 * written by Ralf Baechle <ralf@linux-mips.org>
12 #include <linux/init.h>
13 #include <linux/irqflags.h>
14 #include <linux/notifier.h>
15 #include <linux/prefetch.h>
16 #include <linux/sched.h>
19 #include <asm/current.h>
20 #include <asm/mipsregs.h>
23 #include <asm/netlogic/mips-extns.h>
26 * 64 bit ops are done in inline assembly to support 32 bit
29 void nlm_cop2_save(struct nlm_cop2_state
*r
)
52 : "r"(r
->tx
), "r"(r
->rx
));
54 r
->tx_msg_status
= __read_32bit_c2_register($
2, 0);
55 r
->rx_msg_status
= __read_32bit_c2_register($
3, 0) & 0x0fffffff;
58 void nlm_cop2_restore(struct nlm_cop2_state
*r
)
82 : : "m"(*r
), "r"(r
->tx
), "r"(r
->rx
));
84 __write_32bit_c2_register($
2, 0, r
->tx_msg_status
);
85 rstat
= __read_32bit_c2_register($
3, 0) & 0xf0000000u
;
86 __write_32bit_c2_register($
3, 0, r
->rx_msg_status
| rstat
);
89 static int nlm_cu2_call(struct notifier_block
*nfb
, unsigned long action
,
97 if (!capable(CAP_SYS_ADMIN
) || !capable(CAP_SYS_RAWIO
))
99 local_irq_save(flags
);
100 KSTK_STATUS(current
) |= ST0_CU2
;
101 status
= read_c0_status();
102 write_c0_status(status
| ST0_CU2
);
103 nlm_cop2_restore(&(current
->thread
.cp2
));
104 write_c0_status(status
& ~ST0_CU2
);
105 local_irq_restore(flags
);
106 pr_info("COP2 access enabled for pid %d (%s)\n",
107 current
->pid
, current
->comm
);
108 return NOTIFY_BAD
; /* Don't call default notifier */
111 return NOTIFY_OK
; /* Let default notifier send signals */
114 static int __init
nlm_cu2_setup(void)
116 return cu2_notifier(nlm_cu2_call
, 0);
118 early_initcall(nlm_cu2_setup
);