aboutsummaryrefslogtreecommitdiffstats
path: root/amdgpu
diff options
context:
space:
mode:
authorMichel Dänzer2017-11-30 11:52:06 -0600
committerMichel Dänzer2017-12-05 05:50:20 -0600
commitf05a2b4cb1aedb906524718db8ba2e62383f3064 (patch)
treee5dacbd15c3eacc2642441ac4d176179046a67b0 /amdgpu
parent5219809a3223e0328ae43a8975bfd6bf713c9ef1 (diff)
downloadexternal-libdrm-f05a2b4cb1aedb906524718db8ba2e62383f3064.tar.gz
external-libdrm-f05a2b4cb1aedb906524718db8ba2e62383f3064.tar.xz
external-libdrm-f05a2b4cb1aedb906524718db8ba2e62383f3064.zip
amdgpu: Only remember the device's marketing name
There's no point in keeping around the full table of marketing names, when amdgpu_get_marketing_name only ever returns the device's marketing name. Acked-by: Slava Abramov <slava.abramov@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'amdgpu')
-rw-r--r--amdgpu/Android.mk3
-rw-r--r--amdgpu/Makefile.am5
-rw-r--r--amdgpu/amdgpu_asic_id.c88
-rw-r--r--amdgpu/amdgpu_device.c23
-rw-r--r--amdgpu/amdgpu_internal.h11
5 files changed, 28 insertions, 102 deletions
diff --git a/amdgpu/Android.mk b/amdgpu/Android.mk
index ce273019..1f028d0b 100644
--- a/amdgpu/Android.mk
+++ b/amdgpu/Android.mk
@@ -11,8 +11,7 @@ LOCAL_SHARED_LIBRARIES := libdrm
11LOCAL_SRC_FILES := $(LIBDRM_AMDGPU_FILES) 11LOCAL_SRC_FILES := $(LIBDRM_AMDGPU_FILES)
12 12
13LOCAL_CFLAGS := \ 13LOCAL_CFLAGS := \
14 -DAMDGPU_ASIC_ID_TABLE=\"/vendor/etc/hwdata/amdgpu.ids\" \ 14 -DAMDGPU_ASIC_ID_TABLE=\"/vendor/etc/hwdata/amdgpu.ids\"
15 -DAMDGPU_ASIC_ID_TABLE_NUM_ENTRIES=$(shell egrep -ci '^[0-9a-f]{4},.*[0-9a-f]+,' $(LIBDRM_TOP)/data/amdgpu.ids)
16 15
17LOCAL_REQUIRED_MODULES := amdgpu.ids 16LOCAL_REQUIRED_MODULES := amdgpu.ids
18 17
diff --git a/amdgpu/Makefile.am b/amdgpu/Makefile.am
index 66f6f676..a1b0d05c 100644
--- a/amdgpu/Makefile.am
+++ b/amdgpu/Makefile.am
@@ -31,10 +31,7 @@ AM_CFLAGS = \
31 -I$(top_srcdir)/include/drm 31 -I$(top_srcdir)/include/drm
32 32
33libdrmdatadir = @libdrmdatadir@ 33libdrmdatadir = @libdrmdatadir@
34ASIC_ID_TABLE_NUM_ENTRIES := $(shell egrep -ci '^[0-9a-f]{4},.*[0-9a-f]+,' \ 34AM_CPPFLAGS = -DAMDGPU_ASIC_ID_TABLE=\"${libdrmdatadir}/amdgpu.ids\"
35 $(top_srcdir)/data/amdgpu.ids)
36AM_CPPFLAGS = -DAMDGPU_ASIC_ID_TABLE=\"${libdrmdatadir}/amdgpu.ids\" \
37 -DAMDGPU_ASIC_ID_TABLE_NUM_ENTRIES=$(ASIC_ID_TABLE_NUM_ENTRIES)
38 35
39libdrm_amdgpu_la_LTLIBRARIES = libdrm_amdgpu.la 36libdrm_amdgpu_la_LTLIBRARIES = libdrm_amdgpu.la
40libdrm_amdgpu_ladir = $(libdir) 37libdrm_amdgpu_ladir = $(libdir)
diff --git a/amdgpu/amdgpu_asic_id.c b/amdgpu/amdgpu_asic_id.c
index 0b5f2962..0c8925e5 100644
--- a/amdgpu/amdgpu_asic_id.c
+++ b/amdgpu/amdgpu_asic_id.c
@@ -38,11 +38,13 @@
38#include "amdgpu_drm.h" 38#include "amdgpu_drm.h"
39#include "amdgpu_internal.h" 39#include "amdgpu_internal.h"
40 40
41static int parse_one_line(const char *line, struct amdgpu_asic_id *id) 41static int parse_one_line(struct amdgpu_device *dev, const char *line)
42{ 42{
43 char *buf, *saveptr; 43 char *buf, *saveptr;
44 char *s_did; 44 char *s_did;
45 uint32_t did;
45 char *s_rid; 46 char *s_rid;
47 uint32_t rid;
46 char *s_name; 48 char *s_name;
47 char *endptr; 49 char *endptr;
48 int r = -EINVAL; 50 int r = -EINVAL;
@@ -60,19 +62,29 @@ static int parse_one_line(const char *line, struct amdgpu_asic_id *id)
60 if (!s_did) 62 if (!s_did)
61 goto out; 63 goto out;
62 64
63 id->did = strtol(s_did, &endptr, 16); 65 did = strtol(s_did, &endptr, 16);
64 if (*endptr) 66 if (*endptr)
65 goto out; 67 goto out;
66 68
69 if (did != dev->info.asic_id) {
70 r = -EAGAIN;
71 goto out;
72 }
73
67 /* revision id */ 74 /* revision id */
68 s_rid = strtok_r(NULL, ",", &saveptr); 75 s_rid = strtok_r(NULL, ",", &saveptr);
69 if (!s_rid) 76 if (!s_rid)
70 goto out; 77 goto out;
71 78
72 id->rid = strtol(s_rid, &endptr, 16); 79 rid = strtol(s_rid, &endptr, 16);
73 if (*endptr) 80 if (*endptr)
74 goto out; 81 goto out;
75 82
83 if (rid != dev->info.pci_rev_id) {
84 r = -EAGAIN;
85 goto out;
86 }
87
76 /* marketing name */ 88 /* marketing name */
77 s_name = strtok_r(NULL, ",", &saveptr); 89 s_name = strtok_r(NULL, ",", &saveptr);
78 if (!s_name) 90 if (!s_name)
@@ -84,8 +96,8 @@ static int parse_one_line(const char *line, struct amdgpu_asic_id *id)
84 if (strlen(s_name) == 0) 96 if (strlen(s_name) == 0)
85 goto out; 97 goto out;
86 98
87 id->marketing_name = strdup(s_name); 99 dev->marketing_name = strdup(s_name);
88 if (id->marketing_name) 100 if (dev->marketing_name)
89 r = 0; 101 r = 0;
90 else 102 else
91 r = -ENOMEM; 103 r = -ENOMEM;
@@ -96,17 +108,13 @@ out:
96 return r; 108 return r;
97} 109}
98 110
99void amdgpu_parse_asic_ids(struct amdgpu_asic_id **p_asic_id_table) 111void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
100{ 112{
101 struct amdgpu_asic_id *asic_id_table;
102 struct amdgpu_asic_id *id;
103 FILE *fp; 113 FILE *fp;
104 char *line = NULL; 114 char *line = NULL;
105 size_t len = 0; 115 size_t len = 0;
106 ssize_t n; 116 ssize_t n;
107 int line_num = 1; 117 int line_num = 1;
108 size_t table_size = 0;
109 size_t table_max_size = AMDGPU_ASIC_ID_TABLE_NUM_ENTRIES;
110 int r = 0; 118 int r = 0;
111 119
112 fp = fopen(AMDGPU_ASIC_ID_TABLE, "r"); 120 fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
@@ -116,13 +124,6 @@ void amdgpu_parse_asic_ids(struct amdgpu_asic_id **p_asic_id_table)
116 return; 124 return;
117 } 125 }
118 126
119 asic_id_table = calloc(table_max_size + 1,
120 sizeof(struct amdgpu_asic_id));
121 if (!asic_id_table) {
122 r = -ENOMEM;
123 goto close;
124 }
125
126 /* 1st valid line is file version */ 127 /* 1st valid line is file version */
127 while ((n = getline(&line, &len, fp)) != -1) { 128 while ((n = getline(&line, &len, fp)) != -1) {
128 /* trim trailing newline */ 129 /* trim trailing newline */
@@ -140,52 +141,17 @@ void amdgpu_parse_asic_ids(struct amdgpu_asic_id **p_asic_id_table)
140 } 141 }
141 142
142 while ((n = getline(&line, &len, fp)) != -1) { 143 while ((n = getline(&line, &len, fp)) != -1) {
143 if (table_size > table_max_size) {
144 /* double table size */
145 table_max_size *= 2;
146 id = realloc(asic_id_table, (table_max_size + 1) *
147 sizeof(struct amdgpu_asic_id));
148 if (!id) {
149 r = -ENOMEM;
150 goto free;
151 }
152 asic_id_table = id;
153 }
154
155 id = asic_id_table + table_size;
156
157 /* trim trailing newline */ 144 /* trim trailing newline */
158 if (line[n - 1] == '\n') 145 if (line[n - 1] == '\n')
159 line[n - 1] = '\0'; 146 line[n - 1] = '\0';
160 147
161 r = parse_one_line(line, id); 148 r = parse_one_line(dev, line);
162 if (r) { 149 if (r != -EAGAIN)
163 if (r == -EAGAIN) { 150 break;
164 line_num++;
165 continue;
166 }
167 goto free;
168 }
169 151
170 line_num++; 152 line_num++;
171 table_size++;
172 } 153 }
173 154
174 if (table_size != table_max_size) {
175 id = realloc(asic_id_table, (table_size + 1) *
176 sizeof(struct amdgpu_asic_id));
177 if (!id) {
178 r = -ENOMEM;
179 goto free;
180 }
181 asic_id_table = id;
182 }
183
184 /* end of table */
185 id = asic_id_table + table_size;
186 memset(id, 0, sizeof(struct amdgpu_asic_id));
187
188free:
189 if (r == -EINVAL) { 155 if (r == -EINVAL) {
190 fprintf(stderr, "Invalid format: %s: line %d: %s\n", 156 fprintf(stderr, "Invalid format: %s: line %d: %s\n",
191 AMDGPU_ASIC_ID_TABLE, line_num, line); 157 AMDGPU_ASIC_ID_TABLE, line_num, line);
@@ -195,17 +161,5 @@ free:
195 } 161 }
196 162
197 free(line); 163 free(line);
198
199 if (r && asic_id_table) {
200 while (table_size--) {
201 id = asic_id_table + table_size;
202 free(id->marketing_name);
203 }
204 free(asic_id_table);
205 asic_id_table = NULL;
206 }
207close:
208 fclose(fp); 164 fclose(fp);
209
210 *p_asic_id_table = asic_id_table;
211} 165}
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index e7aaf4fc..eb4b2745 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -130,7 +130,6 @@ static int amdgpu_get_auth(int fd, int *auth)
130 130
131static void amdgpu_device_free_internal(amdgpu_device_handle dev) 131static void amdgpu_device_free_internal(amdgpu_device_handle dev)
132{ 132{
133 const struct amdgpu_asic_id *id;
134 amdgpu_vamgr_deinit(&dev->vamgr_32); 133 amdgpu_vamgr_deinit(&dev->vamgr_32);
135 amdgpu_vamgr_deinit(&dev->vamgr); 134 amdgpu_vamgr_deinit(&dev->vamgr);
136 util_hash_table_destroy(dev->bo_flink_names); 135 util_hash_table_destroy(dev->bo_flink_names);
@@ -140,12 +139,7 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
140 close(dev->fd); 139 close(dev->fd);
141 if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd)) 140 if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
142 close(dev->flink_fd); 141 close(dev->flink_fd);
143 if (dev->asic_ids) { 142 free(dev->marketing_name);
144 for (id = dev->asic_ids; id->did; id++)
145 free(id->marketing_name);
146
147 free(dev->asic_ids);
148 }
149 free(dev); 143 free(dev);
150} 144}
151 145
@@ -280,7 +274,7 @@ int amdgpu_device_initialize(int fd,
280 amdgpu_vamgr_init(&dev->vamgr, start, max, 274 amdgpu_vamgr_init(&dev->vamgr, start, max,
281 dev->dev_info.virtual_address_alignment); 275 dev->dev_info.virtual_address_alignment);
282 276
283 amdgpu_parse_asic_ids(&dev->asic_ids); 277 amdgpu_parse_asic_ids(dev);
284 278
285 *major_version = dev->major_version; 279 *major_version = dev->major_version;
286 *minor_version = dev->minor_version; 280 *minor_version = dev->minor_version;
@@ -306,16 +300,5 @@ int amdgpu_device_deinitialize(amdgpu_device_handle dev)
306 300
307const char *amdgpu_get_marketing_name(amdgpu_device_handle dev) 301const char *amdgpu_get_marketing_name(amdgpu_device_handle dev)
308{ 302{
309 const struct amdgpu_asic_id *id; 303 return dev->marketing_name;
310
311 if (!dev->asic_ids)
312 return NULL;
313
314 for (id = dev->asic_ids; id->did; id++) {
315 if ((id->did == dev->info.asic_id) &&
316 (id->rid == dev->info.pci_rev_id))
317 return id->marketing_name;
318 }
319
320 return NULL;
321} 304}
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index 1aff7f8e..3e044f11 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -69,12 +69,6 @@ struct amdgpu_va {
69 struct amdgpu_bo_va_mgr *vamgr; 69 struct amdgpu_bo_va_mgr *vamgr;
70}; 70};
71 71
72struct amdgpu_asic_id {
73 uint32_t did;
74 uint32_t rid;
75 char *marketing_name;
76};
77
78struct amdgpu_device { 72struct amdgpu_device {
79 atomic_t refcount; 73 atomic_t refcount;
80 int fd; 74 int fd;
@@ -82,8 +76,7 @@ struct amdgpu_device {
82 unsigned major_version; 76 unsigned major_version;
83 unsigned minor_version; 77 unsigned minor_version;
84 78
85 /** Lookup table of asic device id, revision id and marketing name */ 79 char *marketing_name;
86 struct amdgpu_asic_id *asic_ids;
87 /** List of buffer handles. Protected by bo_table_mutex. */ 80 /** List of buffer handles. Protected by bo_table_mutex. */
88 struct util_hash_table *bo_handles; 81 struct util_hash_table *bo_handles;
89 /** List of buffer GEM flink names. Protected by bo_table_mutex. */ 82 /** List of buffer GEM flink names. Protected by bo_table_mutex. */
@@ -148,7 +141,7 @@ drm_private void amdgpu_vamgr_init(struct amdgpu_bo_va_mgr *mgr, uint64_t start,
148 141
149drm_private void amdgpu_vamgr_deinit(struct amdgpu_bo_va_mgr *mgr); 142drm_private void amdgpu_vamgr_deinit(struct amdgpu_bo_va_mgr *mgr);
150 143
151drm_private void amdgpu_parse_asic_ids(struct amdgpu_asic_id **asic_ids); 144drm_private void amdgpu_parse_asic_ids(struct amdgpu_device *dev);
152 145
153drm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev); 146drm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev);
154 147