1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2022 Loongson Technology Corporation Limited
4  */
5 
6 #ifndef _ASM_LOONGARCH_FTRACE_H
7 #define _ASM_LOONGARCH_FTRACE_H
8 
9 #define FTRACE_PLT_IDX		0
10 #define FTRACE_REGS_PLT_IDX	1
11 #define NR_FTRACE_PLTS		2
12 
13 #define GRAPH_FAKE_OFFSET (sizeof(struct pt_regs) - offsetof(struct pt_regs, regs[1]))
14 
15 #ifdef CONFIG_FUNCTION_TRACER
16 
17 #define MCOUNT_INSN_SIZE 4		/* sizeof mcount call */
18 
19 #ifndef __ASSEMBLY__
20 
21 #ifndef CONFIG_DYNAMIC_FTRACE
22 
23 #define mcount _mcount
24 extern void _mcount(void);
25 extern void prepare_ftrace_return(unsigned long self_addr, unsigned long callsite_sp, unsigned long old);
26 
27 #else
28 
29 struct dyn_ftrace;
30 struct dyn_arch_ftrace { };
31 
32 #define ARCH_SUPPORTS_FTRACE_OPS 1
33 #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
34 
35 #define ftrace_init_nop ftrace_init_nop
36 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
37 
38 static inline unsigned long ftrace_call_adjust(unsigned long addr)
39 {
40 	return addr;
41 }
42 
43 void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent);
44 
45 #endif /* CONFIG_DYNAMIC_FTRACE */
46 
47 #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
48 struct ftrace_ops;
49 
50 struct ftrace_regs {
51 	struct pt_regs regs;
52 };
53 
54 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
55 {
56 	return &fregs->regs;
57 }
58 
59 #define ftrace_graph_func ftrace_graph_func
60 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
61 		       struct ftrace_ops *op, struct ftrace_regs *fregs);
62 #endif
63 
64 #endif /* __ASSEMBLY__ */
65 
66 #endif /* CONFIG_FUNCTION_TRACER */
67 
68 #endif /* _ASM_LOONGARCH_FTRACE_H */
69