ftrace.h 2.2 KB

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