]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/amdkfd: New IOCTL to allocate queue GWS (v2)
authorOak Zeng <Oak.Zeng@amd.com>
Tue, 7 May 2019 03:11:14 +0000 (22:11 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 28 Apr 2020 20:20:30 +0000 (16:20 -0400)
Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

v2: re-introduce this API with the following fixes squashed in:
- drm/amdkfd: fix null pointer dereference on dev
- drm/amdkfd: Return proper error code for gws alloc API
- drm/amdkfd: Remove GPU ID in GWS queue creation

Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
include/uapi/linux/kfd_ioctl.h

index 0ec5f25adf56b134461685e7cf8516caa681690f..5eb1314f500b8ff51f785d53f1fb8755a002510d 100644 (file)
@@ -1584,6 +1584,43 @@ copy_from_user_failed:
        return err;
 }
 
+static int kfd_ioctl_alloc_queue_gws(struct file *filep,
+               struct kfd_process *p, void *data)
+{
+       int retval;
+       struct kfd_ioctl_alloc_queue_gws_args *args = data;
+       struct queue *q;
+       struct kfd_dev *dev;
+
+       if (!hws_gws_support)
+               return -ENODEV;
+
+       mutex_lock(&p->mutex);
+       q = pqm_get_user_queue(&p->pqm, args->queue_id);
+
+       if (q) {
+               dev = q->device;
+       } else {
+               retval = -EINVAL;
+               goto out_unlock;
+       }
+
+       if (dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS) {
+               retval = -ENODEV;
+               goto out_unlock;
+       }
+
+       retval = pqm_set_gws(&p->pqm, args->queue_id, args->num_gws ? dev->gws : NULL);
+       mutex_unlock(&p->mutex);
+
+       args->first_gws = 0;
+       return retval;
+
+out_unlock:
+       mutex_unlock(&p->mutex);
+       return retval;
+}
+
 static int kfd_ioctl_get_dmabuf_info(struct file *filep,
                struct kfd_process *p, void *data)
 {
@@ -1786,6 +1823,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
        AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
                                kfd_ioctl_import_dmabuf, 0),
 
+       AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
+                       kfd_ioctl_alloc_queue_gws, 0),
 };
 
 #define AMDKFD_CORE_IOCTL_COUNT        ARRAY_SIZE(amdkfd_ioctls)
index 4a3049841086d826ea8d798606a7af82dd44ffc1..5e7f1fb6761bff59c81a0c7ea9fa7b7affe84f0e 100644 (file)
@@ -923,6 +923,8 @@ int pqm_set_gws(struct process_queue_manager *pqm, unsigned int qid,
                        void *gws);
 struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm,
                                                unsigned int qid);
+struct queue *pqm_get_user_queue(struct process_queue_manager *pqm,
+                                               unsigned int qid);
 int pqm_get_wave_state(struct process_queue_manager *pqm,
                       unsigned int qid,
                       void __user *ctl_stack,
index 084c35f55d591f025d95053effe2d61b2117bf46..eb1635ac89887c18534e1ce1e969469386fcbf45 100644 (file)
@@ -476,6 +476,15 @@ struct kernel_queue *pqm_get_kernel_queue(
        return NULL;
 }
 
+struct queue *pqm_get_user_queue(struct process_queue_manager *pqm,
+                                       unsigned int qid)
+{
+       struct process_queue_node *pqn;
+
+       pqn = get_queue_by_qid(pqm, qid);
+       return pqn ? pqn->q : NULL;
+}
+
 int pqm_get_wave_state(struct process_queue_manager *pqm,
                       unsigned int qid,
                       void __user *ctl_stack,
index 20917c59f39c9a2a27bf1b62e907d5e2a31f88a6..4f6676428c5c7fd8c40b3d992c4200e81a3e4234 100644 (file)
@@ -410,6 +410,20 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
        __u32 n_success;                /* to/from KFD */
 };
 
+/* Allocate GWS for specific queue
+ *
+ * @queue_id:    queue's id that GWS is allocated for
+ * @num_gws:     how many GWS to allocate
+ * @first_gws:   index of the first GWS allocated.
+ *               only support contiguous GWS allocation
+ */
+struct kfd_ioctl_alloc_queue_gws_args {
+       __u32 queue_id;         /* to KFD */
+       __u32 num_gws;          /* to KFD */
+       __u32 first_gws;        /* from KFD */
+       __u32 pad;
+};
+
 struct kfd_ioctl_get_dmabuf_info_args {
        __u64 size;             /* from KFD */
        __u64 metadata_ptr;     /* to KFD */
@@ -529,7 +543,10 @@ enum kfd_mmio_remap {
 #define AMDKFD_IOC_IMPORT_DMABUF               \
                AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
 
+#define AMDKFD_IOC_ALLOC_QUEUE_GWS             \
+               AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
+
 #define AMDKFD_COMMAND_START           0x01
-#define AMDKFD_COMMAND_END             0x1E
+#define AMDKFD_COMMAND_END             0x1F
 
 #endif