1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_FTRACE 3 #define _ASM_POWERPC_FTRACE 4 5 #include <asm/types.h> 6 7 #ifdef CONFIG_FUNCTION_TRACER 8 #define MCOUNT_ADDR ((unsigned long)(_mcount)) 9 #define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */ 10 11 #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 12 13 #ifndef __ASSEMBLY__ 14 extern void _mcount(void); 15 16 static inline unsigned long ftrace_call_adjust(unsigned long addr) 17 { 18 /* relocation of mcount call site is the same as the address */ 19 return addr; 20 } 21 22 unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip, 23 unsigned long sp); 24 25 struct dyn_arch_ftrace { 26 struct module *mod; 27 }; 28 29 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS 30 struct ftrace_regs { 31 struct pt_regs regs; 32 }; 33 34 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) 35 { 36 /* We clear regs.msr in ftrace_call */ 37 return fregs->regs.msr ? &fregs->regs : NULL; 38 } 39 40 static __always_inline void ftrace_instruction_pointer_set(struct ftrace_regs *fregs, 41 unsigned long ip) 42 { 43 regs_set_return_ip(&fregs->regs, ip); 44 } 45 46 struct ftrace_ops; 47 48 #define ftrace_graph_func ftrace_graph_func 49 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, 50 struct ftrace_ops *op, struct ftrace_regs *fregs); 51 #endif 52 #endif /* __ASSEMBLY__ */ 53 54 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 55 #define ARCH_SUPPORTS_FTRACE_OPS 1 56 #endif 57 #endif /* CONFIG_FUNCTION_TRACER */ 58 59 #ifndef __ASSEMBLY__ 60 #ifdef CONFIG_FTRACE_SYSCALLS 61 /* 62 * Some syscall entry functions on powerpc start with "ppc_" (fork and clone, 63 * for instance) or ppc32_/ppc64_. We should also match the sys_ variant with 64 * those. 65 */ 66 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME 67 #ifdef PPC64_ELF_ABI_v1 68 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) 69 { 70 /* We need to skip past the initial dot, and the __se_sys alias */ 71 return !strcmp(sym + 1, name) || 72 (!strncmp(sym, ".__se_sys", 9) && !strcmp(sym + 6, name)) || 73 (!strncmp(sym, ".ppc_", 5) && !strcmp(sym + 5, name + 4)) || 74 (!strncmp(sym, ".ppc32_", 7) && !strcmp(sym + 7, name + 4)) || 75 (!strncmp(sym, ".ppc64_", 7) && !strcmp(sym + 7, name + 4)); 76 } 77 #else 78 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) 79 { 80 return !strcmp(sym, name) || 81 (!strncmp(sym, "__se_sys", 8) && !strcmp(sym + 5, name)) || 82 (!strncmp(sym, "ppc_", 4) && !strcmp(sym + 4, name + 4)) || 83 (!strncmp(sym, "ppc32_", 6) && !strcmp(sym + 6, name + 4)) || 84 (!strncmp(sym, "ppc64_", 6) && !strcmp(sym + 6, name + 4)); 85 } 86 #endif /* PPC64_ELF_ABI_v1 */ 87 #endif /* CONFIG_FTRACE_SYSCALLS */ 88 89 #ifdef CONFIG_PPC64 90 #include <asm/paca.h> 91 92 static inline void this_cpu_disable_ftrace(void) 93 { 94 get_paca()->ftrace_enabled = 0; 95 } 96 97 static inline void this_cpu_enable_ftrace(void) 98 { 99 get_paca()->ftrace_enabled = 1; 100 } 101 102 /* Disable ftrace on this CPU if possible (may not be implemented) */ 103 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) 104 { 105 get_paca()->ftrace_enabled = ftrace_enabled; 106 } 107 108 static inline u8 this_cpu_get_ftrace_enabled(void) 109 { 110 return get_paca()->ftrace_enabled; 111 } 112 113 #else /* CONFIG_PPC64 */ 114 static inline void this_cpu_disable_ftrace(void) { } 115 static inline void this_cpu_enable_ftrace(void) { } 116 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { } 117 static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; } 118 #endif /* CONFIG_PPC64 */ 119 #endif /* !__ASSEMBLY__ */ 120 121 #endif /* _ASM_POWERPC_FTRACE */ 122