ivpu_debugfs.c 13 KB

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