ivpu_debugfs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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_clear(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)
  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 ssize_t
  276. ivpu_reset_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  277. {
  278. struct ivpu_device *vdev = file->private_data;
  279. if (!size)
  280. return -EINVAL;
  281. if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
  282. return -ENODEV;
  283. if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COPY))
  284. return -ENODEV;
  285. return size;
  286. }
  287. static const struct file_operations ivpu_reset_engine_fops = {
  288. .owner = THIS_MODULE,
  289. .open = simple_open,
  290. .write = ivpu_reset_engine_fn,
  291. };
  292. static ssize_t
  293. ivpu_resume_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
  294. {
  295. struct ivpu_device *vdev = file->private_data;
  296. if (!size)
  297. return -EINVAL;
  298. if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
  299. return -ENODEV;
  300. if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COPY))
  301. return -ENODEV;
  302. return size;
  303. }
  304. static const struct file_operations ivpu_resume_engine_fops = {
  305. .owner = THIS_MODULE,
  306. .open = simple_open,
  307. .write = ivpu_resume_engine_fn,
  308. };
  309. static int dct_active_get(void *data, u64 *active_percent)
  310. {
  311. struct ivpu_device *vdev = data;
  312. *active_percent = vdev->pm->dct_active_percent;
  313. return 0;
  314. }
  315. static int dct_active_set(void *data, u64 active_percent)
  316. {
  317. struct ivpu_device *vdev = data;
  318. int ret;
  319. if (active_percent > 100)
  320. return -EINVAL;
  321. ret = ivpu_rpm_get(vdev);
  322. if (ret)
  323. return ret;
  324. if (active_percent)
  325. ret = ivpu_pm_dct_enable(vdev, active_percent);
  326. else
  327. ret = ivpu_pm_dct_disable(vdev);
  328. ivpu_rpm_put(vdev);
  329. return ret;
  330. }
  331. DEFINE_DEBUGFS_ATTRIBUTE(ivpu_dct_fops, dct_active_get, dct_active_set, "%llu\n");
  332. void ivpu_debugfs_init(struct ivpu_device *vdev)
  333. {
  334. struct dentry *debugfs_root = vdev->drm.debugfs_root;
  335. drm_debugfs_add_files(&vdev->drm, vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list));
  336. debugfs_create_file("force_recovery", 0200, debugfs_root, vdev,
  337. &ivpu_force_recovery_fops);
  338. debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev,
  339. &dvfs_mode_fops);
  340. debugfs_create_file("fw_dyndbg", 0200, debugfs_root, vdev,
  341. &fw_dyndbg_fops);
  342. debugfs_create_file("fw_log", 0644, debugfs_root, vdev,
  343. &fw_log_fops);
  344. debugfs_create_file("fw_trace_destination_mask", 0200, debugfs_root, vdev,
  345. &fw_trace_destination_mask_fops);
  346. debugfs_create_file("fw_trace_hw_comp_mask", 0200, debugfs_root, vdev,
  347. &fw_trace_hw_comp_mask_fops);
  348. debugfs_create_file("fw_trace_level", 0200, debugfs_root, vdev,
  349. &fw_trace_level_fops);
  350. debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
  351. &ivpu_reset_engine_fops);
  352. debugfs_create_file("resume_engine", 0200, debugfs_root, vdev,
  353. &ivpu_resume_engine_fops);
  354. if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX) {
  355. debugfs_create_file("fw_profiling_freq_drive", 0200,
  356. debugfs_root, vdev, &fw_profiling_freq_fops);
  357. debugfs_create_file("dct", 0644, debugfs_root, vdev, &ivpu_dct_fops);
  358. }
  359. }