blob: a9490841c8012e49a63395df82248210b7d69e6c [file] [log] [blame]
Vineet Gupta5793e272015-03-05 19:13:56 +05301/*
2 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
3 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#ifndef __ASM_IRQFLAGS_ARCOMPACT_H
11#define __ASM_IRQFLAGS_ARCOMPACT_H
12
13/* vineetg: March 2010 : local_irq_save( ) optimisation
14 * -Remove explicit mov of current status32 into reg, that is not needed
15 * -Use BIC insn instead of INVERTED + AND
16 * -Conditionally disable interrupts (if they are not enabled, don't disable)
17*/
18
19#include <asm/arcregs.h>
20
21/* status32 Reg bits related to Interrupt Handling */
22#define STATUS_E1_BIT 1 /* Int 1 enable */
23#define STATUS_E2_BIT 2 /* Int 2 enable */
24#define STATUS_A1_BIT 3 /* Int 1 active */
25#define STATUS_A2_BIT 4 /* Int 2 active */
26
27#define STATUS_E1_MASK (1<<STATUS_E1_BIT)
28#define STATUS_E2_MASK (1<<STATUS_E2_BIT)
29#define STATUS_A1_MASK (1<<STATUS_A1_BIT)
30#define STATUS_A2_MASK (1<<STATUS_A2_BIT)
31#define STATUS_IE_MASK (STATUS_E1_MASK | STATUS_E2_MASK)
32
33/* Other Interrupt Handling related Aux regs */
34#define AUX_IRQ_LEV 0x200 /* IRQ Priority: L1 or L2 */
35#define AUX_IRQ_HINT 0x201 /* For generating Soft Interrupts */
36#define AUX_IRQ_LV12 0x43 /* interrupt level register */
37
38#define AUX_IENABLE 0x40c
39#define AUX_ITRIGGER 0x40d
40#define AUX_IPULSE 0x415
41
Vineet Gupta1f6ccff2013-05-13 18:30:41 +053042#define ISA_INIT_STATUS_BITS STATUS_IE_MASK
43
Vineet Gupta5793e272015-03-05 19:13:56 +053044#ifndef __ASSEMBLY__
45
46/******************************************************************
47 * IRQ Control Macros
48 *
49 * All of them have "memory" clobber (compiler barrier) which is needed to
50 * ensure that LD/ST requiring irq safetly (R-M-W when LLSC is not available)
51 * are redone after IRQs are re-enabled (and gcc doesn't reuse stale register)
52 *
53 * Noted at the time of Abilis Timer List corruption
54 * Orig Bug + Rejected solution : https://lkml.org/lkml/2013/3/29/67
55 * Reasoning : https://lkml.org/lkml/2013/4/8/15
56 *
57 ******************************************************************/
58
59/*
60 * Save IRQ state and disable IRQs
61 */
62static inline long arch_local_irq_save(void)
63{
64 unsigned long temp, flags;
65
66 __asm__ __volatile__(
67 " lr %1, [status32] \n"
68 " bic %0, %1, %2 \n"
69 " and.f 0, %1, %2 \n"
70 " flag.nz %0 \n"
71 : "=r"(temp), "=r"(flags)
72 : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
73 : "memory", "cc");
74
75 return flags;
76}
77
78/*
79 * restore saved IRQ state
80 */
81static inline void arch_local_irq_restore(unsigned long flags)
82{
83
84 __asm__ __volatile__(
85 " flag %0 \n"
86 :
87 : "r"(flags)
88 : "memory");
89}
90
91/*
92 * Unconditionally Enable IRQs
93 */
Vineet Gupta9dbd3d92015-09-05 22:47:30 +053094static inline void arch_local_irq_enable(void)
95{
96 unsigned long temp;
97
98 __asm__ __volatile__(
99 " lr %0, [status32] \n"
100 " or %0, %0, %1 \n"
101 " flag %0 \n"
102 : "=&r"(temp)
103 : "n"((STATUS_E1_MASK | STATUS_E2_MASK))
104 : "cc", "memory");
105}
106
Vineet Gupta5793e272015-03-05 19:13:56 +0530107
108/*
109 * Unconditionally Disable IRQs
110 */
111static inline void arch_local_irq_disable(void)
112{
113 unsigned long temp;
114
115 __asm__ __volatile__(
116 " lr %0, [status32] \n"
117 " and %0, %0, %1 \n"
118 " flag %0 \n"
119 : "=&r"(temp)
120 : "n"(~(STATUS_E1_MASK | STATUS_E2_MASK))
121 : "memory");
122}
123
124/*
125 * save IRQ state
126 */
127static inline long arch_local_save_flags(void)
128{
129 unsigned long temp;
130
131 __asm__ __volatile__(
132 " lr %0, [status32] \n"
133 : "=&r"(temp)
134 :
135 : "memory");
136
137 return temp;
138}
139
140/*
141 * Query IRQ state
142 */
143static inline int arch_irqs_disabled_flags(unsigned long flags)
144{
145 return !(flags & (STATUS_E1_MASK
146#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
147 | STATUS_E2_MASK
148#endif
149 ));
150}
151
152static inline int arch_irqs_disabled(void)
153{
154 return arch_irqs_disabled_flags(arch_local_save_flags());
155}
156
157#else
158
159#ifdef CONFIG_TRACE_IRQFLAGS
160
161.macro TRACE_ASM_IRQ_DISABLE
162 bl trace_hardirqs_off
163.endm
164
165.macro TRACE_ASM_IRQ_ENABLE
166 bl trace_hardirqs_on
167.endm
168
169#else
170
171.macro TRACE_ASM_IRQ_DISABLE
172.endm
173
174.macro TRACE_ASM_IRQ_ENABLE
175.endm
176
177#endif
178
179.macro IRQ_DISABLE scratch
180 lr \scratch, [status32]
181 bic \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
182 flag \scratch
183 TRACE_ASM_IRQ_DISABLE
184.endm
185
186.macro IRQ_ENABLE scratch
187 lr \scratch, [status32]
188 or \scratch, \scratch, (STATUS_E1_MASK | STATUS_E2_MASK)
189 flag \scratch
190 TRACE_ASM_IRQ_ENABLE
191.endm
192
193#endif /* __ASSEMBLY__ */
194
195#endif