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  */
393cb5f1a3SSteven Rostedt #define TRACE_ENABLE_INTS	TRACE_WITH_FRAME_BUFFER(.trace_hardirqs_on)
403cb5f1a3SSteven Rostedt #define TRACE_DISABLE_INTS	TRACE_WITH_FRAME_BUFFER(.trace_hardirqs_off)
413cb5f1a3SSteven Rostedt 
427230c564SBenjamin Herrenschmidt /*
437230c564SBenjamin Herrenschmidt  * This is used by assembly code to soft-disable interrupts
447230c564SBenjamin Herrenschmidt  */
457230c564SBenjamin Herrenschmidt #define SOFT_DISABLE_INTS(__rA, __rB)		\
467230c564SBenjamin Herrenschmidt 	lbz	__rA,PACASOFTIRQEN(r13);	\
477230c564SBenjamin Herrenschmidt 	lbz	__rB,PACAIRQHAPPENED(r13);	\
487230c564SBenjamin Herrenschmidt 	cmpwi	cr0,__rA,0;			\
497230c564SBenjamin Herrenschmidt 	li	__rA,0;				\
507230c564SBenjamin Herrenschmidt 	ori	__rB,__rB,PACA_IRQ_HARD_DIS;	\
517230c564SBenjamin Herrenschmidt 	stb	__rB,PACAIRQHAPPENED(r13);	\
527230c564SBenjamin Herrenschmidt 	beq	44f;				\
537230c564SBenjamin Herrenschmidt 	stb	__rA,PACASOFTIRQEN(r13);	\
547230c564SBenjamin Herrenschmidt 	TRACE_DISABLE_INTS;			\
557230c564SBenjamin Herrenschmidt 44:
567230c564SBenjamin Herrenschmidt 
57b8b572e1SStephen Rothwell #else
58b8b572e1SStephen Rothwell #define TRACE_ENABLE_INTS
59b8b572e1SStephen Rothwell #define TRACE_DISABLE_INTS
607230c564SBenjamin Herrenschmidt 
617230c564SBenjamin Herrenschmidt #define SOFT_DISABLE_INTS(__rA, __rB)		\
627230c564SBenjamin Herrenschmidt 	lbz	__rA,PACAIRQHAPPENED(r13);	\
637230c564SBenjamin Herrenschmidt 	li	__rB,0;				\
647230c564SBenjamin Herrenschmidt 	ori	__rA,__rA,PACA_IRQ_HARD_DIS;	\
657230c564SBenjamin Herrenschmidt 	stb	__rB,PACASOFTIRQEN(r13);	\
667230c564SBenjamin Herrenschmidt 	stb	__rA,PACAIRQHAPPENED(r13)
67b8b572e1SStephen Rothwell #endif
68b8b572e1SStephen Rothwell #endif
69b8b572e1SStephen Rothwell 
70b8b572e1SStephen Rothwell #endif
71