Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'amdkfd-fixes-2015-01-06' of git://people.freedesktop.org/~gabbayo/linux into drm-fixes

- Complete overhaul to the main IOCTL function, kfd_ioctl(), according to
drm_ioctl() example. This includes changing the IOCTL definitions, so it
breaks compatibility with previous versions of the userspace. However,
because the kernel was not officialy released yet, and this the first
kernel that includes amdkfd, I assume I can still do that at this stage.

- A couple of bug fixes for the non-HWS path (used for bring-ups and
debugging purposes only).

* tag 'amdkfd-fixes-2015-01-06' of git://people.freedesktop.org/~gabbayo/linux:
drm/amdkfd: rewrite kfd_ioctl() according to drm_ioctl()
drm/amdkfd: reformat IOCTL definitions to drm-style
drm/amdkfd: Do copy_to/from_user in general kfd_ioctl()
drm/amdkfd: unmap VMID<-->PASID when relesing VMID (non-HWS)
drm/radeon: Assign VMID to PASID for IH in non-HWS mode
drm/radeon: do not leave queue acquired if timeout happens in kgd_hqd_destroy()
drm/amdkfd: Load mqd to hqd in non-HWS mode
drm/amd: Fixing typos in kfd<->kgd interface

+236 -168
+169 -148
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
··· 126 126 return 0; 127 127 } 128 128 129 - static long kfd_ioctl_get_version(struct file *filep, struct kfd_process *p, 130 - void __user *arg) 129 + static int kfd_ioctl_get_version(struct file *filep, struct kfd_process *p, 130 + void *data) 131 131 { 132 - struct kfd_ioctl_get_version_args args; 132 + struct kfd_ioctl_get_version_args *args = data; 133 133 int err = 0; 134 134 135 - args.major_version = KFD_IOCTL_MAJOR_VERSION; 136 - args.minor_version = KFD_IOCTL_MINOR_VERSION; 137 - 138 - if (copy_to_user(arg, &args, sizeof(args))) 139 - err = -EFAULT; 135 + args->major_version = KFD_IOCTL_MAJOR_VERSION; 136 + args->minor_version = KFD_IOCTL_MINOR_VERSION; 140 137 141 138 return err; 142 139 } ··· 217 220 return 0; 218 221 } 219 222 220 - static long kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 221 - void __user *arg) 223 + static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 224 + void *data) 222 225 { 223 - struct kfd_ioctl_create_queue_args args; 226 + struct kfd_ioctl_create_queue_args *args = data; 224 227 struct kfd_dev *dev; 225 228 int err = 0; 226 229 unsigned int queue_id; ··· 229 232 230 233 memset(&q_properties, 0, sizeof(struct queue_properties)); 231 234 232 - if (copy_from_user(&args, arg, sizeof(args))) 233 - return -EFAULT; 234 - 235 235 pr_debug("kfd: creating queue ioctl\n"); 236 236 237 - err = set_queue_properties_from_user(&q_properties, &args); 237 + err = set_queue_properties_from_user(&q_properties, args); 238 238 if (err) 239 239 return err; 240 240 241 - dev = kfd_device_by_id(args.gpu_id); 241 + dev = kfd_device_by_id(args->gpu_id); 242 242 if (dev == NULL) 243 243 return -EINVAL; 244 244 ··· 243 249 244 250 pdd = kfd_bind_process_to_device(dev, p); 245 251 if (IS_ERR(pdd)) { 246 - err = PTR_ERR(pdd); 252 + err = -ESRCH; 247 253 goto err_bind_process; 248 254 } 249 255 ··· 256 262 if (err != 0) 257 263 goto err_create_queue; 258 264 259 - args.queue_id = queue_id; 265 + args->queue_id = queue_id; 260 266 261 267 /* Return gpu_id as doorbell offset for mmap usage */ 262 - args.doorbell_offset = args.gpu_id << PAGE_SHIFT; 263 - 264 - if (copy_to_user(arg, &args, sizeof(args))) { 265 - err = -EFAULT; 266 - goto err_copy_args_out; 267 - } 268 + args->doorbell_offset = args->gpu_id << PAGE_SHIFT; 268 269 269 270 mutex_unlock(&p->mutex); 270 271 271 - pr_debug("kfd: queue id %d was created successfully\n", args.queue_id); 272 + pr_debug("kfd: queue id %d was created successfully\n", args->queue_id); 272 273 273 274 pr_debug("ring buffer address == 0x%016llX\n", 274 - args.ring_base_address); 275 + args->ring_base_address); 275 276 276 277 pr_debug("read ptr address == 0x%016llX\n", 277 - args.read_pointer_address); 278 + args->read_pointer_address); 278 279 279 280 pr_debug("write ptr address == 0x%016llX\n", 280 - args.write_pointer_address); 281 + args->write_pointer_address); 281 282 282 283 return 0; 283 284 284 - err_copy_args_out: 285 - pqm_destroy_queue(&p->pqm, queue_id); 286 285 err_create_queue: 287 286 err_bind_process: 288 287 mutex_unlock(&p->mutex); ··· 283 296 } 284 297 285 298 static int kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p, 286 - void __user *arg) 299 + void *data) 287 300 { 288 301 int retval; 289 - struct kfd_ioctl_destroy_queue_args args; 290 - 291 - if (copy_from_user(&args, arg, sizeof(args))) 292 - return -EFAULT; 302 + struct kfd_ioctl_destroy_queue_args *args = data; 293 303 294 304 pr_debug("kfd: destroying queue id %d for PASID %d\n", 295 - args.queue_id, 305 + args->queue_id, 296 306 p->pasid); 297 307 298 308 mutex_lock(&p->mutex); 299 309 300 - retval = pqm_destroy_queue(&p->pqm, args.queue_id); 310 + retval = pqm_destroy_queue(&p->pqm, args->queue_id); 301 311 302 312 mutex_unlock(&p->mutex); 303 313 return retval; 304 314 } 305 315 306 316 static int kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p, 307 - void __user *arg) 317 + void *data) 308 318 { 309 319 int retval; 310 - struct kfd_ioctl_update_queue_args args; 320 + struct kfd_ioctl_update_queue_args *args = data; 311 321 struct queue_properties properties; 312 322 313 - if (copy_from_user(&args, arg, sizeof(args))) 314 - return -EFAULT; 315 - 316 - if (args.queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) { 323 + if (args->queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) { 317 324 pr_err("kfd: queue percentage must be between 0 to KFD_MAX_QUEUE_PERCENTAGE\n"); 318 325 return -EINVAL; 319 326 } 320 327 321 - if (args.queue_priority > KFD_MAX_QUEUE_PRIORITY) { 328 + if (args->queue_priority > KFD_MAX_QUEUE_PRIORITY) { 322 329 pr_err("kfd: queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n"); 323 330 return -EINVAL; 324 331 } 325 332 326 - if ((args.ring_base_address) && 333 + if ((args->ring_base_address) && 327 334 (!access_ok(VERIFY_WRITE, 328 - (const void __user *) args.ring_base_address, 335 + (const void __user *) args->ring_base_address, 329 336 sizeof(uint64_t)))) { 330 337 pr_err("kfd: can't access ring base address\n"); 331 338 return -EFAULT; 332 339 } 333 340 334 - if (!is_power_of_2(args.ring_size) && (args.ring_size != 0)) { 341 + if (!is_power_of_2(args->ring_size) && (args->ring_size != 0)) { 335 342 pr_err("kfd: ring size must be a power of 2 or 0\n"); 336 343 return -EINVAL; 337 344 } 338 345 339 - properties.queue_address = args.ring_base_address; 340 - properties.queue_size = args.ring_size; 341 - properties.queue_percent = args.queue_percentage; 342 - properties.priority = args.queue_priority; 346 + properties.queue_address = args->ring_base_address; 347 + properties.queue_size = args->ring_size; 348 + properties.queue_percent = args->queue_percentage; 349 + properties.priority = args->queue_priority; 343 350 344 351 pr_debug("kfd: updating queue id %d for PASID %d\n", 345 - args.queue_id, p->pasid); 352 + args->queue_id, p->pasid); 346 353 347 354 mutex_lock(&p->mutex); 348 355 349 - retval = pqm_update_queue(&p->pqm, args.queue_id, &properties); 356 + retval = pqm_update_queue(&p->pqm, args->queue_id, &properties); 350 357 351 358 mutex_unlock(&p->mutex); 352 359 353 360 return retval; 354 361 } 355 362 356 - static long kfd_ioctl_set_memory_policy(struct file *filep, 357 - struct kfd_process *p, void __user *arg) 363 + static int kfd_ioctl_set_memory_policy(struct file *filep, 364 + struct kfd_process *p, void *data) 358 365 { 359 - struct kfd_ioctl_set_memory_policy_args args; 366 + struct kfd_ioctl_set_memory_policy_args *args = data; 360 367 struct kfd_dev *dev; 361 368 int err = 0; 362 369 struct kfd_process_device *pdd; 363 370 enum cache_policy default_policy, alternate_policy; 364 371 365 - if (copy_from_user(&args, arg, sizeof(args))) 366 - return -EFAULT; 367 - 368 - if (args.default_policy != KFD_IOC_CACHE_POLICY_COHERENT 369 - && args.default_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { 372 + if (args->default_policy != KFD_IOC_CACHE_POLICY_COHERENT 373 + && args->default_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { 370 374 return -EINVAL; 371 375 } 372 376 373 - if (args.alternate_policy != KFD_IOC_CACHE_POLICY_COHERENT 374 - && args.alternate_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { 377 + if (args->alternate_policy != KFD_IOC_CACHE_POLICY_COHERENT 378 + && args->alternate_policy != KFD_IOC_CACHE_POLICY_NONCOHERENT) { 375 379 return -EINVAL; 376 380 } 377 381 378 - dev = kfd_device_by_id(args.gpu_id); 382 + dev = kfd_device_by_id(args->gpu_id); 379 383 if (dev == NULL) 380 384 return -EINVAL; 381 385 ··· 374 396 375 397 pdd = kfd_bind_process_to_device(dev, p); 376 398 if (IS_ERR(pdd)) { 377 - err = PTR_ERR(pdd); 399 + err = -ESRCH; 378 400 goto out; 379 401 } 380 402 381 - default_policy = (args.default_policy == KFD_IOC_CACHE_POLICY_COHERENT) 403 + default_policy = (args->default_policy == KFD_IOC_CACHE_POLICY_COHERENT) 382 404 ? cache_policy_coherent : cache_policy_noncoherent; 383 405 384 406 alternate_policy = 385 - (args.alternate_policy == KFD_IOC_CACHE_POLICY_COHERENT) 407 + (args->alternate_policy == KFD_IOC_CACHE_POLICY_COHERENT) 386 408 ? cache_policy_coherent : cache_policy_noncoherent; 387 409 388 410 if (!dev->dqm->set_cache_memory_policy(dev->dqm, 389 411 &pdd->qpd, 390 412 default_policy, 391 413 alternate_policy, 392 - (void __user *)args.alternate_aperture_base, 393 - args.alternate_aperture_size)) 414 + (void __user *)args->alternate_aperture_base, 415 + args->alternate_aperture_size)) 394 416 err = -EINVAL; 395 417 396 418 out: ··· 399 421 return err; 400 422 } 401 423 402 - static long kfd_ioctl_get_clock_counters(struct file *filep, 403 - struct kfd_process *p, void __user *arg) 424 + static int kfd_ioctl_get_clock_counters(struct file *filep, 425 + struct kfd_process *p, void *data) 404 426 { 405 - struct kfd_ioctl_get_clock_counters_args args; 427 + struct kfd_ioctl_get_clock_counters_args *args = data; 406 428 struct kfd_dev *dev; 407 429 struct timespec time; 408 430 409 - if (copy_from_user(&args, arg, sizeof(args))) 410 - return -EFAULT; 411 - 412 - dev = kfd_device_by_id(args.gpu_id); 431 + dev = kfd_device_by_id(args->gpu_id); 413 432 if (dev == NULL) 414 433 return -EINVAL; 415 434 416 435 /* Reading GPU clock counter from KGD */ 417 - args.gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd); 436 + args->gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd); 418 437 419 438 /* No access to rdtsc. Using raw monotonic time */ 420 439 getrawmonotonic(&time); 421 - args.cpu_clock_counter = (uint64_t)timespec_to_ns(&time); 440 + args->cpu_clock_counter = (uint64_t)timespec_to_ns(&time); 422 441 423 442 get_monotonic_boottime(&time); 424 - args.system_clock_counter = (uint64_t)timespec_to_ns(&time); 443 + args->system_clock_counter = (uint64_t)timespec_to_ns(&time); 425 444 426 445 /* Since the counter is in nano-seconds we use 1GHz frequency */ 427 - args.system_clock_freq = 1000000000; 428 - 429 - if (copy_to_user(arg, &args, sizeof(args))) 430 - return -EFAULT; 446 + args->system_clock_freq = 1000000000; 431 447 432 448 return 0; 433 449 } 434 450 435 451 436 452 static int kfd_ioctl_get_process_apertures(struct file *filp, 437 - struct kfd_process *p, void __user *arg) 453 + struct kfd_process *p, void *data) 438 454 { 439 - struct kfd_ioctl_get_process_apertures_args args; 455 + struct kfd_ioctl_get_process_apertures_args *args = data; 440 456 struct kfd_process_device_apertures *pAperture; 441 457 struct kfd_process_device *pdd; 442 458 443 459 dev_dbg(kfd_device, "get apertures for PASID %d", p->pasid); 444 460 445 - if (copy_from_user(&args, arg, sizeof(args))) 446 - return -EFAULT; 447 - 448 - args.num_of_nodes = 0; 461 + args->num_of_nodes = 0; 449 462 450 463 mutex_lock(&p->mutex); 451 464 ··· 445 476 /* Run over all pdd of the process */ 446 477 pdd = kfd_get_first_process_device_data(p); 447 478 do { 448 - pAperture = &args.process_apertures[args.num_of_nodes]; 479 + pAperture = 480 + &args->process_apertures[args->num_of_nodes]; 449 481 pAperture->gpu_id = pdd->dev->id; 450 482 pAperture->lds_base = pdd->lds_base; 451 483 pAperture->lds_limit = pdd->lds_limit; ··· 456 486 pAperture->scratch_limit = pdd->scratch_limit; 457 487 458 488 dev_dbg(kfd_device, 459 - "node id %u\n", args.num_of_nodes); 489 + "node id %u\n", args->num_of_nodes); 460 490 dev_dbg(kfd_device, 461 491 "gpu id %u\n", pdd->dev->id); 462 492 dev_dbg(kfd_device, ··· 472 502 dev_dbg(kfd_device, 473 503 "scratch_limit %llX\n", pdd->scratch_limit); 474 504 475 - args.num_of_nodes++; 505 + args->num_of_nodes++; 476 506 } while ((pdd = kfd_get_next_process_device_data(p, pdd)) != NULL && 477 - (args.num_of_nodes < NUM_OF_SUPPORTED_GPUS)); 507 + (args->num_of_nodes < NUM_OF_SUPPORTED_GPUS)); 478 508 } 479 509 480 510 mutex_unlock(&p->mutex); 481 511 482 - if (copy_to_user(arg, &args, sizeof(args))) 483 - return -EFAULT; 484 - 485 512 return 0; 486 513 } 514 + 515 + #define AMDKFD_IOCTL_DEF(ioctl, _func, _flags) \ 516 + [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, .cmd_drv = 0, .name = #ioctl} 517 + 518 + /** Ioctl table */ 519 + static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = { 520 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_VERSION, 521 + kfd_ioctl_get_version, 0), 522 + 523 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_CREATE_QUEUE, 524 + kfd_ioctl_create_queue, 0), 525 + 526 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_DESTROY_QUEUE, 527 + kfd_ioctl_destroy_queue, 0), 528 + 529 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_SET_MEMORY_POLICY, 530 + kfd_ioctl_set_memory_policy, 0), 531 + 532 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_CLOCK_COUNTERS, 533 + kfd_ioctl_get_clock_counters, 0), 534 + 535 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_GET_PROCESS_APERTURES, 536 + kfd_ioctl_get_process_apertures, 0), 537 + 538 + AMDKFD_IOCTL_DEF(AMDKFD_IOC_UPDATE_QUEUE, 539 + kfd_ioctl_update_queue, 0), 540 + }; 541 + 542 + #define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls) 487 543 488 544 static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 489 545 { 490 546 struct kfd_process *process; 491 - long err = -EINVAL; 547 + amdkfd_ioctl_t *func; 548 + const struct amdkfd_ioctl_desc *ioctl = NULL; 549 + unsigned int nr = _IOC_NR(cmd); 550 + char stack_kdata[128]; 551 + char *kdata = NULL; 552 + unsigned int usize, asize; 553 + int retcode = -EINVAL; 492 554 493 - dev_dbg(kfd_device, 494 - "ioctl cmd 0x%x (#%d), arg 0x%lx\n", 495 - cmd, _IOC_NR(cmd), arg); 555 + if (nr >= AMDKFD_CORE_IOCTL_COUNT) 556 + goto err_i1; 557 + 558 + if ((nr >= AMDKFD_COMMAND_START) && (nr < AMDKFD_COMMAND_END)) { 559 + u32 amdkfd_size; 560 + 561 + ioctl = &amdkfd_ioctls[nr]; 562 + 563 + amdkfd_size = _IOC_SIZE(ioctl->cmd); 564 + usize = asize = _IOC_SIZE(cmd); 565 + if (amdkfd_size > asize) 566 + asize = amdkfd_size; 567 + 568 + cmd = ioctl->cmd; 569 + } else 570 + goto err_i1; 571 + 572 + dev_dbg(kfd_device, "ioctl cmd 0x%x (#%d), arg 0x%lx\n", cmd, nr, arg); 496 573 497 574 process = kfd_get_process(current); 498 - if (IS_ERR(process)) 499 - return PTR_ERR(process); 500 - 501 - switch (cmd) { 502 - case KFD_IOC_GET_VERSION: 503 - err = kfd_ioctl_get_version(filep, process, (void __user *)arg); 504 - break; 505 - case KFD_IOC_CREATE_QUEUE: 506 - err = kfd_ioctl_create_queue(filep, process, 507 - (void __user *)arg); 508 - break; 509 - 510 - case KFD_IOC_DESTROY_QUEUE: 511 - err = kfd_ioctl_destroy_queue(filep, process, 512 - (void __user *)arg); 513 - break; 514 - 515 - case KFD_IOC_SET_MEMORY_POLICY: 516 - err = kfd_ioctl_set_memory_policy(filep, process, 517 - (void __user *)arg); 518 - break; 519 - 520 - case KFD_IOC_GET_CLOCK_COUNTERS: 521 - err = kfd_ioctl_get_clock_counters(filep, process, 522 - (void __user *)arg); 523 - break; 524 - 525 - case KFD_IOC_GET_PROCESS_APERTURES: 526 - err = kfd_ioctl_get_process_apertures(filep, process, 527 - (void __user *)arg); 528 - break; 529 - 530 - case KFD_IOC_UPDATE_QUEUE: 531 - err = kfd_ioctl_update_queue(filep, process, 532 - (void __user *)arg); 533 - break; 534 - 535 - default: 536 - dev_err(kfd_device, 537 - "unknown ioctl cmd 0x%x, arg 0x%lx)\n", 538 - cmd, arg); 539 - err = -EINVAL; 540 - break; 575 + if (IS_ERR(process)) { 576 + dev_dbg(kfd_device, "no process\n"); 577 + goto err_i1; 541 578 } 542 579 543 - if (err < 0) 544 - dev_err(kfd_device, 545 - "ioctl error %ld for ioctl cmd 0x%x (#%d)\n", 546 - err, cmd, _IOC_NR(cmd)); 580 + /* Do not trust userspace, use our own definition */ 581 + func = ioctl->func; 547 582 548 - return err; 583 + if (unlikely(!func)) { 584 + dev_dbg(kfd_device, "no function\n"); 585 + retcode = -EINVAL; 586 + goto err_i1; 587 + } 588 + 589 + if (cmd & (IOC_IN | IOC_OUT)) { 590 + if (asize <= sizeof(stack_kdata)) { 591 + kdata = stack_kdata; 592 + } else { 593 + kdata = kmalloc(asize, GFP_KERNEL); 594 + if (!kdata) { 595 + retcode = -ENOMEM; 596 + goto err_i1; 597 + } 598 + } 599 + if (asize > usize) 600 + memset(kdata + usize, 0, asize - usize); 601 + } 602 + 603 + if (cmd & IOC_IN) { 604 + if (copy_from_user(kdata, (void __user *)arg, usize) != 0) { 605 + retcode = -EFAULT; 606 + goto err_i1; 607 + } 608 + } else if (cmd & IOC_OUT) { 609 + memset(kdata, 0, usize); 610 + } 611 + 612 + retcode = func(filep, process, kdata); 613 + 614 + if (cmd & IOC_OUT) 615 + if (copy_to_user((void __user *)arg, kdata, usize) != 0) 616 + retcode = -EFAULT; 617 + 618 + err_i1: 619 + if (!ioctl) 620 + dev_dbg(kfd_device, "invalid ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n", 621 + task_pid_nr(current), cmd, nr); 622 + 623 + if (kdata != stack_kdata) 624 + kfree(kdata); 625 + 626 + if (retcode) 627 + dev_dbg(kfd_device, "ret = %d\n", retcode); 628 + 629 + return retcode; 549 630 } 550 631 551 632 static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
+15
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
··· 161 161 { 162 162 int bit = qpd->vmid - KFD_VMID_START_OFFSET; 163 163 164 + /* Release the vmid mapping */ 165 + set_pasid_vmid_mapping(dqm, 0, qpd->vmid); 166 + 164 167 set_bit(bit, (unsigned long *)&dqm->vmid_bitmap); 165 168 qpd->vmid = 0; 166 169 q->properties.vmid = 0; ··· 272 269 &q->gart_mqd_addr, &q->properties); 273 270 if (retval != 0) { 274 271 deallocate_hqd(dqm, q); 272 + return retval; 273 + } 274 + 275 + pr_debug("kfd: loading mqd to hqd on pipe (%d) queue (%d)\n", 276 + q->pipe, 277 + q->queue); 278 + 279 + retval = mqd->load_mqd(mqd, q->mqd, q->pipe, 280 + q->queue, q->properties.write_ptr); 281 + if (retval != 0) { 282 + deallocate_hqd(dqm, q); 283 + mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj); 275 284 return retval; 276 285 } 277 286
+1 -1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c
··· 184 184 uint32_t queue_id) 185 185 { 186 186 187 - return kfd2kgd->hqd_is_occupies(mm->dev->kgd, queue_address, 187 + return kfd2kgd->hqd_is_occupied(mm->dev->kgd, queue_address, 188 188 pipe_id, queue_id); 189 189 190 190 }
+18
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
··· 463 463 bool is_32bit_user_mode; 464 464 }; 465 465 466 + /** 467 + * Ioctl function type. 468 + * 469 + * \param filep pointer to file structure. 470 + * \param p amdkfd process pointer. 471 + * \param data pointer to arg that was copied from user. 472 + */ 473 + typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p, 474 + void *data); 475 + 476 + struct amdkfd_ioctl_desc { 477 + unsigned int cmd; 478 + int flags; 479 + amdkfd_ioctl_t *func; 480 + unsigned int cmd_drv; 481 + const char *name; 482 + }; 483 + 466 484 void kfd_process_create_wq(void); 467 485 void kfd_process_destroy_wq(void); 468 486 struct kfd_process *kfd_create_process(const struct task_struct *);
+1 -1
drivers/gpu/drm/amd/include/kgd_kfd_interface.h
··· 183 183 int (*hqd_load)(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id, 184 184 uint32_t queue_id, uint32_t __user *wptr); 185 185 186 - bool (*hqd_is_occupies)(struct kgd_dev *kgd, uint64_t queue_address, 186 + bool (*hqd_is_occupied)(struct kgd_dev *kgd, uint64_t queue_address, 187 187 uint32_t pipe_id, uint32_t queue_id); 188 188 189 189 int (*hqd_destroy)(struct kgd_dev *kgd, uint32_t reset_type,
+2
drivers/gpu/drm/radeon/cikd.h
··· 2156 2156 #define ATC_VM_APERTURE1_HIGH_ADDR 0x330Cu 2157 2157 #define ATC_VM_APERTURE1_LOW_ADDR 0x3304u 2158 2158 2159 + #define IH_VMID_0_LUT 0x3D40u 2160 + 2159 2161 #endif
+8 -3
drivers/gpu/drm/radeon/radeon_kfd.c
··· 72 72 static int kgd_hqd_load(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id, 73 73 uint32_t queue_id, uint32_t __user *wptr); 74 74 75 - static bool kgd_hqd_is_occupies(struct kgd_dev *kgd, uint64_t queue_address, 75 + static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address, 76 76 uint32_t pipe_id, uint32_t queue_id); 77 77 78 78 static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, ··· 92 92 .init_memory = kgd_init_memory, 93 93 .init_pipeline = kgd_init_pipeline, 94 94 .hqd_load = kgd_hqd_load, 95 - .hqd_is_occupies = kgd_hqd_is_occupies, 95 + .hqd_is_occupied = kgd_hqd_is_occupied, 96 96 .hqd_destroy = kgd_hqd_destroy, 97 97 .get_fw_version = get_fw_version 98 98 }; ··· 390 390 cpu_relax(); 391 391 write_register(kgd, ATC_VMID_PASID_MAPPING_UPDATE_STATUS, 1U << vmid); 392 392 393 + /* Mapping vmid to pasid also for IH block */ 394 + write_register(kgd, IH_VMID_0_LUT + vmid * sizeof(uint32_t), 395 + pasid_mapping); 396 + 393 397 return 0; 394 398 } 395 399 ··· 533 529 return 0; 534 530 } 535 531 536 - static bool kgd_hqd_is_occupies(struct kgd_dev *kgd, uint64_t queue_address, 532 + static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address, 537 533 uint32_t pipe_id, uint32_t queue_id) 538 534 { 539 535 uint32_t act; ··· 572 568 if (timeout == 0) { 573 569 pr_err("kfd: cp queue preemption time out (%dms)\n", 574 570 temp); 571 + release_queue(kgd); 575 572 return -ETIME; 576 573 } 577 574 msleep(20);
+22 -15
include/uapi/linux/kfd_ioctl.h
··· 128 128 uint32_t pad; 129 129 }; 130 130 131 - #define KFD_IOC_MAGIC 'K' 131 + #define AMDKFD_IOCTL_BASE 'K' 132 + #define AMDKFD_IO(nr) _IO(AMDKFD_IOCTL_BASE, nr) 133 + #define AMDKFD_IOR(nr, type) _IOR(AMDKFD_IOCTL_BASE, nr, type) 134 + #define AMDKFD_IOW(nr, type) _IOW(AMDKFD_IOCTL_BASE, nr, type) 135 + #define AMDKFD_IOWR(nr, type) _IOWR(AMDKFD_IOCTL_BASE, nr, type) 132 136 133 - #define KFD_IOC_GET_VERSION \ 134 - _IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args) 137 + #define AMDKFD_IOC_GET_VERSION \ 138 + AMDKFD_IOR(0x01, struct kfd_ioctl_get_version_args) 135 139 136 - #define KFD_IOC_CREATE_QUEUE \ 137 - _IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args) 140 + #define AMDKFD_IOC_CREATE_QUEUE \ 141 + AMDKFD_IOWR(0x02, struct kfd_ioctl_create_queue_args) 138 142 139 - #define KFD_IOC_DESTROY_QUEUE \ 140 - _IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args) 143 + #define AMDKFD_IOC_DESTROY_QUEUE \ 144 + AMDKFD_IOWR(0x03, struct kfd_ioctl_destroy_queue_args) 141 145 142 - #define KFD_IOC_SET_MEMORY_POLICY \ 143 - _IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args) 146 + #define AMDKFD_IOC_SET_MEMORY_POLICY \ 147 + AMDKFD_IOW(0x04, struct kfd_ioctl_set_memory_policy_args) 144 148 145 - #define KFD_IOC_GET_CLOCK_COUNTERS \ 146 - _IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args) 149 + #define AMDKFD_IOC_GET_CLOCK_COUNTERS \ 150 + AMDKFD_IOWR(0x05, struct kfd_ioctl_get_clock_counters_args) 147 151 148 - #define KFD_IOC_GET_PROCESS_APERTURES \ 149 - _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args) 152 + #define AMDKFD_IOC_GET_PROCESS_APERTURES \ 153 + AMDKFD_IOR(0x06, struct kfd_ioctl_get_process_apertures_args) 150 154 151 - #define KFD_IOC_UPDATE_QUEUE \ 152 - _IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args) 155 + #define AMDKFD_IOC_UPDATE_QUEUE \ 156 + AMDKFD_IOW(0x07, struct kfd_ioctl_update_queue_args) 157 + 158 + #define AMDKFD_COMMAND_START 0x01 159 + #define AMDKFD_COMMAND_END 0x08 153 160 154 161 #endif