2 * Copyright 2016-2017 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/debugfs.h>
24 #include <linux/uaccess.h>
28 static struct dentry
*debugfs_root
;
30 static int kfd_debugfs_open(struct inode
*inode
, struct file
*file
)
32 int (*show
)(struct seq_file
*, void *) = inode
->i_private
;
34 return single_open(file
, show
, NULL
);
37 static ssize_t
kfd_debugfs_hang_hws_write(struct file
*file
,
38 const char __user
*user_buf
, size_t size
, loff_t
*ppos
)
47 pr_err("Invalid input for gpu id.\n");
50 if (copy_from_user(tmp
, user_buf
, size
)) {
54 if (kstrtoint(tmp
, 10, &gpu_id
)) {
55 pr_err("Invalid input for gpu id.\n");
58 dev
= kfd_device_by_id(gpu_id
);
60 kfd_debugfs_hang_hws(dev
);
63 pr_err("Cannot find device %d.\n", gpu_id
);
69 static const struct file_operations kfd_debugfs_fops
= {
71 .open
= kfd_debugfs_open
,
74 .release
= single_release
,
77 static const struct file_operations kfd_debugfs_hang_hws_fops
= {
79 .open
= kfd_debugfs_open
,
81 .write
= kfd_debugfs_hang_hws_write
,
83 .release
= single_release
,
86 void kfd_debugfs_init(void)
90 debugfs_root
= debugfs_create_dir("kfd", NULL
);
91 if (!debugfs_root
|| debugfs_root
== ERR_PTR(-ENODEV
)) {
92 pr_warn("Failed to create kfd debugfs dir\n");
96 ent
= debugfs_create_file("mqds", S_IFREG
| 0444, debugfs_root
,
97 kfd_debugfs_mqds_by_process
,
100 pr_warn("Failed to create mqds in kfd debugfs\n");
102 ent
= debugfs_create_file("hqds", S_IFREG
| 0444, debugfs_root
,
103 kfd_debugfs_hqds_by_device
,
106 pr_warn("Failed to create hqds in kfd debugfs\n");
108 ent
= debugfs_create_file("rls", S_IFREG
| 0444, debugfs_root
,
109 kfd_debugfs_rls_by_device
,
112 ent
= debugfs_create_file("hang_hws", S_IFREG
| 0644, debugfs_root
,
114 &kfd_debugfs_hang_hws_fops
);
117 pr_warn("Failed to create rls in kfd debugfs\n");
120 void kfd_debugfs_fini(void)
122 debugfs_remove_recursive(debugfs_root
);