blob: 5530070e0d05dd51248afb9a8780eb3a86b173a7 [file] [log] [blame]
Jim Quinlane97c5b62012-09-06 11:36:56 -04001/*
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) 1994, 95, 96, 97, 98, 99, 2003 by Ralf Baechle
7 * Copyright (C) 1996 by Paul M. Antoine
8 * Copyright (C) 1999 Silicon Graphics
9 * Copyright (C) 2000 MIPS Technologies, Inc.
10 */
11#include <asm/irqflags.h>
12#include <asm/hazards.h>
13#include <linux/compiler.h>
14#include <linux/preempt.h>
15#include <linux/export.h>
Ralf Baechle02b849f2013-02-08 18:13:30 +010016#include <linux/stringify.h>
Jim Quinlane97c5b62012-09-06 11:36:56 -040017
Markos Chandras8716a762014-11-13 11:54:31 +000018#if !defined(CONFIG_CPU_MIPSR2) && !defined(CONFIG_CPU_MIPSR6)
Jim Quinlane97c5b62012-09-06 11:36:56 -040019
20/*
21 * For cli() we have to insert nops to make sure that the new value
22 * has actually arrived in the status register before the end of this
23 * macro.
24 * R4000/R4400 need three nops, the R4600 two nops and the R10000 needs
25 * no nops at all.
26 */
27/*
28 * For TX49, operating only IE bit is not enough.
29 *
30 * If mfc0 $12 follows store and the mfc0 is last instruction of a
31 * page and fetching the next instruction causes TLB miss, the result
32 * of the mfc0 might wrongly contain EXL bit.
33 *
34 * ERT-TX49H2-027, ERT-TX49H3-012, ERT-TX49HL3-006, ERT-TX49H4-008
35 *
36 * Workaround: mask EXL bit of the result or place a nop before mfc0.
37 */
Ralf Baechle02b849f2013-02-08 18:13:30 +010038notrace void arch_local_irq_disable(void)
39{
40 preempt_disable();
41
42 __asm__ __volatile__(
Jim Quinlane97c5b62012-09-06 11:36:56 -040043 " .set push \n"
44 " .set noat \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040045 " mfc0 $1,$12 \n"
46 " ori $1,0x1f \n"
47 " xori $1,0x1f \n"
48 " .set noreorder \n"
49 " mtc0 $1,$12 \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010050 " " __stringify(__irq_disable_hazard) " \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040051 " .set pop \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010052 : /* no outputs */
53 : /* no inputs */
54 : "memory");
Jim Quinlane97c5b62012-09-06 11:36:56 -040055
Jim Quinlane97c5b62012-09-06 11:36:56 -040056 preempt_enable();
57}
58EXPORT_SYMBOL(arch_local_irq_disable);
59
Ralf Baechle02b849f2013-02-08 18:13:30 +010060notrace unsigned long arch_local_irq_save(void)
61{
62 unsigned long flags;
63
64 preempt_disable();
65
66 __asm__ __volatile__(
Jim Quinlane97c5b62012-09-06 11:36:56 -040067 " .set push \n"
68 " .set reorder \n"
69 " .set noat \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010070 " mfc0 %[flags], $12 \n"
71 " ori $1, %[flags], 0x1f \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040072 " xori $1, 0x1f \n"
73 " .set noreorder \n"
74 " mtc0 $1, $12 \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010075 " " __stringify(__irq_disable_hazard) " \n"
Jim Quinlane97c5b62012-09-06 11:36:56 -040076 " .set pop \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010077 : [flags] "=r" (flags)
78 : /* no inputs */
79 : "memory");
Jim Quinlane97c5b62012-09-06 11:36:56 -040080
Jim Quinlane97c5b62012-09-06 11:36:56 -040081 preempt_enable();
Ralf Baechle02b849f2013-02-08 18:13:30 +010082
Jim Quinlane97c5b62012-09-06 11:36:56 -040083 return flags;
84}
85EXPORT_SYMBOL(arch_local_irq_save);
86
Al Cooperf93a1a02012-11-15 18:16:14 -050087notrace void arch_local_irq_restore(unsigned long flags)
Jim Quinlane97c5b62012-09-06 11:36:56 -040088{
89 unsigned long __tmp1;
90
Jim Quinlane97c5b62012-09-06 11:36:56 -040091 preempt_disable();
Ralf Baechle02b849f2013-02-08 18:13:30 +010092
Jim Quinlane97c5b62012-09-06 11:36:56 -040093 __asm__ __volatile__(
Ralf Baechle02b849f2013-02-08 18:13:30 +010094 " .set push \n"
95 " .set noreorder \n"
96 " .set noat \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +010097 " mfc0 $1, $12 \n"
98 " andi %[flags], 1 \n"
99 " ori $1, 0x1f \n"
100 " xori $1, 0x1f \n"
101 " or %[flags], $1 \n"
102 " mtc0 %[flags], $12 \n"
Ralf Baechle02b849f2013-02-08 18:13:30 +0100103 " " __stringify(__irq_disable_hazard) " \n"
104 " .set pop \n"
105 : [flags] "=r" (__tmp1)
106 : "0" (flags)
107 : "memory");
108
Jim Quinlane97c5b62012-09-06 11:36:56 -0400109 preempt_enable();
110}
111EXPORT_SYMBOL(arch_local_irq_restore);
112
Huacai Chen6e526842016-01-21 21:09:47 +0800113#endif /* !CONFIG_CPU_MIPSR2 && !CONFIG_CPU_MIPSR6 */