ivpu_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2020-2024 Intel Corporation
  4. */
  5. #include <linux/debugfs.h>
  6. #include <drm/drm_debugfs.h>
  7. #include <drm/drm_file.h>
  8. #include <drm/drm_print.h>
  9. #include <uapi/drm/ivpu_accel.h>
  10. #include "ivpu_debugfs.h"
  11. #include "ivpu_drv.h"
  12. #include "ivpu_fw.h"
  13. #include "ivpu_fw_log.h"
  14. #include "ivpu_gem.h"
  15. #include "ivpu_hw.h"
  16. #include "ivpu_jsm_msg.h"
  17. #include "ivpu_pm.h"
  18. static inline struct ivpu_device *seq_to_ivpu(struct seq_file *s)
  19. {
  20. struct drm_debugfs_entry *entry = s->private;
  21. return to_ivpu_device(entry->dev);
  22. }
  23. static int bo_list_show(struct seq_file *s, void *v)
  24. {
  25. struct drm_printer p = drm_seq_file_printer(s);
  26. struct ivpu_device *vdev = seq_to_ivpu(s);
  27. ivpu_bo_list(&vdev->drm, &p);
  28. return 0;
  29. }
  30. static int fw_name_show(struct seq_file *s, void *v)
  31. {
  32. struct ivpu_device *vdev = seq_to_ivpu(s);
  33. seq_printf(s, "%s\n", vdev->fw->name);
  34. return 0;
  35. }
  36. static int fw_trace_capability_show(struct seq_file *s, void *v)
  37. {
  38. struct ivpu_device *vdev = seq_to_ivpu(s);
  39. u64 trace_hw_component_mask;
  40. u32 trace_destination_mask;
  41. int ret;
  42. ret = ivpu_jsm_trace_get_capability(vdev, &trace_destination_mask,
  43. &trace_hw_component_mask);
  44. if (!ret) {
  45. seq_printf(s,
  46. "trace_destination_mask: %#18x\n"
  47. "trace_hw_component_mask: %#18llx\n",
  48. trace_destination_mask, trace_hw_component_mask);
  49. }
  50. return 0;
  51. }
  52. static int fw_trace_config_show(struct seq_file *s, void *v)
  53. {
  54. struct ivpu_device *vdev = seq_to_ivpu(s);
  55. /**
  56. * WA: VPU_JSM_MSG_TRACE_GET_CONFIG command is not working yet,
  57. * so we use values from vdev->fw instead of calling ivpu_jsm_trace_get_config()
  58. */
  59. u32 trace_level = vdev->fw->trace_level;
  60. u32 trace_destination_mask = vdev->fw->trace_destination_mask;
  61. u64 trace_hw_component_mask = vdev->fw->trace_hw_component_mask;
  62. seq_printf(s,
  63. "trace_level: %#18x\n"
  64. "trace_destination_mask: %#18x\n"
  65. "trace_hw_component_mask: %#18llx\n",
  66. trace_level, trace_destination_mask, trace_hw_component_mask);
  67. return 0;
  68. }
  69. static int last_bootmode_show(struct seq_file *s, void *v)
  70. {
  71. struct ivpu_device *vdev = seq_to_ivpu(s);
  72. seq_printf(s, "%s\n", (vdev->pm->is_warmboot) ? "warmboot" : "coldboot");
  73. return 0;
  74. }
  75. static int reset_counter_show(struct seq_file *s, void *v)
  76. {
  77. struct ivpu_device *vdev = seq_to_ivpu(s);
  78. seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_counter));
  79. return 0;
  80. }
  81. static int reset_pending_show(struct seq_file *s, void *v)
  82. {
  83. struct ivpu_device *vdev = seq_to_ivpu(s);
  84. seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_pending));
  85. return 0;
  86. }
  87. static int firewall_irq_counter_show(struct seq_file *s, void *v)
  88. {
  89. struct ivpu_device *vdev = seq_to_ivpu(s);
  90. seq_printf(s, "%d\n", atomic_read(&vdev->hw->firewall_irq_counter));
  91. return 0;
  92. }
  93. static const struct drm_debugfs_info vdev_debugfs_list[] = {
  94. {"bo_list", bo_list_show, 0},
  95. {"fw_name", fw_name_show, 0},
  96. {"fw_trace_capability", fw_trace_capability_show, 0},
  97. {"fw_trace_config", fw_trace_config_show, 0},
  98. {"last_bootmode", last_bootmode_show, 0},
  99. {"reset_counter", reset_counter_show, 0},
  100. {"reset_pending", reset_pending_show, 0},
  101. {"firewall_irq_counter", firewall_irq_counter_show, 0},
  102. };
  103. static ssize_t
  104. dvfs_mode_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  105. {
  106. struct ivpu_device *vdev = file->private_data;
  107. struct ivpu_fw_info *fw = vdev->fw;
  108. u32 dvfs_mode;
  109. int ret;
  110. ret = kstrtou32_from_user(user_buf, size, 0, &dvfs_mode);
  111. if (ret < 0)
  112. return ret;
  113. fw->dvfs_mode = dvfs_mode;
  114. ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
  115. if (ret)
  116. return ret;
  117. return size;
  118. }
  119. static const struct file_operations dvfs_mode_fops = {
  120. .owner = THIS_MODULE,
  121. .open = simple_open,
  122. .write = dvfs_mode_fops_write,
  123. };
  124. static ssize_t
  125. fw_dyndbg_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  126. {
  127. struct ivpu_device *vdev = file->private_data;
  128. char buffer[VPU_DYNDBG_CMD_MAX_LEN] = {};
  129. int ret;
  130. if (size >= VPU_DYNDBG_CMD_MAX_LEN)
  131. return -EINVAL;
  132. ret = strncpy_from_user(buffer, user_buf, size);
  133. if (ret < 0)
  134. return ret;
  135. ivpu_jsm_dyndbg_control(vdev, buffer, size);
  136. return size;
  137. }
  138. static const struct file_operations fw_dyndbg_fops = {
  139. .owner = THIS_MODULE,
  140. .open = simple_open,
  141. .write = fw_dyndbg_fops_write,
  142. };
  143. static int fw_log_show(struct seq_file *s, void *v)
  144. {
  145. struct ivpu_device *vdev = s->private;
  146. struct drm_printer p = drm_seq_file_printer(s);
  147. ivpu_fw_log_print(vdev, true, &p);
  148. return 0;
  149. }
  150. static int fw_log_fops_open(struct inode *inode, struct file *file)
  151. {
  152. return single_open(file, fw_log_show, inode->i_private);
  153. }
  154. static ssize_t
  155. fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  156. {
  157. struct seq_file *s = file->private_data;
  158. struct ivpu_device *vdev = s->private;
  159. if (!size)
  160. return -EINVAL;
  161. ivpu_fw_log_mark_read(vdev);
  162. return size;
  163. }
  164. static const struct file_operations fw_log_fops = {
  165. .owner = THIS_MODULE,
  166. .open = fw_log_fops_open,
  167. .write = fw_log_fops_write,
  168. .read = seq_read,
  169. .llseek = seq_lseek,
  170. .release = single_release,
  171. };
  172. static ssize_t
  173. fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf,
  174. size_t size, loff_t *pos)
  175. {
  176. struct ivpu_device *vdev = file->private_data;
  177. bool enable;
  178. int ret;
  179. ret = kstrtobool_from_user(user_buf, size, &enable);
  180. if (ret < 0)
  181. return ret;
  182. ivpu_hw_profiling_freq_drive(vdev, enable);
  183. ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
  184. if (ret)
  185. return ret;
  186. return size;
  187. }
  188. static const struct file_operations fw_profiling_freq_fops = {
  189. .owner = THIS_MODULE,
  190. .open = simple_open,
  191. .write = fw_profiling_freq_fops_write,
  192. };
  193. static ssize_t
  194. fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf,
  195. size_t size, loff_t *pos)
  196. {
  197. struct ivpu_device *vdev = file->private_data;
  198. struct ivpu_fw_info *fw = vdev->fw;
  199. u32 trace_destination_mask;
  200. int ret;
  201. ret = kstrtou32_from_user(user_buf, size, 0, &trace_destination_mask);
  202. if (ret < 0)
  203. return ret;
  204. fw->trace_destination_mask = trace_destination_mask;
  205. ivpu_jsm_trace_set_config(vdev, fw->trace_level, trace_destination_mask,
  206. fw->trace_hw_component_mask);
  207. return size;
  208. }
  209. static const struct file_operations fw_trace_destination_mask_fops = {
  210. .owner = THIS_MODULE,
  211. .open = simple_open,
  212. .write = fw_trace_destination_mask_fops_write,
  213. };
  214. static ssize_t
  215. fw_trace_hw_comp_mask_fops_write(struct file *file, const char __user *user_buf,
  216. size_t size, loff_t *pos)
  217. {
  218. struct ivpu_device *vdev = file->private_data;
  219. struct ivpu_fw_info *fw = vdev->fw;
  220. u64 trace_hw_component_mask;
  221. int ret;
  222. ret = kstrtou64_from_user(user_buf, size, 0, &trace_hw_component_mask);
  223. if (ret < 0)
  224. return ret;
  225. fw->trace_hw_component_mask = trace_hw_component_mask;
  226. ivpu_jsm_trace_set_config(vdev, fw->trace_level, fw->trace_destination_mask,
  227. trace_hw_component_mask);
  228. return size;
  229. }
  230. static const struct file_operations fw_trace_hw_comp_mask_fops = {
  231. .owner = THIS_MODULE,
  232. .open = simple_open,
  233. .write = fw_trace_hw_comp_mask_fops_write,
  234. };
  235. static ssize_t
  236. fw_trace_level_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  237. {
  238. struct ivpu_device *vdev = file->private_data;
  239. struct ivpu_fw_info *fw = vdev->fw;
  240. u32 trace_level;
  241. int ret;
  242. ret = kstrtou32_from_user(user_buf, size, 0, &trace_level);
  243. if (ret < 0)
  244. return ret;
  245. fw->trace_level = trace_level;
  246. ivpu_jsm_trace_set_config(vdev, trace_level, fw->trace_destination_mask,
  247. fw->trace_hw_component_mask);
  248. return size;
  249. }
  250. static const struct file_operations fw_trace_level_fops = {
  251. .owner = THIS_MODULE,
  252. .open = simple_open,
  253. .write = fw_trace_level_fops_write,
  254. };
  255. static ssize_t
  256. ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  257. {
  258. struct ivpu_device *vdev = file->private_data;
  259. int ret;
  260. if (!size)
  261. return -EINVAL;
  262. ret = ivpu_rpm_get(vdev);
  263. if (ret < 0)
  264. return ret;
  265. ivpu_pm_trigger_recovery(vdev, "debugfs");
  266. flush_work(&vdev->pm->recovery_work);
  267. ivpu_rpm_put(vdev);
  268. return size;
  269. }
  270. static const struct file_operations ivpu_force_recovery_fops = {
  271. .owner = THIS_MODULE,
  272. .open = simple_open,
  273. .write = ivpu_force_recovery_fn,
  274. };
  275. static int ivpu_reset_engine_fn(void *data, u64 val)
  276. {
  277. struct ivpu_device *vdev = (struct ivpu_device *)data;
  278. return ivpu_jsm_reset_engine(vdev, (u32)val);
  279. }
  280. DEFINE_DEBUGFS_ATTRIBUTE(ivpu_reset_engine_fops, NULL, ivpu_reset_engine_fn, "0x%02llx\n");
  281. static int ivpu_resume_engine_fn(void *data, u64 val)
  282. {
  283. struct ivpu_device *vdev = (struct ivpu_device *)data;
  284. return ivpu_jsm_hws_resume_engine(vdev, (u32)val);
  285. }
  286. DEFINE_DEBUGFS_ATTRIBUTE(ivpu_resume_engine_fops, NULL, ivpu_resume_engine_fn, "0x%02llx\n");
  287. static int dct_active_get(void *data, u64 *active_percent)
  288. {
  289. struct ivpu_device *vdev = data;
  290. *active_percent = vdev->pm->dct_active_percent;
  291. return 0;
  292. }
  293. static int dct_active_set(void *data, u64 active_percent)
  294. {
  295. struct ivpu_device *vdev = data;
  296. int ret;
  297. if (active_percent > 100)
  298. return -EINVAL;
  299. ret = ivpu_rpm_get(vdev);
  300. if (ret < 0)
  301. return ret;
  302. if (active_percent)
  303. ret = ivpu_pm_dct_enable(vdev, active_percent);
  304. else
  305. ret = ivpu_pm_dct_disable(vdev);
  306. ivpu_rpm_put(vdev);
  307. return ret;
  308. }
  309. DEFINE_DEBUGFS_ATTRIBUTE(ivpu_dct_fops, dct_active_get, dct_active_set, "%llu\n");
  310. static int priority_bands_show(struct seq_file *s, void *v)
  311. {
  312. struct ivpu_device *vdev = s->private;
  313. struct ivpu_hw_info *hw = vdev->hw;
  314. for (int band = VPU_JOB_SCHEDULING_PRIORITY_BAND_IDLE;
  315. band < VPU_JOB_SCHEDULING_PRIORITY_BAND_COUNT; band++) {
  316. switch (band) {
  317. case VPU_JOB_SCHEDULING_PRIORITY_BAND_IDLE:
  318. seq_puts(s, "Idle: ");
  319. break;
  320. case VPU_JOB_SCHEDULING_PRIORITY_BAND_NORMAL:
  321. seq_puts(s, "Normal: ");
  322. break;
  323. case VPU_JOB_SCHEDULING_PRIORITY_BAND_FOCUS:
  324. seq_puts(s, "Focus: ");
  325. break;
  326. case VPU_JOB_SCHEDULING_PRIORITY_BAND_REALTIME:
  327. seq_puts(s, "Realtime: ");
  328. break;
  329. }
  330. seq_printf(s, "grace_period %9u process_grace_period %9u process_quantum %9u\n",
  331. hw->hws.grace_period[band], hw->hws.process_grace_period[band],
  332. hw->hws.process_quantum[band]);
  333. }
  334. return 0;
  335. }
  336. static int priority_bands_fops_open(struct inode *inode, struct file *file)
  337. {
  338. return single_open(file, priority_bands_show, inode->i_private);
  339. }
  340. static ssize_t
  341. priority_bands_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  342. {
  343. struct seq_file *s = file->private_data;
  344. struct ivpu_device *vdev = s->private;
  345. char buf[64];
  346. u32 grace_period;
  347. u32 process_grace_period;
  348. u32 process_quantum;
  349. u32 band;
  350. int ret;
  351. if (size >= sizeof(buf))
  352. return -EINVAL;
  353. ret = simple_write_to_buffer(buf, sizeof(buf) - 1, pos, user_buf, size);
  354. if (ret < 0)
  355. return ret;
  356. buf[size] = '\0';
  357. ret = sscanf(buf, "%u %u %u %u", &band, &grace_period, &process_grace_period,
  358. &process_quantum);
  359. if (ret != 4)
  360. return -EINVAL;
  361. if (band >= VPU_JOB_SCHEDULING_PRIORITY_BAND_COUNT)
  362. return -EINVAL;
  363. vdev->hw->hws.grace_period[band] = grace_period;
  364. vdev->hw->hws.process_grace_period[band] = process_grace_period;
  365. vdev->hw->hws.process_quantum[band] = process_quantum;
  366. return size;
  367. }
  368. static const struct file_operations ivpu_hws_priority_bands_fops = {
  369. .owner = THIS_MODULE,
  370. .open = priority_bands_fops_open,
  371. .write = priority_bands_fops_write,
  372. .read = seq_read,
  373. .llseek = seq_lseek,
  374. .release = single_release,
  375. };
  376. void ivpu_debugfs_init(struct ivpu_device *vdev)
  377. {
  378. struct dentry *debugfs_root = vdev->drm.debugfs_root;
  379. drm_debugfs_add_files(&vdev->drm, vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list));
  380. debugfs_create_file("force_recovery", 0200, debugfs_root, vdev,
  381. &ivpu_force_recovery_fops);
  382. debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev,
  383. &dvfs_mode_fops);
  384. debugfs_create_file("fw_dyndbg", 0200, debugfs_root, vdev,
  385. &fw_dyndbg_fops);
  386. debugfs_create_file("fw_log", 0644, debugfs_root, vdev,
  387. &fw_log_fops);
  388. debugfs_create_file("fw_trace_destination_mask", 0200, debugfs_root, vdev,
  389. &fw_trace_destination_mask_fops);
  390. debugfs_create_file("fw_trace_hw_comp_mask", 0200, debugfs_root, vdev,
  391. &fw_trace_hw_comp_mask_fops);
  392. debugfs_create_file("fw_trace_level", 0200, debugfs_root, vdev,
  393. &fw_trace_level_fops);
  394. debugfs_create_file("hws_priority_bands", 0200, debugfs_root, vdev,
  395. &ivpu_hws_priority_bands_fops);
  396. debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
  397. &ivpu_reset_engine_fops);
  398. debugfs_create_file("resume_engine", 0200, debugfs_root, vdev,
  399. &ivpu_resume_engine_fops);
  400. if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX) {
  401. debugfs_create_file("fw_profiling_freq_drive", 0200,
  402. debugfs_root, vdev, &fw_profiling_freq_fops);
  403. debugfs_create_file("dct", 0644, debugfs_root, vdev, &ivpu_dct_fops);
  404. }
  405. }