Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) 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 | */ |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 11 | #ifndef _ASM_IRQFLAGS_H |
| 12 | #define _ASM_IRQFLAGS_H |
| 13 | |
| 14 | #ifndef __ASSEMBLY__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Ralf Baechle | 8a1e97e | 2007-03-29 23:42:42 +0100 | [diff] [blame] | 16 | #include <linux/compiler.h> |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 17 | #include <linux/stringify.h> |
Markos Chandras | 8716a76 | 2014-11-13 11:54:31 +0000 | [diff] [blame] | 18 | #include <asm/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/hazards.h> |
| 20 | |
Markos Chandras | 8716a76 | 2014-11-13 11:54:31 +0000 | [diff] [blame] | 21 | #if defined(CONFIG_CPU_MIPSR2) || defined (CONFIG_CPU_MIPSR6) |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 22 | |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 23 | static inline void arch_local_irq_disable(void) |
| 24 | { |
| 25 | __asm__ __volatile__( |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 26 | " .set push \n" |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 27 | " .set noat \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 28 | " di \n" |
| 29 | " " __stringify(__irq_disable_hazard) " \n" |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 30 | " .set pop \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 31 | : /* no outputs */ |
| 32 | : /* no inputs */ |
| 33 | : "memory"); |
| 34 | } |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 35 | |
| 36 | static inline unsigned long arch_local_irq_save(void) |
| 37 | { |
| 38 | unsigned long flags; |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 39 | |
| 40 | asm __volatile__( |
| 41 | " .set push \n" |
| 42 | " .set reorder \n" |
| 43 | " .set noat \n" |
Huacai Chen | 1e820da3 | 2016-03-03 09:45:13 +0800 | [diff] [blame] | 44 | #if defined(CONFIG_CPU_LOONGSON3) |
| 45 | " mfc0 %[flags], $12 \n" |
| 46 | " di \n" |
| 47 | #else |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 48 | " di %[flags] \n" |
Huacai Chen | 1e820da3 | 2016-03-03 09:45:13 +0800 | [diff] [blame] | 49 | #endif |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 50 | " andi %[flags], 1 \n" |
| 51 | " " __stringify(__irq_disable_hazard) " \n" |
| 52 | " .set pop \n" |
| 53 | : [flags] "=r" (flags) |
| 54 | : /* no inputs */ |
| 55 | : "memory"); |
| 56 | |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 57 | return flags; |
| 58 | } |
| 59 | |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 60 | static inline void arch_local_irq_restore(unsigned long flags) |
| 61 | { |
| 62 | unsigned long __tmp1; |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 63 | |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 64 | __asm__ __volatile__( |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 65 | " .set push \n" |
| 66 | " .set noreorder \n" |
| 67 | " .set noat \n" |
Ralf Baechle | 67e38cf | 2015-05-26 18:20:06 +0200 | [diff] [blame] | 68 | #if defined(CONFIG_IRQ_MIPS_CPU) |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 69 | /* |
| 70 | * Slow, but doesn't suffer from a relatively unlikely race |
| 71 | * condition we're having since days 1. |
| 72 | */ |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 73 | " beqz %[flags], 1f \n" |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 74 | " di \n" |
| 75 | " ei \n" |
| 76 | "1: \n" |
| 77 | #else |
| 78 | /* |
| 79 | * Fast, dangerous. Life is fun, life is good. |
| 80 | */ |
| 81 | " mfc0 $1, $12 \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 82 | " ins $1, %[flags], 0, 1 \n" |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 83 | " mtc0 $1, $12 \n" |
| 84 | #endif |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 85 | " " __stringify(__irq_disable_hazard) " \n" |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 86 | " .set pop \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 87 | : [flags] "=r" (__tmp1) |
| 88 | : "0" (flags) |
| 89 | : "memory"); |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 92 | #else |
| 93 | /* Functions that require preempt_{dis,en}able() are in mips-atomic.c */ |
| 94 | void arch_local_irq_disable(void); |
| 95 | unsigned long arch_local_irq_save(void); |
| 96 | void arch_local_irq_restore(unsigned long flags); |
Markos Chandras | 8716a76 | 2014-11-13 11:54:31 +0000 | [diff] [blame] | 97 | #endif /* CONFIG_CPU_MIPSR2 || CONFIG_CPU_MIPSR6 */ |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 98 | |
| 99 | static inline void arch_local_irq_enable(void) |
| 100 | { |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 101 | __asm__ __volatile__( |
Ralf Baechle | ff88f8a | 2005-07-12 14:54:31 +0000 | [diff] [blame] | 102 | " .set push \n" |
| 103 | " .set reorder \n" |
| 104 | " .set noat \n" |
Markos Chandras | 8716a76 | 2014-11-13 11:54:31 +0000 | [diff] [blame] | 105 | #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) |
Ralf Baechle | ff88f8a | 2005-07-12 14:54:31 +0000 | [diff] [blame] | 106 | " ei \n" |
| 107 | #else |
| 108 | " mfc0 $1,$12 \n" |
| 109 | " ori $1,0x1f \n" |
| 110 | " xori $1,0x1e \n" |
| 111 | " mtc0 $1,$12 \n" |
| 112 | #endif |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 113 | " " __stringify(__irq_enable_hazard) " \n" |
Ralf Baechle | ff88f8a | 2005-07-12 14:54:31 +0000 | [diff] [blame] | 114 | " .set pop \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 115 | : /* no outputs */ |
| 116 | : /* no inputs */ |
| 117 | : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 120 | static inline unsigned long arch_local_save_flags(void) |
| 121 | { |
| 122 | unsigned long flags; |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 123 | |
| 124 | asm __volatile__( |
| 125 | " .set push \n" |
| 126 | " .set reorder \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 127 | " mfc0 %[flags], $12 \n" |
Ralf Baechle | 02b849f | 2013-02-08 18:13:30 +0100 | [diff] [blame] | 128 | " .set pop \n" |
| 129 | : [flags] "=r" (flags)); |
| 130 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 131 | return flags; |
| 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Kevin D. Kissell | 8531a35 | 2008-09-09 21:48:52 +0200 | [diff] [blame] | 134 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 135 | static inline int arch_irqs_disabled_flags(unsigned long flags) |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 136 | { |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 137 | return !(flags & 1); |
Ralf Baechle | 41c594a | 2006-04-05 09:45:45 +0100 | [diff] [blame] | 138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Jim Quinlan | e97c5b6 | 2012-09-06 11:36:56 -0400 | [diff] [blame] | 140 | #endif /* #ifndef __ASSEMBLY__ */ |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Do the CPU's IRQ-state tracing from assembly code. |
| 144 | */ |
| 145 | #ifdef CONFIG_TRACE_IRQFLAGS |
Atsushi Nemoto | eae6c0d | 2006-09-26 23:43:40 +0900 | [diff] [blame] | 146 | /* Reload some registers clobbered by trace_hardirqs_on */ |
| 147 | #ifdef CONFIG_64BIT |
| 148 | # define TRACE_IRQS_RELOAD_REGS \ |
| 149 | LONG_L $11, PT_R11(sp); \ |
| 150 | LONG_L $10, PT_R10(sp); \ |
| 151 | LONG_L $9, PT_R9(sp); \ |
| 152 | LONG_L $8, PT_R8(sp); \ |
| 153 | LONG_L $7, PT_R7(sp); \ |
| 154 | LONG_L $6, PT_R6(sp); \ |
| 155 | LONG_L $5, PT_R5(sp); \ |
| 156 | LONG_L $4, PT_R4(sp); \ |
| 157 | LONG_L $2, PT_R2(sp) |
| 158 | #else |
| 159 | # define TRACE_IRQS_RELOAD_REGS \ |
| 160 | LONG_L $7, PT_R7(sp); \ |
| 161 | LONG_L $6, PT_R6(sp); \ |
| 162 | LONG_L $5, PT_R5(sp); \ |
| 163 | LONG_L $4, PT_R4(sp); \ |
| 164 | LONG_L $2, PT_R2(sp) |
| 165 | #endif |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 166 | # define TRACE_IRQS_ON \ |
Atsushi Nemoto | eae6c0d | 2006-09-26 23:43:40 +0900 | [diff] [blame] | 167 | CLI; /* make sure trace_hardirqs_on() is called in kernel level */ \ |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 168 | jal trace_hardirqs_on |
Atsushi Nemoto | eae6c0d | 2006-09-26 23:43:40 +0900 | [diff] [blame] | 169 | # define TRACE_IRQS_ON_RELOAD \ |
| 170 | TRACE_IRQS_ON; \ |
| 171 | TRACE_IRQS_RELOAD_REGS |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 172 | # define TRACE_IRQS_OFF \ |
| 173 | jal trace_hardirqs_off |
| 174 | #else |
| 175 | # define TRACE_IRQS_ON |
Atsushi Nemoto | eae6c0d | 2006-09-26 23:43:40 +0900 | [diff] [blame] | 176 | # define TRACE_IRQS_ON_RELOAD |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 177 | # define TRACE_IRQS_OFF |
| 178 | #endif |
| 179 | |
| 180 | #endif /* _ASM_IRQFLAGS_H */ |