msm_vidc_debug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. #define CREATE_TRACE_POINTS
  7. #include "msm_vidc_debug.h"
  8. #include "msm_vidc_driver.h"
  9. #include "msm_vidc.h"
  10. #include "msm_vidc_core.h"
  11. #include "msm_vidc_inst.h"
  12. #include "msm_vidc_internal.h"
  13. #include "msm_vidc_events.h"
  14. extern struct msm_vidc_core *g_core;
  15. #define MAX_SSR_STRING_LEN 64
  16. #define MAX_STABILITY_STRING_LEN 64
  17. #define MAX_DEBUG_LEVEL_STRING_LEN 15
  18. #define MSM_VIDC_MIN_STATS_DELAY_MS 200
  19. #define MSM_VIDC_MAX_STATS_DELAY_MS 10000
  20. unsigned int msm_vidc_debug = (DRV_LOG | FW_LOG);
  21. static int debug_level_set(const char *val,
  22. const struct kernel_param *kp)
  23. {
  24. struct msm_vidc_core *core = NULL;
  25. unsigned int dvalue;
  26. int ret;
  27. if (!kp || !kp->arg || !val) {
  28. d_vpr_e("%s: Invalid params\n", __func__);
  29. return -EINVAL;
  30. }
  31. core = *(struct msm_vidc_core **)kp->arg;
  32. if (!core || !core->capabilities) {
  33. d_vpr_e("%s: Invalid core/capabilities\n", __func__);
  34. return -EINVAL;
  35. }
  36. ret = kstrtouint(val, 0, &dvalue);
  37. if (ret)
  38. return ret;
  39. msm_vidc_debug = dvalue;
  40. /* check if driver or FW logmask is more than default level */
  41. if (((dvalue & DRV_LOGMASK) & ~(DRV_LOG)) ||
  42. ((dvalue & FW_LOGMASK) & ~(FW_LOG))) {
  43. core->capabilities[HW_RESPONSE_TIMEOUT].value = 4 * HW_RESPONSE_TIMEOUT_VALUE;
  44. core->capabilities[SW_PC_DELAY].value = 4 * SW_PC_DELAY_VALUE;
  45. core->capabilities[FW_UNLOAD_DELAY].value = 4 * FW_UNLOAD_DELAY_VALUE;
  46. } else {
  47. /* reset timeout values, if user reduces the logging */
  48. core->capabilities[HW_RESPONSE_TIMEOUT].value = HW_RESPONSE_TIMEOUT_VALUE;
  49. core->capabilities[SW_PC_DELAY].value = SW_PC_DELAY_VALUE;
  50. core->capabilities[FW_UNLOAD_DELAY].value = FW_UNLOAD_DELAY_VALUE;
  51. }
  52. d_vpr_h("timeout updated: hw_response %u, sw_pc %u, fw_unload %u, debug_level %#x\n",
  53. core->capabilities[HW_RESPONSE_TIMEOUT].value,
  54. core->capabilities[SW_PC_DELAY].value,
  55. core->capabilities[FW_UNLOAD_DELAY].value,
  56. msm_vidc_debug);
  57. return 0;
  58. }
  59. static int debug_level_get(char *buffer, const struct kernel_param *kp)
  60. {
  61. return scnprintf(buffer, PAGE_SIZE, "%#x", msm_vidc_debug);
  62. }
  63. static const struct kernel_param_ops msm_vidc_debug_fops = {
  64. .set = debug_level_set,
  65. .get = debug_level_get,
  66. };
  67. static int fw_dump_set(const char *val,
  68. const struct kernel_param *kp)
  69. {
  70. struct msm_vidc_core *core = NULL;
  71. unsigned int dvalue;
  72. int ret;
  73. if (!kp || !kp->arg || !val) {
  74. d_vpr_e("%s: Invalid params\n", __func__);
  75. return -EINVAL;
  76. }
  77. core = *(struct msm_vidc_core **) kp->arg;
  78. if (!core || !core->capabilities) {
  79. d_vpr_e("%s: Invalid core/capabilities\n", __func__);
  80. return -EINVAL;
  81. }
  82. ret = kstrtouint(val, 0, &dvalue);
  83. if (ret)
  84. return ret;
  85. msm_vidc_fw_dump = dvalue;
  86. d_vpr_h("fw dump %s\n", msm_vidc_fw_dump ? "Enabled" : "Disabled");
  87. return 0;
  88. }
  89. static int fw_dump_get(char *buffer, const struct kernel_param *kp)
  90. {
  91. return scnprintf(buffer, PAGE_SIZE, "%#x", msm_vidc_fw_dump);
  92. }
  93. static const struct kernel_param_ops msm_vidc_fw_dump_fops = {
  94. .set = fw_dump_set,
  95. .get = fw_dump_get,
  96. };
  97. module_param_cb(msm_vidc_debug, &msm_vidc_debug_fops, &g_core, 0644);
  98. module_param_cb(msm_vidc_fw_dump, &msm_vidc_fw_dump_fops, &g_core, 0644);
  99. bool msm_vidc_lossless_encode = !true;
  100. EXPORT_SYMBOL(msm_vidc_lossless_encode);
  101. /* disabled synx fence by default temporarily */
  102. bool msm_vidc_disable_synx_fence = !false;
  103. EXPORT_SYMBOL(msm_vidc_disable_synx_fence);
  104. bool msm_vidc_syscache_disable = !true;
  105. EXPORT_SYMBOL(msm_vidc_syscache_disable);
  106. int msm_vidc_clock_voting = !1;
  107. int msm_vidc_ddr_bw = !1;
  108. int msm_vidc_llc_bw = !1;
  109. bool msm_vidc_fw_dump = !true;
  110. EXPORT_SYMBOL(msm_vidc_fw_dump);
  111. unsigned int msm_vidc_enable_bugon = !1;
  112. EXPORT_SYMBOL(msm_vidc_enable_bugon);
  113. #define MAX_DBG_BUF_SIZE 4096
  114. struct core_inst_pair {
  115. struct msm_vidc_core *core;
  116. struct msm_vidc_inst *inst;
  117. };
  118. /* debug fs support */
  119. static inline void tic(struct msm_vidc_inst *i, enum profiling_points p,
  120. char *b)
  121. {
  122. if (!i->debug.pdata[p].name[0])
  123. memcpy(i->debug.pdata[p].name, b, 64);
  124. if (i->debug.pdata[p].sampling) {
  125. i->debug.pdata[p].start = ktime_get_ns() / 1000 / 1000;
  126. i->debug.pdata[p].sampling = false;
  127. }
  128. }
  129. static inline void toc(struct msm_vidc_inst *i, enum profiling_points p)
  130. {
  131. if (!i->debug.pdata[p].sampling) {
  132. i->debug.pdata[p].stop = ktime_get_ns() / 1000 / 1000;
  133. i->debug.pdata[p].cumulative += i->debug.pdata[p].stop -
  134. i->debug.pdata[p].start;
  135. i->debug.pdata[p].sampling = true;
  136. }
  137. }
  138. void msm_vidc_show_stats(void *inst)
  139. {
  140. int x;
  141. struct msm_vidc_inst *i = (struct msm_vidc_inst *) inst;
  142. if (!i) {
  143. d_vpr_e("%s: invalid params\n", __func__);
  144. return;
  145. }
  146. for (x = 0; x < MAX_PROFILING_POINTS; x++) {
  147. if (i->debug.pdata[x].name[0]) {
  148. if (i->debug.samples) {
  149. i_vpr_p(i, "%s averaged %llu ms/sample\n",
  150. i->debug.pdata[x].name,
  151. i->debug.pdata[x].cumulative /
  152. i->debug.samples);
  153. }
  154. i_vpr_p(i, "%s Samples: %d\n",
  155. i->debug.pdata[x].name, i->debug.samples);
  156. }
  157. }
  158. }
  159. static u32 write_str(char *buffer,
  160. size_t size, const char *fmt, ...)
  161. {
  162. va_list args;
  163. u32 len;
  164. va_start(args, fmt);
  165. len = vscnprintf(buffer, size, fmt, args);
  166. va_end(args);
  167. return len;
  168. }
  169. static ssize_t core_info_read(struct file* file, char __user* buf,
  170. size_t count, loff_t* ppos)
  171. {
  172. struct msm_vidc_core *core = file->private_data;
  173. char *cur, *end, *dbuf = NULL;
  174. ssize_t len = 0;
  175. int rc = 0;
  176. if (!core || !core->resource) {
  177. d_vpr_e("%s: invalid params %pK\n", __func__, core);
  178. return 0;
  179. }
  180. rc = msm_vidc_vmem_alloc(MAX_DBG_BUF_SIZE, (void **)&dbuf, __func__);
  181. if (rc)
  182. return rc;
  183. cur = dbuf;
  184. end = cur + MAX_DBG_BUF_SIZE;
  185. cur += write_str(cur, end - cur, "Core state: %d\n", core->state);
  186. cur += write_str(cur, end - cur,
  187. "FW version : %s\n", core->fw_version);
  188. cur += write_str(cur, end - cur,
  189. "register_base: 0x%x\n", core->resource->register_base_addr);
  190. cur += write_str(cur, end - cur, "irq: %u\n", core->resource->irq);
  191. len = simple_read_from_buffer(buf, count, ppos,
  192. dbuf, cur - dbuf);
  193. msm_vidc_vmem_free((void **)&dbuf);
  194. return len;
  195. }
  196. static const struct file_operations core_info_fops = {
  197. .open = simple_open,
  198. .read = core_info_read,
  199. };
  200. static ssize_t stats_delay_write_ms(struct file *filp, const char __user *buf,
  201. size_t count, loff_t *ppos)
  202. {
  203. int rc = 0;
  204. struct msm_vidc_core *core = filp->private_data;
  205. char kbuf[MAX_DEBUG_LEVEL_STRING_LEN] = {0};
  206. u32 delay_ms = 0;
  207. /* filter partial writes and invalid commands */
  208. if (*ppos != 0 || count >= sizeof(kbuf) || count == 0) {
  209. d_vpr_e("returning error - pos %lld, count %lu\n", *ppos, count);
  210. rc = -EINVAL;
  211. }
  212. rc = simple_write_to_buffer(kbuf, sizeof(kbuf) - 1, ppos, buf, count);
  213. if (rc < 0) {
  214. d_vpr_e("%s: User memory fault\n", __func__);
  215. rc = -EFAULT;
  216. goto exit;
  217. }
  218. rc = kstrtoint(kbuf, 0, &delay_ms);
  219. if (rc) {
  220. d_vpr_e("returning error err %d\n", rc);
  221. rc = -EINVAL;
  222. goto exit;
  223. }
  224. delay_ms = clamp_t(u32, delay_ms, MSM_VIDC_MIN_STATS_DELAY_MS, MSM_VIDC_MAX_STATS_DELAY_MS);
  225. core->capabilities[STATS_TIMEOUT_MS].value = delay_ms;
  226. d_vpr_h("Stats delay is updated to - %d ms\n", delay_ms);
  227. exit:
  228. return rc;
  229. }
  230. static ssize_t stats_delay_read_ms(struct file *file, char __user *buf,
  231. size_t count, loff_t *ppos)
  232. {
  233. size_t len;
  234. char kbuf[MAX_DEBUG_LEVEL_STRING_LEN];
  235. struct msm_vidc_core *core = file->private_data;
  236. len = scnprintf(kbuf, sizeof(kbuf), "%u\n", core->capabilities[STATS_TIMEOUT_MS].value);
  237. return simple_read_from_buffer(buf, count, ppos, kbuf, len);
  238. }
  239. static const struct file_operations stats_delay_fops = {
  240. .open = simple_open,
  241. .write = stats_delay_write_ms,
  242. .read = stats_delay_read_ms,
  243. };
  244. static ssize_t trigger_ssr_write(struct file* filp, const char __user* buf,
  245. size_t count, loff_t* ppos)
  246. {
  247. unsigned long ssr_trigger_val = 0;
  248. int rc = 0;
  249. struct msm_vidc_core* core = filp->private_data;
  250. size_t size = MAX_SSR_STRING_LEN;
  251. char kbuf[MAX_SSR_STRING_LEN + 1] = { 0 };
  252. if (!buf)
  253. return -EINVAL;
  254. if (!count)
  255. goto exit;
  256. if (count < size)
  257. size = count;
  258. if (copy_from_user(kbuf, buf, size)) {
  259. d_vpr_e("%s: User memory fault\n", __func__);
  260. rc = -EFAULT;
  261. goto exit;
  262. }
  263. rc = kstrtoul(kbuf, 0, &ssr_trigger_val);
  264. if (rc) {
  265. d_vpr_e("returning error err %d\n", rc);
  266. rc = -EINVAL;
  267. }
  268. else {
  269. msm_vidc_trigger_ssr(core, ssr_trigger_val);
  270. rc = count;
  271. }
  272. exit:
  273. return rc;
  274. }
  275. static const struct file_operations ssr_fops = {
  276. .open = simple_open,
  277. .write = trigger_ssr_write,
  278. };
  279. static ssize_t trigger_stability_write(struct file *filp, const char __user *buf,
  280. size_t count, loff_t *ppos)
  281. {
  282. unsigned long stability_trigger_val = 0;
  283. int rc = 0;
  284. struct msm_vidc_core *core = filp->private_data;
  285. size_t size = MAX_STABILITY_STRING_LEN;
  286. char kbuf[MAX_STABILITY_STRING_LEN + 1] = { 0 };
  287. if (!buf)
  288. return -EINVAL;
  289. if (!count)
  290. goto exit;
  291. if (count < size)
  292. size = count;
  293. if (copy_from_user(kbuf, buf, size)) {
  294. d_vpr_e("%s: User memory fault\n", __func__);
  295. rc = -EFAULT;
  296. goto exit;
  297. }
  298. rc = kstrtoul(kbuf, 0, &stability_trigger_val);
  299. if (rc) {
  300. d_vpr_e("%s: returning error err %d\n", __func__, rc);
  301. rc = -EINVAL;
  302. } else {
  303. msm_vidc_trigger_stability(core, stability_trigger_val);
  304. rc = count;
  305. }
  306. exit:
  307. return rc;
  308. }
  309. static const struct file_operations stability_fops = {
  310. .open = simple_open,
  311. .write = trigger_stability_write,
  312. };
  313. struct dentry* msm_vidc_debugfs_init_drv(void)
  314. {
  315. struct dentry *dir = NULL;
  316. dir = debugfs_create_dir("msm_vidc", NULL);
  317. if (IS_ERR_OR_NULL(dir)) {
  318. dir = NULL;
  319. goto failed_create_dir;
  320. }
  321. debugfs_create_u32("core_clock_voting", 0644, dir,
  322. &msm_vidc_clock_voting);
  323. debugfs_create_u32("ddr_bw_kbps", 0644, dir,
  324. &msm_vidc_ddr_bw);
  325. debugfs_create_u32("llc_bw_kbps", 0644, dir,
  326. &msm_vidc_llc_bw);
  327. debugfs_create_bool("disable_video_syscache", 0644, dir,
  328. &msm_vidc_syscache_disable);
  329. debugfs_create_bool("lossless_encoding", 0644, dir,
  330. &msm_vidc_lossless_encode);
  331. debugfs_create_bool("disable_synx_v2_fence", 0644, dir,
  332. &msm_vidc_disable_synx_fence);
  333. debugfs_create_u32("enable_bugon", 0644, dir,
  334. &msm_vidc_enable_bugon);
  335. return dir;
  336. failed_create_dir:
  337. if (dir)
  338. debugfs_remove_recursive(dir);
  339. return NULL;
  340. }
  341. struct dentry *msm_vidc_debugfs_init_core(void *core_in)
  342. {
  343. struct dentry *dir = NULL;
  344. char debugfs_name[MAX_DEBUGFS_NAME];
  345. struct msm_vidc_core *core = (struct msm_vidc_core *) core_in;
  346. struct dentry *parent;
  347. if (!core || !core->debugfs_parent) {
  348. d_vpr_e("%s: invalid params\n", __func__);
  349. goto failed_create_dir;
  350. }
  351. parent = core->debugfs_parent;
  352. snprintf(debugfs_name, MAX_DEBUGFS_NAME, "core");
  353. dir = debugfs_create_dir(debugfs_name, parent);
  354. if (IS_ERR_OR_NULL(dir)) {
  355. dir = NULL;
  356. d_vpr_e("Failed to create debugfs for msm_vidc\n");
  357. goto failed_create_dir;
  358. }
  359. if (!debugfs_create_file("info", 0444, dir, core, &core_info_fops)) {
  360. d_vpr_e("debugfs_create_file: fail\n");
  361. goto failed_create_dir;
  362. }
  363. if (!debugfs_create_file("trigger_ssr", 0200,
  364. dir, core, &ssr_fops)) {
  365. d_vpr_e("debugfs_create_file: fail\n");
  366. goto failed_create_dir;
  367. }
  368. if (!debugfs_create_file("trigger_stability", 0200, dir, core, &stability_fops)) {
  369. d_vpr_e("trigger_stability debugfs_create_file: fail\n");
  370. goto failed_create_dir;
  371. }
  372. if (!debugfs_create_file("stats_delay_ms", 0644, dir, core, &stats_delay_fops)) {
  373. d_vpr_e("debugfs_create_file: fail\n");
  374. goto failed_create_dir;
  375. }
  376. failed_create_dir:
  377. return dir;
  378. }
  379. static int inst_info_open(struct inode *inode, struct file *file)
  380. {
  381. d_vpr_l("Open inode ptr: %pK\n", inode->i_private);
  382. file->private_data = inode->i_private;
  383. return 0;
  384. }
  385. static int publish_unreleased_reference(struct msm_vidc_inst *inst,
  386. char **dbuf, char *end)
  387. {
  388. return 0;
  389. }
  390. static ssize_t inst_info_read(struct file *file, char __user *buf,
  391. size_t count, loff_t *ppos)
  392. {
  393. struct core_inst_pair *idata = file->private_data;
  394. struct msm_vidc_core *core;
  395. struct msm_vidc_inst *inst;
  396. char *cur, *end, *dbuf = NULL;
  397. int i, j;
  398. ssize_t len = 0;
  399. struct v4l2_format *f;
  400. if (!idata || !idata->core || !idata->inst ||
  401. !idata->inst->capabilities) {
  402. d_vpr_e("%s: invalid params %pK\n", __func__, idata);
  403. return 0;
  404. }
  405. core = idata->core;
  406. inst = idata->inst;
  407. inst = get_inst(core, inst->session_id);
  408. if (!inst) {
  409. d_vpr_h("%s: instance has become obsolete", __func__);
  410. return 0;
  411. }
  412. if (msm_vidc_vmem_alloc(MAX_DBG_BUF_SIZE, (void **)&dbuf, __func__)) {
  413. len = -ENOMEM;
  414. goto failed_alloc;
  415. }
  416. cur = dbuf;
  417. end = cur + MAX_DBG_BUF_SIZE;
  418. f = &inst->fmts[OUTPUT_PORT];
  419. cur += write_str(cur, end - cur, "==============================\n");
  420. cur += write_str(cur, end - cur, "INSTANCE: %pK (%s)\n", inst,
  421. inst->domain == MSM_VIDC_ENCODER ? "Encoder" : "Decoder");
  422. cur += write_str(cur, end - cur, "==============================\n");
  423. cur += write_str(cur, end - cur, "core: %pK\n", inst->core);
  424. cur += write_str(cur, end - cur, "height: %d\n", f->fmt.pix_mp.height);
  425. cur += write_str(cur, end - cur, "width: %d\n", f->fmt.pix_mp.width);
  426. cur += write_str(cur, end - cur, "fps: %d\n",
  427. inst->capabilities->cap[FRAME_RATE].value >> 16);
  428. cur += write_str(cur, end - cur, "state: %d\n", inst->state);
  429. cur += write_str(cur, end - cur, "secure: %d\n",
  430. is_secure_session(inst));
  431. cur += write_str(cur, end - cur, "-----------Formats-------------\n");
  432. for (i = 0; i < MAX_PORT; i++) {
  433. if (i != INPUT_PORT && i != OUTPUT_PORT)
  434. continue;
  435. f = &inst->fmts[i];
  436. cur += write_str(cur, end - cur, "capability: %s\n",
  437. i == INPUT_PORT ? "Output" : "Capture");
  438. cur += write_str(cur, end - cur, "planes : %d\n",
  439. f->fmt.pix_mp.num_planes);
  440. cur += write_str(cur, end - cur,
  441. "type: %s\n", i == INPUT_PORT ?
  442. "Output" : "Capture");
  443. cur += write_str(cur, end - cur, "count: %u\n",
  444. inst->bufq[i].vb2q->num_buffers);
  445. for (j = 0; j < f->fmt.pix_mp.num_planes; j++)
  446. cur += write_str(cur, end - cur,
  447. "size for plane %d: %u\n",
  448. j, f->fmt.pix_mp.plane_fmt[j].sizeimage);
  449. cur += write_str(cur, end - cur, "\n");
  450. }
  451. cur += write_str(cur, end - cur, "-------------------------------\n");
  452. cur += write_str(cur, end - cur, "ETB Count: %d\n",
  453. inst->debug_count.etb);
  454. cur += write_str(cur, end - cur, "EBD Count: %d\n",
  455. inst->debug_count.ebd);
  456. cur += write_str(cur, end - cur, "FTB Count: %d\n",
  457. inst->debug_count.ftb);
  458. cur += write_str(cur, end - cur, "FBD Count: %d\n",
  459. inst->debug_count.fbd);
  460. publish_unreleased_reference(inst, &cur, end);
  461. len = simple_read_from_buffer(buf, count, ppos,
  462. dbuf, cur - dbuf);
  463. msm_vidc_vmem_free((void **)&dbuf);
  464. failed_alloc:
  465. put_inst(inst);
  466. return len;
  467. }
  468. static int inst_info_release(struct inode *inode, struct file *file)
  469. {
  470. d_vpr_l("Release inode ptr: %pK\n", inode->i_private);
  471. file->private_data = NULL;
  472. return 0;
  473. }
  474. static const struct file_operations inst_info_fops = {
  475. .open = inst_info_open,
  476. .read = inst_info_read,
  477. .release = inst_info_release,
  478. };
  479. struct dentry *msm_vidc_debugfs_init_inst(void *instance, struct dentry *parent)
  480. {
  481. struct dentry *dir = NULL, *info = NULL;
  482. char debugfs_name[MAX_DEBUGFS_NAME];
  483. struct core_inst_pair *idata = NULL;
  484. struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
  485. if (!inst) {
  486. d_vpr_e("%s: invalid params\n", __func__);
  487. goto exit;
  488. }
  489. snprintf(debugfs_name, MAX_DEBUGFS_NAME, "inst_%d", inst->session_id);
  490. if (msm_vidc_vmem_alloc(sizeof(struct core_inst_pair), (void **)&idata, __func__))
  491. goto exit;
  492. idata->core = inst->core;
  493. idata->inst = inst;
  494. dir = debugfs_create_dir(debugfs_name, parent);
  495. if (IS_ERR_OR_NULL(dir)) {
  496. dir = NULL;
  497. i_vpr_e(inst,
  498. "%s: Failed to create debugfs for msm_vidc\n",
  499. __func__);
  500. goto failed_create_dir;
  501. }
  502. info = debugfs_create_file("info", 0444, dir,
  503. idata, &inst_info_fops);
  504. if (IS_ERR_OR_NULL(info)) {
  505. i_vpr_e(inst, "%s: debugfs_create_file: fail\n",
  506. __func__);
  507. goto failed_create_file;
  508. }
  509. dir->d_inode->i_private = info->d_inode->i_private;
  510. inst->debug.pdata[FRAME_PROCESSING].sampling = true;
  511. return dir;
  512. failed_create_file:
  513. debugfs_remove_recursive(dir);
  514. dir = NULL;
  515. failed_create_dir:
  516. msm_vidc_vmem_free((void **)&idata);
  517. exit:
  518. return dir;
  519. }
  520. void msm_vidc_debugfs_deinit_inst(void *instance)
  521. {
  522. struct dentry *dentry = NULL;
  523. struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
  524. if (!inst || !inst->debugfs_root)
  525. return;
  526. dentry = inst->debugfs_root;
  527. if (dentry->d_inode) {
  528. i_vpr_l(inst, "%s: Destroy %pK\n",
  529. __func__, dentry->d_inode->i_private);
  530. msm_vidc_vmem_free(&dentry->d_inode->i_private);
  531. dentry->d_inode->i_private = NULL;
  532. }
  533. debugfs_remove_recursive(dentry);
  534. inst->debugfs_root = NULL;
  535. }
  536. void msm_vidc_debugfs_update(void *instance,
  537. enum msm_vidc_debugfs_event e)
  538. {
  539. struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
  540. struct msm_vidc_debug *d;
  541. char a[64] = "Frame processing";
  542. if (!inst) {
  543. d_vpr_e("%s: invalid params\n", __func__);
  544. return;
  545. }
  546. d = &inst->debug;
  547. switch (e) {
  548. case MSM_VIDC_DEBUGFS_EVENT_ETB:
  549. inst->debug_count.etb++;
  550. if (inst->debug_count.ebd &&
  551. inst->debug_count.ftb > inst->debug_count.fbd) {
  552. d->pdata[FRAME_PROCESSING].name[0] = '\0';
  553. tic(inst, FRAME_PROCESSING, a);
  554. }
  555. break;
  556. case MSM_VIDC_DEBUGFS_EVENT_EBD:
  557. inst->debug_count.ebd++;
  558. /*
  559. * Host needs to ensure FW atleast have 2 buffers available always
  560. * one for HW processing and another for fw processing in parallel
  561. * to avoid FW starving for buffers
  562. */
  563. if (inst->debug_count.etb < (inst->debug_count.ebd + 2)) {
  564. toc(inst, FRAME_PROCESSING);
  565. i_vpr_p(inst,
  566. "EBD: FW needs input buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  567. inst->debug_count.etb, inst->debug_count.ebd,
  568. inst->debug_count.ftb, inst->debug_count.fbd);
  569. }
  570. if (inst->debug_count.fbd &&
  571. inst->debug_count.ftb < (inst->debug_count.fbd + 2))
  572. i_vpr_p(inst,
  573. "EBD: FW needs output buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  574. inst->debug_count.etb, inst->debug_count.ebd,
  575. inst->debug_count.ftb, inst->debug_count.fbd);
  576. break;
  577. case MSM_VIDC_DEBUGFS_EVENT_FTB:
  578. inst->debug_count.ftb++;
  579. if (inst->debug_count.ebd &&
  580. inst->debug_count.etb > inst->debug_count.ebd) {
  581. d->pdata[FRAME_PROCESSING].name[0] = '\0';
  582. tic(inst, FRAME_PROCESSING, a);
  583. }
  584. break;
  585. case MSM_VIDC_DEBUGFS_EVENT_FBD:
  586. inst->debug_count.fbd++;
  587. inst->debug.samples++;
  588. /*
  589. * Host needs to ensure FW atleast have 2 buffers available always
  590. * one for HW processing and another for fw processing in parallel
  591. * to avoid FW starving for buffers
  592. */
  593. if (inst->debug_count.ftb < (inst->debug_count.fbd + 2)) {
  594. toc(inst, FRAME_PROCESSING);
  595. i_vpr_p(inst,
  596. "FBD: FW needs output buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  597. inst->debug_count.etb, inst->debug_count.ebd,
  598. inst->debug_count.ftb, inst->debug_count.fbd);
  599. }
  600. if (inst->debug_count.ebd &&
  601. inst->debug_count.etb < (inst->debug_count.ebd + 2))
  602. i_vpr_p(inst,
  603. "FBD: FW needs input buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  604. inst->debug_count.etb, inst->debug_count.ebd,
  605. inst->debug_count.ftb, inst->debug_count.fbd);
  606. break;
  607. default:
  608. i_vpr_e(inst, "invalid event in debugfs: %d\n", e);
  609. break;
  610. }
  611. }
  612. int msm_vidc_check_ratelimit(void)
  613. {
  614. static DEFINE_RATELIMIT_STATE(_rs,
  615. VIDC_DBG_SESSION_RATELIMIT_INTERVAL,
  616. VIDC_DBG_SESSION_RATELIMIT_BURST);
  617. return __ratelimit(&_rs);
  618. }