Heiko Carstens | 5d360a7 | 2008-12-25 13:38:56 +0100 | [diff] [blame] | 1 | #ifndef _ASM_S390_FTRACE_H |
| 2 | #define _ASM_S390_FTRACE_H |
| 3 | |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 4 | #define ARCH_SUPPORTS_FTRACE_OPS 1 |
| 5 | |
Heiko Carstens | e6d60b3 | 2015-01-09 13:08:28 +0100 | [diff] [blame] | 6 | #ifdef CC_USING_HOTPATCH |
| 7 | #define MCOUNT_INSN_SIZE 6 |
| 8 | #else |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 9 | #define MCOUNT_INSN_SIZE 24 |
| 10 | #define MCOUNT_RETURN_FIXUP 18 |
Heiko Carstens | e6d60b3 | 2015-01-09 13:08:28 +0100 | [diff] [blame] | 11 | #endif |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 12 | |
Heiko Carstens | 5d360a7 | 2008-12-25 13:38:56 +0100 | [diff] [blame] | 13 | #ifndef __ASSEMBLY__ |
Heiko Carstens | dfd9f7a | 2009-06-12 10:26:44 +0200 | [diff] [blame] | 14 | |
Heiko Carstens | 5606330 | 2016-05-02 14:38:29 +0200 | [diff] [blame] | 15 | unsigned long return_address(int depth); |
| 16 | |
| 17 | #define ftrace_return_address(n) return_address(n) |
Heiko Carstens | 7eed2e0 | 2014-11-24 14:30:32 +0100 | [diff] [blame] | 18 | |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 19 | void _mcount(void); |
| 20 | void ftrace_caller(void); |
| 21 | |
Heiko Carstens | 2481a87 | 2014-08-15 12:33:46 +0200 | [diff] [blame] | 22 | extern char ftrace_graph_caller_end; |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 23 | extern unsigned long ftrace_plt; |
Heiko Carstens | dfd9f7a | 2009-06-12 10:26:44 +0200 | [diff] [blame] | 24 | |
| 25 | struct dyn_arch_ftrace { }; |
| 26 | |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 27 | #define MCOUNT_ADDR ((unsigned long)_mcount) |
| 28 | #define FTRACE_ADDR ((unsigned long)ftrace_caller) |
Heiko Carstens | dfd9f7a | 2009-06-12 10:26:44 +0200 | [diff] [blame] | 29 | |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 30 | #define KPROBE_ON_FTRACE_NOP 0 |
| 31 | #define KPROBE_ON_FTRACE_CALL 1 |
Heiko Carstens | 5d360a7 | 2008-12-25 13:38:56 +0100 | [diff] [blame] | 32 | |
Heiko Carstens | dfd9f7a | 2009-06-12 10:26:44 +0200 | [diff] [blame] | 33 | static inline unsigned long ftrace_call_adjust(unsigned long addr) |
| 34 | { |
Martin Schwidefsky | f296388 | 2011-05-10 10:10:43 +0200 | [diff] [blame] | 35 | return addr; |
Heiko Carstens | dfd9f7a | 2009-06-12 10:26:44 +0200 | [diff] [blame] | 36 | } |
| 37 | |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 38 | struct ftrace_insn { |
| 39 | u16 opc; |
| 40 | s32 disp; |
| 41 | } __packed; |
| 42 | |
| 43 | static inline void ftrace_generate_nop_insn(struct ftrace_insn *insn) |
| 44 | { |
| 45 | #ifdef CONFIG_FUNCTION_TRACER |
Heiko Carstens | e6d60b3 | 2015-01-09 13:08:28 +0100 | [diff] [blame] | 46 | #ifdef CC_USING_HOTPATCH |
| 47 | /* brcl 0,0 */ |
| 48 | insn->opc = 0xc004; |
| 49 | insn->disp = 0; |
| 50 | #else |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 51 | /* jg .+24 */ |
| 52 | insn->opc = 0xc0f4; |
| 53 | insn->disp = MCOUNT_INSN_SIZE / 2; |
| 54 | #endif |
Heiko Carstens | e6d60b3 | 2015-01-09 13:08:28 +0100 | [diff] [blame] | 55 | #endif |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static inline int is_ftrace_nop(struct ftrace_insn *insn) |
| 59 | { |
| 60 | #ifdef CONFIG_FUNCTION_TRACER |
Heiko Carstens | e6d60b3 | 2015-01-09 13:08:28 +0100 | [diff] [blame] | 61 | #ifdef CC_USING_HOTPATCH |
| 62 | if (insn->disp == 0) |
| 63 | return 1; |
| 64 | #else |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 65 | if (insn->disp == MCOUNT_INSN_SIZE / 2) |
| 66 | return 1; |
| 67 | #endif |
Heiko Carstens | e6d60b3 | 2015-01-09 13:08:28 +0100 | [diff] [blame] | 68 | #endif |
Heiko Carstens | c933146 | 2014-10-15 12:17:38 +0200 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static inline void ftrace_generate_call_insn(struct ftrace_insn *insn, |
| 73 | unsigned long ip) |
| 74 | { |
| 75 | #ifdef CONFIG_FUNCTION_TRACER |
| 76 | unsigned long target; |
| 77 | |
| 78 | /* brasl r0,ftrace_caller */ |
| 79 | target = is_module_addr((void *) ip) ? ftrace_plt : FTRACE_ADDR; |
| 80 | insn->opc = 0xc005; |
| 81 | insn->disp = (target - ip) / 2; |
| 82 | #endif |
| 83 | } |
| 84 | |
Heiko Carstens | dfd9f7a | 2009-06-12 10:26:44 +0200 | [diff] [blame] | 85 | #endif /* __ASSEMBLY__ */ |
Heiko Carstens | 5d360a7 | 2008-12-25 13:38:56 +0100 | [diff] [blame] | 86 | #endif /* _ASM_S390_FTRACE_H */ |