+ if (r) {
+ DRM_ERROR("Failed to allocate bo for userqueue (%d)", r);
+ return r;
+ }
+
+ memset(queue->mqd_cpu_ptr, 0, size);
+ r = amdgpu_bo_reserve(queue->mqd_obj, false);
+ if (unlikely(r != 0)) {
+ DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
+ goto free_mqd;
+ }
+
+ r = uq_mgr->userq_mqd_funcs->mqd_create(uq_mgr, queue);
+ amdgpu_bo_unreserve(queue->mqd_obj);
+ if (r) {
+ DRM_ERROR("Failed to create MQD for queue\n");
+ goto free_mqd;
+ }
+ return 0;
+
+free_mqd:
+ amdgpu_bo_free_kernel(&queue->mqd_obj,
+ &queue->mqd_gpu_addr,
+ &queue->mqd_cpu_ptr);
+ return r;
+}
+
+static void
+amdgpu_userqueue_destroy_mqd(struct amdgpu_userq_mgr *uq_mgr, struct
amdgpu_usermode_queue *queue)
+{
+ uq_mgr->userq_mqd_funcs->mqd_destroy(uq_mgr, queue);
+ amdgpu_bo_free_kernel(&queue->mqd_obj,
+ &queue->mqd_gpu_addr,
+ &queue->mqd_cpu_ptr);
+}
+
static int amdgpu_userqueue_create(struct drm_file *filp, union
drm_amdgpu_userq *args)
{
int r, pasid;
@@ -82,12 +136,21 @@ static int amdgpu_userqueue_create(struct
drm_file *filp, union drm_amdgpu_userq
goto free_queue;
}
+ r = amdgpu_userqueue_create_mqd(uq_mgr, queue);
+ if (r) {
+ DRM_ERROR("Failed to create MQD\n");
+ goto free_qid;
+ }
+
list_add_tail(&queue->userq_node, &uq_mgr->userq_list);
args->out.q_id = queue->queue_id;
args->out.flags = 0;
mutex_unlock(&uq_mgr->userq_mutex);
return 0;
+free_qid:
+ amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
+
free_queue:
mutex_unlock(&uq_mgr->userq_mutex);
kfree(queue);
@@ -107,6 +170,7 @@ static void amdgpu_userqueue_destroy(struct
drm_file *filp, int queue_id)
}
mutex_lock(&uq_mgr->userq_mutex);
+ amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
list_del(&queue->userq_node);
mutex_unlock(&uq_mgr->userq_mutex);
diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
index 9557588fe34f..a6abdfd5cb74 100644
--- a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
+++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
@@ -26,10 +26,13 @@
#define AMDGPU_MAX_USERQ 512
+struct amdgpu_userq_mqd_funcs;
+
struct amdgpu_userq_mgr {
struct idr userq_idr;
struct mutex userq_mutex;
struct list_head userq_list;
+ const struct amdgpu_userq_mqd_funcs *userq_mqd_funcs;
struct amdgpu_device *adev;
};
@@ -57,6 +60,12 @@ struct amdgpu_usermode_queue {
int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct
drm_file *filp);
+struct amdgpu_userq_mqd_funcs {
+ int (*mqd_size)(struct amdgpu_userq_mgr *);
+ int (*mqd_create)(struct amdgpu_userq_mgr *, struct
amdgpu_usermode_queue *);
+ void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct
amdgpu_usermode_queue *);
+};
+
int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr,
struct amdgpu_device *adev);
void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);