1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-2023 Intel Corporation
6 #include <drm/drm_debugfs.h>
7 #include <drm/drm_file.h>
8 #include <drm/drm_print.h>
10 #include <uapi/drm/ivpu_accel.h>
12 #include "ivpu_debugfs.h"
15 #include "ivpu_fw_log.h"
18 #include "ivpu_jsm_msg.h"
21 static inline struct ivpu_device *seq_to_ivpu(struct seq_file *s)
23 struct drm_debugfs_entry *entry = s->private;
25 return to_ivpu_device(entry->dev);
28 static int bo_list_show(struct seq_file *s, void *v)
30 struct drm_printer p = drm_seq_file_printer(s);
31 struct ivpu_device *vdev = seq_to_ivpu(s);
33 ivpu_bo_list(&vdev->drm, &p);
38 static int fw_name_show(struct seq_file *s, void *v)
40 struct ivpu_device *vdev = seq_to_ivpu(s);
42 seq_printf(s, "%s\n", vdev->fw->name);
46 static int fw_trace_capability_show(struct seq_file *s, void *v)
48 struct ivpu_device *vdev = seq_to_ivpu(s);
49 u64 trace_hw_component_mask;
50 u32 trace_destination_mask;
53 ret = ivpu_jsm_trace_get_capability(vdev, &trace_destination_mask,
54 &trace_hw_component_mask);
57 "trace_destination_mask: %#18x\n"
58 "trace_hw_component_mask: %#18llx\n",
59 trace_destination_mask, trace_hw_component_mask);
64 static int fw_trace_config_show(struct seq_file *s, void *v)
66 struct ivpu_device *vdev = seq_to_ivpu(s);
68 * WA: VPU_JSM_MSG_TRACE_GET_CONFIG command is not working yet,
69 * so we use values from vdev->fw instead of calling ivpu_jsm_trace_get_config()
71 u32 trace_level = vdev->fw->trace_level;
72 u32 trace_destination_mask = vdev->fw->trace_destination_mask;
73 u64 trace_hw_component_mask = vdev->fw->trace_hw_component_mask;
76 "trace_level: %#18x\n"
77 "trace_destination_mask: %#18x\n"
78 "trace_hw_component_mask: %#18llx\n",
79 trace_level, trace_destination_mask, trace_hw_component_mask);
84 static int last_bootmode_show(struct seq_file *s, void *v)
86 struct ivpu_device *vdev = seq_to_ivpu(s);
88 seq_printf(s, "%s\n", (vdev->pm->is_warmboot) ? "warmboot" : "coldboot");
93 static int reset_counter_show(struct seq_file *s, void *v)
95 struct ivpu_device *vdev = seq_to_ivpu(s);
97 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_counter));
101 static int reset_pending_show(struct seq_file *s, void *v)
103 struct ivpu_device *vdev = seq_to_ivpu(s);
105 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_pending));
109 static const struct drm_debugfs_info vdev_debugfs_list[] = {
110 {"bo_list", bo_list_show, 0},
111 {"fw_name", fw_name_show, 0},
112 {"fw_trace_capability", fw_trace_capability_show, 0},
113 {"fw_trace_config", fw_trace_config_show, 0},
114 {"last_bootmode", last_bootmode_show, 0},
115 {"reset_counter", reset_counter_show, 0},
116 {"reset_pending", reset_pending_show, 0},
120 dvfs_mode_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
122 struct ivpu_device *vdev = file->private_data;
123 struct ivpu_fw_info *fw = vdev->fw;
127 ret = kstrtou32_from_user(user_buf, size, 0, &dvfs_mode);
131 fw->dvfs_mode = dvfs_mode;
133 ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
140 static const struct file_operations dvfs_mode_fops = {
141 .owner = THIS_MODULE,
143 .write = dvfs_mode_fops_write,
146 static int fw_log_show(struct seq_file *s, void *v)
148 struct ivpu_device *vdev = s->private;
149 struct drm_printer p = drm_seq_file_printer(s);
151 ivpu_fw_log_print(vdev, true, &p);
155 static int fw_log_fops_open(struct inode *inode, struct file *file)
157 return single_open(file, fw_log_show, inode->i_private);
161 fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
163 struct seq_file *s = file->private_data;
164 struct ivpu_device *vdev = s->private;
169 ivpu_fw_log_clear(vdev);
173 static const struct file_operations fw_log_fops = {
174 .owner = THIS_MODULE,
175 .open = fw_log_fops_open,
176 .write = fw_log_fops_write,
179 .release = single_release,
183 fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf,
184 size_t size, loff_t *pos)
186 struct ivpu_device *vdev = file->private_data;
190 ret = kstrtobool_from_user(user_buf, size, &enable);
194 ivpu_hw_profiling_freq_drive(vdev, enable);
196 ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
203 static const struct file_operations fw_profiling_freq_fops = {
204 .owner = THIS_MODULE,
206 .write = fw_profiling_freq_fops_write,
210 fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf,
211 size_t size, loff_t *pos)
213 struct ivpu_device *vdev = file->private_data;
214 struct ivpu_fw_info *fw = vdev->fw;
215 u32 trace_destination_mask;
218 ret = kstrtou32_from_user(user_buf, size, 0, &trace_destination_mask);
222 fw->trace_destination_mask = trace_destination_mask;
224 ivpu_jsm_trace_set_config(vdev, fw->trace_level, trace_destination_mask,
225 fw->trace_hw_component_mask);
230 static const struct file_operations fw_trace_destination_mask_fops = {
231 .owner = THIS_MODULE,
233 .write = fw_trace_destination_mask_fops_write,
237 fw_trace_hw_comp_mask_fops_write(struct file *file, const char __user *user_buf,
238 size_t size, loff_t *pos)
240 struct ivpu_device *vdev = file->private_data;
241 struct ivpu_fw_info *fw = vdev->fw;
242 u64 trace_hw_component_mask;
245 ret = kstrtou64_from_user(user_buf, size, 0, &trace_hw_component_mask);
249 fw->trace_hw_component_mask = trace_hw_component_mask;
251 ivpu_jsm_trace_set_config(vdev, fw->trace_level, fw->trace_destination_mask,
252 trace_hw_component_mask);
257 static const struct file_operations fw_trace_hw_comp_mask_fops = {
258 .owner = THIS_MODULE,
260 .write = fw_trace_hw_comp_mask_fops_write,
264 fw_trace_level_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
266 struct ivpu_device *vdev = file->private_data;
267 struct ivpu_fw_info *fw = vdev->fw;
271 ret = kstrtou32_from_user(user_buf, size, 0, &trace_level);
275 fw->trace_level = trace_level;
277 ivpu_jsm_trace_set_config(vdev, trace_level, fw->trace_destination_mask,
278 fw->trace_hw_component_mask);
283 static const struct file_operations fw_trace_level_fops = {
284 .owner = THIS_MODULE,
286 .write = fw_trace_level_fops_write,
290 ivpu_reset_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
292 struct ivpu_device *vdev = file->private_data;
297 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
299 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COPY))
306 ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
308 struct ivpu_device *vdev = file->private_data;
314 ret = ivpu_rpm_get(vdev);
318 ivpu_pm_trigger_recovery(vdev, "debugfs");
319 flush_work(&vdev->pm->recovery_work);
324 static const struct file_operations ivpu_force_recovery_fops = {
325 .owner = THIS_MODULE,
327 .write = ivpu_force_recovery_fn,
330 static const struct file_operations ivpu_reset_engine_fops = {
331 .owner = THIS_MODULE,
333 .write = ivpu_reset_engine_fn,
336 void ivpu_debugfs_init(struct ivpu_device *vdev)
338 struct dentry *debugfs_root = vdev->drm.debugfs_root;
340 drm_debugfs_add_files(&vdev->drm, vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list));
342 debugfs_create_file("force_recovery", 0200, debugfs_root, vdev,
343 &ivpu_force_recovery_fops);
345 debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev,
348 debugfs_create_file("fw_log", 0644, debugfs_root, vdev,
350 debugfs_create_file("fw_trace_destination_mask", 0200, debugfs_root, vdev,
351 &fw_trace_destination_mask_fops);
352 debugfs_create_file("fw_trace_hw_comp_mask", 0200, debugfs_root, vdev,
353 &fw_trace_hw_comp_mask_fops);
354 debugfs_create_file("fw_trace_level", 0200, debugfs_root, vdev,
355 &fw_trace_level_fops);
357 debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
358 &ivpu_reset_engine_fops);
360 if (ivpu_hw_gen(vdev) >= IVPU_HW_40XX)
361 debugfs_create_file("fw_profiling_freq_drive", 0200,
362 debugfs_root, vdev, &fw_profiling_freq_fops);