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"
17 #include "ivpu_jsm_msg.h"
20 static int bo_list_show(struct seq_file *s, void *v)
22 struct drm_info_node *node = (struct drm_info_node *)s->private;
23 struct drm_printer p = drm_seq_file_printer(s);
25 ivpu_bo_list(node->minor->dev, &p);
30 static int fw_name_show(struct seq_file *s, void *v)
32 struct drm_info_node *node = (struct drm_info_node *)s->private;
33 struct ivpu_device *vdev = to_ivpu_device(node->minor->dev);
35 seq_printf(s, "%s\n", vdev->fw->name);
39 static int fw_trace_capability_show(struct seq_file *s, void *v)
41 struct drm_info_node *node = (struct drm_info_node *)s->private;
42 struct ivpu_device *vdev = to_ivpu_device(node->minor->dev);
43 u64 trace_hw_component_mask;
44 u32 trace_destination_mask;
47 ret = ivpu_jsm_trace_get_capability(vdev, &trace_destination_mask,
48 &trace_hw_component_mask);
51 "trace_destination_mask: %#18x\n"
52 "trace_hw_component_mask: %#18llx\n",
53 trace_destination_mask, trace_hw_component_mask);
58 static int fw_trace_config_show(struct seq_file *s, void *v)
60 struct drm_info_node *node = (struct drm_info_node *)s->private;
61 struct ivpu_device *vdev = to_ivpu_device(node->minor->dev);
63 * WA: VPU_JSM_MSG_TRACE_GET_CONFIG command is not working yet,
64 * so we use values from vdev->fw instead of calling ivpu_jsm_trace_get_config()
66 u32 trace_level = vdev->fw->trace_level;
67 u32 trace_destination_mask = vdev->fw->trace_destination_mask;
68 u64 trace_hw_component_mask = vdev->fw->trace_hw_component_mask;
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);
79 static int last_bootmode_show(struct seq_file *s, void *v)
81 struct drm_info_node *node = (struct drm_info_node *)s->private;
82 struct ivpu_device *vdev = to_ivpu_device(node->minor->dev);
84 seq_printf(s, "%s\n", (vdev->pm->is_warmboot) ? "warmboot" : "coldboot");
89 static int reset_counter_show(struct seq_file *s, void *v)
91 struct drm_info_node *node = (struct drm_info_node *)s->private;
92 struct ivpu_device *vdev = to_ivpu_device(node->minor->dev);
94 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_counter));
98 static int reset_pending_show(struct seq_file *s, void *v)
100 struct drm_info_node *node = (struct drm_info_node *)s->private;
101 struct ivpu_device *vdev = to_ivpu_device(node->minor->dev);
103 seq_printf(s, "%d\n", atomic_read(&vdev->pm->in_reset));
107 static const struct drm_info_list vdev_debugfs_list[] = {
108 {"bo_list", bo_list_show, 0},
109 {"fw_name", fw_name_show, 0},
110 {"fw_trace_capability", fw_trace_capability_show, 0},
111 {"fw_trace_config", fw_trace_config_show, 0},
112 {"last_bootmode", last_bootmode_show, 0},
113 {"reset_counter", reset_counter_show, 0},
114 {"reset_pending", reset_pending_show, 0},
117 static int fw_log_show(struct seq_file *s, void *v)
119 struct ivpu_device *vdev = s->private;
120 struct drm_printer p = drm_seq_file_printer(s);
122 ivpu_fw_log_print(vdev, true, &p);
126 static int fw_log_fops_open(struct inode *inode, struct file *file)
128 return single_open(file, fw_log_show, inode->i_private);
132 fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
134 struct seq_file *s = file->private_data;
135 struct ivpu_device *vdev = s->private;
140 ivpu_fw_log_clear(vdev);
144 static const struct file_operations fw_log_fops = {
145 .owner = THIS_MODULE,
146 .open = fw_log_fops_open,
147 .write = fw_log_fops_write,
150 .release = single_release,
154 fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf,
155 size_t size, loff_t *pos)
157 struct ivpu_device *vdev = file->private_data;
158 struct ivpu_fw_info *fw = vdev->fw;
159 u32 trace_destination_mask;
162 ret = kstrtou32_from_user(user_buf, size, 0, &trace_destination_mask);
166 fw->trace_destination_mask = trace_destination_mask;
168 ivpu_jsm_trace_set_config(vdev, fw->trace_level, trace_destination_mask,
169 fw->trace_hw_component_mask);
174 static const struct file_operations fw_trace_destination_mask_fops = {
175 .owner = THIS_MODULE,
177 .write = fw_trace_destination_mask_fops_write,
181 fw_trace_hw_comp_mask_fops_write(struct file *file, const char __user *user_buf,
182 size_t size, loff_t *pos)
184 struct ivpu_device *vdev = file->private_data;
185 struct ivpu_fw_info *fw = vdev->fw;
186 u64 trace_hw_component_mask;
189 ret = kstrtou64_from_user(user_buf, size, 0, &trace_hw_component_mask);
193 fw->trace_hw_component_mask = trace_hw_component_mask;
195 ivpu_jsm_trace_set_config(vdev, fw->trace_level, fw->trace_destination_mask,
196 trace_hw_component_mask);
201 static const struct file_operations fw_trace_hw_comp_mask_fops = {
202 .owner = THIS_MODULE,
204 .write = fw_trace_hw_comp_mask_fops_write,
208 fw_trace_level_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
210 struct ivpu_device *vdev = file->private_data;
211 struct ivpu_fw_info *fw = vdev->fw;
215 ret = kstrtou32_from_user(user_buf, size, 0, &trace_level);
219 fw->trace_level = trace_level;
221 ivpu_jsm_trace_set_config(vdev, trace_level, fw->trace_destination_mask,
222 fw->trace_hw_component_mask);
227 static const struct file_operations fw_trace_level_fops = {
228 .owner = THIS_MODULE,
230 .write = fw_trace_level_fops_write,
234 ivpu_reset_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
236 struct ivpu_device *vdev = file->private_data;
241 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
243 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COPY))
250 ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
252 struct ivpu_device *vdev = file->private_data;
257 ivpu_pm_schedule_recovery(vdev);
261 static const struct file_operations ivpu_force_recovery_fops = {
262 .owner = THIS_MODULE,
264 .write = ivpu_force_recovery_fn,
267 static const struct file_operations ivpu_reset_engine_fops = {
268 .owner = THIS_MODULE,
270 .write = ivpu_reset_engine_fn,
273 void ivpu_debugfs_init(struct drm_minor *minor)
275 struct ivpu_device *vdev = to_ivpu_device(minor->dev);
277 drm_debugfs_create_files(vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list),
278 minor->debugfs_root, minor);
280 debugfs_create_file("force_recovery", 0200, minor->debugfs_root, vdev,
281 &ivpu_force_recovery_fops);
283 debugfs_create_file("fw_log", 0644, minor->debugfs_root, vdev,
285 debugfs_create_file("fw_trace_destination_mask", 0200, minor->debugfs_root, vdev,
286 &fw_trace_destination_mask_fops);
287 debugfs_create_file("fw_trace_hw_comp_mask", 0200, minor->debugfs_root, vdev,
288 &fw_trace_hw_comp_mask_fops);
289 debugfs_create_file("fw_trace_level", 0200, minor->debugfs_root, vdev,
290 &fw_trace_level_fops);
292 debugfs_create_file("reset_engine", 0200, minor->debugfs_root, vdev,
293 &ivpu_reset_engine_fops);