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