msm_vidc_debug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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_dt.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 = VIDC_ERR | VIDC_PRINTK | FW_ERROR | FW_FATAL | FW_PRINTK;
  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 only driver logmask */
  41. if ((dvalue & 0xFF) > (VIDC_ERR | VIDC_HIGH)) {
  42. core->capabilities[HW_RESPONSE_TIMEOUT].value = 2 * HW_RESPONSE_TIMEOUT_VALUE;
  43. core->capabilities[SW_PC_DELAY].value = 2 * SW_PC_DELAY_VALUE;
  44. core->capabilities[FW_UNLOAD_DELAY].value = 2 * 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 %d 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->dt) {
  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->dt->register_base);
  186. cur += write_str(cur, end - cur,
  187. "register_size: %u\n", core->dt->register_size);
  188. cur += write_str(cur, end - cur, "irq: %u\n", core->dt->irq);
  189. len = simple_read_from_buffer(buf, count, ppos,
  190. dbuf, cur - dbuf);
  191. msm_vidc_vmem_free((void **)&dbuf);
  192. return len;
  193. }
  194. static const struct file_operations core_info_fops = {
  195. .open = simple_open,
  196. .read = core_info_read,
  197. };
  198. static ssize_t stats_delay_write_ms(struct file *filp, const char __user *buf,
  199. size_t count, loff_t *ppos)
  200. {
  201. int rc = 0;
  202. struct msm_vidc_core *core = filp->private_data;
  203. char kbuf[MAX_DEBUG_LEVEL_STRING_LEN] = {0};
  204. u32 delay_ms = 0;
  205. /* filter partial writes and invalid commands */
  206. if (*ppos != 0 || count >= sizeof(kbuf) || count == 0) {
  207. d_vpr_e("returning error - pos %lld, count %lu\n", *ppos, count);
  208. rc = -EINVAL;
  209. }
  210. rc = simple_write_to_buffer(kbuf, sizeof(kbuf) - 1, ppos, buf, count);
  211. if (rc < 0) {
  212. d_vpr_e("%s: User memory fault\n", __func__);
  213. rc = -EFAULT;
  214. goto exit;
  215. }
  216. rc = kstrtoint(kbuf, 0, &delay_ms);
  217. if (rc) {
  218. d_vpr_e("returning error err %d\n", rc);
  219. rc = -EINVAL;
  220. goto exit;
  221. }
  222. delay_ms = clamp_t(u32, delay_ms, MSM_VIDC_MIN_STATS_DELAY_MS, MSM_VIDC_MAX_STATS_DELAY_MS);
  223. core->capabilities[STATS_TIMEOUT_MS].value = delay_ms;
  224. d_vpr_h("Stats delay is updated to - %d ms\n", delay_ms);
  225. exit:
  226. return rc;
  227. }
  228. static ssize_t stats_delay_read_ms(struct file *file, char __user *buf,
  229. size_t count, loff_t *ppos)
  230. {
  231. size_t len;
  232. char kbuf[MAX_DEBUG_LEVEL_STRING_LEN];
  233. struct msm_vidc_core *core = file->private_data;
  234. len = scnprintf(kbuf, sizeof(kbuf), "%u\n", core->capabilities[STATS_TIMEOUT_MS].value);
  235. return simple_read_from_buffer(buf, count, ppos, kbuf, len);
  236. }
  237. static const struct file_operations stats_delay_fops = {
  238. .open = simple_open,
  239. .write = stats_delay_write_ms,
  240. .read = stats_delay_read_ms,
  241. };
  242. static ssize_t trigger_ssr_write(struct file* filp, const char __user* buf,
  243. size_t count, loff_t* ppos)
  244. {
  245. unsigned long ssr_trigger_val = 0;
  246. int rc = 0;
  247. struct msm_vidc_core* core = filp->private_data;
  248. size_t size = MAX_SSR_STRING_LEN;
  249. char kbuf[MAX_SSR_STRING_LEN + 1] = { 0 };
  250. if (!buf)
  251. return -EINVAL;
  252. if (!count)
  253. goto exit;
  254. if (count < size)
  255. size = count;
  256. if (copy_from_user(kbuf, buf, size)) {
  257. d_vpr_e("%s: User memory fault\n", __func__);
  258. rc = -EFAULT;
  259. goto exit;
  260. }
  261. rc = kstrtoul(kbuf, 0, &ssr_trigger_val);
  262. if (rc) {
  263. d_vpr_e("returning error err %d\n", rc);
  264. rc = -EINVAL;
  265. }
  266. else {
  267. msm_vidc_trigger_ssr(core, ssr_trigger_val);
  268. rc = count;
  269. }
  270. exit:
  271. return rc;
  272. }
  273. static const struct file_operations ssr_fops = {
  274. .open = simple_open,
  275. .write = trigger_ssr_write,
  276. };
  277. static ssize_t trigger_stability_write(struct file *filp, const char __user *buf,
  278. size_t count, loff_t *ppos)
  279. {
  280. unsigned long stability_trigger_val = 0;
  281. int rc = 0;
  282. struct msm_vidc_core *core = filp->private_data;
  283. size_t size = MAX_STABILITY_STRING_LEN;
  284. char kbuf[MAX_STABILITY_STRING_LEN + 1] = { 0 };
  285. if (!buf)
  286. return -EINVAL;
  287. if (!count)
  288. goto exit;
  289. if (count < size)
  290. size = count;
  291. if (copy_from_user(kbuf, buf, size)) {
  292. d_vpr_e("%s: User memory fault\n", __func__);
  293. rc = -EFAULT;
  294. goto exit;
  295. }
  296. rc = kstrtoul(kbuf, 0, &stability_trigger_val);
  297. if (rc) {
  298. d_vpr_e("%s: returning error err %d\n", __func__, rc);
  299. rc = -EINVAL;
  300. } else {
  301. msm_vidc_trigger_stability(core, stability_trigger_val);
  302. rc = count;
  303. }
  304. exit:
  305. return rc;
  306. }
  307. static const struct file_operations stability_fops = {
  308. .open = simple_open,
  309. .write = trigger_stability_write,
  310. };
  311. struct dentry* msm_vidc_debugfs_init_drv()
  312. {
  313. struct dentry *dir = NULL;
  314. dir = debugfs_create_dir("msm_vidc", NULL);
  315. if (IS_ERR_OR_NULL(dir)) {
  316. dir = NULL;
  317. goto failed_create_dir;
  318. }
  319. debugfs_create_u32("core_clock_voting", 0644, dir,
  320. &msm_vidc_clock_voting);
  321. debugfs_create_u32("ddr_bw_kbps", 0644, dir,
  322. &msm_vidc_ddr_bw);
  323. debugfs_create_u32("llc_bw_kbps", 0644, dir,
  324. &msm_vidc_llc_bw);
  325. debugfs_create_bool("disable_video_syscache", 0644, dir,
  326. &msm_vidc_syscache_disable);
  327. debugfs_create_bool("lossless_encoding", 0644, dir,
  328. &msm_vidc_lossless_encode);
  329. debugfs_create_u32("enable_bugon", 0644, dir,
  330. &msm_vidc_enable_bugon);
  331. return dir;
  332. failed_create_dir:
  333. if (dir)
  334. debugfs_remove_recursive(dir);
  335. return NULL;
  336. }
  337. struct dentry *msm_vidc_debugfs_init_core(void *core_in)
  338. {
  339. struct dentry *dir = NULL;
  340. char debugfs_name[MAX_DEBUGFS_NAME];
  341. struct msm_vidc_core *core = (struct msm_vidc_core *) core_in;
  342. struct dentry *parent;
  343. if (!core || !core->debugfs_parent) {
  344. d_vpr_e("%s: invalid params\n", __func__);
  345. goto failed_create_dir;
  346. }
  347. parent = core->debugfs_parent;
  348. snprintf(debugfs_name, MAX_DEBUGFS_NAME, "core");
  349. dir = debugfs_create_dir(debugfs_name, parent);
  350. if (IS_ERR_OR_NULL(dir)) {
  351. dir = NULL;
  352. d_vpr_e("Failed to create debugfs for msm_vidc\n");
  353. goto failed_create_dir;
  354. }
  355. if (!debugfs_create_file("info", 0444, dir, core, &core_info_fops)) {
  356. d_vpr_e("debugfs_create_file: fail\n");
  357. goto failed_create_dir;
  358. }
  359. if (!debugfs_create_file("trigger_ssr", 0200,
  360. dir, core, &ssr_fops)) {
  361. d_vpr_e("debugfs_create_file: fail\n");
  362. goto failed_create_dir;
  363. }
  364. if (!debugfs_create_file("trigger_stability", 0200, dir, core, &stability_fops)) {
  365. d_vpr_e("trigger_stability debugfs_create_file: fail\n");
  366. goto failed_create_dir;
  367. }
  368. if (!debugfs_create_file("stats_delay_ms", 0644, dir, core, &stats_delay_fops)) {
  369. d_vpr_e("debugfs_create_file: fail\n");
  370. goto failed_create_dir;
  371. }
  372. failed_create_dir:
  373. return dir;
  374. }
  375. static int inst_info_open(struct inode *inode, struct file *file)
  376. {
  377. d_vpr_l("Open inode ptr: %pK\n", inode->i_private);
  378. file->private_data = inode->i_private;
  379. return 0;
  380. }
  381. static int publish_unreleased_reference(struct msm_vidc_inst *inst,
  382. char **dbuf, char *end)
  383. {
  384. return 0;
  385. }
  386. static ssize_t inst_info_read(struct file *file, char __user *buf,
  387. size_t count, loff_t *ppos)
  388. {
  389. struct core_inst_pair *idata = file->private_data;
  390. struct msm_vidc_core *core;
  391. struct msm_vidc_inst *inst;
  392. char *cur, *end, *dbuf = NULL;
  393. int i, j;
  394. ssize_t len = 0;
  395. struct v4l2_format *f;
  396. if (!idata || !idata->core || !idata->inst ||
  397. !idata->inst->capabilities) {
  398. d_vpr_e("%s: invalid params %pK\n", __func__, idata);
  399. return 0;
  400. }
  401. core = idata->core;
  402. inst = idata->inst;
  403. inst = get_inst(core, inst->session_id);
  404. if (!inst) {
  405. d_vpr_h("%s: instance has become obsolete", __func__);
  406. return 0;
  407. }
  408. if (msm_vidc_vmem_alloc(MAX_DBG_BUF_SIZE, (void **)&dbuf, __func__)) {
  409. len = -ENOMEM;
  410. goto failed_alloc;
  411. }
  412. cur = dbuf;
  413. end = cur + MAX_DBG_BUF_SIZE;
  414. f = &inst->fmts[OUTPUT_PORT];
  415. cur += write_str(cur, end - cur, "==============================\n");
  416. cur += write_str(cur, end - cur, "INSTANCE: %pK (%s)\n", inst,
  417. inst->domain == MSM_VIDC_ENCODER ? "Encoder" : "Decoder");
  418. cur += write_str(cur, end - cur, "==============================\n");
  419. cur += write_str(cur, end - cur, "core: %pK\n", inst->core);
  420. cur += write_str(cur, end - cur, "height: %d\n", f->fmt.pix_mp.height);
  421. cur += write_str(cur, end - cur, "width: %d\n", f->fmt.pix_mp.width);
  422. cur += write_str(cur, end - cur, "fps: %d\n",
  423. inst->capabilities->cap[FRAME_RATE].value >> 16);
  424. cur += write_str(cur, end - cur, "state: %d\n", inst->state);
  425. cur += write_str(cur, end - cur, "secure: %d\n",
  426. is_secure_session(inst));
  427. cur += write_str(cur, end - cur, "-----------Formats-------------\n");
  428. for (i = 0; i < MAX_PORT; i++) {
  429. if (i != INPUT_PORT && i != OUTPUT_PORT)
  430. continue;
  431. f = &inst->fmts[i];
  432. cur += write_str(cur, end - cur, "capability: %s\n",
  433. i == INPUT_PORT ? "Output" : "Capture");
  434. cur += write_str(cur, end - cur, "planes : %d\n",
  435. f->fmt.pix_mp.num_planes);
  436. cur += write_str(cur, end - cur,
  437. "type: %s\n", i == INPUT_PORT ?
  438. "Output" : "Capture");
  439. cur += write_str(cur, end - cur, "count: %u\n",
  440. inst->bufq[i].vb2q->num_buffers);
  441. for (j = 0; j < f->fmt.pix_mp.num_planes; j++)
  442. cur += write_str(cur, end - cur,
  443. "size for plane %d: %u\n",
  444. j, f->fmt.pix_mp.plane_fmt[j].sizeimage);
  445. cur += write_str(cur, end - cur, "\n");
  446. }
  447. cur += write_str(cur, end - cur, "-------------------------------\n");
  448. cur += write_str(cur, end - cur, "ETB Count: %d\n",
  449. inst->debug_count.etb);
  450. cur += write_str(cur, end - cur, "EBD Count: %d\n",
  451. inst->debug_count.ebd);
  452. cur += write_str(cur, end - cur, "FTB Count: %d\n",
  453. inst->debug_count.ftb);
  454. cur += write_str(cur, end - cur, "FBD Count: %d\n",
  455. inst->debug_count.fbd);
  456. publish_unreleased_reference(inst, &cur, end);
  457. len = simple_read_from_buffer(buf, count, ppos,
  458. dbuf, cur - dbuf);
  459. msm_vidc_vmem_free((void **)&dbuf);
  460. failed_alloc:
  461. put_inst(inst);
  462. return len;
  463. }
  464. static int inst_info_release(struct inode *inode, struct file *file)
  465. {
  466. d_vpr_l("Release inode ptr: %pK\n", inode->i_private);
  467. file->private_data = NULL;
  468. return 0;
  469. }
  470. static const struct file_operations inst_info_fops = {
  471. .open = inst_info_open,
  472. .read = inst_info_read,
  473. .release = inst_info_release,
  474. };
  475. struct dentry *msm_vidc_debugfs_init_inst(void *instance, struct dentry *parent)
  476. {
  477. struct dentry *dir = NULL, *info = NULL;
  478. char debugfs_name[MAX_DEBUGFS_NAME];
  479. struct core_inst_pair *idata = NULL;
  480. struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
  481. if (!inst) {
  482. d_vpr_e("%s: invalid params\n", __func__);
  483. goto exit;
  484. }
  485. snprintf(debugfs_name, MAX_DEBUGFS_NAME, "inst_%d", inst->session_id);
  486. if (msm_vidc_vmem_alloc(sizeof(struct core_inst_pair), (void **)&idata, __func__))
  487. goto exit;
  488. idata->core = inst->core;
  489. idata->inst = inst;
  490. dir = debugfs_create_dir(debugfs_name, parent);
  491. if (IS_ERR_OR_NULL(dir)) {
  492. dir = NULL;
  493. i_vpr_e(inst,
  494. "%s: Failed to create debugfs for msm_vidc\n",
  495. __func__);
  496. goto failed_create_dir;
  497. }
  498. info = debugfs_create_file("info", 0444, dir,
  499. idata, &inst_info_fops);
  500. if (IS_ERR_OR_NULL(info)) {
  501. i_vpr_e(inst, "%s: debugfs_create_file: fail\n",
  502. __func__);
  503. goto failed_create_file;
  504. }
  505. dir->d_inode->i_private = info->d_inode->i_private;
  506. inst->debug.pdata[FRAME_PROCESSING].sampling = true;
  507. return dir;
  508. failed_create_file:
  509. debugfs_remove_recursive(dir);
  510. dir = NULL;
  511. failed_create_dir:
  512. msm_vidc_vmem_free((void **)&idata);
  513. exit:
  514. return dir;
  515. }
  516. void msm_vidc_debugfs_deinit_inst(void *instance)
  517. {
  518. struct dentry *dentry = NULL;
  519. struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
  520. if (!inst || !inst->debugfs_root)
  521. return;
  522. dentry = inst->debugfs_root;
  523. if (dentry->d_inode) {
  524. i_vpr_l(inst, "%s: Destroy %pK\n",
  525. __func__, dentry->d_inode->i_private);
  526. msm_vidc_vmem_free(&dentry->d_inode->i_private);
  527. dentry->d_inode->i_private = NULL;
  528. }
  529. debugfs_remove_recursive(dentry);
  530. inst->debugfs_root = NULL;
  531. }
  532. void msm_vidc_debugfs_update(void *instance,
  533. enum msm_vidc_debugfs_event e)
  534. {
  535. struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
  536. struct msm_vidc_debug *d;
  537. char a[64] = "Frame processing";
  538. if (!inst) {
  539. d_vpr_e("%s: invalid params\n", __func__);
  540. return;
  541. }
  542. d = &inst->debug;
  543. switch (e) {
  544. case MSM_VIDC_DEBUGFS_EVENT_ETB:
  545. inst->debug_count.etb++;
  546. if (inst->debug_count.ebd &&
  547. inst->debug_count.ftb > inst->debug_count.fbd) {
  548. d->pdata[FRAME_PROCESSING].name[0] = '\0';
  549. tic(inst, FRAME_PROCESSING, a);
  550. }
  551. break;
  552. case MSM_VIDC_DEBUGFS_EVENT_EBD:
  553. inst->debug_count.ebd++;
  554. /*
  555. * Host needs to ensure FW atleast have 2 buffers available always
  556. * one for HW processing and another for fw processing in parallel
  557. * to avoid FW starving for buffers
  558. */
  559. if (inst->debug_count.etb < (inst->debug_count.ebd + 2)) {
  560. toc(inst, FRAME_PROCESSING);
  561. i_vpr_p(inst,
  562. "EBD: FW needs input buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  563. inst->debug_count.etb, inst->debug_count.ebd,
  564. inst->debug_count.ftb, inst->debug_count.fbd);
  565. }
  566. if (inst->debug_count.fbd &&
  567. inst->debug_count.ftb < (inst->debug_count.fbd + 2))
  568. i_vpr_p(inst,
  569. "EBD: FW needs output buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  570. inst->debug_count.etb, inst->debug_count.ebd,
  571. inst->debug_count.ftb, inst->debug_count.fbd);
  572. break;
  573. case MSM_VIDC_DEBUGFS_EVENT_FTB:
  574. inst->debug_count.ftb++;
  575. if (inst->debug_count.ebd &&
  576. inst->debug_count.etb > inst->debug_count.ebd) {
  577. d->pdata[FRAME_PROCESSING].name[0] = '\0';
  578. tic(inst, FRAME_PROCESSING, a);
  579. }
  580. break;
  581. case MSM_VIDC_DEBUGFS_EVENT_FBD:
  582. inst->debug_count.fbd++;
  583. inst->debug.samples++;
  584. /*
  585. * Host needs to ensure FW atleast have 2 buffers available always
  586. * one for HW processing and another for fw processing in parallel
  587. * to avoid FW starving for buffers
  588. */
  589. if (inst->debug_count.ftb < (inst->debug_count.fbd + 2)) {
  590. toc(inst, FRAME_PROCESSING);
  591. i_vpr_p(inst,
  592. "FBD: FW needs output buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  593. inst->debug_count.etb, inst->debug_count.ebd,
  594. inst->debug_count.ftb, inst->debug_count.fbd);
  595. }
  596. if (inst->debug_count.ebd &&
  597. inst->debug_count.etb < (inst->debug_count.ebd + 2))
  598. i_vpr_p(inst,
  599. "FBD: FW needs input buffers. Processed etb %llu ebd %llu ftb %llu fbd %llu\n",
  600. inst->debug_count.etb, inst->debug_count.ebd,
  601. inst->debug_count.ftb, inst->debug_count.fbd);
  602. break;
  603. default:
  604. i_vpr_e(inst, "invalid event in debugfs: %d\n", e);
  605. break;
  606. }
  607. }
  608. int msm_vidc_check_ratelimit(void)
  609. {
  610. static DEFINE_RATELIMIT_STATE(_rs,
  611. VIDC_DBG_SESSION_RATELIMIT_INTERVAL,
  612. VIDC_DBG_SESSION_RATELIMIT_BURST);
  613. return __ratelimit(&_rs);
  614. }