aboutsummaryrefslogtreecommitdiffstats
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/amdgpu_asic_id.c
parent5219809a3223e0328ae43a8975bfd6bf713c9ef1 (diff)
downloadexternal-libgbm-f05a2b4cb1aedb906524718db8ba2e62383f3064.tar.gz
external-libgbm-f05a2b4cb1aedb906524718db8ba2e62383f3064.tar.xz
external-libgbm-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/amdgpu_asic_id.c')
-rw-r--r--amdgpu/amdgpu_asic_id.c88
1 files changed, 21 insertions, 67 deletions
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}