aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 9f0247cdda5e..7b5c3bb2142e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -35,33 +35,45 @@
35#define AMDGPU_BO_LIST_MAX_PRIORITY 32u 35#define AMDGPU_BO_LIST_MAX_PRIORITY 32u
36#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1) 36#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1)
37 37
38static int amdgpu_bo_list_create(struct amdgpu_fpriv *fpriv, 38static int amdgpu_bo_list_set(struct amdgpu_device *adev,
39 struct amdgpu_bo_list **result, 39 struct drm_file *filp,
40 struct amdgpu_bo_list *list,
41 struct drm_amdgpu_bo_list_entry *info,
42 unsigned num_entries);
43
44static int amdgpu_bo_list_create(struct amdgpu_device *adev,
45 struct drm_file *filp,
46 struct drm_amdgpu_bo_list_entry *info,
47 unsigned num_entries,
40 int *id) 48 int *id)
41{ 49{
42 int r; 50 int r;
51 struct amdgpu_fpriv *fpriv = filp->driver_priv;
52 struct amdgpu_bo_list *list;
43 53
44 *result = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL); 54 list = kzalloc(sizeof(struct amdgpu_bo_list), GFP_KERNEL);
45 if (!*result) 55 if (!list)
46 return -ENOMEM; 56 return -ENOMEM;
47 57
58 /* initialize bo list*/
59 mutex_init(&list->lock);
60
61 r = amdgpu_bo_list_set(adev, filp, list, info, num_entries);
62 if (r) {
63 kfree(list);
64 return r;
65 }
66
67 /* idr alloc should be called only after initialization of bo list. */
48 mutex_lock(&fpriv->bo_list_lock); 68 mutex_lock(&fpriv->bo_list_lock);
49 r = idr_alloc(&fpriv->bo_list_handles, *result, 69 r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
50 1, 0, GFP_KERNEL); 70 mutex_unlock(&fpriv->bo_list_lock);
51 if (r < 0) { 71 if (r < 0) {
52 mutex_unlock(&fpriv->bo_list_lock); 72 kfree(list);
53 kfree(*result);
54 return r; 73 return r;
55 } 74 }
56 *id = r; 75 *id = r;
57 76
58 mutex_init(&(*result)->lock);
59 (*result)->num_entries = 0;
60 (*result)->array = NULL;
61
62 mutex_lock(&(*result)->lock);
63 mutex_unlock(&fpriv->bo_list_lock);
64
65 return 0; 77 return 0;
66} 78}
67 79
@@ -77,6 +89,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
77 mutex_unlock(&list->lock); 89 mutex_unlock(&list->lock);
78 amdgpu_bo_list_free(list); 90 amdgpu_bo_list_free(list);
79 } 91 }
92
80 mutex_unlock(&fpriv->bo_list_lock); 93 mutex_unlock(&fpriv->bo_list_lock);
81} 94}
82 95
@@ -273,16 +286,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
273 286
274 switch (args->in.operation) { 287 switch (args->in.operation) {
275 case AMDGPU_BO_LIST_OP_CREATE: 288 case AMDGPU_BO_LIST_OP_CREATE:
276 r = amdgpu_bo_list_create(fpriv, &list, &handle); 289 r = amdgpu_bo_list_create(adev, filp, info, args->in.bo_number,
290 &handle);
277 if (r) 291 if (r)
278 goto error_free; 292 goto error_free;
279
280 r = amdgpu_bo_list_set(adev, filp, list, info,
281 args->in.bo_number);
282 amdgpu_bo_list_put(list);
283 if (r)
284 goto error_free;
285
286 break; 293 break;
287 294
288 case AMDGPU_BO_LIST_OP_DESTROY: 295 case AMDGPU_BO_LIST_OP_DESTROY: