18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2016-2017 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include <linux/debugfs.h> 248c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include "kfd_priv.h" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic struct dentry *debugfs_root; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic int kfd_debugfs_open(struct inode *inode, struct file *file) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci int (*show)(struct seq_file *, void *) = inode->i_private; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci return single_open(file, show, NULL); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_cistatic int kfd_debugfs_hang_hws_read(struct seq_file *m, void *data) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci seq_printf(m, "echo gpu_id > hang_hws\n"); 398c2ecf20Sopenharmony_ci return 0; 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic ssize_t kfd_debugfs_hang_hws_write(struct file *file, 438c2ecf20Sopenharmony_ci const char __user *user_buf, size_t size, loff_t *ppos) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci struct kfd_dev *dev; 468c2ecf20Sopenharmony_ci char tmp[16]; 478c2ecf20Sopenharmony_ci uint32_t gpu_id; 488c2ecf20Sopenharmony_ci int ret = -EINVAL; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci memset(tmp, 0, 16); 518c2ecf20Sopenharmony_ci if (size >= 16) { 528c2ecf20Sopenharmony_ci pr_err("Invalid input for gpu id.\n"); 538c2ecf20Sopenharmony_ci goto out; 548c2ecf20Sopenharmony_ci } 558c2ecf20Sopenharmony_ci if (copy_from_user(tmp, user_buf, size)) { 568c2ecf20Sopenharmony_ci ret = -EFAULT; 578c2ecf20Sopenharmony_ci goto out; 588c2ecf20Sopenharmony_ci } 598c2ecf20Sopenharmony_ci if (kstrtoint(tmp, 10, &gpu_id)) { 608c2ecf20Sopenharmony_ci pr_err("Invalid input for gpu id.\n"); 618c2ecf20Sopenharmony_ci goto out; 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci dev = kfd_device_by_id(gpu_id); 648c2ecf20Sopenharmony_ci if (dev) { 658c2ecf20Sopenharmony_ci kfd_debugfs_hang_hws(dev); 668c2ecf20Sopenharmony_ci ret = size; 678c2ecf20Sopenharmony_ci } else 688c2ecf20Sopenharmony_ci pr_err("Cannot find device %d.\n", gpu_id); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ciout: 718c2ecf20Sopenharmony_ci return ret; 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic const struct file_operations kfd_debugfs_fops = { 758c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 768c2ecf20Sopenharmony_ci .open = kfd_debugfs_open, 778c2ecf20Sopenharmony_ci .read = seq_read, 788c2ecf20Sopenharmony_ci .llseek = seq_lseek, 798c2ecf20Sopenharmony_ci .release = single_release, 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic const struct file_operations kfd_debugfs_hang_hws_fops = { 838c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 848c2ecf20Sopenharmony_ci .open = kfd_debugfs_open, 858c2ecf20Sopenharmony_ci .read = seq_read, 868c2ecf20Sopenharmony_ci .write = kfd_debugfs_hang_hws_write, 878c2ecf20Sopenharmony_ci .llseek = seq_lseek, 888c2ecf20Sopenharmony_ci .release = single_release, 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid kfd_debugfs_init(void) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci debugfs_root = debugfs_create_dir("kfd", NULL); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root, 968c2ecf20Sopenharmony_ci kfd_debugfs_mqds_by_process, &kfd_debugfs_fops); 978c2ecf20Sopenharmony_ci debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root, 988c2ecf20Sopenharmony_ci kfd_debugfs_hqds_by_device, &kfd_debugfs_fops); 998c2ecf20Sopenharmony_ci debugfs_create_file("rls", S_IFREG | 0444, debugfs_root, 1008c2ecf20Sopenharmony_ci kfd_debugfs_rls_by_device, &kfd_debugfs_fops); 1018c2ecf20Sopenharmony_ci debugfs_create_file("hang_hws", S_IFREG | 0200, debugfs_root, 1028c2ecf20Sopenharmony_ci kfd_debugfs_hang_hws_read, &kfd_debugfs_hang_hws_fops); 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_civoid kfd_debugfs_fini(void) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci debugfs_remove_recursive(debugfs_root); 1088c2ecf20Sopenharmony_ci} 109