1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-2024 Intel Corporation
6 #include <linux/debugfs.h>
8 #include <drm/drm_debugfs.h>
9 #include <drm/drm_file.h>
10 #include <drm/drm_print.h>
12 #include <uapi/drm/ivpu_accel.h>
14 #include "ivpu_debugfs.h"
17 #include "ivpu_fw_log.h"
20 #include "ivpu_jsm_msg.h"
23 static inline struct ivpu_device *seq_to_ivpu(struct seq_file *s)
25 struct drm_debugfs_entry *entry = s->private;
27 return to_ivpu_device(entry->dev);
30 static int bo_list_show(struct seq_file *s, void *v)
32 struct drm_printer p = drm_seq_file_printer(s);
33 struct ivpu_device *vdev = seq_to_ivpu(s);
35 ivpu_bo_list(&vdev->drm, &p);
40 static int fw_name_show(struct seq_file *s, void *v)
42 struct ivpu_device *vdev = seq_to_ivpu(s);
44 seq_printf(s, "%s\n", vdev->fw->name);
48 static int fw_trace_capability_show(struct seq_file *s, void *v)
50 struct ivpu_device *vdev = seq_to_ivpu(s);
51 u64 trace_hw_component_mask;
52 u32 trace_destination_mask;
55 ret = ivpu_jsm_trace_get_capability(vdev, &trace_destination_mask,
56 &trace_hw_component_mask);
59 "trace_destination_mask: %#18x\n"
60 "trace_hw_component_mask: %#18llx\n",
61 trace_destination_mask, trace_hw_component_mask);
66 static int fw_trace_config_show(struct seq_file *s, void *v)
68 struct ivpu_device *vdev = seq_to_ivpu(s);
70 * WA: VPU_JSM_MSG_TRACE_GET_CONFIG command is not working yet,
71 * so we use values from vdev->fw instead of calling ivpu_jsm_trace_get_config()
73 u32 trace_level = vdev->fw->trace_level;
74 u32 trace_destination_mask = vdev->fw->trace_destination_mask;
75 u64 trace_hw_component_mask = vdev->fw->trace_hw_component_mask;
78 "trace_level: %#18x\n"
79 "trace_destination_mask: %#18x\n"
80 "trace_hw_component_mask: %#18llx\n",
81 trace_level, trace_destination_mask, trace_hw_component_mask);
86 static int last_bootmode_show(struct seq_file *s, void *v)
88 struct ivpu_device *vdev = seq_to_ivpu(s);
90 seq_printf(s, "%s\n", (vdev->pm->is_warmboot) ? "warmboot" : "coldboot");
95 static int reset_counter_show(struct seq_file *s, void *v)
97 struct ivpu_device *vdev = seq_to_ivpu(s);
99 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_counter));
103 static int reset_pending_show(struct seq_file *s, void *v)
105 struct ivpu_device *vdev = seq_to_ivpu(s);
107 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_pending));
111 static const struct drm_debugfs_info vdev_debugfs_list[] = {
112 {"bo_list", bo_list_show, 0},
113 {"fw_name", fw_name_show, 0},
114 {"fw_trace_capability", fw_trace_capability_show, 0},
115 {"fw_trace_config", fw_trace_config_show, 0},
116 {"last_bootmode", last_bootmode_show, 0},
117 {"reset_counter", reset_counter_show, 0},
118 {"reset_pending", reset_pending_show, 0},
122 dvfs_mode_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
124 struct ivpu_device *vdev = file->private_data;
125 struct ivpu_fw_info *fw = vdev->fw;
129 ret = kstrtou32_from_user(user_buf, size, 0, &dvfs_mode);
133 fw->dvfs_mode = dvfs_mode;
135 ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
142 static const struct file_operations dvfs_mode_fops = {
143 .owner = THIS_MODULE,
145 .write = dvfs_mode_fops_write,
149 fw_dyndbg_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
151 struct ivpu_device *vdev = file->private_data;
152 char buffer[VPU_DYNDBG_CMD_MAX_LEN] = {};
155 if (size >= VPU_DYNDBG_CMD_MAX_LEN)
158 ret = strncpy_from_user(buffer, user_buf, size);
162 ivpu_jsm_dyndbg_control(vdev, buffer, size);
166 static const struct file_operations fw_dyndbg_fops = {
167 .owner = THIS_MODULE,
169 .write = fw_dyndbg_fops_write,
172 static int fw_log_show(struct seq_file *s, void *v)
174 struct ivpu_device *vdev = s->private;
175 struct drm_printer p = drm_seq_file_printer(s);
177 ivpu_fw_log_print(vdev, true, &p);
181 static int fw_log_fops_open(struct inode *inode, struct file *file)
183 return single_open(file, fw_log_show, inode->i_private);
187 fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
189 struct seq_file *s = file->private_data;
190 struct ivpu_device *vdev = s->private;
195 ivpu_fw_log_clear(vdev);
199 static const struct file_operations fw_log_fops = {
200 .owner = THIS_MODULE,
201 .open = fw_log_fops_open,
202 .write = fw_log_fops_write,
205 .release = single_release,
209 fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf,
210 size_t size, loff_t *pos)
212 struct ivpu_device *vdev = file->private_data;
216 ret = kstrtobool_from_user(user_buf, size, &enable);
220 ivpu_hw_profiling_freq_drive(vdev, enable);
222 ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
229 static const struct file_operations fw_profiling_freq_fops = {
230 .owner = THIS_MODULE,
232 .write = fw_profiling_freq_fops_write,
236 fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf,
237 size_t size, loff_t *pos)
239 struct ivpu_device *vdev = file->private_data;
240 struct ivpu_fw_info *fw = vdev->fw;
241 u32 trace_destination_mask;
244 ret = kstrtou32_from_user(user_buf, size, 0, &trace_destination_mask);
248 fw->trace_destination_mask = trace_destination_mask;
250 ivpu_jsm_trace_set_config(vdev, fw->trace_level, trace_destination_mask,
251 fw->trace_hw_component_mask);
256 static const struct file_operations fw_trace_destination_mask_fops = {
257 .owner = THIS_MODULE,
259 .write = fw_trace_destination_mask_fops_write,
263 fw_trace_hw_comp_mask_fops_write(struct file *file, const char __user *user_buf,
264 size_t size, loff_t *pos)
266 struct ivpu_device *vdev = file->private_data;
267 struct ivpu_fw_info *fw = vdev->fw;
268 u64 trace_hw_component_mask;
271 ret = kstrtou64_from_user(user_buf, size, 0, &trace_hw_component_mask);
275 fw->trace_hw_component_mask = trace_hw_component_mask;
277 ivpu_jsm_trace_set_config(vdev, fw->trace_level, fw->trace_destination_mask,
278 trace_hw_component_mask);
283 static const struct file_operations fw_trace_hw_comp_mask_fops = {
284 .owner = THIS_MODULE,
286 .write = fw_trace_hw_comp_mask_fops_write,
290 fw_trace_level_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
292 struct ivpu_device *vdev = file->private_data;
293 struct ivpu_fw_info *fw = vdev->fw;
297 ret = kstrtou32_from_user(user_buf, size, 0, &trace_level);
301 fw->trace_level = trace_level;
303 ivpu_jsm_trace_set_config(vdev, trace_level, fw->trace_destination_mask,
304 fw->trace_hw_component_mask);
309 static const struct file_operations fw_trace_level_fops = {
310 .owner = THIS_MODULE,
312 .write = fw_trace_level_fops_write,
316 ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
318 struct ivpu_device *vdev = file->private_data;
324 ret = ivpu_rpm_get(vdev);
328 ivpu_pm_trigger_recovery(vdev, "debugfs");
329 flush_work(&vdev->pm->recovery_work);
334 static const struct file_operations ivpu_force_recovery_fops = {
335 .owner = THIS_MODULE,
337 .write = ivpu_force_recovery_fn,
341 ivpu_reset_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
343 struct ivpu_device *vdev = file->private_data;
348 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
350 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COPY))
356 static const struct file_operations ivpu_reset_engine_fops = {
357 .owner = THIS_MODULE,
359 .write = ivpu_reset_engine_fn,
363 ivpu_resume_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
365 struct ivpu_device *vdev = file->private_data;
370 if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
372 if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COPY))
378 static const struct file_operations ivpu_resume_engine_fops = {
379 .owner = THIS_MODULE,
381 .write = ivpu_resume_engine_fn,
384 static int dct_active_get(void *data, u64 *active_percent)
386 struct ivpu_device *vdev = data;
388 *active_percent = vdev->pm->dct_active_percent;
393 static int dct_active_set(void *data, u64 active_percent)
395 struct ivpu_device *vdev = data;
398 if (active_percent > 100)
401 ret = ivpu_rpm_get(vdev);
406 ret = ivpu_pm_dct_enable(vdev, active_percent);
408 ret = ivpu_pm_dct_disable(vdev);
415 DEFINE_DEBUGFS_ATTRIBUTE(ivpu_dct_fops, dct_active_get, dct_active_set, "%llu\n");
417 void ivpu_debugfs_init(struct ivpu_device *vdev)
419 struct dentry *debugfs_root = vdev->drm.debugfs_root;
421 drm_debugfs_add_files(&vdev->drm, vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list));
423 debugfs_create_file("force_recovery", 0200, debugfs_root, vdev,
424 &ivpu_force_recovery_fops);
426 debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev,
429 debugfs_create_file("fw_dyndbg", 0200, debugfs_root, vdev,
431 debugfs_create_file("fw_log", 0644, debugfs_root, vdev,
433 debugfs_create_file("fw_trace_destination_mask", 0200, debugfs_root, vdev,
434 &fw_trace_destination_mask_fops);
435 debugfs_create_file("fw_trace_hw_comp_mask", 0200, debugfs_root, vdev,
436 &fw_trace_hw_comp_mask_fops);
437 debugfs_create_file("fw_trace_level", 0200, debugfs_root, vdev,
438 &fw_trace_level_fops);
440 debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
441 &ivpu_reset_engine_fops);
442 debugfs_create_file("resume_engine", 0200, debugfs_root, vdev,
443 &ivpu_resume_engine_fops);
445 if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX) {
446 debugfs_create_file("fw_profiling_freq_drive", 0200,
447 debugfs_root, vdev, &fw_profiling_freq_fops);
448 debugfs_create_file("dct", 0644, debugfs_root, vdev, &ivpu_dct_fops);