xref: /linux/arch/powerpc/include/asm/ftrace.h (revision 2504e5b9827f7fc76ed0e4593adc852ac7a19851)
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 struct dyn_arch_ftrace {
23 	struct module *mod;
24 };
25 
26 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
27 struct ftrace_regs {
28 	struct pt_regs regs;
29 };
30 
31 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
32 {
33 	return &fregs->regs;
34 }
35 
36 static __always_inline void ftrace_instruction_pointer_set(struct ftrace_regs *fregs,
37 							   unsigned long ip)
38 {
39 	regs_set_return_ip(&fregs->regs, ip);
40 }
41 
42 struct ftrace_ops;
43 
44 #define ftrace_graph_func ftrace_graph_func
45 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
46 		       struct ftrace_ops *op, struct ftrace_regs *fregs);
47 #endif
48 #endif /* __ASSEMBLY__ */
49 
50 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
51 #define ARCH_SUPPORTS_FTRACE_OPS 1
52 #endif
53 #endif /* CONFIG_FUNCTION_TRACER */
54 
55 #ifndef __ASSEMBLY__
56 #ifdef CONFIG_FTRACE_SYSCALLS
57 /*
58  * Some syscall entry functions on powerpc start with "ppc_" (fork and clone,
59  * for instance) or ppc32_/ppc64_. We should also match the sys_ variant with
60  * those.
61  */
62 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
63 #ifdef PPC64_ELF_ABI_v1
64 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
65 {
66 	/* We need to skip past the initial dot, and the __se_sys alias */
67 	return !strcmp(sym + 1, name) ||
68 		(!strncmp(sym, ".__se_sys", 9) && !strcmp(sym + 6, name)) ||
69 		(!strncmp(sym, ".ppc_", 5) && !strcmp(sym + 5, name + 4)) ||
70 		(!strncmp(sym, ".ppc32_", 7) && !strcmp(sym + 7, name + 4)) ||
71 		(!strncmp(sym, ".ppc64_", 7) && !strcmp(sym + 7, name + 4));
72 }
73 #else
74 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
75 {
76 	return !strcmp(sym, name) ||
77 		(!strncmp(sym, "__se_sys", 8) && !strcmp(sym + 5, name)) ||
78 		(!strncmp(sym, "ppc_", 4) && !strcmp(sym + 4, name + 4)) ||
79 		(!strncmp(sym, "ppc32_", 6) && !strcmp(sym + 6, name + 4)) ||
80 		(!strncmp(sym, "ppc64_", 6) && !strcmp(sym + 6, name + 4));
81 }
82 #endif /* PPC64_ELF_ABI_v1 */
83 #endif /* CONFIG_FTRACE_SYSCALLS */
84 
85 #ifdef CONFIG_PPC64
86 #include <asm/paca.h>
87 
88 static inline void this_cpu_disable_ftrace(void)
89 {
90 	get_paca()->ftrace_enabled = 0;
91 }
92 
93 static inline void this_cpu_enable_ftrace(void)
94 {
95 	get_paca()->ftrace_enabled = 1;
96 }
97 
98 /* Disable ftrace on this CPU if possible (may not be implemented) */
99 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled)
100 {
101 	get_paca()->ftrace_enabled = ftrace_enabled;
102 }
103 
104 static inline u8 this_cpu_get_ftrace_enabled(void)
105 {
106 	return get_paca()->ftrace_enabled;
107 }
108 
109 #else /* CONFIG_PPC64 */
110 static inline void this_cpu_disable_ftrace(void) { }
111 static inline void this_cpu_enable_ftrace(void) { }
112 static inline void this_cpu_set_ftrace_enabled(u8 ftrace_enabled) { }
113 static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; }
114 #endif /* CONFIG_PPC64 */
115 #endif /* !__ASSEMBLY__ */
116 
117 #endif /* _ASM_POWERPC_FTRACE */
118