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