aboutsummaryrefslogtreecommitdiffstats
path: root/amdgpu
diff options
context:
space:
mode:
authorKen Wang2015-05-21 04:21:21 -0500
committerAlex Deucher2015-08-05 12:47:50 -0500
commit322d02d025cad1a74138c86937c5d5f3ef6215c7 (patch)
treeccedcb0de4a6da4b4b1bd4b5a8fe897e647fe5f3 /amdgpu
parentba1653eff8bd8ecc3d5fd5b2bbab604878cfa7e0 (diff)
downloadexternal-libgbm-322d02d025cad1a74138c86937c5d5f3ef6215c7.tar.gz
external-libgbm-322d02d025cad1a74138c86937c5d5f3ef6215c7.tar.xz
external-libgbm-322d02d025cad1a74138c86937c5d5f3ef6215c7.zip
amdgpu: make vamgr global
This is the first sub-patch of va interface task, the va task is about adding more va management interfaces for UMD, by design, the vamgr should be per-process rather than per-device. Signed-off-by: Ken Wang <Qingqing.Wang@amd.com> Reviewed-by: Christian K├Ânig <christian.koenig@amd.com>
Diffstat (limited to 'amdgpu')
-rw-r--r--amdgpu/amdgpu_bo.c4
-rw-r--r--amdgpu/amdgpu_device.c4
-rw-r--r--amdgpu/amdgpu_internal.h13
-rw-r--r--amdgpu/amdgpu_vamgr.c48
4 files changed, 50 insertions, 19 deletions
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index e1717194..f8d9c87e 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -71,7 +71,7 @@ void amdgpu_bo_free_internal(amdgpu_bo_handle bo)
71 71
72 amdgpu_close_kms_handle(bo->dev, bo->handle); 72 amdgpu_close_kms_handle(bo->dev, bo->handle);
73 pthread_mutex_destroy(&bo->cpu_access_mutex); 73 pthread_mutex_destroy(&bo->cpu_access_mutex);
74 amdgpu_vamgr_free_va(&bo->dev->vamgr, bo->virtual_mc_base_address, bo->alloc_size); 74 amdgpu_vamgr_free_va(bo->dev->vamgr, bo->virtual_mc_base_address, bo->alloc_size);
75 free(bo); 75 free(bo);
76} 76}
77 77
@@ -84,7 +84,7 @@ static int amdgpu_bo_map(amdgpu_bo_handle bo, uint32_t alignment)
84 84
85 memset(&va, 0, sizeof(va)); 85 memset(&va, 0, sizeof(va));
86 86
87 bo->virtual_mc_base_address = amdgpu_vamgr_find_va(&dev->vamgr, 87 bo->virtual_mc_base_address = amdgpu_vamgr_find_va(dev->vamgr,
88 bo->alloc_size, alignment); 88 bo->alloc_size, alignment);
89 89
90 if (bo->virtual_mc_base_address == AMDGPU_INVALID_VA_ADDRESS) 90 if (bo->virtual_mc_base_address == AMDGPU_INVALID_VA_ADDRESS)
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index 7a997cb5..212e7075 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -207,7 +207,7 @@ int amdgpu_device_initialize(int fd,
207 if (r) 207 if (r)
208 goto cleanup; 208 goto cleanup;
209 209
210 amdgpu_vamgr_init(dev); 210 dev->vamgr = amdgpu_vamgr_get_global(dev);
211 211
212 *major_version = dev->major_version; 212 *major_version = dev->major_version;
213 *minor_version = dev->minor_version; 213 *minor_version = dev->minor_version;
@@ -225,10 +225,10 @@ cleanup:
225 225
226void amdgpu_device_free_internal(amdgpu_device_handle dev) 226void amdgpu_device_free_internal(amdgpu_device_handle dev)
227{ 227{
228 amdgpu_vamgr_reference(&dev->vamgr, NULL);
228 util_hash_table_destroy(dev->bo_flink_names); 229 util_hash_table_destroy(dev->bo_flink_names);
229 util_hash_table_destroy(dev->bo_handles); 230 util_hash_table_destroy(dev->bo_handles);
230 pthread_mutex_destroy(&dev->bo_table_mutex); 231 pthread_mutex_destroy(&dev->bo_table_mutex);
231 pthread_mutex_destroy(&(dev->vamgr.bo_va_mutex));
232 util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd)); 232 util_hash_table_remove(fd_tab, UINT_TO_PTR(dev->fd));
233 free(dev); 233 free(dev);
234} 234}
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index 77b12443..c1cd4da7 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -49,6 +49,7 @@ struct amdgpu_bo_va_hole {
49}; 49};
50 50
51struct amdgpu_bo_va_mgr { 51struct amdgpu_bo_va_mgr {
52 atomic_t refcount;
52 /* the start virtual address */ 53 /* the start virtual address */
53 uint64_t va_offset; 54 uint64_t va_offset;
54 uint64_t va_max; 55 uint64_t va_max;
@@ -70,9 +71,9 @@ struct amdgpu_device {
70 struct util_hash_table *bo_flink_names; 71 struct util_hash_table *bo_flink_names;
71 /** This protects all hash tables. */ 72 /** This protects all hash tables. */
72 pthread_mutex_t bo_table_mutex; 73 pthread_mutex_t bo_table_mutex;
73 struct amdgpu_bo_va_mgr vamgr;
74 struct drm_amdgpu_info_device dev_info; 74 struct drm_amdgpu_info_device dev_info;
75 struct amdgpu_gpu_info info; 75 struct amdgpu_gpu_info info;
76 struct amdgpu_bo_va_mgr *vamgr;
76}; 77};
77 78
78struct amdgpu_bo { 79struct amdgpu_bo {
@@ -142,13 +143,15 @@ void amdgpu_device_free_internal(amdgpu_device_handle dev);
142 143
143void amdgpu_bo_free_internal(amdgpu_bo_handle bo); 144void amdgpu_bo_free_internal(amdgpu_bo_handle bo);
144 145
145void amdgpu_vamgr_init(struct amdgpu_device *dev); 146struct amdgpu_bo_va_mgr* amdgpu_vamgr_get_global(struct amdgpu_device *dev);
147
148void amdgpu_vamgr_reference(struct amdgpu_bo_va_mgr **dst, struct amdgpu_bo_va_mgr *src);
146 149
147uint64_t amdgpu_vamgr_find_va(struct amdgpu_bo_va_mgr *mgr, 150uint64_t amdgpu_vamgr_find_va(struct amdgpu_bo_va_mgr *mgr,
148 uint64_t size, uint64_t alignment); 151 uint64_t size, uint64_t alignment);
149 152
150void amdgpu_vamgr_free_va(struct amdgpu_bo_va_mgr *mgr, uint64_t va, 153void amdgpu_vamgr_free_va(struct amdgpu_bo_va_mgr *mgr, uint64_t va,
151 uint64_t size); 154 uint64_t size);
152 155
153int amdgpu_query_gpu_info_init(amdgpu_device_handle dev); 156int amdgpu_query_gpu_info_init(amdgpu_device_handle dev);
154 157
diff --git a/amdgpu/amdgpu_vamgr.c b/amdgpu/amdgpu_vamgr.c
index 34c28878..b15729fa 100644
--- a/amdgpu/amdgpu_vamgr.c
+++ b/amdgpu/amdgpu_vamgr.c
@@ -28,20 +28,48 @@
28#include "amdgpu_internal.h" 28#include "amdgpu_internal.h"
29#include "util_math.h" 29#include "util_math.h"
30 30
31void amdgpu_vamgr_init(struct amdgpu_device *dev) 31static struct amdgpu_bo_va_mgr vamgr = {{0}};
32
33static void amdgpu_vamgr_init(struct amdgpu_bo_va_mgr *mgr, struct amdgpu_device *dev)
34{
35 mgr->va_offset = dev->dev_info.virtual_address_offset;
36 mgr->va_max = dev->dev_info.virtual_address_max;
37 mgr->va_alignment = dev->dev_info.virtual_address_alignment;
38
39 list_inithead(&mgr->va_holes);
40 pthread_mutex_init(&mgr->bo_va_mutex, NULL);
41}
42
43static void amdgpu_vamgr_deinit(struct amdgpu_bo_va_mgr *mgr)
44{
45 struct amdgpu_bo_va_hole *hole;
46 LIST_FOR_EACH_ENTRY(hole, &mgr->va_holes, list) {
47 list_del(&hole->list);
48 free(hole);
49 }
50 pthread_mutex_destroy(&mgr->bo_va_mutex);
51}
52
53struct amdgpu_bo_va_mgr * amdgpu_vamgr_get_global(struct amdgpu_device *dev)
32{ 54{
33 struct amdgpu_bo_va_mgr *vamgr = &dev->vamgr; 55 int ref;
56 ref = atomic_inc_return(&vamgr.refcount);
34 57
35 vamgr->va_offset = dev->dev_info.virtual_address_offset; 58 if (ref == 1)
36 vamgr->va_max = dev->dev_info.virtual_address_max; 59 amdgpu_vamgr_init(&vamgr, dev);
37 vamgr->va_alignment = dev->dev_info.virtual_address_alignment; 60 return &vamgr;
61}
38 62
39 list_inithead(&vamgr->va_holes); 63void amdgpu_vamgr_reference(struct amdgpu_bo_va_mgr **dst,
40 pthread_mutex_init(&vamgr->bo_va_mutex, NULL); 64 struct amdgpu_bo_va_mgr *src)
65{
66 if (update_references(&(*dst)->refcount, NULL))
67 amdgpu_vamgr_deinit(*dst);
68 *dst = src;
41} 69}
42 70
43uint64_t amdgpu_vamgr_find_va(struct amdgpu_bo_va_mgr *mgr, 71uint64_t amdgpu_vamgr_find_va(struct amdgpu_bo_va_mgr *mgr,
44 uint64_t size, uint64_t alignment) 72 uint64_t size, uint64_t alignment)
45{ 73{
46 struct amdgpu_bo_va_hole *hole, *n; 74 struct amdgpu_bo_va_hole *hole, *n;
47 uint64_t offset = 0, waste = 0; 75 uint64_t offset = 0, waste = 0;
@@ -108,8 +136,8 @@ uint64_t amdgpu_vamgr_find_va(struct amdgpu_bo_va_mgr *mgr,
108 return offset; 136 return offset;
109} 137}
110 138
111void amdgpu_vamgr_free_va(struct amdgpu_bo_va_mgr *mgr, uint64_t va, 139void amdgpu_vamgr_free_va(struct amdgpu_bo_va_mgr *mgr,
112 uint64_t size) 140 uint64_t va, uint64_t size)
113{ 141{
114 struct amdgpu_bo_va_hole *hole; 142 struct amdgpu_bo_va_hole *hole;
115 143