From: Oak Zeng <Oak.Zeng@xxxxxxx> Change-Id: I32e0304cdf6ceeed12ea8d0af62f44e1ab20bffb Signed-off-by: Oak Zeng <Oak.Zeng@xxxxxxx> Reviewd-by: Felix Kuehling <Felix.Kuehling@xxxxxxx> --- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 26 +++++++++++++------ .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 30 +++++++++++++++++++--- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index 5f4062b..37b02ea 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -143,7 +143,8 @@ static int kfd_ioctl_get_version(struct file *filep, struct kfd_process *p, return 0; } -static int set_queue_properties_from_user(struct queue_properties *q_properties, +static int set_queue_properties_from_user(struct kfd_dev *dev, + struct queue_properties *q_properties, struct kfd_ioctl_create_queue_args *args) { if (args->queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) { @@ -213,12 +214,21 @@ static int set_queue_properties_from_user(struct queue_properties *q_properties, q_properties->ctx_save_restore_area_size = args->ctx_save_restore_size; q_properties->ctl_stack_size = args->ctl_stack_size; if (args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE || - args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL) + args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL) { q_properties->type = KFD_QUEUE_TYPE_COMPUTE; - else if (args->queue_type == KFD_IOC_QUEUE_TYPE_SDMA) + } else if (args->queue_type == KFD_IOC_QUEUE_TYPE_SDMA) { + q_properties->sdma_engine_id = + dev->device_info->num_sdma_engines; q_properties->type = KFD_QUEUE_TYPE_SDMA; - else + } else if (args->queue_type >= KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(0) && + args->queue_type < KFD_IOC_QUEUE_TYPE_SDMA_ENGINE( + dev->device_info->num_sdma_engines)) { + q_properties->sdma_engine_id = + args->queue_type - KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(0); + q_properties->type = KFD_QUEUE_TYPE_SDMA; + } else { return -ENOTSUPP; + } if (args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL) q_properties->format = KFD_QUEUE_FORMAT_AQL; @@ -265,10 +275,6 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, pr_debug("Creating queue ioctl\n"); - err = set_queue_properties_from_user(&q_properties, args); - if (err) - return err; - pr_debug("Looking for gpu id 0x%x\n", args->gpu_id); dev = kfd_device_by_id(args->gpu_id); if (!dev) { @@ -276,6 +282,10 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, return -EINVAL; } + err = set_queue_properties_from_user(dev, &q_properties, args); + if (err) + return err; + mutex_lock(&p->mutex); pdd = kfd_bind_process_to_device(dev, p); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c index 7bf4bca..bc8f955 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -916,14 +916,34 @@ static int stop_nocpsch(struct device_queue_manager *dqm) } static int allocate_sdma_queue(struct device_queue_manager *dqm, + unsigned int sdma_engine_id, unsigned int *sdma_queue_id) { - int bit; + int bit = -1; if (dqm->sdma_bitmap == 0) return -ENOMEM; - bit = __ffs64(dqm->sdma_bitmap); + /* If sdma_engine_id is valid, + * allocate queue on specific engine + */ + if (sdma_engine_id < get_num_sdma_engines(dqm)) { + unsigned int i; + + for (i = sdma_engine_id; i < get_num_sdma_queues(dqm); + i += get_num_sdma_engines(dqm)) { + if (dqm->sdma_bitmap & (1<<i)) { + bit = i; + break; + } + } + if (bit == -1) + return -EBUSY; + /* Otherwise allocate from any engine */ + } else { + bit = __ffs64(dqm->sdma_bitmap); + } + dqm->sdma_bitmap &= ~(1ULL << bit); *sdma_queue_id = bit; @@ -949,7 +969,8 @@ static int create_sdma_queue_nocpsch(struct device_queue_manager *dqm, if (!mqd_mgr) return -ENOMEM; - retval = allocate_sdma_queue(dqm, &q->sdma_id); + retval = allocate_sdma_queue(dqm, q->properties.sdma_engine_id, + &q->sdma_id); if (retval) return retval; @@ -1168,7 +1189,8 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q, } if (q->properties.type == KFD_QUEUE_TYPE_SDMA) { - retval = allocate_sdma_queue(dqm, &q->sdma_id); + retval = allocate_sdma_queue(dqm, q->properties.sdma_engine_id, + &q->sdma_id); if (retval) goto out_unlock; q->properties.sdma_queue_id = -- 2.7.4 _______________________________________________ amd-gfx mailing list amd-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/amd-gfx