diff options
author | Monk Liu | 2017-08-08 11:09:07 -0500 |
---|---|---|
committer | Alex Deucher | 2017-08-08 11:16:20 -0500 |
commit | 687d250797ff0028fee949cdd66c9f012f69992d (patch) | |
tree | a200b5b5a360d4a7a2a686206055fa8d539e0c80 | |
parent | 2a89ae5d7a7d5845226ed85146140ff4c8788d59 (diff) | |
download | external-libgbm-687d250797ff0028fee949cdd66c9f012f69992d.tar.gz external-libgbm-687d250797ff0028fee949cdd66c9f012f69992d.tar.xz external-libgbm-687d250797ff0028fee949cdd66c9f012f69992d.zip |
amdgpu: merge and cleanup amdgpu_bo_free
since bo_reference and bo_internal_free are
all only used by bo_free, so we just merge them
together
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Monk Liu <monk.liu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | amdgpu/amdgpu_bo.c | 52 | ||||
-rw-r--r-- | amdgpu/amdgpu_internal.h | 33 |
2 files changed, 29 insertions, 56 deletions
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 803fe54c..3853fd03 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c | |||
@@ -53,27 +53,6 @@ static void amdgpu_close_kms_handle(amdgpu_device_handle dev, | |||
53 | drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &args); | 53 | drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &args); |
54 | } | 54 | } |
55 | 55 | ||
56 | drm_private void amdgpu_bo_free_internal(amdgpu_bo_handle bo) | ||
57 | { | ||
58 | /* Remove the buffer from the hash tables. */ | ||
59 | util_hash_table_remove(bo->dev->bo_handles, | ||
60 | (void*)(uintptr_t)bo->handle); | ||
61 | if (bo->flink_name) { | ||
62 | util_hash_table_remove(bo->dev->bo_flink_names, | ||
63 | (void*)(uintptr_t)bo->flink_name); | ||
64 | } | ||
65 | |||
66 | /* Release CPU access. */ | ||
67 | if (bo->cpu_map_count > 0) { | ||
68 | bo->cpu_map_count = 1; | ||
69 | amdgpu_bo_cpu_unmap(bo); | ||
70 | } | ||
71 | |||
72 | amdgpu_close_kms_handle(bo->dev, bo->handle); | ||
73 | pthread_mutex_destroy(&bo->cpu_access_mutex); | ||
74 | free(bo); | ||
75 | } | ||
76 | |||
77 | int amdgpu_bo_alloc(amdgpu_device_handle dev, | 56 | int amdgpu_bo_alloc(amdgpu_device_handle dev, |
78 | struct amdgpu_bo_alloc_request *alloc_buffer, | 57 | struct amdgpu_bo_alloc_request *alloc_buffer, |
79 | amdgpu_bo_handle *buf_handle) | 58 | amdgpu_bo_handle *buf_handle) |
@@ -417,8 +396,35 @@ int amdgpu_bo_import(amdgpu_device_handle dev, | |||
417 | 396 | ||
418 | int amdgpu_bo_free(amdgpu_bo_handle buf_handle) | 397 | int amdgpu_bo_free(amdgpu_bo_handle buf_handle) |
419 | { | 398 | { |
420 | /* Just drop the reference. */ | 399 | struct amdgpu_device *dev; |
421 | amdgpu_bo_reference(&buf_handle, NULL); | 400 | struct amdgpu_bo *bo = buf_handle; |
401 | |||
402 | assert(bo != NULL); | ||
403 | dev = bo->dev; | ||
404 | pthread_mutex_lock(&dev->bo_table_mutex); | ||
405 | |||
406 | if (update_references(&bo->refcount, NULL)) { | ||
407 | /* Remove the buffer from the hash tables. */ | ||
408 | util_hash_table_remove(dev->bo_handles, | ||
409 | (void*)(uintptr_t)bo->handle); | ||
410 | |||
411 | if (bo->flink_name) { | ||
412 | util_hash_table_remove(dev->bo_flink_names, | ||
413 | (void*)(uintptr_t)bo->flink_name); | ||
414 | } | ||
415 | |||
416 | /* Release CPU access. */ | ||
417 | if (bo->cpu_map_count > 0) { | ||
418 | bo->cpu_map_count = 1; | ||
419 | amdgpu_bo_cpu_unmap(bo); | ||
420 | } | ||
421 | |||
422 | amdgpu_close_kms_handle(dev, bo->handle); | ||
423 | pthread_mutex_destroy(&bo->cpu_access_mutex); | ||
424 | free(bo); | ||
425 | } | ||
426 | |||
427 | pthread_mutex_unlock(&dev->bo_table_mutex); | ||
422 | return 0; | 428 | return 0; |
423 | } | 429 | } |
424 | 430 | ||
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h index 28d1f38f..56d15112 100644 --- a/amdgpu/amdgpu_internal.h +++ b/amdgpu/amdgpu_internal.h | |||
@@ -143,8 +143,6 @@ struct amdgpu_semaphore { | |||
143 | * Functions. | 143 | * Functions. |
144 | */ | 144 | */ |
145 | 145 | ||
146 | drm_private void amdgpu_bo_free_internal(amdgpu_bo_handle bo); | ||
147 | |||
148 | drm_private void amdgpu_vamgr_init(struct amdgpu_bo_va_mgr *mgr, uint64_t start, | 146 | drm_private void amdgpu_vamgr_init(struct amdgpu_bo_va_mgr *mgr, uint64_t start, |
149 | uint64_t max, uint64_t alignment); | 147 | uint64_t max, uint64_t alignment); |
150 | 148 | ||
@@ -189,35 +187,4 @@ static inline bool update_references(atomic_t *dst, atomic_t *src) | |||
189 | return false; | 187 | return false; |
190 | } | 188 | } |
191 | 189 | ||
192 | /** | ||
193 | * Assignment between two amdgpu_bo pointers with reference counting. | ||
194 | * | ||
195 | * Usage: | ||
196 | * struct amdgpu_bo *dst = ... , *src = ...; | ||
197 | * | ||
198 | * dst = src; | ||
199 | * // No reference counting. Only use this when you need to move | ||
200 | * // a reference from one pointer to another. | ||
201 | * | ||
202 | * amdgpu_bo_reference(&dst, src); | ||
203 | * // Reference counters are updated. dst is decremented and src is | ||
204 | * // incremented. dst is freed if its reference counter is 0. | ||
205 | */ | ||
206 | static inline void amdgpu_bo_reference(struct amdgpu_bo **dst, | ||
207 | struct amdgpu_bo *src) | ||
208 | { | ||
209 | pthread_mutex_t *mlock; | ||
210 | struct amdgpu_bo* bo = *dst; | ||
211 | |||
212 | assert(bo != NULL); | ||
213 | mlock = &bo->dev->bo_table_mutex; | ||
214 | pthread_mutex_lock(mlock); | ||
215 | |||
216 | if (update_references(&bo->refcount, src?&src->refcount:NULL)) | ||
217 | amdgpu_bo_free_internal(bo); | ||
218 | |||
219 | pthread_mutex_unlock(mlock); | ||
220 | *dst = src; | ||
221 | } | ||
222 | |||
223 | #endif | 190 | #endif |