cam_debug_util.h 15 KB

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