aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiaojie Yuan2017-05-31 15:22:50 -0500
committerMichel Dänzer2017-06-12 20:21:39 -0500
commit7e6bf88cac315a9fa41818cf72a7b5d18a2cb1fc (patch)
treeb9d9c516ea93037df1d9d248939ca8d26a524e3e
parent87dac00db38fa962c2fd6aa66c8482a9d7464903 (diff)
downloadexternal-libdrm-7e6bf88cac315a9fa41818cf72a7b5d18a2cb1fc.tar.gz
external-libdrm-7e6bf88cac315a9fa41818cf72a7b5d18a2cb1fc.tar.xz
external-libdrm-7e6bf88cac315a9fa41818cf72a7b5d18a2cb1fc.zip
amdgpu: move asic id table to a separate file
v2: fix an off by one error and leading white spaces v3: use thread safe strtok_r(); initialize len before calling getline(); change printf() to drmMsg(); add initial amdgpu.ids v4: integrate some recent internal changes, including format changes v5: fix line number for empty/commented lines; realloc to save memory; indentation changes v6: remove a line error v7: [Michel Dänzer] * Move amdgpu.ids to new data directory * Remove placeholder entries from amdgpu.ids * Set libdrmdatadir variable in configure.ac instead of Makefile.am [Emil Velikov] * Use isblank() instead of open-coding it [Emil Velikov] * Don't leak asic_id_table memory if realloc fails [Emil Velikov] * Check and bump table_max_size at the beginning of the while loop [Emil Velikov] * Initialize table_max_size to the number of entries in data/amdgpu.ids v8: [Michel Dänzer] * Make sure amdgpu_asic_id.c gets rebuilt when amdgpu.ids changes Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Samuel Li <Samuel.Li@amd.com>
-rw-r--r--Makefile.am1
-rw-r--r--amdgpu/Makefile.am7
-rw-r--r--amdgpu/Makefile.sources2
-rw-r--r--amdgpu/amdgpu_asic_id.c219
-rw-r--r--amdgpu/amdgpu_asic_id.h165
-rw-r--r--amdgpu/amdgpu_device.c28
-rw-r--r--amdgpu/amdgpu_internal.h10
-rw-r--r--configure.ac4
-rw-r--r--data/Makefile.am23
-rw-r--r--data/amdgpu.ids159
10 files changed, 445 insertions, 173 deletions
diff --git a/Makefile.am b/Makefile.am
index dfb8fcdb..7b86214e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -109,6 +109,7 @@ SUBDIRS = \
109 $(TEGRA_SUBDIR) \ 109 $(TEGRA_SUBDIR) \
110 $(VC4_SUBDIR) \ 110 $(VC4_SUBDIR) \
111 $(ETNAVIV_SUBDIR) \ 111 $(ETNAVIV_SUBDIR) \
112 data \
112 tests \ 113 tests \
113 $(MAN_SUBDIR) 114 $(MAN_SUBDIR)
114 115
diff --git a/amdgpu/Makefile.am b/amdgpu/Makefile.am
index cf7bc1ba..66f6f676 100644
--- a/amdgpu/Makefile.am
+++ b/amdgpu/Makefile.am
@@ -30,12 +30,19 @@ AM_CFLAGS = \
30 $(PTHREADSTUBS_CFLAGS) \ 30 $(PTHREADSTUBS_CFLAGS) \
31 -I$(top_srcdir)/include/drm 31 -I$(top_srcdir)/include/drm
32 32
33libdrmdatadir = @libdrmdatadir@
34ASIC_ID_TABLE_NUM_ENTRIES := $(shell egrep -ci '^[0-9a-f]{4},.*[0-9a-f]+,' \
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
33libdrm_amdgpu_la_LTLIBRARIES = libdrm_amdgpu.la 39libdrm_amdgpu_la_LTLIBRARIES = libdrm_amdgpu.la
34libdrm_amdgpu_ladir = $(libdir) 40libdrm_amdgpu_ladir = $(libdir)
35libdrm_amdgpu_la_LDFLAGS = -version-number 1:0:0 -no-undefined 41libdrm_amdgpu_la_LDFLAGS = -version-number 1:0:0 -no-undefined
36libdrm_amdgpu_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ 42libdrm_amdgpu_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
37 43
38libdrm_amdgpu_la_SOURCES = $(LIBDRM_AMDGPU_FILES) 44libdrm_amdgpu_la_SOURCES = $(LIBDRM_AMDGPU_FILES)
45amdgpu_asic_id.lo: $(top_srcdir)/data/amdgpu.ids
39 46
40libdrm_amdgpuincludedir = ${includedir}/libdrm 47libdrm_amdgpuincludedir = ${includedir}/libdrm
41libdrm_amdgpuinclude_HEADERS = $(LIBDRM_AMDGPU_H_FILES) 48libdrm_amdgpuinclude_HEADERS = $(LIBDRM_AMDGPU_H_FILES)
diff --git a/amdgpu/Makefile.sources b/amdgpu/Makefile.sources
index 487b9e0a..bc3abaa6 100644
--- a/amdgpu/Makefile.sources
+++ b/amdgpu/Makefile.sources
@@ -1,5 +1,5 @@
1LIBDRM_AMDGPU_FILES := \ 1LIBDRM_AMDGPU_FILES := \
2 amdgpu_asic_id.h \ 2 amdgpu_asic_id.c \
3 amdgpu_bo.c \ 3 amdgpu_bo.c \
4 amdgpu_cs.c \ 4 amdgpu_cs.c \
5 amdgpu_device.c \ 5 amdgpu_device.c \
diff --git a/amdgpu/amdgpu_asic_id.c b/amdgpu/amdgpu_asic_id.c
new file mode 100644
index 00000000..3a88896b
--- /dev/null
+++ b/amdgpu/amdgpu_asic_id.c
@@ -0,0 +1,219 @@
1/*
2 * Copyright © 2017 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <ctype.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <stdint.h>
33#include <string.h>
34#include <unistd.h>
35#include <errno.h>
36
37#include "xf86drm.h"
38#include "amdgpu_drm.h"
39#include "amdgpu_internal.h"
40
41static int parse_one_line(const char *line, struct amdgpu_asic_id *id)
42{
43 char *buf, *saveptr;
44 char *s_did;
45 char *s_rid;
46 char *s_name;
47 char *endptr;
48 int r = 0;
49
50 buf = strdup(line);
51 if (!buf)
52 return -ENOMEM;
53
54 /* ignore empty line and commented line */
55 if (strlen(line) == 0 || line[0] == '#') {
56 r = -EAGAIN;
57 goto out;
58 }
59
60 /* device id */
61 s_did = strtok_r(buf, ",", &saveptr);
62 if (!s_did) {
63 r = -EINVAL;
64 goto out;
65 }
66
67 id->did = strtol(s_did, &endptr, 16);
68 if (*endptr) {
69 r = -EINVAL;
70 goto out;
71 }
72
73 /* revision id */
74 s_rid = strtok_r(NULL, ",", &saveptr);
75 if (!s_rid) {
76 r = -EINVAL;
77 goto out;
78 }
79
80 id->rid = strtol(s_rid, &endptr, 16);
81 if (*endptr) {
82 r = -EINVAL;
83 goto out;
84 }
85
86 /* marketing name */
87 s_name = strtok_r(NULL, ",", &saveptr);
88 if (!s_name) {
89 r = -EINVAL;
90 goto out;
91 }
92 /* trim leading whitespaces or tabs */
93 while (isblank(*s_name))
94 s_name++;
95 if (strlen(s_name) == 0) {
96 r = -EINVAL;
97 goto out;
98 }
99
100 id->marketing_name = strdup(s_name);
101 if (id->marketing_name == NULL) {
102 r = -EINVAL;
103 goto out;
104 }
105
106out:
107 free(buf);
108
109 return r;
110}
111
112int amdgpu_parse_asic_ids(struct amdgpu_asic_id **p_asic_id_table)
113{
114 struct amdgpu_asic_id *asic_id_table;
115 struct amdgpu_asic_id *id;
116 FILE *fp;
117 char *line = NULL;
118 size_t len = 0;
119 ssize_t n;
120 int line_num = 1;
121 size_t table_size = 0;
122 size_t table_max_size = AMDGPU_ASIC_ID_TABLE_NUM_ENTRIES;
123 int r = 0;
124
125 fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
126 if (!fp) {
127 fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
128 strerror(errno));
129 return -EINVAL;
130 }
131
132 asic_id_table = calloc(table_max_size + 1,
133 sizeof(struct amdgpu_asic_id));
134 if (!asic_id_table) {
135 r = -ENOMEM;
136 goto close;
137 }
138
139 /* 1st valid line is file version */
140 while ((n = getline(&line, &len, fp)) != -1) {
141 /* trim trailing newline */
142 if (line[n - 1] == '\n')
143 line[n - 1] = '\0';
144
145 /* ignore empty line and commented line */
146 if (strlen(line) == 0 || line[0] == '#') {
147 line_num++;
148 continue;
149 }
150
151 drmMsg("%s version: %s\n", AMDGPU_ASIC_ID_TABLE, line);
152 break;
153 }
154
155 while ((n = getline(&line, &len, fp)) != -1) {
156 if (table_size > table_max_size) {
157 /* double table size */
158 table_max_size *= 2;
159 id = realloc(asic_id_table, (table_max_size + 1) *
160 sizeof(struct amdgpu_asic_id));
161 if (!id) {
162 r = -ENOMEM;
163 goto free;
164 }
165 asic_id_table = id;
166 }
167
168 id = asic_id_table + table_size;
169
170 /* trim trailing newline */
171 if (line[n - 1] == '\n')
172 line[n - 1] = '\0';
173
174 r = parse_one_line(line, id);
175 if (r) {
176 if (r == -EAGAIN) {
177 line_num++;
178 continue;
179 }
180 fprintf(stderr, "Invalid format: %s: line %d: %s\n",
181 AMDGPU_ASIC_ID_TABLE, line_num, line);
182 goto free;
183 }
184
185 line_num++;
186 table_size++;
187 }
188
189 /* end of table */
190 id = asic_id_table + table_size;
191 memset(id, 0, sizeof(struct amdgpu_asic_id));
192
193 if (table_size != table_max_size) {
194 id = realloc(asic_id_table, (table_size + 1) *
195 sizeof(struct amdgpu_asic_id));
196 if (!id)
197 r = -ENOMEM;
198 else
199 asic_id_table = id;
200 }
201
202free:
203 free(line);
204
205 if (r && asic_id_table) {
206 while (table_size--) {
207 id = asic_id_table + table_size;
208 free(id->marketing_name);
209 }
210 free(asic_id_table);
211 asic_id_table = NULL;
212 }
213close:
214 fclose(fp);
215
216 *p_asic_id_table = asic_id_table;
217
218 return r;
219}
diff --git a/amdgpu/amdgpu_asic_id.h b/amdgpu/amdgpu_asic_id.h
deleted file mode 100644
index 3e7d736b..00000000
--- a/amdgpu/amdgpu_asic_id.h
+++ /dev/null
@@ -1,165 +0,0 @@
1/*
2 * Copyright © 2016 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25#ifndef __AMDGPU_ASIC_ID_H__
26#define __AMDGPU_ASIC_ID_H__
27
28static struct amdgpu_asic_id_table_t {
29 uint32_t did;
30 uint32_t rid;
31 const char *marketing_name;
32} const amdgpu_asic_id_table [] = {
33 {0x6600, 0x0, "AMD Radeon HD 8600/8700M"},
34 {0x6600, 0x81, "AMD Radeon R7 M370"},
35 {0x6601, 0x0, "AMD Radeon HD 8500M/8700M"},
36 {0x6604, 0x0, "AMD Radeon R7 M265 Series"},
37 {0x6604, 0x81, "AMD Radeon R7 M350"},
38 {0x6605, 0x0, "AMD Radeon R7 M260 Series"},
39 {0x6605, 0x81, "AMD Radeon R7 M340"},
40 {0x6606, 0x0, "AMD Radeon HD 8790M"},
41 {0x6607, 0x0, "AMD Radeon HD8530M"},
42 {0x6608, 0x0, "AMD FirePro W2100"},
43 {0x6610, 0x0, "AMD Radeon HD 8600 Series"},
44 {0x6610, 0x81, "AMD Radeon R7 350"},
45 {0x6610, 0x83, "AMD Radeon R5 340"},
46 {0x6611, 0x0, "AMD Radeon HD 8500 Series"},
47 {0x6613, 0x0, "AMD Radeon HD 8500 series"},
48 {0x6617, 0xC7, "AMD Radeon R7 240 Series"},
49 {0x6640, 0x0, "AMD Radeon HD 8950"},
50 {0x6640, 0x80, "AMD Radeon R9 M380"},
51 {0x6646, 0x0, "AMD Radeon R9 M280X"},
52 {0x6646, 0x80, "AMD Radeon R9 M470X"},
53 {0x6647, 0x0, "AMD Radeon R9 M270X"},
54 {0x6647, 0x80, "AMD Radeon R9 M380"},
55 {0x6649, 0x0, "AMD FirePro W5100"},
56 {0x6658, 0x0, "AMD Radeon R7 200 Series"},
57 {0x665C, 0x0, "AMD Radeon HD 7700 Series"},
58 {0x665D, 0x0, "AMD Radeon R7 200 Series"},
59 {0x665F, 0x81, "AMD Radeon R7 300 Series"},
60 {0x6660, 0x0, "AMD Radeon HD 8600M Series"},
61 {0x6660, 0x81, "AMD Radeon R5 M335"},
62 {0x6660, 0x83, "AMD Radeon R5 M330"},
63 {0x6663, 0x0, "AMD Radeon HD 8500M Series"},
64 {0x6663, 0x83, "AMD Radeon R5 M320"},
65 {0x6664, 0x0, "AMD Radeon R5 M200 Series"},
66 {0x6665, 0x0, "AMD Radeon R5 M200 Series"},
67 {0x6665, 0x83, "AMD Radeon R5 M320"},
68 {0x6667, 0x0, "AMD Radeon R5 M200 Series"},
69 {0x666F, 0x0, "AMD Radeon HD 8500M"},
70 {0x6780, 0x0, "ATI FirePro V (FireGL V) Graphics Adapter"},
71 {0x678A, 0x0, "ATI FirePro V (FireGL V) Graphics Adapter"},
72 {0x6798, 0x0, "AMD Radeon HD 7900 Series"},
73 {0x679A, 0x0, "AMD Radeon HD 7900 Series"},
74 {0x679B, 0x0, "AMD Radeon HD 7900 Series"},
75 {0x679E, 0x0, "AMD Radeon HD 7800 Series"},
76 {0x67A0, 0x0, "HAWAII XTGL (67A0)"},
77 {0x67A1, 0x0, "HAWAII GL40 (67A1)"},
78 {0x67B0, 0x0, "AMD Radeon R9 200 Series"},
79 {0x67B0, 0x80, "AMD Radeon R9 390 Series"},
80 {0x67B1, 0x0, "AMD Radeon R9 200 Series"},
81 {0x67B1, 0x80, "AMD Radeon R9 390 Series"},
82 {0x67B9, 0x0, "AMD Radeon R9 200 Series"},
83 {0x67DF, 0xC4, "AMD Radeon RX 480 Graphics"},
84 {0x67DF, 0xC5, "AMD Radeon RX 470 Graphics"},
85 {0x67DF, 0xC7, "AMD Radeon RX 480 Graphics"},
86 {0x67DF, 0xCF, "AMD Radeon RX 470 Graphics"},
87 {0x67C4, 0x00, "AMD Radeon Pro WX 7100 Graphics"},
88 {0x67C7, 0x00, "AMD Radeon Pro WX 5100 Graphics"},
89 {0x67C0, 0x00, "AMD Radeon Pro WX 7100 Graphics"},
90 {0x67E0, 0x00, "AMD Radeon Pro WX Series Graphics"},
91 {0x67E3, 0x00, "AMD Radeon Pro WX 4100 Graphics"},
92 {0x67E8, 0x00, "AMD Radeon Pro WX Series Graphics"},
93 {0x67E8, 0x01, "AMD Radeon Pro WX Series Graphics"},
94 {0x67E8, 0x80, "AMD Radeon E9260 Graphics"},
95 {0x67EB, 0x00, "AMD Radeon Pro WX Series Graphics"},
96 {0x67EF, 0xC0, "AMD Radeon RX Graphics"},
97 {0x67EF, 0xC1, "AMD Radeon RX 460 Graphics"},
98 {0x67EF, 0xC5, "AMD Radeon RX 460 Graphics"},
99 {0x67EF, 0xC7, "AMD Radeon RX Graphics"},
100 {0x67EF, 0xCF, "AMD Radeon RX 460 Graphics"},
101 {0x67EF, 0xEF, "AMD Radeon RX Graphics"},
102 {0x67FF, 0xC0, "AMD Radeon RX Graphics"},
103 {0x67FF, 0xC1, "AMD Radeon RX Graphics"},
104 {0x6800, 0x0, "AMD Radeon HD 7970M"},
105 {0x6801, 0x0, "AMD Radeon(TM) HD8970M"},
106 {0x6808, 0x0, "ATI FirePro V(FireGL V) Graphics Adapter"},
107 {0x6809, 0x0, "ATI FirePro V(FireGL V) Graphics Adapter"},
108 {0x6810, 0x0, "AMD Radeon(TM) HD 8800 Series"},
109 {0x6810, 0x81, "AMD Radeon R7 370 Series"},
110 {0x6811, 0x0, "AMD Radeon(TM) HD8800 Series"},
111 {0x6811, 0x81, "AMD Radeon R7 300 Series"},
112 {0x6818, 0x0, "AMD Radeon HD 7800 Series"},
113 {0x6819, 0x0, "AMD Radeon HD 7800 Series"},
114 {0x6820, 0x0, "AMD Radeon HD 8800M Series"},
115 {0x6820, 0x81, "AMD Radeon R9 M375"},
116 {0x6820, 0x83, "AMD Radeon R9 M375X"},
117 {0x6821, 0x0, "AMD Radeon HD 8800M Series"},
118 {0x6821, 0x87, "AMD Radeon R7 M380"},
119 {0x6821, 0x83, "AMD Radeon R9 M370X"},
120 {0x6822, 0x0, "AMD Radeon E8860"},
121 {0x6823, 0x0, "AMD Radeon HD 8800M Series"},
122 {0x6825, 0x0, "AMD Radeon HD 7800M Series"},
123 {0x6827, 0x0, "AMD Radeon HD 7800M Series"},
124 {0x6828, 0x0, "ATI FirePro V(FireGL V) Graphics Adapter"},
125 {0x682B, 0x0, "AMD Radeon HD 8800M Series"},
126 {0x682B, 0x87, "AMD Radeon R9 M360"},
127 {0x682C, 0x0, "AMD FirePro W4100"},
128 {0x682D, 0x0, "AMD Radeon HD 7700M Series"},
129 {0x682F, 0x0, "AMD Radeon HD 7700M Series"},
130 {0x6835, 0x0, "AMD Radeon R7 Series / HD 9000 Series"},
131 {0x6837, 0x0, "AMD Radeon HD7700 Series"},
132 {0x683D, 0x0, "AMD Radeon HD 7700 Series"},
133 {0x683F, 0x0, "AMD Radeon HD 7700 Series"},
134 {0x6900, 0x0, "AMD Radeon R7 M260"},
135 {0x6900, 0x81, "AMD Radeon R7 M360"},
136 {0x6900, 0x83, "AMD Radeon R7 M340"},
137 {0x6901, 0x0, "AMD Radeon R5 M255"},
138 {0x6907, 0x0, "AMD Radeon R5 M255"},
139 {0x6907, 0x87, "AMD Radeon R5 M315"},
140 {0x6920, 0x0, "AMD Radeon R9 M395X"},
141 {0x6920, 0x1, "AMD Radeon R9 M390X"},
142 {0x6921, 0x0, "AMD Radeon R9 M295X"},
143 {0x6929, 0x0, "AMD FirePro S7150"},
144 {0x692B, 0x0, "AMD FirePro W7100"},
145 {0x6938, 0x0, "AMD Radeon R9 200 Series"},
146 {0x6938, 0xF0, "AMD Radeon R9 200 Series"},
147 {0x6938, 0xF1, "AMD Radeon R9 380 Series"},
148 {0x6939, 0xF0, "AMD Radeon R9 200 Series"},
149 {0x6939, 0x0, "AMD Radeon R9 200 Series"},
150 {0x6939, 0xF1, "AMD Radeon R9 380 Series"},
151 {0x7300, 0xC8, "AMD Radeon R9 Fury Series"},
152 {0x7300, 0xCB, "AMD Radeon R9 Fury Series"},
153 {0x7300, 0xCA, "AMD Radeon R9 Fury Series"},
154 {0x9874, 0xC4, "AMD Radeon R7 Graphics"},
155 {0x9874, 0xC5, "AMD Radeon R6 Graphics"},
156 {0x9874, 0xC6, "AMD Radeon R6 Graphics"},
157 {0x9874, 0xC7, "AMD Radeon R5 Graphics"},
158 {0x9874, 0x81, "AMD Radeon R6 Graphics"},
159 {0x9874, 0x87, "AMD Radeon R5 Graphics"},
160 {0x9874, 0x85, "AMD Radeon R6 Graphics"},
161 {0x9874, 0x84, "AMD Radeon R7 Graphics"},
162
163 {0x0000, 0x0, "\0"},
164};
165#endif
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index f473d2da..9a238d97 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -44,7 +44,6 @@
44#include "amdgpu_internal.h" 44#include "amdgpu_internal.h"
45#include "util_hash_table.h" 45#include "util_hash_table.h"
46#include "util_math.h" 46#include "util_math.h"
47#include "amdgpu_asic_id.h"
48 47
49#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x))) 48#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
50#define UINT_TO_PTR(x) ((void *)((intptr_t)(x))) 49#define UINT_TO_PTR(x) ((void *)((intptr_t)(x)))
@@ -131,6 +130,7 @@ static int amdgpu_get_auth(int fd, int *auth)
131 130
132static void amdgpu_device_free_internal(amdgpu_device_handle dev) 131static void amdgpu_device_free_internal(amdgpu_device_handle dev)
133{ 132{
133 const struct amdgpu_asic_id *id;
134 amdgpu_vamgr_deinit(&dev->vamgr_32); 134 amdgpu_vamgr_deinit(&dev->vamgr_32);
135 amdgpu_vamgr_deinit(&dev->vamgr); 135 amdgpu_vamgr_deinit(&dev->vamgr);
136 util_hash_table_destroy(dev->bo_flink_names); 136 util_hash_table_destroy(dev->bo_flink_names);
@@ -140,6 +140,12 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
140 close(dev->fd); 140 close(dev->fd);
141 if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd)) 141 if ((dev->flink_fd >= 0) && (dev->fd != dev->flink_fd))
142 close(dev->flink_fd); 142 close(dev->flink_fd);
143 if (dev->asic_ids) {
144 for (id = dev->asic_ids; id->did; id++)
145 free(id->marketing_name);
146
147 free(dev->asic_ids);
148 }
143 free(dev); 149 free(dev);
144} 150}
145 151
@@ -267,6 +273,12 @@ int amdgpu_device_initialize(int fd,
267 amdgpu_vamgr_init(&dev->vamgr_32, start, max, 273 amdgpu_vamgr_init(&dev->vamgr_32, start, max,
268 dev->dev_info.virtual_address_alignment); 274 dev->dev_info.virtual_address_alignment);
269 275
276 r = amdgpu_parse_asic_ids(&dev->asic_ids);
277 if (r) {
278 fprintf(stderr, "%s: Cannot parse ASIC IDs, 0x%x.",
279 __func__, r);
280 }
281
270 *major_version = dev->major_version; 282 *major_version = dev->major_version;
271 *minor_version = dev->minor_version; 283 *minor_version = dev->minor_version;
272 *device_handle = dev; 284 *device_handle = dev;
@@ -297,13 +309,15 @@ int amdgpu_device_deinitialize(amdgpu_device_handle dev)
297 309
298const char *amdgpu_get_marketing_name(amdgpu_device_handle dev) 310const char *amdgpu_get_marketing_name(amdgpu_device_handle dev)
299{ 311{
300 const struct amdgpu_asic_id_table_t *t = amdgpu_asic_id_table; 312 const struct amdgpu_asic_id *id;
313
314 if (!dev->asic_ids)
315 return NULL;
301 316
302 while (t->did) { 317 for (id = dev->asic_ids; id->did; id++) {
303 if ((t->did == dev->info.asic_id) && 318 if ((id->did == dev->info.asic_id) &&
304 (t->rid == dev->info.pci_rev_id)) 319 (id->rid == dev->info.pci_rev_id))
305 return t->marketing_name; 320 return id->marketing_name;
306 t++;
307 } 321 }
308 322
309 return NULL; 323 return NULL;
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index cf119a53..e68246bf 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -69,6 +69,12 @@ 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
72struct amdgpu_device { 78struct amdgpu_device {
73 atomic_t refcount; 79 atomic_t refcount;
74 int fd; 80 int fd;
@@ -76,6 +82,8 @@ struct amdgpu_device {
76 unsigned major_version; 82 unsigned major_version;
77 unsigned minor_version; 83 unsigned minor_version;
78 84
85 /** Lookup table of asic device id, revision id and marketing name */
86 struct amdgpu_asic_id *asic_ids;
79 /** List of buffer handles. Protected by bo_table_mutex. */ 87 /** List of buffer handles. Protected by bo_table_mutex. */
80 struct util_hash_table *bo_handles; 88 struct util_hash_table *bo_handles;
81 /** List of buffer GEM flink names. Protected by bo_table_mutex. */ 89 /** List of buffer GEM flink names. Protected by bo_table_mutex. */
@@ -149,6 +157,8 @@ amdgpu_vamgr_find_va(struct amdgpu_bo_va_mgr *mgr, uint64_t size,
149drm_private void 157drm_private void
150amdgpu_vamgr_free_va(struct amdgpu_bo_va_mgr *mgr, uint64_t va, uint64_t size); 158amdgpu_vamgr_free_va(struct amdgpu_bo_va_mgr *mgr, uint64_t va, uint64_t size);
151 159
160drm_private int amdgpu_parse_asic_ids(struct amdgpu_asic_id **asic_ids);
161
152drm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev); 162drm_private int amdgpu_query_gpu_info_init(amdgpu_device_handle dev);
153 163
154drm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout); 164drm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout);
diff --git a/configure.ac b/configure.ac
index 1cfb8c27..aa9529cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,9 @@ fi
84 84
85pkgconfigdir=${libdir}/pkgconfig 85pkgconfigdir=${libdir}/pkgconfig
86AC_SUBST(pkgconfigdir) 86AC_SUBST(pkgconfigdir)
87libdrmdatadir=${datadir}/libdrm
88AC_SUBST(libdrmdatadir)
89
87AC_ARG_ENABLE([udev], 90AC_ARG_ENABLE([udev],
88 [AS_HELP_STRING([--enable-udev], 91 [AS_HELP_STRING([--enable-udev],
89 [Enable support for using udev instead of mknod (default: disabled)])], 92 [Enable support for using udev instead of mknod (default: disabled)])],
@@ -527,6 +530,7 @@ fi
527AC_SUBST(WARN_CFLAGS) 530AC_SUBST(WARN_CFLAGS)
528AC_CONFIG_FILES([ 531AC_CONFIG_FILES([
529 Makefile 532 Makefile
533 data/Makefile
530 libkms/Makefile 534 libkms/Makefile
531 libkms/libkms.pc 535 libkms/libkms.pc
532 intel/Makefile 536 intel/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644
index 00000000..eba915dd
--- /dev/null
+++ b/data/Makefile.am
@@ -0,0 +1,23 @@
1# Copyright © 2017 Advanced Micro Devices, Inc.
2# All Rights Reserved.
3#
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the "Software"),
6# to deal in the Software without restriction, including without limitation
7# on the rights to use, copy, modify, merge, publish, distribute, sub
8# license, and/or sell copies of the Software, and to permit persons to whom
9# the Software is furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice (including the next
12# paragraph) shall be included in all copies or substantial portions of the
13# Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18# ADAM JACKSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22libdrmdatadir = @libdrmdatadir@
23dist_libdrmdata_DATA = amdgpu.ids
diff --git a/data/amdgpu.ids b/data/amdgpu.ids
new file mode 100644
index 00000000..0b98c3c3
--- /dev/null
+++ b/data/amdgpu.ids
@@ -0,0 +1,159 @@
1# List of AMDGPU IDs
2#
3# Syntax:
4# device_id, revision_id, product_name <-- single tab after comma
5
61.0.0
76600, 0, AMD Radeon HD 8600/8700M
86600, 81, AMD Radeon (TM) R7 M370
96601, 0, AMD Radeon (TM) HD 8500M/8700M
106604, 0, AMD Radeon R7 M265 Series
116604, 81, AMD Radeon (TM) R7 M350
126605, 0, AMD Radeon R7 M260 Series
136605, 81, AMD Radeon (TM) R7 M340
146606, 0, AMD Radeon HD 8790M
156607, 0, AMD Radeon (TM) HD8530M
166608, 0, AMD FirePro W2100
176610, 0, AMD Radeon HD 8600 Series
186610, 81, AMD Radeon (TM) R7 350
196610, 83, AMD Radeon (TM) R5 340
206611, 0, AMD Radeon HD 8500 Series
216613, 0, AMD Radeon HD 8500 series
226617, C7, AMD Radeon R7 240 Series
236640, 0, AMD Radeon HD 8950
246640, 80, AMD Radeon (TM) R9 M380
256646, 0, AMD Radeon R9 M280X
266646, 80, AMD Radeon (TM) R9 M470X
276647, 0, AMD Radeon R9 M270X
286647, 80, AMD Radeon (TM) R9 M380
296649, 0, AMD FirePro W5100
306658, 0, AMD Radeon R7 200 Series
31665C, 0, AMD Radeon HD 7700 Series
32665D, 0, AMD Radeon R7 200 Series
33665F, 81, AMD Radeon (TM) R7 300 Series
346660, 0, AMD Radeon HD 8600M Series
356660, 81, AMD Radeon (TM) R5 M335
366660, 83, AMD Radeon (TM) R5 M330
376663, 0, AMD Radeon HD 8500M Series
386663, 83, AMD Radeon (TM) R5 M320
396664, 0, AMD Radeon R5 M200 Series
406665, 0, AMD Radeon R5 M200 Series
416665, 83, AMD Radeon (TM) R5 M320
426667, 0, AMD Radeon R5 M200 Series
43666F, 0, AMD Radeon HD 8500M
446780, 0, ATI FirePro V (FireGL V) Graphics Adapter
45678A, 0, ATI FirePro V (FireGL V) Graphics Adapter
466798, 0, AMD Radeon HD 7900 Series
47679A, 0, AMD Radeon HD 7900 Series
48679B, 0, AMD Radeon HD 7900 Series
49679E, 0, AMD Radeon HD 7800 Series
5067A0, 0, AMD Radeon FirePro W9100
5167A1, 0, AMD Radeon FirePro W8100
5267B0, 0, AMD Radeon R9 200 Series
5367B0, 80, AMD Radeon (TM) R9 390 Series
5467B1, 0, AMD Radeon R9 200 Series
5567B1, 80, AMD Radeon (TM) R9 390 Series
5667B9, 0, AMD Radeon R9 200 Series
5767DF, C1, Radeon RX 580 Series
5867DF, C2, Radeon RX 570 Series
5967DF, C3, Radeon RX 580 Series
6067DF, C4, AMD Radeon (TM) RX 480 Graphics
6167DF, C5, AMD Radeon (TM) RX 470 Graphics
6267DF, C6, Radeon RX 570 Series
6367DF, C7, AMD Radeon (TM) RX 480 Graphics
6467DF, CF, AMD Radeon (TM) RX 470 Graphics
6567DF, E3, Radeon RX Series
6667DF, E7, Radeon RX 580 Series
6767DF, EF, Radeon RX 570 Series
6867C2, 01, AMD Radeon (TM) Pro V7350x2
6967C2, 02, AMD Radeon (TM) Pro V7300X
7067C4, 00, AMD Radeon (TM) Pro WX 7100 Graphics
7167C7, 00, AMD Radeon (TM) Pro WX 5100 Graphics
7267C0, 00, AMD Radeon (TM) Pro WX 7100 Graphics
7367D0, 01, AMD Radeon (TM) Pro V7350x2
7467D0, 02, AMD Radeon (TM) Pro V7300X
7567E0, 00, AMD Radeon (TM) Pro WX Series
7667E3, 00, AMD Radeon (TM) Pro WX 4100
7767E8, 00, AMD Radeon (TM) Pro WX Series
7867E8, 01, AMD Radeon (TM) Pro WX Series
7967E8, 80, AMD Radeon (TM) E9260 Graphics
8067EB, 00, AMD Radeon (TM) Pro V5300X
8167EF, C0, AMD Radeon (TM) RX Graphics
8267EF, C1, AMD Radeon (TM) RX 460 Graphics
8367EF, C3, Radeon RX Series
8467EF, C5, AMD Radeon (TM) RX 460 Graphics
8567EF, C7, AMD Radeon (TM) RX Graphics
8667EF, CF, AMD Radeon (TM) RX 460 Graphics
8767EF, E1, Radeon RX Series
8867EF, E3, Radeon RX Series
8967EF, E7, Radeon RX Series
9067EF, EF, AMD Radeon (TM) RX Graphics
9167EF, FF, Radeon RX Series
9267FF, C0, AMD Radeon (TM) RX Graphics
9367FF, C1, AMD Radeon (TM) RX Graphics
9467FF, FF, Radeon RX 550 Series
956800, 0, AMD Radeon HD 7970M
966801, 0, AMD Radeon(TM) HD8970M
976808, 0, ATI FirePro V(FireGL V) Graphics Adapter
986809, 0, ATI FirePro V(FireGL V) Graphics Adapter
996810, 0, AMD Radeon(TM) HD 8800 Series
1006810, 81, AMD Radeon (TM) R7 370 Series
1016811, 0, AMD Radeon(TM) HD8800 Series
1026811, 81, AMD Radeon (TM) R7 300 Series
1036818, 0, AMD Radeon HD 7800 Series
1046819, 0, AMD Radeon HD 7800 Series
1056820, 0, AMD Radeon HD 8800M Series
1066820, 81, AMD Radeon (TM) R9 M375
1076820, 83, AMD Radeon (TM) R9 M375X
1086821, 0, AMD Radeon HD 8800M Series
1096821, 87, AMD Radeon (TM) R7 M380
1106821, 83, AMD Radeon R9 (TM) M370X
1116822, 0, AMD Radeon E8860
1126823, 0, AMD Radeon HD 8800M Series
1136825, 0, AMD Radeon HD 7800M Series
1146827, 0, AMD Radeon HD 7800M Series
1156828, 0, ATI FirePro V(FireGL V) Graphics Adapter
116682B, 0, AMD Radeon HD 8800M Series
117682B, 87, AMD Radeon (TM) R9 M360
118682C, 0, AMD FirePro W4100
119682D, 0, AMD Radeon HD 7700M Series
120682F, 0, AMD Radeon HD 7700M Series
1216835, 0, AMD Radeon R7 Series / HD 9000 Series
1226837, 0, AMD Radeon HD7700 Series
123683D, 0, AMD Radeon HD 7700 Series
124683F, 0, AMD Radeon HD 7700 Series
1256900, 0, AMD Radeon R7 M260
1266900, 81, AMD Radeon (TM) R7 M360
1276900, 83, AMD Radeon (TM) R7 M340
1286901, 0, AMD Radeon R5 M255
1296907, 0, AMD Radeon R5 M255
1306907, 87, AMD Radeon (TM) R5 M315
1316920, 0, AMD RADEON R9 M395X
1326920, 1, AMD RADEON R9 M390X
1336921, 0, AMD Radeon R9 M295X
1346929, 0, AMD FirePro S7150
135692B, 0, AMD FirePro W7100
1366938, 0, AMD Radeon R9 200 Series
1376938, F0, AMD Radeon R9 200 Series
1386938, F1, AMD Radeon (TM) R9 380 Series
1396939, F0, AMD Radeon R9 200 Series
1406939, 0, AMD Radeon R9 200 Series
1416939, F1, AMD Radeon (TM) R9 380 Series
1426985, 00, AMD Radeon Pro WX3100
1436995, 00, AMD Radeon Pro WX2100
144699F, C0, Radeon 500 Series
145699F, C3, Radeon 500 Series
146699F, C7, Radeon RX 550 Series
1477300, C1, AMD FirePro (TM) S9300 x2
1487300, C8, AMD Radeon (TM) R9 Fury Series
1497300, C9, Radeon (TM) Pro Duo
1507300, CB, AMD Radeon (TM) R9 Fury Series
1517300, CA, AMD Radeon (TM) R9 Fury Series
1529874, C4, AMD Radeon R7 Graphics
1539874, C5, AMD Radeon R6 Graphics
1549874, C6, AMD Radeon R6 Graphics
1559874, C7, AMD Radeon R5 Graphics
1569874, 81, AMD Radeon R6 Graphics
1579874, 87, AMD Radeon R5 Graphics
1589874, 85, AMD Radeon R6 Graphics
1599874, 84, AMD Radeon R7 Graphics