1b8b572e1SStephen Rothwell /*
2b8b572e1SStephen Rothwell  * IRQ flags handling
3b8b572e1SStephen Rothwell  */
4b8b572e1SStephen Rothwell #ifndef _ASM_IRQFLAGS_H
5b8b572e1SStephen Rothwell #define _ASM_IRQFLAGS_H
6b8b572e1SStephen Rothwell 
7b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__
8b8b572e1SStephen Rothwell /*
9df9ee292SDavid Howells  * Get definitions for arch_local_save_flags(x), etc.
10b8b572e1SStephen Rothwell  */
11b8b572e1SStephen Rothwell #include <asm/hw_irq.h>
12b8b572e1SStephen Rothwell 
13b8b572e1SStephen Rothwell #else
14b8b572e1SStephen Rothwell #ifdef CONFIG_TRACE_IRQFLAGS
153cb5f1a3SSteven Rostedt #ifdef CONFIG_IRQSOFF_TRACER
163cb5f1a3SSteven Rostedt /*
173cb5f1a3SSteven Rostedt  * Since the ftrace irqsoff latency trace checks CALLER_ADDR1,
183cb5f1a3SSteven Rostedt  * which is the stack frame here, we need to force a stack frame
193cb5f1a3SSteven Rostedt  * in case we came from user space.
203cb5f1a3SSteven Rostedt  */
213cb5f1a3SSteven Rostedt #define TRACE_WITH_FRAME_BUFFER(func)		\
223cb5f1a3SSteven Rostedt 	mflr	r0;				\
233cb5f1a3SSteven Rostedt 	stdu	r1, -32(r1);			\
243cb5f1a3SSteven Rostedt 	std	r0, 16(r1);			\
253cb5f1a3SSteven Rostedt 	stdu	r1, -32(r1);			\
263cb5f1a3SSteven Rostedt 	bl func;				\
273cb5f1a3SSteven Rostedt 	ld	r1, 0(r1);			\
283cb5f1a3SSteven Rostedt 	ld	r1, 0(r1);
293cb5f1a3SSteven Rostedt #else
303cb5f1a3SSteven Rostedt #define TRACE_WITH_FRAME_BUFFER(func)		\
313cb5f1a3SSteven Rostedt 	bl func;
323cb5f1a3SSteven Rostedt #endif
333cb5f1a3SSteven Rostedt 
34b8b572e1SStephen Rothwell /*
35b8b572e1SStephen Rothwell  * Most of the CPU's IRQ-state tracing is done from assembly code; we
36b8b572e1SStephen Rothwell  * have to call a C function so call a wrapper that saves all the
37b8b572e1SStephen Rothwell  * C-clobbered registers.
38b8b572e1SStephen Rothwell  */
39b1576fecSAnton Blanchard #define TRACE_ENABLE_INTS	TRACE_WITH_FRAME_BUFFER(trace_hardirqs_on)
40b1576fecSAnton Blanchard #define TRACE_DISABLE_INTS	TRACE_WITH_FRAME_BUFFER(trace_hardirqs_off)
413cb5f1a3SSteven Rostedt 
427230c564SBenjamin Herrenschmidt /*
43de021bb7STiejun Chen  * This is used by assembly code to soft-disable interrupts first and
44de021bb7STiejun Chen  * reconcile irq state.
457230c564SBenjamin Herrenschmidt  */
46de021bb7STiejun Chen #define RECONCILE_IRQ_STATE(__rA, __rB)		\
477230c564SBenjamin Herrenschmidt 	lbz	__rA,PACASOFTIRQEN(r13);	\
487230c564SBenjamin Herrenschmidt 	lbz	__rB,PACAIRQHAPPENED(r13);	\
497230c564SBenjamin Herrenschmidt 	cmpwi	cr0,__rA,0;			\
507230c564SBenjamin Herrenschmidt 	li	__rA,0;				\
517230c564SBenjamin Herrenschmidt 	ori	__rB,__rB,PACA_IRQ_HARD_DIS;	\
527230c564SBenjamin Herrenschmidt 	stb	__rB,PACAIRQHAPPENED(r13);	\
537230c564SBenjamin Herrenschmidt 	beq	44f;				\
547230c564SBenjamin Herrenschmidt 	stb	__rA,PACASOFTIRQEN(r13);	\
557230c564SBenjamin Herrenschmidt 	TRACE_DISABLE_INTS;			\
567230c564SBenjamin Herrenschmidt 44:
577230c564SBenjamin Herrenschmidt 
58b8b572e1SStephen Rothwell #else
59b8b572e1SStephen Rothwell #define TRACE_ENABLE_INTS
60b8b572e1SStephen Rothwell #define TRACE_DISABLE_INTS
617230c564SBenjamin Herrenschmidt 
62de021bb7STiejun Chen #define RECONCILE_IRQ_STATE(__rA, __rB)		\
637230c564SBenjamin Herrenschmidt 	lbz	__rA,PACAIRQHAPPENED(r13);	\
647230c564SBenjamin Herrenschmidt 	li	__rB,0;				\
657230c564SBenjamin Herrenschmidt 	ori	__rA,__rA,PACA_IRQ_HARD_DIS;	\
667230c564SBenjamin Herrenschmidt 	stb	__rB,PACASOFTIRQEN(r13);	\
677230c564SBenjamin Herrenschmidt 	stb	__rA,PACAIRQHAPPENED(r13)
68b8b572e1SStephen Rothwell #endif
69b8b572e1SStephen Rothwell #endif
70b8b572e1SStephen Rothwell 
71b8b572e1SStephen Rothwell #endif
72