Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v6.11-rc3 450 lines 11 kB view raw
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (C) 2020-2024 Intel Corporation 4 */ 5 6#include <linux/debugfs.h> 7 8#include <drm/drm_debugfs.h> 9#include <drm/drm_file.h> 10#include <drm/drm_print.h> 11 12#include <uapi/drm/ivpu_accel.h> 13 14#include "ivpu_debugfs.h" 15#include "ivpu_drv.h" 16#include "ivpu_fw.h" 17#include "ivpu_fw_log.h" 18#include "ivpu_gem.h" 19#include "ivpu_hw.h" 20#include "ivpu_jsm_msg.h" 21#include "ivpu_pm.h" 22 23static inline struct ivpu_device *seq_to_ivpu(struct seq_file *s) 24{ 25 struct drm_debugfs_entry *entry = s->private; 26 27 return to_ivpu_device(entry->dev); 28} 29 30static int bo_list_show(struct seq_file *s, void *v) 31{ 32 struct drm_printer p = drm_seq_file_printer(s); 33 struct ivpu_device *vdev = seq_to_ivpu(s); 34 35 ivpu_bo_list(&vdev->drm, &p); 36 37 return 0; 38} 39 40static int fw_name_show(struct seq_file *s, void *v) 41{ 42 struct ivpu_device *vdev = seq_to_ivpu(s); 43 44 seq_printf(s, "%s\n", vdev->fw->name); 45 return 0; 46} 47 48static int fw_trace_capability_show(struct seq_file *s, void *v) 49{ 50 struct ivpu_device *vdev = seq_to_ivpu(s); 51 u64 trace_hw_component_mask; 52 u32 trace_destination_mask; 53 int ret; 54 55 ret = ivpu_jsm_trace_get_capability(vdev, &trace_destination_mask, 56 &trace_hw_component_mask); 57 if (!ret) { 58 seq_printf(s, 59 "trace_destination_mask: %#18x\n" 60 "trace_hw_component_mask: %#18llx\n", 61 trace_destination_mask, trace_hw_component_mask); 62 } 63 return 0; 64} 65 66static int fw_trace_config_show(struct seq_file *s, void *v) 67{ 68 struct ivpu_device *vdev = seq_to_ivpu(s); 69 /** 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() 72 */ 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; 76 77 seq_printf(s, 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); 82 83 return 0; 84} 85 86static int last_bootmode_show(struct seq_file *s, void *v) 87{ 88 struct ivpu_device *vdev = seq_to_ivpu(s); 89 90 seq_printf(s, "%s\n", (vdev->pm->is_warmboot) ? "warmboot" : "coldboot"); 91 92 return 0; 93} 94 95static int reset_counter_show(struct seq_file *s, void *v) 96{ 97 struct ivpu_device *vdev = seq_to_ivpu(s); 98 99 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_counter)); 100 return 0; 101} 102 103static int reset_pending_show(struct seq_file *s, void *v) 104{ 105 struct ivpu_device *vdev = seq_to_ivpu(s); 106 107 seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_pending)); 108 return 0; 109} 110 111static 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}, 119}; 120 121static ssize_t 122dvfs_mode_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 123{ 124 struct ivpu_device *vdev = file->private_data; 125 struct ivpu_fw_info *fw = vdev->fw; 126 u32 dvfs_mode; 127 int ret; 128 129 ret = kstrtou32_from_user(user_buf, size, 0, &dvfs_mode); 130 if (ret < 0) 131 return ret; 132 133 fw->dvfs_mode = dvfs_mode; 134 135 ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev)); 136 if (ret) 137 return ret; 138 139 return size; 140} 141 142static const struct file_operations dvfs_mode_fops = { 143 .owner = THIS_MODULE, 144 .open = simple_open, 145 .write = dvfs_mode_fops_write, 146}; 147 148static ssize_t 149fw_dyndbg_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 150{ 151 struct ivpu_device *vdev = file->private_data; 152 char buffer[VPU_DYNDBG_CMD_MAX_LEN] = {}; 153 int ret; 154 155 if (size >= VPU_DYNDBG_CMD_MAX_LEN) 156 return -EINVAL; 157 158 ret = strncpy_from_user(buffer, user_buf, size); 159 if (ret < 0) 160 return ret; 161 162 ivpu_jsm_dyndbg_control(vdev, buffer, size); 163 return size; 164} 165 166static const struct file_operations fw_dyndbg_fops = { 167 .owner = THIS_MODULE, 168 .open = simple_open, 169 .write = fw_dyndbg_fops_write, 170}; 171 172static int fw_log_show(struct seq_file *s, void *v) 173{ 174 struct ivpu_device *vdev = s->private; 175 struct drm_printer p = drm_seq_file_printer(s); 176 177 ivpu_fw_log_print(vdev, true, &p); 178 return 0; 179} 180 181static int fw_log_fops_open(struct inode *inode, struct file *file) 182{ 183 return single_open(file, fw_log_show, inode->i_private); 184} 185 186static ssize_t 187fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 188{ 189 struct seq_file *s = file->private_data; 190 struct ivpu_device *vdev = s->private; 191 192 if (!size) 193 return -EINVAL; 194 195 ivpu_fw_log_clear(vdev); 196 return size; 197} 198 199static const struct file_operations fw_log_fops = { 200 .owner = THIS_MODULE, 201 .open = fw_log_fops_open, 202 .write = fw_log_fops_write, 203 .read = seq_read, 204 .llseek = seq_lseek, 205 .release = single_release, 206}; 207 208static ssize_t 209fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf, 210 size_t size, loff_t *pos) 211{ 212 struct ivpu_device *vdev = file->private_data; 213 bool enable; 214 int ret; 215 216 ret = kstrtobool_from_user(user_buf, size, &enable); 217 if (ret < 0) 218 return ret; 219 220 ivpu_hw_profiling_freq_drive(vdev, enable); 221 222 ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev)); 223 if (ret) 224 return ret; 225 226 return size; 227} 228 229static const struct file_operations fw_profiling_freq_fops = { 230 .owner = THIS_MODULE, 231 .open = simple_open, 232 .write = fw_profiling_freq_fops_write, 233}; 234 235static ssize_t 236fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf, 237 size_t size, loff_t *pos) 238{ 239 struct ivpu_device *vdev = file->private_data; 240 struct ivpu_fw_info *fw = vdev->fw; 241 u32 trace_destination_mask; 242 int ret; 243 244 ret = kstrtou32_from_user(user_buf, size, 0, &trace_destination_mask); 245 if (ret < 0) 246 return ret; 247 248 fw->trace_destination_mask = trace_destination_mask; 249 250 ivpu_jsm_trace_set_config(vdev, fw->trace_level, trace_destination_mask, 251 fw->trace_hw_component_mask); 252 253 return size; 254} 255 256static const struct file_operations fw_trace_destination_mask_fops = { 257 .owner = THIS_MODULE, 258 .open = simple_open, 259 .write = fw_trace_destination_mask_fops_write, 260}; 261 262static ssize_t 263fw_trace_hw_comp_mask_fops_write(struct file *file, const char __user *user_buf, 264 size_t size, loff_t *pos) 265{ 266 struct ivpu_device *vdev = file->private_data; 267 struct ivpu_fw_info *fw = vdev->fw; 268 u64 trace_hw_component_mask; 269 int ret; 270 271 ret = kstrtou64_from_user(user_buf, size, 0, &trace_hw_component_mask); 272 if (ret < 0) 273 return ret; 274 275 fw->trace_hw_component_mask = trace_hw_component_mask; 276 277 ivpu_jsm_trace_set_config(vdev, fw->trace_level, fw->trace_destination_mask, 278 trace_hw_component_mask); 279 280 return size; 281} 282 283static const struct file_operations fw_trace_hw_comp_mask_fops = { 284 .owner = THIS_MODULE, 285 .open = simple_open, 286 .write = fw_trace_hw_comp_mask_fops_write, 287}; 288 289static ssize_t 290fw_trace_level_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 291{ 292 struct ivpu_device *vdev = file->private_data; 293 struct ivpu_fw_info *fw = vdev->fw; 294 u32 trace_level; 295 int ret; 296 297 ret = kstrtou32_from_user(user_buf, size, 0, &trace_level); 298 if (ret < 0) 299 return ret; 300 301 fw->trace_level = trace_level; 302 303 ivpu_jsm_trace_set_config(vdev, trace_level, fw->trace_destination_mask, 304 fw->trace_hw_component_mask); 305 306 return size; 307} 308 309static const struct file_operations fw_trace_level_fops = { 310 .owner = THIS_MODULE, 311 .open = simple_open, 312 .write = fw_trace_level_fops_write, 313}; 314 315static ssize_t 316ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 317{ 318 struct ivpu_device *vdev = file->private_data; 319 int ret; 320 321 if (!size) 322 return -EINVAL; 323 324 ret = ivpu_rpm_get(vdev); 325 if (ret) 326 return ret; 327 328 ivpu_pm_trigger_recovery(vdev, "debugfs"); 329 flush_work(&vdev->pm->recovery_work); 330 ivpu_rpm_put(vdev); 331 return size; 332} 333 334static const struct file_operations ivpu_force_recovery_fops = { 335 .owner = THIS_MODULE, 336 .open = simple_open, 337 .write = ivpu_force_recovery_fn, 338}; 339 340static ssize_t 341ivpu_reset_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 342{ 343 struct ivpu_device *vdev = file->private_data; 344 345 if (!size) 346 return -EINVAL; 347 348 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COMPUTE)) 349 return -ENODEV; 350 if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COPY)) 351 return -ENODEV; 352 353 return size; 354} 355 356static const struct file_operations ivpu_reset_engine_fops = { 357 .owner = THIS_MODULE, 358 .open = simple_open, 359 .write = ivpu_reset_engine_fn, 360}; 361 362static ssize_t 363ivpu_resume_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos) 364{ 365 struct ivpu_device *vdev = file->private_data; 366 367 if (!size) 368 return -EINVAL; 369 370 if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COMPUTE)) 371 return -ENODEV; 372 if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COPY)) 373 return -ENODEV; 374 375 return size; 376} 377 378static const struct file_operations ivpu_resume_engine_fops = { 379 .owner = THIS_MODULE, 380 .open = simple_open, 381 .write = ivpu_resume_engine_fn, 382}; 383 384static int dct_active_get(void *data, u64 *active_percent) 385{ 386 struct ivpu_device *vdev = data; 387 388 *active_percent = vdev->pm->dct_active_percent; 389 390 return 0; 391} 392 393static int dct_active_set(void *data, u64 active_percent) 394{ 395 struct ivpu_device *vdev = data; 396 int ret; 397 398 if (active_percent > 100) 399 return -EINVAL; 400 401 ret = ivpu_rpm_get(vdev); 402 if (ret) 403 return ret; 404 405 if (active_percent) 406 ret = ivpu_pm_dct_enable(vdev, active_percent); 407 else 408 ret = ivpu_pm_dct_disable(vdev); 409 410 ivpu_rpm_put(vdev); 411 412 return ret; 413} 414 415DEFINE_DEBUGFS_ATTRIBUTE(ivpu_dct_fops, dct_active_get, dct_active_set, "%llu\n"); 416 417void ivpu_debugfs_init(struct ivpu_device *vdev) 418{ 419 struct dentry *debugfs_root = vdev->drm.debugfs_root; 420 421 drm_debugfs_add_files(&vdev->drm, vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list)); 422 423 debugfs_create_file("force_recovery", 0200, debugfs_root, vdev, 424 &ivpu_force_recovery_fops); 425 426 debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev, 427 &dvfs_mode_fops); 428 429 debugfs_create_file("fw_dyndbg", 0200, debugfs_root, vdev, 430 &fw_dyndbg_fops); 431 debugfs_create_file("fw_log", 0644, debugfs_root, vdev, 432 &fw_log_fops); 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); 439 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); 444 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); 449 } 450}