| 1 | /* |
| 2 | * Copyright 2014 Advanced Micro Devices, Inc. |
| 3 | * |
| 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: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 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. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/export.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/fs.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> |
| 33 | #include <linux/mm.h> |
| 34 | #include <uapi/asm-generic/mman-common.h> |
| 35 | #include <asm/processor.h> |
| 36 | #include "kfd_priv.h" |
| 37 | #include "kfd_device_queue_manager.h" |
| 38 | |
| 39 | static long kfd_ioctl(struct file *, unsigned int, unsigned long); |
| 40 | static int kfd_open(struct inode *, struct file *); |
| 41 | static int kfd_mmap(struct file *, struct vm_area_struct *); |
| 42 | |
| 43 | static const char kfd_dev_name[] = "kfd"; |
| 44 | |
| 45 | static const struct file_operations kfd_fops = { |
| 46 | .owner = THIS_MODULE, |
| 47 | .unlocked_ioctl = kfd_ioctl, |
| 48 | .compat_ioctl = kfd_ioctl, |
| 49 | .open = kfd_open, |
| 50 | .mmap = kfd_mmap, |
| 51 | }; |
| 52 | |
| 53 | static int kfd_char_dev_major = -1; |
| 54 | static struct class *kfd_class; |
| 55 | struct device *kfd_device; |
| 56 | |
| 57 | int kfd_chardev_init(void) |
| 58 | { |
| 59 | int err = 0; |
| 60 | |
| 61 | kfd_char_dev_major = register_chrdev(0, kfd_dev_name, &kfd_fops); |
| 62 | err = kfd_char_dev_major; |
| 63 | if (err < 0) |
| 64 | goto err_register_chrdev; |
| 65 | |
| 66 | kfd_class = class_create(THIS_MODULE, kfd_dev_name); |
| 67 | err = PTR_ERR(kfd_class); |
| 68 | if (IS_ERR(kfd_class)) |
| 69 | goto err_class_create; |
| 70 | |
| 71 | kfd_device = device_create(kfd_class, NULL, |
| 72 | MKDEV(kfd_char_dev_major, 0), |
| 73 | NULL, kfd_dev_name); |
| 74 | err = PTR_ERR(kfd_device); |
| 75 | if (IS_ERR(kfd_device)) |
| 76 | goto err_device_create; |
| 77 | |
| 78 | return 0; |
| 79 | |
| 80 | err_device_create: |
| 81 | class_destroy(kfd_class); |
| 82 | err_class_create: |
| 83 | unregister_chrdev(kfd_char_dev_major, kfd_dev_name); |
| 84 | err_register_chrdev: |
| 85 | return err; |
| 86 | } |
| 87 | |
| 88 | void kfd_chardev_exit(void) |
| 89 | { |
| 90 | device_destroy(kfd_class, MKDEV(kfd_char_dev_major, 0)); |
| 91 | class_destroy(kfd_class); |
| 92 | unregister_chrdev(kfd_char_dev_major, kfd_dev_name); |
| 93 | } |
| 94 | |
| 95 | struct device *kfd_chardev(void) |
| 96 | { |
| 97 | return kfd_device; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | static int kfd_open(struct inode *inode, struct file *filep) |
| 102 | { |
| 103 | struct kfd_process *process; |
| 104 | bool is_32bit_user_mode; |
| 105 | |
| 106 | if (iminor(inode) != 0) |
| 107 | return -ENODEV; |
| 108 | |
| 109 | is_32bit_user_mode = is_compat_task(); |
| 110 | |
| 111 | if (is_32bit_user_mode == true) { |
| 112 | dev_warn(kfd_device, |
| 113 | "Process %d (32-bit) failed to open /dev/kfd\n" |
| 114 | "32-bit processes are not supported by amdkfd\n", |
| 115 | current->pid); |
| 116 | return -EPERM; |
| 117 | } |
| 118 | |
| 119 | process = kfd_create_process(current); |
| 120 | if (IS_ERR(process)) |
| 121 | return PTR_ERR(process); |
| 122 | |
| 123 | dev_dbg(kfd_device, "process %d opened, compat mode (32 bit) - %d\n", |
| 124 | process->pasid, process->is_32bit_user_mode); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int kfd_ioctl_get_version(struct file *filep, struct kfd_process *p, |
| 130 | void *data) |
| 131 | { |
| 132 | struct kfd_ioctl_get_version_args *args = data; |
| 133 | int err = 0; |
| 134 | |
| 135 | args->major_version = KFD_IOCTL_MAJOR_VERSION; |
| 136 | args->minor_version = KFD_IOCTL_MINOR_VERSION; |
| 137 | |
| 138 | return err; |
| 139 | } |
| 140 | |
| 141 | static int set_queue_properties_from_user(struct queue_properties *q_properties, |
| 142 | struct kfd_ioctl_create_queue_args *args) |
| 143 | { |
| 144 | if (args->queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) { |
| 145 | pr_err("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n"); |
| 146 | return -EINVAL; |
| 147 | } |
| 148 | |
| 149 | if (args->queue_priority > KFD_MAX_QUEUE_PRIORITY) { |
| 150 | pr_err("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n"); |
| 151 | return -EINVAL; |
| 152 | } |
| 153 | |
| 154 | if ((args->ring_base_address) && |
| 155 | (!access_ok(VERIFY_WRITE, |
| 156 | (const void __user *) args->ring_base_address, |
| 157 | sizeof(uint64_t)))) { |
| 158 | pr_err("kfd: can't access ring base address\n"); |
| 159 | return -EFAULT; |
| 160 | } |
| 161 | |
| 162 | if (!is_power_of_2(args->ring_size) && (args->ring_size != 0)) { |
| 163 | pr_err("kfd: ring size must be a power of 2 or 0\n"); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | |
| 167 | if (!access_ok(VERIFY_WRITE, |
| 168 | (const void __user *) args->read_pointer_address, |
| 169 | sizeof(uint32_t))) { |
| 170 | pr_err("kfd: can't access read pointer\n"); |
| 171 | return -EFAULT; |
| 172 | } |
| 173 | |
| 174 | if (!access_ok(VERIFY_WRITE, |
| 175 | (const void __user *) args->write_pointer_address, |
| 176 | sizeof(uint32_t))) { |
| 177 | pr_err("kfd: can't access write pointer\n"); |
| 178 | return -EFAULT; |
| 179 | } |
| 180 | |
| 181 | q_properties->is_interop = false; |
| 182 | q_properties->queue_percent = args->queue_percentage; |
| 183 | q_properties->priority = args->queue_priority; |
| 184 | q_properties->queue_address = args->ring_base_address; |
| 185 | q_properties->queue_size = args->ring_size; |
| 186 | q_properties->read_ptr = (uint32_t *) args->read_pointer_address; |
| 187 | q_properties->write_ptr = (uint32_t *) args->write_pointer_address; |
| 188 | if (args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE || |
| 189 | args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL) |
| 190 | q_properties->type = KFD_QUEUE_TYPE_COMPUTE; |
| 191 | else |
| 192 | return -ENOTSUPP; |
| 193 | |
| 194 | if (args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL) |
| 195 | q_properties->format = KFD_QUEUE_FORMAT_AQL; |
| 196 | else |
| 197 | q_properties->format = KFD_QUEUE_FORMAT_PM4; |
| 198 | |
| 199 | pr_debug("Queue Percentage (%d, %d)\n", |
| 200 | q_properties->queue_percent, args->queue_percentage); |
| 201 | |
| 202 | pr_debug("Queue Priority (%d, %d)\n", |
| 203 | q_properties->priority, args->queue_priority); |
| 204 | |
| 205 | pr_debug("Queue Address (0x%llX, 0x%llX)\n", |
| 206 | q_properties->queue_address, args->ring_base_address); |
| 207 | |
| 208 | pr_debug("Queue Size (0x%llX, %u)\n", |
| 209 | q_properties->queue_size, args->ring_size); |
| 210 | |
| 211 | pr_debug("Queue r/w Pointers (0x%llX, 0x%llX)\n", |
| 212 | (uint64_t) q_properties->read_ptr, |
| 213 | (uint64_t) q_properties->write_ptr); |
| 214 | |
| 215 | pr_debug("Queue Format (%d)\n", q_properties->format); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, |
| 221 | void *data) |
| 222 | { |
| 223 | struct kfd_ioctl_create_queue_args *args = data; |
| 224 | struct kfd_dev *dev; |
| 225 | int err = 0; |
| 226 | unsigned int queue_id; |
| 227 | struct kfd_process_device *pdd; |
| 228 | struct queue_properties q_properties; |
| 229 | |
| 230 | memset(&q_properties, 0, sizeof(struct queue_properties)); |
| 231 | |
| 232 | pr_debug("kfd: creating queue ioctl\n"); |
| 233 | |
| 234 | err = set_queue_properties_from_user(&q_properties, args); |
| 235 | if (err) |
| 236 | return err; |
| 237 | |
| 238 | dev = kfd_device_by_id(args->gpu_id); |
| 239 | if (dev == NULL) |
| 240 | return -EINVAL; |
| 241 | |
| 242 | mutex_lock(&p->mutex); |
| 243 | |
| 244 | pdd = kfd_bind_process_to_device(dev, p); |
| 245 | if (IS_ERR(pdd)) { |
| 246 | err = -ESRCH; |
| 247 | goto err_bind_process; |
| 248 | } |
| 249 | |
| 250 | pr_debug("kfd: creating queue for PASID %d on GPU 0x%x\n", |
| 251 | p->pasid, |
| 252 | dev->id); |
| 253 | |
| 254 | err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, 0, |
| 255 | KFD_QUEUE_TYPE_COMPUTE, &queue_id); |
| 256 | if (err != 0) |
| 257 | goto err_create_queue; |
| 258 | |
| 259 | args->queue_id = queue_id; |
| 260 | |
| 261 | /* Return gpu_id as doorbell offset for mmap usage */ |
| 262 | args->doorbell_offset = args->gpu_id << PAGE_SHIFT; |
| 263 | |
| 264 | mutex_unlock(&p->mutex); |
| 265 | |
| 266 | pr_debug("kfd: queue id %d was created successfully\n", args->queue_id); |
| 267 | |
| 268 | pr_debug("ring buffer address == 0x%016llX\n", |
| 269 | args->ring_base_address); |
| 270 | |
| 271 | pr_debug("read ptr address == 0x%016llX\n", |
| 272 | args->read_pointer_address); |
| 273 | |
| 274 | pr_debug("write ptr address == 0x%016llX\n", |
| 275 | args->write_pointer_address); |
| 276 | |
| 277 | return 0; |
| 278 | |
| 279 | err_create_queue: |
| 280 | err_bind_process: |
| 281 | mutex_unlock(&p->mutex); |
| 282 | return err; |
| 283 | } |
| 284 | |
| 285 | static int kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p, |
| 286 | void *data) |
| 287 | { |
| 288 | int retval; |
| 289 | struct kfd_ioctl_destroy_queue_args *args = data; |
| 290 | |
| 291 | pr_debug("kfd: destroying queue id %d for PASID %d\n", |
| 292 | args->queue_id, |
| 293 | p->pasid); |
| 294 | |
| 295 | mutex_lock(&p->mutex); |
| 296 | |
| 297 | retval = pqm_destroy_queue(&p->pqm, args->queue_id); |
| 298 | |
| 299 | mutex_unlock(&p->mutex); |
| 300 | return retval; |
| 301 | } |
| 302 | |
| 303 | static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p, |
| 304 | void *data) |
| 305 | { |
| 306 | int retval; |
| 307 | struct kfd_ioctl_update_queue_args *args = data; |
| 308 | struct queue_properties properties; |
| 309 | |
| 310 | if (args->queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) { |
| 311 | pr_err("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n"); |
| 312 | return -EINVAL; |
| 313 | } |
| 314 | |
| 315 | if (args->queue_priority > KFD_MAX_QUEUE_PRIORITY) { |
| 316 | pr_err("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n"); |
| 317 | return -EINVAL; |
| 318 | } |
| 319 | |
| 320 | if ((args->ring_base_address) && |
| 321 | (!access_ok(VERIFY_WRITE, |
| 322 | (const void __user *) args->ring_base_address, |
| 323 | sizeof(uint64_t)))) { |
| 324 | pr_err("kfd: can't access ring base address\n"); |
| 325 | return -EFAULT; |
| 326 | } |
| 327 | |
| 328 | if (!is_power_of_2(args->ring_size) && (args->ring_size != 0)) { |
| 329 | pr_err("kfd: ring size must be a power of 2 or 0\n"); |
| 330 | return -EINVAL; |
| 331 | } |
| 332 | |
| 333 | properties.queue_address = args->ring_base_address; |
| 334 | properties.queue_size = args->ring_size; |
| 335 | properties.queue_percent = args->queue_percentage; |
| 336 | properties.priority = args->queue_priority; |
| 337 | |
| 338 | pr_debug("kfd: updating queue id %d for PASID %d\n", |
| 339 | args->queue_id, p->pasid); |
| 340 | |
| 341 | mutex_lock(&p->mutex); |
| 342 | |
| 343 | retval = pqm_update_queue(&p->pqm, args->queue_id, &properties); |
| 344 | |
| 345 | mutex_unlock(&p->mutex); |
| 346 | |
| 347 | return retval; |
| 348 | } |
| 349 | |
| 350 | static int kfd_ioctl_set_memory_policy(struct file *filep, |
| 351 | struct kfd_process *p, void *data) |
| 352 | { |
| 353 | struct kfd_ioctl_set_memory_policy_args *args = data; |
| 354 | struct kfd_dev *dev; |
| 355 | int err = 0; |
| 356 | struct kfd_process_device *pdd; |
| 357 | enum cache_policy default_policy, alternate_policy; |
| 358 | |
| 359 | if (args->default_policy != KFD_IOC_CACHE_POLICY_COHERENT |
| 360 | && args->default_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { |
| 361 | return -EINVAL; |
| 362 | } |
| 363 | |
| 364 | if (args->alternate_policy != KFD_IOC_CACHE_POLICY_COHERENT |
| 365 | && args->alternate_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
| 369 | dev = kfd_device_by_id(args->gpu_id); |
| 370 | if (dev == NULL) |
| 371 | return -EINVAL; |
| 372 | |
| 373 | mutex_lock(&p->mutex); |
| 374 | |
| 375 | pdd = kfd_bind_process_to_device(dev, p); |
| 376 | if (IS_ERR(pdd)) { |
| 377 | err = -ESRCH; |
| 378 | goto out; |
| 379 | } |
| 380 | |
| 381 | default_policy = (args->default_policy == KFD_IOC_CACHE_POLICY_COHERENT) |
| 382 | ? cache_policy_coherent : cache_policy_noncoherent; |
| 383 | |
| 384 | alternate_policy = |
| 385 | (args->alternate_policy == KFD_IOC_CACHE_POLICY_COHERENT) |
| 386 | ? cache_policy_coherent : cache_policy_noncoherent; |
| 387 | |
| 388 | if (!dev->dqm->set_cache_memory_policy(dev->dqm, |
| 389 | &pdd->qpd, |
| 390 | default_policy, |
| 391 | alternate_policy, |
| 392 | (void __user *)args->alternate_aperture_base, |
| 393 | args->alternate_aperture_size)) |
| 394 | err = -EINVAL; |
| 395 | |
| 396 | out: |
| 397 | mutex_unlock(&p->mutex); |
| 398 | |
| 399 | return err; |
| 400 | } |
| 401 | |
| 402 | static int kfd_ioctl_get_clock_counters(struct file *filep, |
| 403 | struct kfd_process *p, void *data) |
| 404 | { |
| 405 | struct kfd_ioctl_get_clock_counters_args *args = data; |
| 406 | struct kfd_dev *dev; |
| 407 | struct timespec time; |
| 408 | |
| 409 | dev = kfd_device_by_id(args->gpu_id); |
| 410 | if (dev == NULL) |
| 411 | return -EINVAL; |
| 412 | |
| 413 | /* Reading GPU clock counter from KGD */ |
| 414 | args->gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd); |
| 415 | |
| 416 | /* No access to rdtsc. Using raw monotonic time */ |
| 417 | getrawmonotonic(&time); |
| 418 | args->cpu_clock_counter = (uint64_t)timespec_to_ns(&time); |
| 419 | |
| 420 | get_monotonic_boottime(&time); |
| 421 | args->system_clock_counter = (uint64_t)timespec_to_ns(&time); |
| 422 | |
| 423 | /* Since the counter is in nano-seconds we use 1GHz frequency */ |
| 424 | args->system_clock_freq = 1000000000; |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | static int kfd_ioctl_get_process_apertures(struct file *filp, |
| 431 | struct kfd_process *p, void *data) |
| 432 | { |
| 433 | struct kfd_ioctl_get_process_apertures_args *args = data; |
| 434 | struct kfd_process_device_apertures *pAperture; |
| 435 | struct kfd_process_device *pdd; |
| 436 | |
| 437 | dev_dbg(kfd_device, "get apertures for PASID %d", p->pasid); |
| 438 | |
| 439 | args->num_of_nodes = 0; |
| 440 | |
| 441 | mutex_lock(&p->mutex); |
| 442 | |
| 443 | /*if the process-device list isn't empty*/ |
| 444 | if (kfd_has_process_device_data(p)) { |
| 445 | /* Run over all pdd of the process */ |
| 446 | pdd = kfd_get_first_process_device_data(p); |
| 447 | do { |
| 448 | pAperture = |
| 449 | &args->process_apertures[args->num_of_nodes]; |
| 450 | pAperture->gpu_id = pdd->dev->id; |
| 451 | pAperture->lds_base = pdd->lds_base; |
| 452 | pAperture->lds_limit = pdd->lds_limit; |
| 453 | pAperture->gpuvm_base = pdd->gpuvm_base; |
| 454 | pAperture->gpuvm_limit = pdd->gpuvm_limit; |
| 455 | pAperture->scratch_base = pdd->scratch_base; |
| 456 | pAperture->scratch_limit = pdd->scratch_limit; |
| 457 | |
| 458 | dev_dbg(kfd_device, |
| 459 | "node id %u\n", args->num_of_nodes); |
| 460 | dev_dbg(kfd_device, |
| 461 | "gpu id %u\n", pdd->dev->id); |
| 462 | dev_dbg(kfd_device, |
| 463 | "lds_base %llX\n", pdd->lds_base); |
| 464 | dev_dbg(kfd_device, |
| 465 | "lds_limit %llX\n", pdd->lds_limit); |
| 466 | dev_dbg(kfd_device, |
| 467 | "gpuvm_base %llX\n", pdd->gpuvm_base); |
| 468 | dev_dbg(kfd_device, |
| 469 | "gpuvm_limit %llX\n", pdd->gpuvm_limit); |
| 470 | dev_dbg(kfd_device, |
| 471 | "scratch_base %llX\n", pdd->scratch_base); |
| 472 | dev_dbg(kfd_device, |
| 473 | "scratch_limit %llX\n", pdd->scratch_limit); |
| 474 | |
| 475 | args->num_of_nodes++; |
| 476 | } while ((pdd = kfd_get_next_process_device_data(p, pdd)) != NULL && |
| 477 | (args->num_of_nodes < NUM_OF_SUPPORTED_GPUS)); |
| 478 | } |
| 479 | |
| 480 | mutex_unlock(&p->mutex); |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) |
| 486 | { |
| 487 | struct kfd_process *process; |
| 488 | char stack_kdata[128]; |
| 489 | char *kdata = NULL; |
| 490 | unsigned int usize, asize; |
| 491 | int retcode = -EINVAL; |
| 492 | |
| 493 | dev_dbg(kfd_device, |
| 494 | "ioctl cmd 0x%x (#%d), arg 0x%lx\n", |
| 495 | cmd, _IOC_NR(cmd), arg); |
| 496 | |
| 497 | process = kfd_get_process(current); |
| 498 | if (IS_ERR(process)) |
| 499 | return PTR_ERR(process); |
| 500 | |
| 501 | if (cmd & (IOC_IN | IOC_OUT)) { |
| 502 | if (asize <= sizeof(stack_kdata)) { |
| 503 | kdata = stack_kdata; |
| 504 | } else { |
| 505 | kdata = kmalloc(asize, GFP_KERNEL); |
| 506 | if (!kdata) { |
| 507 | retcode = -ENOMEM; |
| 508 | goto err_i1; |
| 509 | } |
| 510 | } |
| 511 | if (asize > usize) |
| 512 | memset(kdata + usize, 0, asize - usize); |
| 513 | } |
| 514 | |
| 515 | if (cmd & IOC_IN) { |
| 516 | if (copy_from_user(kdata, (void __user *)arg, usize) != 0) { |
| 517 | retcode = -EFAULT; |
| 518 | goto err_i1; |
| 519 | } |
| 520 | } else if (cmd & IOC_OUT) { |
| 521 | memset(kdata, 0, usize); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | switch (cmd) { |
| 526 | case AMDKFD_IOC_GET_VERSION: |
| 527 | retcode = kfd_ioctl_get_version(filep, process, kdata); |
| 528 | break; |
| 529 | |
| 530 | case AMDKFD_IOC_CREATE_QUEUE: |
| 531 | retcode = kfd_ioctl_create_queue(filep, process, |
| 532 | kdata); |
| 533 | break; |
| 534 | |
| 535 | case AMDKFD_IOC_DESTROY_QUEUE: |
| 536 | retcode = kfd_ioctl_destroy_queue(filep, process, |
| 537 | kdata); |
| 538 | break; |
| 539 | |
| 540 | case AMDKFD_IOC_SET_MEMORY_POLICY: |
| 541 | retcode = kfd_ioctl_set_memory_policy(filep, process, |
| 542 | kdata); |
| 543 | break; |
| 544 | |
| 545 | case AMDKFD_IOC_GET_CLOCK_COUNTERS: |
| 546 | retcode = kfd_ioctl_get_clock_counters(filep, process, |
| 547 | kdata); |
| 548 | break; |
| 549 | |
| 550 | case AMDKFD_IOC_GET_PROCESS_APERTURES: |
| 551 | retcode = kfd_ioctl_get_process_apertures(filep, process, |
| 552 | kdata); |
| 553 | break; |
| 554 | |
| 555 | case AMDKFD_IOC_UPDATE_QUEUE: |
| 556 | retcode = kfd_ioctl_update_queue(filep, process, |
| 557 | kdata); |
| 558 | break; |
| 559 | |
| 560 | default: |
| 561 | dev_dbg(kfd_device, |
| 562 | "unknown ioctl cmd 0x%x, arg 0x%lx)\n", |
| 563 | cmd, arg); |
| 564 | retcode = -EINVAL; |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | if (cmd & IOC_OUT) |
| 569 | if (copy_to_user((void __user *)arg, kdata, usize) != 0) |
| 570 | retcode = -EFAULT; |
| 571 | |
| 572 | err_i1: |
| 573 | if (kdata != stack_kdata) |
| 574 | kfree(kdata); |
| 575 | |
| 576 | if (retcode) |
| 577 | dev_dbg(kfd_device, "ret = %d\n", retcode); |
| 578 | |
| 579 | return retcode; |
| 580 | } |
| 581 | |
| 582 | static int kfd_mmap(struct file *filp, struct vm_area_struct *vma) |
| 583 | { |
| 584 | struct kfd_process *process; |
| 585 | |
| 586 | process = kfd_get_process(current); |
| 587 | if (IS_ERR(process)) |
| 588 | return PTR_ERR(process); |
| 589 | |
| 590 | return kfd_doorbell_mmap(process, vma); |
| 591 | } |