aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
diff options
context:
space:
mode:
authorOded Gabbay <oded.gabbay@amd.com>2014-07-16 16:25:31 -0400
committerOded Gabbay <oded.gabbay@amd.com>2014-07-16 16:25:31 -0400
commit19f6d2a660340d01bcdb7a09557efeeee28d1517 (patch)
treec19d39c617ea7afe653169e36cf570b03cb4d94b /drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
parent5b5c4e40a37e858e2bff8cd91be8e972256392c4 (diff)
amdkfd: Add basic modules to amdkfd
This patch adds the process module and three helper modules: - kfd_process, which handles process which open /dev/kfd - kfd_doorbell, which provides helper functions for doorbell allocation, release and mapping to userspace - kfd_pasid, which provides helper functions for pasid allocation and release - kfd_aperture, which provides helper functions for managing the LDS, Local GPU memory and Scratch memory apertures of the process This patch only contains the basic kfd_process module, which doesn't contain the reference to the queue scheduler. This was done to allow easier code review. Also, this patch doesn't contain the calls to the IOMMU driver for binding the pasid to the device. Again, this was done to allow easier code review The kfd_process object is created when a process opens /dev/kfd and is closed when the mm_struct of that process is teared-down. v3: Removed kfd_vidmem.c file Replaced direct mmput call to mmu_notifier release Removed typedefs Moved bool field to end of the structure Added new kernel params for gart usage limitation Added initialization of sa manager Fixed debug messages Remove support for LDS in 32 bit Changed code to support mmap of doorbell pages from userspace Added documentation for apertures v4: Replaced RCU by SRCU for kfd_process list management v5: Move amdkfd from drm/radeon/ to drm/amd/ Rename kfd_aperture.c to kfd_flat_memory.c Protect against multiple init calls MQD size is H/W dependent so moved it to device info structure Rename kfd_mem_obj structure's members Use delayed function for process tear-down Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdkfd/kfd_chardev.c')
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_chardev.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index d7c32eb7d16a..58441cd1b1d2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -38,6 +38,7 @@
38 38
39static long kfd_ioctl(struct file *, unsigned int, unsigned long); 39static long kfd_ioctl(struct file *, unsigned int, unsigned long);
40static int kfd_open(struct inode *, struct file *); 40static int kfd_open(struct inode *, struct file *);
41static int kfd_mmap(struct file *, struct vm_area_struct *);
41 42
42static const char kfd_dev_name[] = "kfd"; 43static const char kfd_dev_name[] = "kfd";
43 44
@@ -46,6 +47,7 @@ static const struct file_operations kfd_fops = {
46 .unlocked_ioctl = kfd_ioctl, 47 .unlocked_ioctl = kfd_ioctl,
47 .compat_ioctl = kfd_ioctl, 48 .compat_ioctl = kfd_ioctl,
48 .open = kfd_open, 49 .open = kfd_open,
50 .mmap = kfd_mmap,
49}; 51};
50 52
51static int kfd_char_dev_major = -1; 53static int kfd_char_dev_major = -1;
@@ -98,9 +100,22 @@ struct device *kfd_chardev(void)
98 100
99static int kfd_open(struct inode *inode, struct file *filep) 101static int kfd_open(struct inode *inode, struct file *filep)
100{ 102{
103 struct kfd_process *process;
104
101 if (iminor(inode) != 0) 105 if (iminor(inode) != 0)
102 return -ENODEV; 106 return -ENODEV;
103 107
108 process = kfd_create_process(current);
109 if (IS_ERR(process))
110 return PTR_ERR(process);
111
112 process->is_32bit_user_mode = is_compat_task();
113
114 dev_dbg(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
115 process->pasid, process->is_32bit_user_mode);
116
117 kfd_init_apertures(process);
118
104 return 0; 119 return 0;
105} 120}
106 121
@@ -156,8 +171,9 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
156 "ioctl cmd 0x%x (#%d), arg 0x%lx\n", 171 "ioctl cmd 0x%x (#%d), arg 0x%lx\n",
157 cmd, _IOC_NR(cmd), arg); 172 cmd, _IOC_NR(cmd), arg);
158 173
159 /* TODO: add function that retrieves process */ 174 process = kfd_get_process(current);
160 process = NULL; 175 if (IS_ERR(process))
176 return PTR_ERR(process);
161 177
162 switch (cmd) { 178 switch (cmd) {
163 case KFD_IOC_GET_VERSION: 179 case KFD_IOC_GET_VERSION:
@@ -208,3 +224,14 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
208 224
209 return err; 225 return err;
210} 226}
227
228static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
229{
230 struct kfd_process *process;
231
232 process = kfd_get_process(current);
233 if (IS_ERR(process))
234 return PTR_ERR(process);
235
236 return kfd_doorbell_mmap(process, vma);
237}