msm_cvp_debug.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __MSM_CVP_DEBUG__
  6. #define __MSM_CVP_DEBUG__
  7. #include <linux/debugfs.h>
  8. #include <linux/delay.h>
  9. #include "msm_cvp_internal.h"
  10. #include "msm_cvp_events.h"
  11. #ifndef CVP_DBG_LABEL
  12. #define CVP_DBG_LABEL "msm_cvp"
  13. #endif
  14. #define CVP_DBG_TAG CVP_DBG_LABEL ": %4s: "
  15. /* To enable messages OR these values and
  16. * echo the result to debugfs file.
  17. *
  18. * To enable all messages set debug_level = 0x101F
  19. */
  20. enum cvp_msg_prio {
  21. CVP_ERR = 0x000001,
  22. CVP_WARN = 0x000002,
  23. CVP_INFO = 0x000004,
  24. CVP_CMD = 0x000008,
  25. CVP_PROF = 0x000010,
  26. CVP_PKT = 0x000020,
  27. CVP_MEM = 0x000040,
  28. CVP_SYNX = 0x000080,
  29. CVP_CORE = 0x000100,
  30. CVP_REG = 0x000200,
  31. CVP_PWR = 0x000400,
  32. CVP_DSP = 0x000800,
  33. CVP_FW = 0x001000,
  34. CVP_SESS = 0x002000,
  35. CVP_HFI = 0x004000,
  36. CVP_VM = 0x008000,
  37. CVP_DBG = CVP_MEM | CVP_SYNX | CVP_CORE | CVP_REG | CVP_CMD |
  38. CVP_PWR | CVP_DSP | CVP_SESS | CVP_HFI | CVP_PKT | CVP_VM,
  39. };
  40. enum cvp_msg_out {
  41. CVP_OUT_PRINTK = 0,
  42. };
  43. enum msm_cvp_debugfs_event {
  44. MSM_CVP_DEBUGFS_EVENT_ETB,
  45. MSM_CVP_DEBUGFS_EVENT_EBD,
  46. MSM_CVP_DEBUGFS_EVENT_FTB,
  47. MSM_CVP_DEBUGFS_EVENT_FBD,
  48. };
  49. extern int msm_cvp_debug;
  50. extern int msm_cvp_debug_out;
  51. extern int msm_cvp_fw_debug;
  52. extern int msm_cvp_fw_debug_mode;
  53. extern int msm_cvp_fw_low_power_mode;
  54. extern bool msm_cvp_fw_coverage;
  55. extern bool msm_cvp_auto_pil;
  56. extern bool msm_cvp_thermal_mitigation_disabled;
  57. extern bool msm_cvp_cacheop_disabled;
  58. extern int msm_cvp_clock_voting;
  59. extern bool msm_cvp_syscache_disable;
  60. extern bool msm_cvp_dsp_disable;
  61. extern bool msm_cvp_mmrm_enabled;
  62. extern bool msm_cvp_dcvs_disable;
  63. extern int msm_cvp_minidump_enable;
  64. extern bool cvp_kernel_fence_enabled;
  65. #define dprintk(__level, __fmt, arg...) \
  66. do { \
  67. if (msm_cvp_debug & __level) { \
  68. if (msm_cvp_debug_out == CVP_OUT_PRINTK) { \
  69. pr_info(CVP_DBG_TAG __fmt, \
  70. get_debug_level_str(__level), \
  71. ## arg); \
  72. } \
  73. } \
  74. } while (0)
  75. /* dprintk_rl is designed for printing frequent recurring errors */
  76. #define dprintk_rl(__level, __fmt, arg...) \
  77. do { \
  78. if (msm_cvp_debug & __level) { \
  79. if (msm_cvp_debug_out == CVP_OUT_PRINTK) { \
  80. pr_info_ratelimited(CVP_DBG_TAG __fmt, \
  81. get_debug_level_str(__level), \
  82. ## arg); \
  83. } \
  84. } \
  85. } while (0)
  86. #define MSM_CVP_ERROR(value) \
  87. do { if (value) \
  88. dprintk(CVP_ERR, "BugOn"); \
  89. WARN_ON(value); \
  90. } while (0)
  91. struct dentry *msm_cvp_debugfs_init_drv(void);
  92. struct dentry *msm_cvp_debugfs_init_core(struct msm_cvp_core *core,
  93. struct dentry *parent);
  94. struct dentry *msm_cvp_debugfs_init_inst(struct msm_cvp_inst *inst,
  95. struct dentry *parent);
  96. void msm_cvp_debugfs_deinit_inst(struct msm_cvp_inst *inst);
  97. static inline char *get_debug_level_str(int level)
  98. {
  99. switch (level) {
  100. case CVP_ERR:
  101. return "err";
  102. case CVP_WARN:
  103. return "warn";
  104. case CVP_INFO:
  105. return "info";
  106. case CVP_CMD:
  107. return "cmd";
  108. case CVP_DBG:
  109. return "dbg";
  110. case CVP_PROF:
  111. return "prof";
  112. case CVP_PKT:
  113. return "pkt";
  114. case CVP_MEM:
  115. return "mem";
  116. case CVP_SYNX:
  117. return "synx";
  118. case CVP_CORE:
  119. return "core";
  120. case CVP_REG:
  121. return "reg";
  122. case CVP_PWR:
  123. return "pwr";
  124. case CVP_DSP:
  125. return "dsp";
  126. case CVP_FW:
  127. return "fw";
  128. case CVP_SESS:
  129. return "sess";
  130. case CVP_HFI:
  131. return "hfi";
  132. case CVP_VM:
  133. return "vm";
  134. default:
  135. return "???";
  136. }
  137. }
  138. static inline void show_stats(struct msm_cvp_inst *i)
  139. {
  140. int x;
  141. for (x = 0; x < MAX_PROFILING_POINTS; x++) {
  142. if (i->debug.pdata[x].name[0] &&
  143. (msm_cvp_debug & CVP_PROF)) {
  144. if (i->debug.samples) {
  145. dprintk(CVP_PROF, "%s averaged %d ms/sample\n",
  146. i->debug.pdata[x].name,
  147. i->debug.pdata[x].cumulative /
  148. i->debug.samples);
  149. }
  150. dprintk(CVP_PROF, "%s Samples: %d\n",
  151. i->debug.pdata[x].name,
  152. i->debug.samples);
  153. }
  154. }
  155. }
  156. static inline void msm_cvp_res_handle_fatal_hw_error(
  157. struct msm_cvp_platform_resources *resources,
  158. bool enable_fatal)
  159. {
  160. enable_fatal &= resources->debug_timeout;
  161. MSM_CVP_ERROR(enable_fatal);
  162. }
  163. static inline void msm_cvp_handle_hw_error(struct msm_cvp_core *core)
  164. {
  165. bool enable_fatal = true;
  166. /*
  167. * In current implementation user-initiated SSR triggers
  168. * a fatal error from hardware. However, there is no way
  169. * to know if fatal error is due to SSR or not. Handle
  170. * user SSR as non-fatal.
  171. */
  172. if (core->trigger_ssr) {
  173. core->trigger_ssr = false;
  174. enable_fatal = false;
  175. }
  176. /* CVP driver can decide FATAL handling of HW errors
  177. * based on multiple factors. This condition check will
  178. * be enhanced later.
  179. */
  180. msm_cvp_res_handle_fatal_hw_error(&core->resources, enable_fatal);
  181. }
  182. #endif