xref: /linux/arch/powerpc/include/asm/irqflags.h (revision 6fdcba32711044c35c0e1b094cbd8f3f0b4472c9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * IRQ flags handling
4  */
5 #ifndef _ASM_IRQFLAGS_H
6 #define _ASM_IRQFLAGS_H
7 
8 #ifndef __ASSEMBLY__
9 /*
10  * Get definitions for arch_local_save_flags(x), etc.
11  */
12 #include <asm/hw_irq.h>
13 
14 #else
15 #ifdef CONFIG_TRACE_IRQFLAGS
16 #ifdef CONFIG_IRQSOFF_TRACER
17 /*
18  * Since the ftrace irqsoff latency trace checks CALLER_ADDR1,
19  * which is the stack frame here, we need to force a stack frame
20  * in case we came from user space.
21  */
22 #define TRACE_WITH_FRAME_BUFFER(func)		\
23 	mflr	r0;				\
24 	stdu	r1, -STACK_FRAME_OVERHEAD(r1);	\
25 	std	r0, 16(r1);			\
26 	stdu	r1, -STACK_FRAME_OVERHEAD(r1);	\
27 	bl func;				\
28 	ld	r1, 0(r1);			\
29 	ld	r1, 0(r1);
30 #else
31 #define TRACE_WITH_FRAME_BUFFER(func)		\
32 	bl func;
33 #endif
34 
35 /*
36  * These are calls to C code, so the caller must be prepared for volatiles to
37  * be clobbered.
38  */
39 #define TRACE_ENABLE_INTS	TRACE_WITH_FRAME_BUFFER(trace_hardirqs_on)
40 #define TRACE_DISABLE_INTS	TRACE_WITH_FRAME_BUFFER(trace_hardirqs_off)
41 
42 /*
43  * This is used by assembly code to soft-disable interrupts first and
44  * reconcile irq state.
45  *
46  * NB: This may call C code, so the caller must be prepared for volatiles to
47  * be clobbered.
48  */
49 #define RECONCILE_IRQ_STATE(__rA, __rB)		\
50 	lbz	__rA,PACAIRQSOFTMASK(r13);	\
51 	lbz	__rB,PACAIRQHAPPENED(r13);	\
52 	andi.	__rA,__rA,IRQS_DISABLED;	\
53 	li	__rA,IRQS_DISABLED;		\
54 	ori	__rB,__rB,PACA_IRQ_HARD_DIS;	\
55 	stb	__rB,PACAIRQHAPPENED(r13);	\
56 	bne	44f;				\
57 	stb	__rA,PACAIRQSOFTMASK(r13);	\
58 	TRACE_DISABLE_INTS;			\
59 44:
60 
61 #else
62 #define TRACE_ENABLE_INTS
63 #define TRACE_DISABLE_INTS
64 
65 #define RECONCILE_IRQ_STATE(__rA, __rB)		\
66 	lbz	__rA,PACAIRQHAPPENED(r13);	\
67 	li	__rB,IRQS_DISABLED;		\
68 	ori	__rA,__rA,PACA_IRQ_HARD_DIS;	\
69 	stb	__rB,PACAIRQSOFTMASK(r13);	\
70 	stb	__rA,PACAIRQHAPPENED(r13)
71 #endif
72 #endif
73 
74 #endif
75