2 * Copyright 2014 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/device.h>
24 #include <linux/export.h>
25 #include <linux/err.h>
27 #include <linux/sched.h>
28 #include <linux/slab.h>
29 #include <linux/uaccess.h>
30 #include <linux/compat.h>
31 #include <uapi/linux/kfd_ioctl.h>
32 #include <linux/time.h>
34 #include <linux/uaccess.h>
35 #include <uapi/asm-generic/mman-common.h>
36 #include <asm/processor.h>
39 static long kfd_ioctl(struct file *, unsigned int, unsigned long);
40 static int kfd_open(struct inode *, struct file *);
42 static const char kfd_dev_name[] = "kfd";
44 static const struct file_operations kfd_fops = {
46 .unlocked_ioctl = kfd_ioctl,
47 .compat_ioctl = kfd_ioctl,
51 static int kfd_char_dev_major = -1;
52 static struct class *kfd_class;
53 struct device *kfd_device;
55 int kfd_chardev_init(void)
59 kfd_char_dev_major = register_chrdev(0, kfd_dev_name, &kfd_fops);
60 err = kfd_char_dev_major;
62 goto err_register_chrdev;
64 kfd_class = class_create(THIS_MODULE, kfd_dev_name);
65 err = PTR_ERR(kfd_class);
66 if (IS_ERR(kfd_class))
67 goto err_class_create;
69 kfd_device = device_create(kfd_class, NULL,
70 MKDEV(kfd_char_dev_major, 0),
72 err = PTR_ERR(kfd_device);
73 if (IS_ERR(kfd_device))
74 goto err_device_create;
79 class_destroy(kfd_class);
81 unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
86 void kfd_chardev_exit(void)
88 device_destroy(kfd_class, MKDEV(kfd_char_dev_major, 0));
89 class_destroy(kfd_class);
90 unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
93 struct device *kfd_chardev(void)
99 static int kfd_open(struct inode *inode, struct file *filep)
101 if (iminor(inode) != 0)
107 static long kfd_ioctl_get_version(struct file *filep, struct kfd_process *p,
113 static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
119 static int kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p,
125 static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p,
131 static long kfd_ioctl_set_memory_policy(struct file *filep,
132 struct kfd_process *p, void __user *arg)
137 static long kfd_ioctl_get_clock_counters(struct file *filep,
138 struct kfd_process *p, void __user *arg)
144 static int kfd_ioctl_get_process_apertures(struct file *filp,
145 struct kfd_process *p, void __user *arg)
150 static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
152 struct kfd_process *process;
156 "ioctl cmd 0x%x (#%d), arg 0x%lx\n",
157 cmd, _IOC_NR(cmd), arg);
159 /* TODO: add function that retrieves process */
163 case KFD_IOC_GET_VERSION:
164 err = kfd_ioctl_get_version(filep, process, (void __user *)arg);
166 case KFD_IOC_CREATE_QUEUE:
167 err = kfd_ioctl_create_queue(filep, process,
171 case KFD_IOC_DESTROY_QUEUE:
172 err = kfd_ioctl_destroy_queue(filep, process,
176 case KFD_IOC_SET_MEMORY_POLICY:
177 err = kfd_ioctl_set_memory_policy(filep, process,
181 case KFD_IOC_GET_CLOCK_COUNTERS:
182 err = kfd_ioctl_get_clock_counters(filep, process,
186 case KFD_IOC_GET_PROCESS_APERTURES:
187 err = kfd_ioctl_get_process_apertures(filep, process,
191 case KFD_IOC_UPDATE_QUEUE:
192 err = kfd_ioctl_update_queue(filep, process,
198 "unknown ioctl cmd 0x%x, arg 0x%lx)\n",
206 "ioctl error %ld for ioctl cmd 0x%x (#%d)\n",
207 err, cmd, _IOC_NR(cmd));