| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (C) 2020-2024 Intel Corporation
- */
- #include <linux/debugfs.h>
- #include <drm/drm_debugfs.h>
- #include <drm/drm_file.h>
- #include <drm/drm_print.h>
- #include <uapi/drm/ivpu_accel.h>
- #include "ivpu_debugfs.h"
- #include "ivpu_drv.h"
- #include "ivpu_fw.h"
- #include "ivpu_fw_log.h"
- #include "ivpu_gem.h"
- #include "ivpu_hw.h"
- #include "ivpu_jsm_msg.h"
- #include "ivpu_pm.h"
- static inline struct ivpu_device *seq_to_ivpu(struct seq_file *s)
- {
- struct drm_debugfs_entry *entry = s->private;
- return to_ivpu_device(entry->dev);
- }
- static int bo_list_show(struct seq_file *s, void *v)
- {
- struct drm_printer p = drm_seq_file_printer(s);
- struct ivpu_device *vdev = seq_to_ivpu(s);
- ivpu_bo_list(&vdev->drm, &p);
- return 0;
- }
- static int fw_name_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- seq_printf(s, "%s\n", vdev->fw->name);
- return 0;
- }
- static int fw_trace_capability_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- u64 trace_hw_component_mask;
- u32 trace_destination_mask;
- int ret;
- ret = ivpu_jsm_trace_get_capability(vdev, &trace_destination_mask,
- &trace_hw_component_mask);
- if (!ret) {
- seq_printf(s,
- "trace_destination_mask: %#18x\n"
- "trace_hw_component_mask: %#18llx\n",
- trace_destination_mask, trace_hw_component_mask);
- }
- return 0;
- }
- static int fw_trace_config_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- /**
- * WA: VPU_JSM_MSG_TRACE_GET_CONFIG command is not working yet,
- * so we use values from vdev->fw instead of calling ivpu_jsm_trace_get_config()
- */
- u32 trace_level = vdev->fw->trace_level;
- u32 trace_destination_mask = vdev->fw->trace_destination_mask;
- u64 trace_hw_component_mask = vdev->fw->trace_hw_component_mask;
- seq_printf(s,
- "trace_level: %#18x\n"
- "trace_destination_mask: %#18x\n"
- "trace_hw_component_mask: %#18llx\n",
- trace_level, trace_destination_mask, trace_hw_component_mask);
- return 0;
- }
- static int last_bootmode_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- seq_printf(s, "%s\n", (vdev->pm->is_warmboot) ? "warmboot" : "coldboot");
- return 0;
- }
- static int reset_counter_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_counter));
- return 0;
- }
- static int reset_pending_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- seq_printf(s, "%d\n", atomic_read(&vdev->pm->reset_pending));
- return 0;
- }
- static int firewall_irq_counter_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = seq_to_ivpu(s);
- seq_printf(s, "%d\n", atomic_read(&vdev->hw->firewall_irq_counter));
- return 0;
- }
- static const struct drm_debugfs_info vdev_debugfs_list[] = {
- {"bo_list", bo_list_show, 0},
- {"fw_name", fw_name_show, 0},
- {"fw_trace_capability", fw_trace_capability_show, 0},
- {"fw_trace_config", fw_trace_config_show, 0},
- {"last_bootmode", last_bootmode_show, 0},
- {"reset_counter", reset_counter_show, 0},
- {"reset_pending", reset_pending_show, 0},
- {"firewall_irq_counter", firewall_irq_counter_show, 0},
- };
- static ssize_t
- dvfs_mode_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- struct ivpu_fw_info *fw = vdev->fw;
- u32 dvfs_mode;
- int ret;
- ret = kstrtou32_from_user(user_buf, size, 0, &dvfs_mode);
- if (ret < 0)
- return ret;
- fw->dvfs_mode = dvfs_mode;
- ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
- if (ret)
- return ret;
- return size;
- }
- static const struct file_operations dvfs_mode_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = dvfs_mode_fops_write,
- };
- static ssize_t
- fw_dyndbg_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- char buffer[VPU_DYNDBG_CMD_MAX_LEN] = {};
- int ret;
- if (size >= VPU_DYNDBG_CMD_MAX_LEN)
- return -EINVAL;
- ret = strncpy_from_user(buffer, user_buf, size);
- if (ret < 0)
- return ret;
- ivpu_jsm_dyndbg_control(vdev, buffer, size);
- return size;
- }
- static const struct file_operations fw_dyndbg_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = fw_dyndbg_fops_write,
- };
- static int fw_log_show(struct seq_file *s, void *v)
- {
- struct ivpu_device *vdev = s->private;
- struct drm_printer p = drm_seq_file_printer(s);
- ivpu_fw_log_print(vdev, true, &p);
- return 0;
- }
- static int fw_log_fops_open(struct inode *inode, struct file *file)
- {
- return single_open(file, fw_log_show, inode->i_private);
- }
- static ssize_t
- fw_log_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct seq_file *s = file->private_data;
- struct ivpu_device *vdev = s->private;
- if (!size)
- return -EINVAL;
- ivpu_fw_log_clear(vdev);
- return size;
- }
- static const struct file_operations fw_log_fops = {
- .owner = THIS_MODULE,
- .open = fw_log_fops_open,
- .write = fw_log_fops_write,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
- };
- static ssize_t
- fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf,
- size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- bool enable;
- int ret;
- ret = kstrtobool_from_user(user_buf, size, &enable);
- if (ret < 0)
- return ret;
- ivpu_hw_profiling_freq_drive(vdev, enable);
- ret = pci_try_reset_function(to_pci_dev(vdev->drm.dev));
- if (ret)
- return ret;
- return size;
- }
- static const struct file_operations fw_profiling_freq_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = fw_profiling_freq_fops_write,
- };
- static ssize_t
- fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf,
- size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- struct ivpu_fw_info *fw = vdev->fw;
- u32 trace_destination_mask;
- int ret;
- ret = kstrtou32_from_user(user_buf, size, 0, &trace_destination_mask);
- if (ret < 0)
- return ret;
- fw->trace_destination_mask = trace_destination_mask;
- ivpu_jsm_trace_set_config(vdev, fw->trace_level, trace_destination_mask,
- fw->trace_hw_component_mask);
- return size;
- }
- static const struct file_operations fw_trace_destination_mask_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = fw_trace_destination_mask_fops_write,
- };
- static ssize_t
- fw_trace_hw_comp_mask_fops_write(struct file *file, const char __user *user_buf,
- size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- struct ivpu_fw_info *fw = vdev->fw;
- u64 trace_hw_component_mask;
- int ret;
- ret = kstrtou64_from_user(user_buf, size, 0, &trace_hw_component_mask);
- if (ret < 0)
- return ret;
- fw->trace_hw_component_mask = trace_hw_component_mask;
- ivpu_jsm_trace_set_config(vdev, fw->trace_level, fw->trace_destination_mask,
- trace_hw_component_mask);
- return size;
- }
- static const struct file_operations fw_trace_hw_comp_mask_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = fw_trace_hw_comp_mask_fops_write,
- };
- static ssize_t
- fw_trace_level_fops_write(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- struct ivpu_fw_info *fw = vdev->fw;
- u32 trace_level;
- int ret;
- ret = kstrtou32_from_user(user_buf, size, 0, &trace_level);
- if (ret < 0)
- return ret;
- fw->trace_level = trace_level;
- ivpu_jsm_trace_set_config(vdev, trace_level, fw->trace_destination_mask,
- fw->trace_hw_component_mask);
- return size;
- }
- static const struct file_operations fw_trace_level_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = fw_trace_level_fops_write,
- };
- static ssize_t
- ivpu_force_recovery_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- int ret;
- if (!size)
- return -EINVAL;
- ret = ivpu_rpm_get(vdev);
- if (ret)
- return ret;
- ivpu_pm_trigger_recovery(vdev, "debugfs");
- flush_work(&vdev->pm->recovery_work);
- ivpu_rpm_put(vdev);
- return size;
- }
- static const struct file_operations ivpu_force_recovery_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = ivpu_force_recovery_fn,
- };
- static ssize_t
- ivpu_reset_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- if (!size)
- return -EINVAL;
- if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
- return -ENODEV;
- if (ivpu_jsm_reset_engine(vdev, DRM_IVPU_ENGINE_COPY))
- return -ENODEV;
- return size;
- }
- static const struct file_operations ivpu_reset_engine_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = ivpu_reset_engine_fn,
- };
- static ssize_t
- ivpu_resume_engine_fn(struct file *file, const char __user *user_buf, size_t size, loff_t *pos)
- {
- struct ivpu_device *vdev = file->private_data;
- if (!size)
- return -EINVAL;
- if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COMPUTE))
- return -ENODEV;
- if (ivpu_jsm_hws_resume_engine(vdev, DRM_IVPU_ENGINE_COPY))
- return -ENODEV;
- return size;
- }
- static const struct file_operations ivpu_resume_engine_fops = {
- .owner = THIS_MODULE,
- .open = simple_open,
- .write = ivpu_resume_engine_fn,
- };
- static int dct_active_get(void *data, u64 *active_percent)
- {
- struct ivpu_device *vdev = data;
- *active_percent = vdev->pm->dct_active_percent;
- return 0;
- }
- static int dct_active_set(void *data, u64 active_percent)
- {
- struct ivpu_device *vdev = data;
- int ret;
- if (active_percent > 100)
- return -EINVAL;
- ret = ivpu_rpm_get(vdev);
- if (ret)
- return ret;
- if (active_percent)
- ret = ivpu_pm_dct_enable(vdev, active_percent);
- else
- ret = ivpu_pm_dct_disable(vdev);
- ivpu_rpm_put(vdev);
- return ret;
- }
- DEFINE_DEBUGFS_ATTRIBUTE(ivpu_dct_fops, dct_active_get, dct_active_set, "%llu\n");
- void ivpu_debugfs_init(struct ivpu_device *vdev)
- {
- struct dentry *debugfs_root = vdev->drm.debugfs_root;
- drm_debugfs_add_files(&vdev->drm, vdev_debugfs_list, ARRAY_SIZE(vdev_debugfs_list));
- debugfs_create_file("force_recovery", 0200, debugfs_root, vdev,
- &ivpu_force_recovery_fops);
- debugfs_create_file("dvfs_mode", 0200, debugfs_root, vdev,
- &dvfs_mode_fops);
- debugfs_create_file("fw_dyndbg", 0200, debugfs_root, vdev,
- &fw_dyndbg_fops);
- debugfs_create_file("fw_log", 0644, debugfs_root, vdev,
- &fw_log_fops);
- debugfs_create_file("fw_trace_destination_mask", 0200, debugfs_root, vdev,
- &fw_trace_destination_mask_fops);
- debugfs_create_file("fw_trace_hw_comp_mask", 0200, debugfs_root, vdev,
- &fw_trace_hw_comp_mask_fops);
- debugfs_create_file("fw_trace_level", 0200, debugfs_root, vdev,
- &fw_trace_level_fops);
- debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
- &ivpu_reset_engine_fops);
- debugfs_create_file("resume_engine", 0200, debugfs_root, vdev,
- &ivpu_resume_engine_fops);
- if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX) {
- debugfs_create_file("fw_profiling_freq_drive", 0200,
- debugfs_root, vdev, &fw_profiling_freq_fops);
- debugfs_create_file("dct", 0644, debugfs_root, vdev, &ivpu_dct_fops);
- }
- }
|