cam_debug_util.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundataion. All rights reserved.
  4. */
  5. #include <linux/io.h>
  6. #include <linux/slab.h>
  7. #include <linux/module.h>
  8. #include "cam_trace.h"
  9. #include "cam_debug_util.h"
  10. static uint debug_mdl;
  11. module_param(debug_mdl, uint, 0644);
  12. /* 0x0 - only logs, 0x1 - only trace, 0x2 - logs + trace */
  13. static uint debug_type;
  14. module_param(debug_type, uint, 0644);
  15. static uint debug_priority;
  16. module_param(debug_priority, uint, 0644);
  17. struct camera_debug_settings cam_debug;
  18. const struct camera_debug_settings *cam_debug_get_settings()
  19. {
  20. return &cam_debug;
  21. }
  22. static int cam_debug_parse_cpas_settings(const char *setting, u64 value)
  23. {
  24. if (!strcmp(setting, "camnoc_bw")) {
  25. cam_debug.cpas_settings.camnoc_bw = value;
  26. } else if (!strcmp(setting, "mnoc_hf_0_ab_bw")) {
  27. cam_debug.cpas_settings.mnoc_hf_0_ab_bw = value;
  28. } else if (!strcmp(setting, "mnoc_hf_0_ib_bw")) {
  29. cam_debug.cpas_settings.mnoc_hf_0_ib_bw = value;
  30. } else if (!strcmp(setting, "mnoc_hf_1_ab_bw")) {
  31. cam_debug.cpas_settings.mnoc_hf_1_ab_bw = value;
  32. } else if (!strcmp(setting, "mnoc_hf_1_ib_bw")) {
  33. cam_debug.cpas_settings.mnoc_hf_1_ib_bw = value;
  34. } else if (!strcmp(setting, "mnoc_sf_0_ab_bw")) {
  35. cam_debug.cpas_settings.mnoc_sf_0_ab_bw = value;
  36. } else if (!strcmp(setting, "mnoc_sf_0_ib_bw")) {
  37. cam_debug.cpas_settings.mnoc_sf_0_ib_bw = value;
  38. } else if (!strcmp(setting, "mnoc_sf_1_ab_bw")) {
  39. cam_debug.cpas_settings.mnoc_sf_1_ab_bw = value;
  40. } else if (!strcmp(setting, "mnoc_sf_1_ib_bw")) {
  41. cam_debug.cpas_settings.mnoc_sf_1_ib_bw = value;
  42. } else if (!strcmp(setting, "mnoc_sf_icp_ab_bw")) {
  43. cam_debug.cpas_settings.mnoc_sf_icp_ab_bw = value;
  44. } else if (!strcmp(setting, "mnoc_sf_icp_ib_bw")) {
  45. cam_debug.cpas_settings.mnoc_sf_icp_ib_bw = value;
  46. } else {
  47. CAM_ERR(CAM_UTIL, "Unsupported cpas sysfs entry");
  48. return -EINVAL;
  49. }
  50. return 0;
  51. }
  52. ssize_t cam_debug_sysfs_node_store(struct device *dev,
  53. struct device_attribute *attr, const char *buf, size_t count)
  54. {
  55. int rc = 0;
  56. char *local_buf = NULL, *local_buf_temp = NULL;
  57. char *driver;
  58. char *setting = NULL;
  59. char *value_str = NULL;
  60. u64 value;
  61. CAM_INFO(CAM_UTIL, "Sysfs debug attr name:[%s] buf:[%s] bytes:[%d]",
  62. attr->attr.name, buf, count);
  63. local_buf = kmemdup(buf, (count + sizeof(char)), GFP_KERNEL);
  64. local_buf_temp = local_buf;
  65. driver = strsep(&local_buf, "#");
  66. if (!driver) {
  67. CAM_ERR(CAM_UTIL,
  68. "Invalid input driver name buf:[%s], count:%d",
  69. buf, count);
  70. goto error;
  71. }
  72. setting = strsep(&local_buf, "=");
  73. if (!setting) {
  74. CAM_ERR(CAM_UTIL, "Invalid input setting buf:[%s], count:%d",
  75. buf, count);
  76. goto error;
  77. }
  78. value_str = strsep(&local_buf, "=");
  79. if (!value_str) {
  80. CAM_ERR(CAM_UTIL, "Invalid input value buf:[%s], count:%d",
  81. buf, count);
  82. goto error;
  83. }
  84. rc = kstrtou64(value_str, 0, &value);
  85. if (rc < 0) {
  86. CAM_ERR(CAM_UTIL, "Error converting value:[%s], buf:[%s]",
  87. value_str, buf);
  88. goto error;
  89. }
  90. CAM_INFO(CAM_UTIL,
  91. "Processing sysfs store for driver:[%s], setting:[%s], value:[%llu]",
  92. driver, setting, value);
  93. if (!strcmp(driver, "cpas")) {
  94. rc = cam_debug_parse_cpas_settings(setting, value);
  95. if (rc)
  96. goto error;
  97. } else {
  98. CAM_ERR(CAM_UTIL, "Unsupported driver in camera debug node");
  99. goto error;
  100. }
  101. kfree(local_buf_temp);
  102. return count;
  103. error:
  104. kfree(local_buf_temp);
  105. return -EPERM;
  106. }
  107. const char *cam_get_module_name(unsigned int module_id)
  108. {
  109. const char *name = NULL;
  110. switch (module_id) {
  111. case CAM_CDM:
  112. name = "CAM-CDM";
  113. break;
  114. case CAM_CORE:
  115. name = "CAM-CORE";
  116. break;
  117. case CAM_CRM:
  118. name = "CAM-CRM";
  119. break;
  120. case CAM_CPAS:
  121. name = "CAM-CPAS";
  122. break;
  123. case CAM_ISP:
  124. name = "CAM-ISP";
  125. break;
  126. case CAM_SENSOR:
  127. name = "CAM-SENSOR";
  128. break;
  129. case CAM_SMMU:
  130. name = "CAM-SMMU";
  131. break;
  132. case CAM_SYNC:
  133. name = "CAM-SYNC";
  134. break;
  135. case CAM_ICP:
  136. name = "CAM-ICP";
  137. break;
  138. case CAM_JPEG:
  139. name = "CAM-JPEG";
  140. break;
  141. case CAM_FD:
  142. name = "CAM-FD";
  143. break;
  144. case CAM_LRME:
  145. name = "CAM-LRME";
  146. break;
  147. case CAM_FLASH:
  148. name = "CAM-FLASH";
  149. break;
  150. case CAM_ACTUATOR:
  151. name = "CAM-ACTUATOR";
  152. break;
  153. case CAM_CCI:
  154. name = "CAM-CCI";
  155. break;
  156. case CAM_CSIPHY:
  157. name = "CAM-CSIPHY";
  158. break;
  159. case CAM_EEPROM:
  160. name = "CAM-EEPROM";
  161. break;
  162. case CAM_UTIL:
  163. name = "CAM-UTIL";
  164. break;
  165. case CAM_CTXT:
  166. name = "CAM-CTXT";
  167. break;
  168. case CAM_HFI:
  169. name = "CAM-HFI";
  170. break;
  171. case CAM_OIS:
  172. name = "CAM-OIS";
  173. break;
  174. case CAM_IRQ_CTRL:
  175. name = "CAM-IRQ-CTRL";
  176. break;
  177. case CAM_MEM:
  178. name = "CAM-MEM";
  179. break;
  180. case CAM_PERF:
  181. name = "CAM-PERF";
  182. break;
  183. case CAM_REQ:
  184. name = "CAM-REQ";
  185. break;
  186. case CAM_CUSTOM:
  187. name = "CAM-CUSTOM";
  188. break;
  189. case CAM_OPE:
  190. name = "CAM-OPE";
  191. break;
  192. case CAM_PRESIL:
  193. name = "CAM-PRESIL";
  194. break;
  195. case CAM_RES:
  196. name = "CAM-RES";
  197. break;
  198. case CAM_IO_ACCESS:
  199. name = "CAM-IO-ACCESS";
  200. break;
  201. case CAM_SFE:
  202. name = "CAM-SFE";
  203. break;
  204. case CAM_CRE:
  205. name = "CAM-CRE";
  206. break;
  207. default:
  208. name = "CAM";
  209. break;
  210. }
  211. return name;
  212. }
  213. const char *cam_get_tag_name(unsigned int tag_id)
  214. {
  215. const char *name = NULL;
  216. switch (tag_id) {
  217. case CAM_TYPE_TRACE:
  218. name = "CAM_TRACE";
  219. break;
  220. case CAM_TYPE_ERR:
  221. name = "CAM_ERR";
  222. break;
  223. case CAM_TYPE_WARN:
  224. name = "CAM_WARN";
  225. break;
  226. case CAM_TYPE_INFO:
  227. name = "CAM_INFO";
  228. break;
  229. case CAM_TYPE_DBG:
  230. name = "CAM_DBG";
  231. break;
  232. default:
  233. name = "CAM";
  234. break;
  235. }
  236. return name;
  237. }
  238. static inline void __cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len,
  239. unsigned int tag, unsigned int module_id, const char *func, const int line,
  240. const bool is_final_print, const char *fmt, va_list args)
  241. {
  242. size_t buf_len = *len;
  243. if (is_final_print)
  244. buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "%s: %s: %s: %d: ",
  245. cam_get_tag_name(tag), cam_get_module_name(module_id), func, line);
  246. else
  247. buf_len += scnprintf(buf + buf_len, (buf_size - buf_len), "\n%-8s: %s:\t",
  248. cam_get_tag_name(tag), cam_get_module_name(module_id));
  249. buf_len += vscnprintf(buf + buf_len, (buf_size - buf_len), fmt, args);
  250. *len = buf_len;
  251. }
  252. void cam_print_to_buffer(char *buf, const size_t buf_size, size_t *len, unsigned int tag,
  253. unsigned int module_id, const char *fmt, ...)
  254. {
  255. va_list args;
  256. va_start(args, fmt);
  257. __cam_print_to_buffer(buf, buf_size, len, tag, module_id, "", 0, false, fmt, args);
  258. va_end(args);
  259. }
  260. void cam_debug_log(unsigned int module_id, unsigned int priority,
  261. const char *func, const int line, const char *fmt, ...)
  262. {
  263. if ((debug_mdl & module_id) && (priority >= debug_priority)) {
  264. char str_buf[STR_BUFFER_MAX_LENGTH];
  265. size_t len = 0;
  266. va_list args;
  267. va_start(args, fmt);
  268. __cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, CAM_TYPE_DBG, module_id,
  269. func, line, true, fmt, args);
  270. if ((debug_type == 0) || (debug_type == 2))
  271. pr_info("%s\n", str_buf);
  272. if ((debug_type == 1) || (debug_type == 2))
  273. trace_cam_log_debug(str_buf);
  274. va_end(args);
  275. }
  276. }
  277. void cam_debug_trace(unsigned int tag, unsigned int module_id,
  278. const char *func, const int line, const char *fmt, ...)
  279. {
  280. if ((tag == CAM_TYPE_TRACE) || (debug_type == 1) || (debug_type == 2)) {
  281. char str_buf[STR_BUFFER_MAX_LENGTH];
  282. size_t len = 0;
  283. va_list args;
  284. va_start(args, fmt);
  285. __cam_print_to_buffer(str_buf, STR_BUFFER_MAX_LENGTH, &len, tag,
  286. module_id, func, line, true, fmt, args);
  287. trace_cam_log_debug(str_buf);
  288. va_end(args);
  289. }
  290. }