msm_cvp_debug.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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_PROF = 0x000010,
  25. CVP_PKT = 0x000020,
  26. CVP_MEM = 0x000040,
  27. CVP_SYNX = 0x000080,
  28. CVP_CORE = 0x000100,
  29. CVP_REG = 0x000200,
  30. CVP_PWR = 0x000400,
  31. CVP_DSP = 0x000800,
  32. CVP_FW = 0x001000,
  33. CVP_SESS = 0x002000,
  34. CVP_HFI = 0x004000,
  35. CVP_VM = 0x008000,
  36. CVP_DBG = CVP_MEM | CVP_SYNX | CVP_CORE | CVP_REG |
  37. CVP_PWR | CVP_DSP | CVP_SESS | CVP_HFI | CVP_PKT | CVP_VM,
  38. };
  39. enum cvp_msg_out {
  40. CVP_OUT_PRINTK = 0,
  41. };
  42. enum msm_cvp_debugfs_event {
  43. MSM_CVP_DEBUGFS_EVENT_ETB,
  44. MSM_CVP_DEBUGFS_EVENT_EBD,
  45. MSM_CVP_DEBUGFS_EVENT_FTB,
  46. MSM_CVP_DEBUGFS_EVENT_FBD,
  47. };
  48. extern int msm_cvp_debug;
  49. extern int msm_cvp_debug_out;
  50. extern int msm_cvp_fw_debug;
  51. extern int msm_cvp_fw_debug_mode;
  52. extern int msm_cvp_fw_low_power_mode;
  53. extern bool msm_cvp_fw_coverage;
  54. extern bool msm_cvp_auto_pil;
  55. extern bool msm_cvp_thermal_mitigation_disabled;
  56. extern bool msm_cvp_cacheop_disabled;
  57. extern int msm_cvp_clock_voting;
  58. extern bool msm_cvp_syscache_disable;
  59. extern bool msm_cvp_dsp_disable;
  60. extern bool msm_cvp_mmrm_enabled;
  61. extern bool msm_cvp_dcvs_disable;
  62. extern int msm_cvp_minidump_enable;
  63. /* If bit 31 is set: disabling ratelimit use of pr_info */
  64. #define RATELIMIT_DISABLE_MASK 0x80000000
  65. #define dprintk(__level, __fmt, arg...) \
  66. do { \
  67. if ((msm_cvp_debug & __level) \
  68. && (msm_cvp_debug_out == CVP_OUT_PRINTK)) { \
  69. if (msm_cvp_debug & RATELIMIT_DISABLE_MASK) { \
  70. pr_info(CVP_DBG_TAG __fmt, \
  71. get_debug_level_str(__level), \
  72. ## arg); \
  73. } else { \
  74. pr_info_ratelimited(CVP_DBG_TAG __fmt, \
  75. get_debug_level_str(__level), \
  76. ## arg); \
  77. } \
  78. } \
  79. } while (0)
  80. #define MSM_CVP_ERROR(value) \
  81. do { if (value) \
  82. dprintk(CVP_ERR, "BugOn"); \
  83. WARN_ON(value); \
  84. } while (0)
  85. struct dentry *msm_cvp_debugfs_init_drv(void);
  86. struct dentry *msm_cvp_debugfs_init_core(struct msm_cvp_core *core,
  87. struct dentry *parent);
  88. struct dentry *msm_cvp_debugfs_init_inst(struct msm_cvp_inst *inst,
  89. struct dentry *parent);
  90. void msm_cvp_debugfs_deinit_inst(struct msm_cvp_inst *inst);
  91. static inline char *get_debug_level_str(int level)
  92. {
  93. switch (level) {
  94. case CVP_ERR:
  95. return "err";
  96. case CVP_WARN:
  97. return "warn";
  98. case CVP_INFO:
  99. return "info";
  100. case CVP_DBG:
  101. return "dbg";
  102. case CVP_PROF:
  103. return "prof";
  104. case CVP_PKT:
  105. return "pkt";
  106. case CVP_MEM:
  107. return "mem";
  108. case CVP_SYNX:
  109. return "synx";
  110. case CVP_CORE:
  111. return "core";
  112. case CVP_REG:
  113. return "reg";
  114. case CVP_PWR:
  115. return "pwr";
  116. case CVP_DSP:
  117. return "dsp";
  118. case CVP_FW:
  119. return "fw";
  120. case CVP_SESS:
  121. return "sess";
  122. case CVP_HFI:
  123. return "hfi";
  124. default:
  125. return "???";
  126. }
  127. }
  128. static inline void show_stats(struct msm_cvp_inst *i)
  129. {
  130. int x;
  131. for (x = 0; x < MAX_PROFILING_POINTS; x++) {
  132. if (i->debug.pdata[x].name[0] &&
  133. (msm_cvp_debug & CVP_PROF)) {
  134. if (i->debug.samples) {
  135. dprintk(CVP_PROF, "%s averaged %d ms/sample\n",
  136. i->debug.pdata[x].name,
  137. i->debug.pdata[x].cumulative /
  138. i->debug.samples);
  139. }
  140. dprintk(CVP_PROF, "%s Samples: %d\n",
  141. i->debug.pdata[x].name,
  142. i->debug.samples);
  143. }
  144. }
  145. }
  146. static inline void msm_cvp_res_handle_fatal_hw_error(
  147. struct msm_cvp_platform_resources *resources,
  148. bool enable_fatal)
  149. {
  150. enable_fatal &= resources->debug_timeout;
  151. MSM_CVP_ERROR(enable_fatal);
  152. }
  153. static inline void msm_cvp_handle_hw_error(struct msm_cvp_core *core)
  154. {
  155. bool enable_fatal = true;
  156. /*
  157. * In current implementation user-initiated SSR triggers
  158. * a fatal error from hardware. However, there is no way
  159. * to know if fatal error is due to SSR or not. Handle
  160. * user SSR as non-fatal.
  161. */
  162. if (core->trigger_ssr) {
  163. core->trigger_ssr = false;
  164. enable_fatal = false;
  165. }
  166. /* CVP driver can decide FATAL handling of HW errors
  167. * based on multiple factors. This condition check will
  168. * be enhanced later.
  169. */
  170. msm_cvp_res_handle_fatal_hw_error(&core->resources, enable_fatal);
  171. }
  172. #endif