msm_vidc_debug.c 19 KB

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