Home | History | Annotate | Line # | Download | only in amdkfd
      1  1.1  riastrad /*	$NetBSD: kfd_debugfs.c,v 1.2 2021/12/18 23:44:59 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2016-2017 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  */
     24  1.1  riastrad 
     25  1.1  riastrad #include <sys/cdefs.h>
     26  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: kfd_debugfs.c,v 1.2 2021/12/18 23:44:59 riastradh Exp $");
     27  1.1  riastrad 
     28  1.1  riastrad #include <linux/debugfs.h>
     29  1.1  riastrad #include <linux/uaccess.h>
     30  1.1  riastrad 
     31  1.1  riastrad #include "kfd_priv.h"
     32  1.1  riastrad 
     33  1.1  riastrad static struct dentry *debugfs_root;
     34  1.1  riastrad 
     35  1.1  riastrad static int kfd_debugfs_open(struct inode *inode, struct file *file)
     36  1.1  riastrad {
     37  1.1  riastrad 	int (*show)(struct seq_file *, void *) = inode->i_private;
     38  1.1  riastrad 
     39  1.1  riastrad 	return single_open(file, show, NULL);
     40  1.1  riastrad }
     41  1.1  riastrad 
     42  1.1  riastrad static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
     43  1.1  riastrad 	const char __user *user_buf, size_t size, loff_t *ppos)
     44  1.1  riastrad {
     45  1.1  riastrad 	struct kfd_dev *dev;
     46  1.1  riastrad 	char tmp[16];
     47  1.1  riastrad 	uint32_t gpu_id;
     48  1.1  riastrad 	int ret = -EINVAL;
     49  1.1  riastrad 
     50  1.1  riastrad 	memset(tmp, 0, 16);
     51  1.1  riastrad 	if (size >= 16) {
     52  1.1  riastrad 		pr_err("Invalid input for gpu id.\n");
     53  1.1  riastrad 		goto out;
     54  1.1  riastrad 	}
     55  1.1  riastrad 	if (copy_from_user(tmp, user_buf, size)) {
     56  1.1  riastrad 		ret = -EFAULT;
     57  1.1  riastrad 		goto out;
     58  1.1  riastrad 	}
     59  1.1  riastrad 	if (kstrtoint(tmp, 10, &gpu_id)) {
     60  1.1  riastrad 		pr_err("Invalid input for gpu id.\n");
     61  1.1  riastrad 		goto out;
     62  1.1  riastrad 	}
     63  1.1  riastrad 	dev = kfd_device_by_id(gpu_id);
     64  1.1  riastrad 	if (dev) {
     65  1.1  riastrad 		kfd_debugfs_hang_hws(dev);
     66  1.1  riastrad 		ret = size;
     67  1.1  riastrad 	} else
     68  1.1  riastrad 		pr_err("Cannot find device %d.\n", gpu_id);
     69  1.1  riastrad 
     70  1.1  riastrad out:
     71  1.1  riastrad 	return ret;
     72  1.1  riastrad }
     73  1.1  riastrad 
     74  1.1  riastrad static const struct file_operations kfd_debugfs_fops = {
     75  1.1  riastrad 	.owner = THIS_MODULE,
     76  1.1  riastrad 	.open = kfd_debugfs_open,
     77  1.1  riastrad 	.read = seq_read,
     78  1.1  riastrad 	.llseek = seq_lseek,
     79  1.1  riastrad 	.release = single_release,
     80  1.1  riastrad };
     81  1.1  riastrad 
     82  1.1  riastrad static const struct file_operations kfd_debugfs_hang_hws_fops = {
     83  1.1  riastrad 	.owner = THIS_MODULE,
     84  1.1  riastrad 	.open = kfd_debugfs_open,
     85  1.1  riastrad 	.read = seq_read,
     86  1.1  riastrad 	.write = kfd_debugfs_hang_hws_write,
     87  1.1  riastrad 	.llseek = seq_lseek,
     88  1.1  riastrad 	.release = single_release,
     89  1.1  riastrad };
     90  1.1  riastrad 
     91  1.1  riastrad void kfd_debugfs_init(void)
     92  1.1  riastrad {
     93  1.1  riastrad 	debugfs_root = debugfs_create_dir("kfd", NULL);
     94  1.1  riastrad 
     95  1.1  riastrad 	debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root,
     96  1.1  riastrad 			    kfd_debugfs_mqds_by_process, &kfd_debugfs_fops);
     97  1.1  riastrad 	debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root,
     98  1.1  riastrad 			    kfd_debugfs_hqds_by_device, &kfd_debugfs_fops);
     99  1.1  riastrad 	debugfs_create_file("rls", S_IFREG | 0444, debugfs_root,
    100  1.1  riastrad 			    kfd_debugfs_rls_by_device, &kfd_debugfs_fops);
    101  1.1  riastrad 	debugfs_create_file("hang_hws", S_IFREG | 0200, debugfs_root,
    102  1.1  riastrad 			    NULL, &kfd_debugfs_hang_hws_fops);
    103  1.1  riastrad }
    104  1.1  riastrad 
    105  1.1  riastrad void kfd_debugfs_fini(void)
    106  1.1  riastrad {
    107  1.1  riastrad 	debugfs_remove_recursive(debugfs_root);
    108  1.1  riastrad }
    109