msm_vidc_debug.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021,, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __MSM_VIDC_DEBUG__
  7. #define __MSM_VIDC_DEBUG__
  8. #include <linux/types.h>
  9. #include <linux/errno.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/delay.h>
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #ifndef VIDC_DBG_LABEL
  15. #define VIDC_DBG_LABEL "msm_vidc"
  16. #endif
  17. /* Allow only 6 prints/sec */
  18. #define VIDC_DBG_SESSION_RATELIMIT_INTERVAL (1 * HZ)
  19. #define VIDC_DBG_SESSION_RATELIMIT_BURST 6
  20. #define VIDC_DBG_TAG_INST VIDC_DBG_LABEL ": %4s: %s: "
  21. #define VIDC_DBG_TAG_CORE VIDC_DBG_LABEL ": %4s: %08x: %s: "
  22. #define FW_DBG_TAG VIDC_DBG_LABEL ": %6s: "
  23. #define DEFAULT_SID ((u32)-1)
  24. #ifndef MSM_VIDC_EMPTY_BRACE
  25. #define MSM_VIDC_EMPTY_BRACE {},
  26. #endif
  27. extern unsigned int msm_vidc_debug;
  28. extern bool msm_vidc_lossless_encode;
  29. extern bool msm_vidc_syscache_disable;
  30. extern int msm_vidc_clock_voting;
  31. extern int msm_vidc_ddr_bw;
  32. extern int msm_vidc_llc_bw;
  33. extern bool msm_vidc_fw_dump;
  34. extern unsigned int msm_vidc_enable_bugon;
  35. extern bool msm_vidc_disable_synx_fence;
  36. /* do not modify the log message as it is used in test scripts */
  37. #define FMT_STRING_SET_CTRL \
  38. "%s: state %s, name %s, id 0x%x value %d\n"
  39. #define FMT_STRING_STATE_CHANGE \
  40. "%s: state changed to %s from %s\n"
  41. #define FMT_STRING_MSG_SFR \
  42. "SFR Message from FW: %s\n"
  43. #define FMT_STRING_FAULT_HANDLER \
  44. "%s: faulting address: %lx\n"
  45. #define FMT_STRING_SET_CAP \
  46. "set cap: name: %24s, cap value: %#10x, hfi: %#10llx\n"
  47. /* To enable messages OR these values and
  48. * echo the result to debugfs file.
  49. *
  50. * To enable all messages set msm_vidc_debug = 0x101F
  51. */
  52. enum vidc_msg_prio {
  53. VIDC_ERR = 0x00000001,
  54. VIDC_HIGH = 0x00000002,
  55. VIDC_LOW = 0x00000004,
  56. VIDC_PERF = 0x00000008,
  57. VIDC_PKT = 0x00000010,
  58. VIDC_BUS = 0x00000020,
  59. VIDC_STAT = 0x00000040,
  60. VIDC_ENCODER = 0x00000100,
  61. VIDC_DECODER = 0x00000200,
  62. VIDC_PRINTK = 0x00001000,
  63. VIDC_FTRACE = 0x00002000,
  64. FW_LOW = 0x00010000,
  65. FW_MED = 0x00020000,
  66. FW_HIGH = 0x00040000,
  67. FW_ERROR = 0x00080000,
  68. FW_FATAL = 0x00100000,
  69. FW_PERF = 0x00200000,
  70. FW_PRINTK = 0x10000000,
  71. FW_FTRACE = 0x20000000,
  72. };
  73. #define DRV_LOG (VIDC_ERR | VIDC_PRINTK)
  74. #define DRV_LOGSHIFT (0)
  75. #define DRV_LOGMASK (0x0FFF)
  76. #define FW_LOG (FW_ERROR | FW_FATAL | FW_PRINTK)
  77. #define FW_LOGSHIFT (16)
  78. #define FW_LOGMASK (0x0FFF0000)
  79. #define dprintk_inst(__level, __level_str, inst, __fmt, ...) \
  80. do { \
  81. if (inst && (msm_vidc_debug & (__level))) { \
  82. pr_info(VIDC_DBG_TAG_INST __fmt, \
  83. __level_str, \
  84. inst->debug_str, \
  85. ##__VA_ARGS__); \
  86. } \
  87. } while (0)
  88. #define i_vpr_e(inst, __fmt, ...) dprintk_inst(VIDC_ERR, "err ", inst, __fmt, ##__VA_ARGS__)
  89. #define i_vpr_i(inst, __fmt, ...) dprintk_inst(VIDC_HIGH, "high", inst, __fmt, ##__VA_ARGS__)
  90. #define i_vpr_h(inst, __fmt, ...) dprintk_inst(VIDC_HIGH, "high", inst, __fmt, ##__VA_ARGS__)
  91. #define i_vpr_l(inst, __fmt, ...) dprintk_inst(VIDC_LOW, "low ", inst, __fmt, ##__VA_ARGS__)
  92. #define i_vpr_p(inst, __fmt, ...) dprintk_inst(VIDC_PERF, "perf", inst, __fmt, ##__VA_ARGS__)
  93. #define i_vpr_t(inst, __fmt, ...) dprintk_inst(VIDC_PKT, "pkt ", inst, __fmt, ##__VA_ARGS__)
  94. #define i_vpr_b(inst, __fmt, ...) dprintk_inst(VIDC_BUS, "bus ", inst, __fmt, ##__VA_ARGS__)
  95. #define i_vpr_s(inst, __fmt, ...) dprintk_inst(VIDC_STAT, "stat", inst, __fmt, ##__VA_ARGS__)
  96. #define i_vpr_hp(inst, __fmt, ...) \
  97. dprintk_inst(VIDC_HIGH | VIDC_PERF, "high", inst, __fmt, ##__VA_ARGS__)
  98. #define i_vpr_hs(inst, __fmt, ...) \
  99. dprintk_inst(VIDC_HIGH | VIDC_STAT, "high", inst, __fmt, ##__VA_ARGS__)
  100. #define dprintk_core(__level, __level_str, __fmt, ...) \
  101. do { \
  102. if (msm_vidc_debug & (__level)) { \
  103. pr_info(VIDC_DBG_TAG_CORE __fmt, \
  104. __level_str, \
  105. DEFAULT_SID, \
  106. "codec", \
  107. ##__VA_ARGS__); \
  108. } \
  109. } while (0)
  110. #define d_vpr_e(__fmt, ...) dprintk_core(VIDC_ERR, "err ", __fmt, ##__VA_ARGS__)
  111. #define d_vpr_h(__fmt, ...) dprintk_core(VIDC_HIGH, "high", __fmt, ##__VA_ARGS__)
  112. #define d_vpr_l(__fmt, ...) dprintk_core(VIDC_LOW, "low ", __fmt, ##__VA_ARGS__)
  113. #define d_vpr_p(__fmt, ...) dprintk_core(VIDC_PERF, "perf", __fmt, ##__VA_ARGS__)
  114. #define d_vpr_t(__fmt, ...) dprintk_core(VIDC_PKT, "pkt ", __fmt, ##__VA_ARGS__)
  115. #define d_vpr_b(__fmt, ...) dprintk_core(VIDC_BUS, "bus ", __fmt, ##__VA_ARGS__)
  116. #define d_vpr_s(__fmt, ...) dprintk_core(VIDC_STAT, "stat", __fmt, ##__VA_ARGS__)
  117. #define d_vpr_hs(__fmt, ...) \
  118. dprintk_core(VIDC_HIGH | VIDC_STAT, "high", __fmt, ##__VA_ARGS__)
  119. #define dprintk_ratelimit(__level, __level_str, __fmt, ...) \
  120. do { \
  121. if (msm_vidc_check_ratelimit()) { \
  122. dprintk_core(__level, __level_str, __fmt, ##__VA_ARGS__); \
  123. } \
  124. } while (0)
  125. #define dprintk_firmware(__level, __fmt, ...) \
  126. do { \
  127. if (__level & FW_PRINTK) { \
  128. pr_info(FW_DBG_TAG __fmt, \
  129. "fw", \
  130. ##__VA_ARGS__); \
  131. } \
  132. } while (0)
  133. #define MSM_VIDC_FATAL(value) \
  134. do { \
  135. if (value) { \
  136. d_vpr_e("bug on\n"); \
  137. BUG_ON(value); \
  138. } \
  139. } while (0)
  140. enum msm_vidc_debugfs_event {
  141. MSM_VIDC_DEBUGFS_EVENT_ETB,
  142. MSM_VIDC_DEBUGFS_EVENT_EBD,
  143. MSM_VIDC_DEBUGFS_EVENT_FTB,
  144. MSM_VIDC_DEBUGFS_EVENT_FBD,
  145. };
  146. enum msm_vidc_bug_on_error {
  147. MSM_VIDC_BUG_ON_FATAL = BIT(0),
  148. MSM_VIDC_BUG_ON_NOC = BIT(1),
  149. MSM_VIDC_BUG_ON_WD_TIMEOUT = BIT(2),
  150. };
  151. struct dentry *msm_vidc_debugfs_init_drv(void);
  152. struct dentry *msm_vidc_debugfs_init_core(void *core);
  153. struct dentry *msm_vidc_debugfs_init_inst(void *inst,
  154. struct dentry *parent);
  155. void msm_vidc_debugfs_deinit_inst(void *inst);
  156. void msm_vidc_debugfs_update(void *inst,
  157. enum msm_vidc_debugfs_event e);
  158. int msm_vidc_check_ratelimit(void);
  159. void msm_vidc_show_stats(void *inst);
  160. #endif