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 #ifdef CONFIG_FUNCTION_TRACER 14 15 #define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */ 16 17 #ifndef __ASSEMBLY__ 18 19 #ifndef CONFIG_DYNAMIC_FTRACE 20 21 #define mcount _mcount 22 extern void _mcount(void); 23 extern void prepare_ftrace_return(unsigned long self_addr, unsigned long callsite_sp, unsigned long old); 24 25 #else 26 27 struct dyn_ftrace; 28 struct dyn_arch_ftrace { }; 29 30 #define ARCH_SUPPORTS_FTRACE_OPS 1 31 32 #define ftrace_init_nop ftrace_init_nop 33 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); 34 35 static inline unsigned long ftrace_call_adjust(unsigned long addr) 36 { 37 return addr; 38 } 39 40 void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent); 41 42 #endif /* CONFIG_DYNAMIC_FTRACE */ 43 44 #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS 45 struct ftrace_ops; 46 47 #include <linux/ftrace_regs.h> 48 49 static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) 50 { 51 return &arch_ftrace_regs(fregs)->regs; 52 } 53 54 static __always_inline void 55 ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, unsigned long ip) 56 { 57 instruction_pointer_set(&arch_ftrace_regs(fregs)->regs, ip); 58 } 59 60 #define ftrace_graph_func ftrace_graph_func 61 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, 62 struct ftrace_ops *op, struct ftrace_regs *fregs); 63 64 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS 65 static inline void 66 __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr) 67 { 68 regs->regs[13] = addr; /* t1 */ 69 } 70 71 #define arch_ftrace_set_direct_caller(fregs, addr) \ 72 __arch_ftrace_set_direct_caller(&arch_ftrace_regs(fregs)->regs, addr) 73 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ 74 75 #endif 76 77 #endif /* __ASSEMBLY__ */ 78 79 #endif /* CONFIG_FUNCTION_TRACER */ 80 81 #ifndef __ASSEMBLY__ 82 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 83 struct fgraph_ret_regs { 84 /* a0 - a1 */ 85 unsigned long regs[2]; 86 87 unsigned long fp; 88 unsigned long __unused; 89 }; 90 91 static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs) 92 { 93 return ret_regs->regs[0]; 94 } 95 96 static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs) 97 { 98 return ret_regs->fp; 99 } 100 #endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */ 101 #endif 102 103 #endif /* _ASM_LOONGARCH_FTRACE_H */ 104