drm/amdkfd: Process-device data creation and lookup split
authorAlexey Skidanov <Alexey.Skidanov@amd.com>
Tue, 18 Nov 2014 12:00:04 +0000 (14:00 +0200)
committerOded Gabbay <oded.gabbay@amd.com>
Fri, 9 Jan 2015 20:25:58 +0000 (22:25 +0200)
This patch splits the current kfd_get_process_device_data() to two
functions, one that specifically creates a pdd and another one which
just do lookup.

This is done to enhance the readability and maintainability of the code.

Signed-off-by: Alexey Skidanov <Alexey.Skidanov@amd.com>
Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/amd/amdkfd/kfd_process.c
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c

index 924e90c072e513180ec8991b50333f2af663a3f5..fb94f1a2b91147f747a239447ac31957bd241bbd 100644 (file)
@@ -75,7 +75,6 @@ get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
        nybble = (pdd->lds_base >> 60) & 0x0E;
 
        return nybble;
-
 }
 
 static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
index b5791a5c7c06156f73121629383ca9618741f853..1a9b355dd114595f8bcf156907e486ebe2bbbdb4 100644 (file)
@@ -137,10 +137,6 @@ int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma)
        if (dev == NULL)
                return -EINVAL;
 
-       /* Find if pdd exists for combination of process and gpu id */
-       if (!kfd_get_process_device_data(dev, process, 0))
-               return -EINVAL;
-
        /* Calculate physical address of doorbell */
        address = kfd_get_process_doorbells(dev, process);
 
index e64aa99e5e416349071f3c0906be347ed42e3e53..35b98757463305c9d1740542704f64cfc9db702a 100644 (file)
@@ -303,10 +303,11 @@ int kfd_init_apertures(struct kfd_process *process)
        while ((dev = kfd_topology_enum_kfd_devices(id)) != NULL &&
                id < NUM_OF_SUPPORTED_GPUS) {
 
-               pdd = kfd_get_process_device_data(dev, process, 1);
-               if (!pdd)
+               pdd = kfd_create_process_device_data(dev, process);
+               if (pdd == NULL) {
+                       pr_err("Failed to create process device data\n");
                        return -1;
-
+               }
                /*
                 * For 64 bit process aperture will be statically reserved in
                 * the x86_64 non canonical process address space
index ba2bba8b5731dfddedbb95bf191c0e155ffe47c5..a2e053cff720a3437e7840ba34355e466758685b 100644 (file)
@@ -473,8 +473,9 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
                                                        struct kfd_process *p);
 void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid);
 struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
-                                                       struct kfd_process *p,
-                                                       int create_pdd);
+                                                       struct kfd_process *p);
+struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
+                                                       struct kfd_process *p);
 
 /* Process device data iterator */
 struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p);
index 3c76ef05cbcf798483b482ac09b7bc62223d92c5..a369c149d1727e78cb67413578e6fe7ddd11d614 100644 (file)
@@ -311,24 +311,29 @@ err_alloc_process:
 }
 
 struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
-                                                       struct kfd_process *p,
-                                                       int create_pdd)
+                                                       struct kfd_process *p)
 {
        struct kfd_process_device *pdd = NULL;
 
        list_for_each_entry(pdd, &p->per_device_data, per_device_list)
                if (pdd->dev == dev)
-                       return pdd;
-
-       if (create_pdd) {
-               pdd = kzalloc(sizeof(*pdd), GFP_KERNEL);
-               if (pdd != NULL) {
-                       pdd->dev = dev;
-                       INIT_LIST_HEAD(&pdd->qpd.queues_list);
-                       INIT_LIST_HEAD(&pdd->qpd.priv_queue_list);
-                       pdd->qpd.dqm = dev->dqm;
-                       list_add(&pdd->per_device_list, &p->per_device_data);
-               }
+                       break;
+
+       return pdd;
+}
+
+struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
+                                                       struct kfd_process *p)
+{
+       struct kfd_process_device *pdd = NULL;
+
+       pdd = kzalloc(sizeof(*pdd), GFP_KERNEL);
+       if (pdd != NULL) {
+               pdd->dev = dev;
+               INIT_LIST_HEAD(&pdd->qpd.queues_list);
+               INIT_LIST_HEAD(&pdd->qpd.priv_queue_list);
+               pdd->qpd.dqm = dev->dqm;
+               list_add(&pdd->per_device_list, &p->per_device_data);
        }
 
        return pdd;
@@ -344,11 +349,14 @@ struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
 struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
                                                        struct kfd_process *p)
 {
-       struct kfd_process_device *pdd = kfd_get_process_device_data(dev, p, 1);
+       struct kfd_process_device *pdd;
        int err;
 
-       if (pdd == NULL)
+       pdd = kfd_get_process_device_data(dev, p);
+       if (!pdd) {
+               pr_err("Process device data doesn't exist\n");
                return ERR_PTR(-ENOMEM);
+       }
 
        if (pdd->bound)
                return pdd;
@@ -384,7 +392,7 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid)
 
        pqm_uninit(&p->pqm);
 
-       pdd = kfd_get_process_device_data(dev, p, 0);
+       pdd = kfd_get_process_device_data(dev, p);
 
        /*
         * Just mark pdd as unbound, because we still need it to call
index 47526780d736ced5470bfb2822a3892f879b0320..d12f9d32275b20915dc627a8d721c2f11152af42 100644 (file)
@@ -167,8 +167,11 @@ int pqm_create_queue(struct process_queue_manager *pqm,
        q = NULL;
        kq = NULL;
 
-       pdd = kfd_get_process_device_data(dev, pqm->process, 1);
-       BUG_ON(!pdd);
+       pdd = kfd_get_process_device_data(dev, pqm->process);
+       if (!pdd) {
+               pr_err("Process device data doesn't exist\n");
+               return -1;
+       }
 
        retval = find_available_queue_slot(pqm, qid);
        if (retval != 0)
@@ -273,8 +276,11 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
                dev = pqn->q->device;
        BUG_ON(!dev);
 
-       pdd = kfd_get_process_device_data(dev, pqm->process, 1);
-       BUG_ON(!pdd);
+       pdd = kfd_get_process_device_data(dev, pqm->process);
+       if (!pdd) {
+               pr_err("Process device data doesn't exist\n");
+               return -1;
+       }
 
        if (pqn->kq) {
                /* destroy kernel queue (DIQ) */