cam_debug_util.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_DEBUG_UTIL_H_
  6. #define _CAM_DEBUG_UTIL_H_
  7. #include <linux/platform_device.h>
  8. /* Module IDs used for debug logging */
  9. #define CAM_CDM BIT_ULL(0)
  10. #define CAM_CORE BIT_ULL(1)
  11. #define CAM_CPAS BIT_ULL(2)
  12. #define CAM_ISP BIT_ULL(3)
  13. #define CAM_CRM BIT_ULL(4)
  14. #define CAM_SENSOR BIT_ULL(5)
  15. #define CAM_SMMU BIT_ULL(6)
  16. #define CAM_SYNC BIT_ULL(7)
  17. #define CAM_ICP BIT_ULL(8)
  18. #define CAM_JPEG BIT_ULL(9)
  19. #define CAM_FD BIT_ULL(10)
  20. #define CAM_LRME BIT_ULL(11)
  21. #define CAM_FLASH BIT_ULL(12)
  22. #define CAM_ACTUATOR BIT_ULL(13)
  23. #define CAM_CCI BIT_ULL(14)
  24. #define CAM_CSIPHY BIT_ULL(15)
  25. #define CAM_EEPROM BIT_ULL(16)
  26. #define CAM_UTIL BIT_ULL(17)
  27. #define CAM_HFI BIT_ULL(18)
  28. #define CAM_CTXT BIT_ULL(19)
  29. #define CAM_OIS BIT_ULL(20)
  30. #define CAM_RES BIT_ULL(21)
  31. #define CAM_MEM BIT_ULL(22)
  32. #define CAM_IRQ_CTRL BIT_ULL(23)
  33. #define CAM_REQ BIT_ULL(24)
  34. #define CAM_PERF BIT_ULL(25)
  35. #define CAM_CUSTOM BIT_ULL(26)
  36. #define CAM_PRESIL BIT_ULL(27)
  37. #define CAM_OPE BIT_ULL(28)
  38. #define CAM_IO_ACCESS BIT_ULL(29)
  39. #define CAM_SFE BIT_ULL(30)
  40. #define CAM_CRE BIT_ULL(31)
  41. #define CAM_PRESIL_CORE BIT_ULL(32)
  42. /* Log level types */
  43. #define CAM_TYPE_TRACE (1 << 0)
  44. #define CAM_TYPE_ERR (1 << 1)
  45. #define CAM_TYPE_WARN (1 << 2)
  46. #define CAM_TYPE_INFO (1 << 3)
  47. #define CAM_TYPE_DBG (1 << 4)
  48. #define STR_BUFFER_MAX_LENGTH 512
  49. /*
  50. * enum cam_debug_priority - Priority of debug log (0 = Lowest)
  51. */
  52. enum cam_debug_priority {
  53. CAM_DBG_PRIORITY_0,
  54. CAM_DBG_PRIORITY_1,
  55. CAM_DBG_PRIORITY_2,
  56. };
  57. /**
  58. * struct cam_cpas_debug_settings - Sysfs debug settings for cpas driver
  59. */
  60. struct cam_cpas_debug_settings {
  61. uint64_t mnoc_hf_0_ab_bw;
  62. uint64_t mnoc_hf_0_ib_bw;
  63. uint64_t mnoc_hf_1_ab_bw;
  64. uint64_t mnoc_hf_1_ib_bw;
  65. uint64_t mnoc_sf_0_ab_bw;
  66. uint64_t mnoc_sf_0_ib_bw;
  67. uint64_t mnoc_sf_1_ab_bw;
  68. uint64_t mnoc_sf_1_ib_bw;
  69. uint64_t mnoc_sf_icp_ab_bw;
  70. uint64_t mnoc_sf_icp_ib_bw;
  71. uint64_t camnoc_bw;
  72. };
  73. /**
  74. * struct camera_debug_settings - Sysfs debug settings for camera
  75. *
  76. * @cpas_settings: Debug settings for cpas driver.
  77. */
  78. struct camera_debug_settings {
  79. struct cam_cpas_debug_settings cpas_settings;
  80. };
  81. /*
  82. * cam_debug_log()
  83. *
  84. * @brief : Get the Module name from module ID and print
  85. * respective debug logs
  86. *
  87. * @module_id : Respective Module ID which is calling this function
  88. * @priority : Priority of the debug log
  89. * @func : Function which is calling to print logs
  90. * @line : Line number associated with the function which is calling
  91. * to print log
  92. * @fmt : Formatted string which needs to be print in the log
  93. *
  94. */
  95. void cam_debug_log(unsigned long long module_id, unsigned int priority,
  96. const char *func, const int line, const char *fmt, ...);
  97. /*
  98. * cam_debug_trace()
  99. *
  100. * @brief : Get the Module name from module ID and print
  101. * respective debug logs in ftrace
  102. *
  103. * @tag : Tag indicating whether TRACE, ERR, WARN, INFO, DBG
  104. * @module_id : Respective Module ID which is calling this function
  105. * @func : Function which is calling to print logs
  106. * @line : Line number associated with the function which is calling
  107. * to print log
  108. * @fmt : Formatted string which needs to be print in the log
  109. *
  110. */
  111. void cam_debug_trace(unsigned int tag, unsigned long long module_id,
  112. const char *func, const int line, const char *fmt, ...);
  113. /*
  114. * cam_get_module_name()
  115. *
  116. * @brief : Get the module name from module ID
  117. *
  118. * @module_id : Module ID which is using this function
  119. */
  120. const char *cam_get_module_name(unsigned long long module_id);
  121. /*
  122. * CAM_TRACE
  123. * @brief : This Macro will print logs in ftrace
  124. *
  125. * @__module : Respective module id which is been calling this Macro
  126. * @fmt : Formatted string which needs to be print in log
  127. * @args : Arguments which needs to be print in log
  128. */
  129. #define CAM_TRACE(__module, fmt, args...) \
  130. ({ \
  131. cam_debug_trace(CAM_TYPE_TRACE, __module, __func__, __LINE__, \
  132. fmt, ##args); \
  133. })
  134. /*
  135. * CAM_ERR
  136. * @brief : This Macro will print error logs
  137. *
  138. * @__module : Respective module id which is been calling this Macro
  139. * @fmt : Formatted string which needs to be print in log
  140. * @args : Arguments which needs to be print in log
  141. */
  142. #define CAM_ERR(__module, fmt, args...) \
  143. ({ \
  144. pr_info("CAM_ERR: %s: %s: %d " fmt "\n", \
  145. cam_get_module_name(__module), __func__, \
  146. __LINE__, ##args); \
  147. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  148. fmt, ##args); \
  149. })
  150. /*
  151. * CAM_WARN
  152. * @brief : This Macro will print warning logs
  153. *
  154. * @__module : Respective module id which is been calling this Macro
  155. * @fmt : Formatted string which needs to be print in log
  156. * @args : Arguments which needs to be print in log
  157. */
  158. #define CAM_WARN(__module, fmt, args...) \
  159. ({ \
  160. pr_info("CAM_WARN: %s: %s: %d " fmt "\n", \
  161. cam_get_module_name(__module), __func__, \
  162. __LINE__, ##args); \
  163. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  164. fmt, ##args); \
  165. })
  166. /*
  167. * CAM_INFO
  168. * @brief : This Macro will print Information logs
  169. *
  170. * @__module : Respective module id which is been calling this Macro
  171. * @fmt : Formatted string which needs to be print in log
  172. * @args : Arguments which needs to be print in log
  173. */
  174. #define CAM_INFO(__module, fmt, args...) \
  175. ({ \
  176. pr_info("CAM_INFO: %s: %s: %d " fmt "\n", \
  177. cam_get_module_name(__module), __func__, \
  178. __LINE__, ##args); \
  179. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  180. fmt, ##args); \
  181. })
  182. /*
  183. * CAM_INFO_RATE_LIMIT
  184. * @brief : This Macro will print info logs with ratelimit
  185. *
  186. * @__module : Respective module id which is been calling this Macro
  187. * @fmt : Formatted string which needs to be print in log
  188. * @args : Arguments which needs to be print in log
  189. */
  190. #define CAM_INFO_RATE_LIMIT(__module, fmt, args...) \
  191. ({ \
  192. pr_info_ratelimited("CAM_INFO: %s: %s: %d " fmt "\n", \
  193. cam_get_module_name(__module), __func__, \
  194. __LINE__, ##args); \
  195. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  196. fmt, ##args); \
  197. })
  198. /*
  199. * CAM_DBG
  200. * @brief : This Macro will print debug logs when enabled using GROUP and
  201. * if its priority is greater than the priority parameter
  202. *
  203. * @__module : Respective module id which is been calling this Macro
  204. * @fmt : Formatted string which needs to be print in log
  205. * @args : Arguments which needs to be print in log
  206. */
  207. #define CAM_DBG(__module, fmt, args...) \
  208. cam_debug_log(__module, CAM_DBG_PRIORITY_0, __func__, __LINE__, \
  209. fmt, ##args)
  210. #define CAM_DBG_PR1(__module, fmt, args...) \
  211. cam_debug_log(__module, CAM_DBG_PRIORITY_1, __func__, __LINE__, \
  212. fmt, ##args)
  213. #define CAM_DBG_PR2(__module, fmt, args...) \
  214. cam_debug_log(__module, CAM_DBG_PRIORITY_2, __func__, __LINE__, \
  215. fmt, ##args)
  216. /*
  217. * CAM_ERR_RATE_LIMIT
  218. * @brief : This Macro will print error print logs with ratelimit
  219. */
  220. #define CAM_ERR_RATE_LIMIT(__module, fmt, args...) \
  221. ({ \
  222. pr_info_ratelimited("CAM_ERR: %s: %s: %d " fmt "\n", \
  223. cam_get_module_name(__module), __func__, \
  224. __LINE__, ##args); \
  225. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  226. fmt, ##args); \
  227. })
  228. /*
  229. * CAM_WARN_RATE_LIMIT
  230. * @brief : This Macro will print warning logs with ratelimit
  231. *
  232. * @__module : Respective module id which is been calling this Macro
  233. * @fmt : Formatted string which needs to be print in log
  234. * @args : Arguments which needs to be print in log
  235. */
  236. #define CAM_WARN_RATE_LIMIT(__module, fmt, args...) \
  237. ({ \
  238. pr_info_ratelimited("CAM_WARN: %s: %s: %d " fmt "\n", \
  239. cam_get_module_name(__module), __func__, \
  240. __LINE__, ##args); \
  241. cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__, \
  242. fmt, ##args); \
  243. })
  244. /*
  245. * CAM_WARN_RATE_LIMIT_CUSTOM
  246. * @brief : This Macro will print warn logs with custom ratelimit
  247. *
  248. * @__module : Respective module id which is been calling this Macro
  249. * @interval : Time interval in seconds
  250. * @burst : No of logs to print in interval time
  251. * @fmt : Formatted string which needs to be print in log
  252. * @args : Arguments which needs to be print in log
  253. */
  254. #define CAM_WARN_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  255. ({ \
  256. static DEFINE_RATELIMIT_STATE(_rs, \
  257. (interval * HZ), \
  258. burst); \
  259. if (__ratelimit(&_rs)) \
  260. pr_info( \
  261. "CAM_WARN: %s: %s: %d " fmt "\n", \
  262. cam_get_module_name(__module), __func__, \
  263. __LINE__, ##args); \
  264. cam_debug_trace(CAM_TYPE_WARN, __module, __func__, __LINE__, \
  265. fmt, ##args); \
  266. })
  267. /*
  268. * CAM_INFO_RATE_LIMIT_CUSTOM
  269. * @brief : This Macro will print info logs with custom ratelimit
  270. *
  271. * @__module : Respective module id which is been calling this Macro
  272. * @interval : Time interval in seconds
  273. * @burst : No of logs to print in interval time
  274. * @fmt : Formatted string which needs to be print in log
  275. * @args : Arguments which needs to be print in log
  276. */
  277. #define CAM_INFO_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  278. ({ \
  279. static DEFINE_RATELIMIT_STATE(_rs, \
  280. (interval * HZ), \
  281. burst); \
  282. if (__ratelimit(&_rs)) \
  283. pr_info( \
  284. "CAM_INFO: %s: %s: %d " fmt "\n", \
  285. cam_get_module_name(__module), __func__, \
  286. __LINE__, ##args); \
  287. cam_debug_trace(CAM_TYPE_INFO, __module, __func__, __LINE__, \
  288. fmt, ##args); \
  289. })
  290. /*
  291. * CAM_ERR_RATE_LIMIT_CUSTOM
  292. * @brief : This Macro will print error logs with custom ratelimit
  293. *
  294. * @__module : Respective module id which is been calling this Macro
  295. * @interval : Time interval in seconds
  296. * @burst : No of logs to print in interval time
  297. * @fmt : Formatted string which needs to be print in log
  298. * @args : Arguments which needs to be print in log
  299. */
  300. #define CAM_ERR_RATE_LIMIT_CUSTOM(__module, interval, burst, fmt, args...) \
  301. ({ \
  302. static DEFINE_RATELIMIT_STATE(_rs, \
  303. (interval * HZ), \
  304. burst); \
  305. if (__ratelimit(&_rs)) \
  306. pr_info( \
  307. "CAM_ERR: %s: %s: %d " fmt "\n", \
  308. cam_get_module_name(__module), __func__, \
  309. __LINE__, ##args); \
  310. cam_debug_trace(CAM_TYPE_ERR, __module, __func__, __LINE__, \
  311. fmt, ##args); \
  312. })
  313. /**
  314. * cam_print_to_buffer
  315. * @brief: Function to print to camera logs to a buffer. Don't use directly. Use macros
  316. * provided below.
  317. *
  318. * @buf: Buffer to print into
  319. * @buf_size: Total size of the buffer
  320. * @len: Pointer to variable used to keep track of the length
  321. * @tag: Log level tag to be prefixed
  322. * @module_id: Module id tag to be prefixed
  323. * @fmt: Formatted string which needs to be print in log
  324. * @args: Arguments which needs to be print in log
  325. */
  326. void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag,
  327. unsigned long long module_id, const char *fmt, ...);
  328. /**
  329. * CAM_[ERR/WARN/INFO]_BUF
  330. * @brief: Macro to print a new line into log buffer.
  331. *
  332. * @module_id: Module id tag to be prefixed
  333. * @buf: Buffer to print into
  334. * @buf_size: Total size of the buffer
  335. * @len: Pointer to the variable used to keep track of the length
  336. * @fmt: Formatted string which needs to be print in log
  337. * @args: Arguments which needs to be print in log
  338. */
  339. #define CAM_ERR_BUF(module_id, buf, buf_size, len, fmt, args...) \
  340. cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_ERR, module_id, fmt, ##args)
  341. #define CAM_WARN_BUF(module_id, buf, buf_size, len, fmt, args...) \
  342. cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_WARN, module_id, fmt, ##args)
  343. #define CAM_INFO_BUF(module_id, buf, buf_size, len, fmt, args...) \
  344. cam_print_to_buffer(buf, buf_size, len, CAM_TYPE_INFO, module_id, fmt, ##args)
  345. /**
  346. * @brief : API to get camera debug settings
  347. * @return const struct camera_debug_settings pointer.
  348. */
  349. const struct camera_debug_settings *cam_debug_get_settings(void);
  350. /**
  351. * @brief : API to parse and store input from sysfs debug node
  352. * @return Number of bytes read from buffer on success, or -EPERM on error.
  353. */
  354. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  355. struct device_attribute *attr, const char *buf, size_t count);
  356. #endif /* _CAM_DEBUG_UTIL_H_ */