aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov2015-08-07 11:09:35 -0500
committerEmil Velikov2015-08-13 11:43:36 -0500
commitbddf4df4a17df30624f27c5e85f859a1b09f8fc0 (patch)
treeb9854882fc81b841b457e8ffb5b4cadcb6b5059a /amdgpu/amdgpu_device.c
parentb47181897770520bb5afcebc2c2c3ffaf7729a36 (diff)
downloadexternal-libdrm-bddf4df4a17df30624f27c5e85f859a1b09f8fc0.tar.gz
external-libdrm-bddf4df4a17df30624f27c5e85f859a1b09f8fc0.tar.xz
external-libdrm-bddf4df4a17df30624f27c5e85f859a1b09f8fc0.zip
amdgpu: hide the final internal functions from global namespace
Thus the only symbols that we export are the ones officially provided by the API. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Christian K├Ânig <christian.koenig@amd.com> Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
Diffstat (limited to 'amdgpu/amdgpu_device.c')
-rw-r--r--amdgpu/amdgpu_device.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index bf941c1e..c6bbae81 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -47,7 +47,7 @@
47#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x))) 47#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
48#define UINT_TO_PTR(x) ((void *)((intptr_t)(x))) 48#define UINT_TO_PTR(x) ((void *)((intptr_t)(x)))
49 49
50pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER; 50static pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
51static struct util_hash_table *fd_tab; 51static struct util_hash_table *fd_tab;
52 52
53static unsigned handle_hash(void *key) 53static unsigned handle_hash(void *key)
@@ -127,6 +127,41 @@ static int amdgpu_get_auth(int fd, int *auth)
127 return r; 127 return r;
128} 128}
129 129
130static void amdgpu_device_free_internal(amdgpu_device_handle dev)
131{
132 amdgpu_vamgr_reference(&dev->vamgr, NULL);
133 util_hash_table_destroy(dev->bo_flink_names);
134 util_hash_table_destroy(dev->bo_handles);
135 pthread_mutex_destroy(&dev->bo_table_mutex);
136 util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
137 close(dev->fd);
138 if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
139 close(dev->flink_fd);
140 free(dev);
141}
142
143/**
144 * Assignment between two amdgpu_device pointers with reference counting.
145 *
146 * Usage:
147 * struct amdgpu_device *dst = ... , *src = ...;
148 *
149 * dst = src;
150 * // No reference counting. Only use this when you need to move
151 * // a reference from one pointer to another.
152 *
153 * amdgpu_device_reference(&dst, src);
154 * // Reference counters are updated. dst is decremented and src is
155 * // incremented. dst is freed if its reference counter is 0.
156 */
157static void amdgpu_device_reference(struct amdgpu_device **dst,
158 struct amdgpu_device *src)
159{
160 if (update_references(&(*dst)->refcount, &src->refcount))
161 amdgpu_device_free_internal(*dst);
162 *dst = src;
163}
164
130int amdgpu_device_initialize(int fd, 165int amdgpu_device_initialize(int fd,
131 uint32_t *major_version, 166 uint32_t *major_version,
132 uint32_t *minor_version, 167 uint32_t *minor_version,
@@ -232,29 +267,8 @@ cleanup:
232 return r; 267 return r;
233} 268}
234 269
235void amdgpu_device_free_internal(amdgpu_device_handle dev)
236{
237 amdgpu_vamgr_reference(&dev->vamgr, NULL);
238 util_hash_table_destroy(dev->bo_flink_names);
239 util_hash_table_destroy(dev->bo_handles);
240 pthread_mutex_destroy(&dev->bo_table_mutex);
241 util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
242 close(dev->fd);
243 if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
244 close(dev->flink_fd);
245 free(dev);
246}
247
248int amdgpu_device_deinitialize(amdgpu_device_handle dev) 270int amdgpu_device_deinitialize(amdgpu_device_handle dev)
249{ 271{
250 amdgpu_device_reference(&dev, NULL); 272 amdgpu_device_reference(&dev, NULL);
251 return 0; 273 return 0;
252} 274}
253
254void amdgpu_device_reference(struct amdgpu_device **dst,
255 struct amdgpu_device *src)
256{
257 if (update_references(&(*dst)->refcount, &src->refcount))
258 amdgpu_device_free_internal(*dst);
259 *dst = src;
260}