2 * Copyright © 2017 Advanced Micro Devices, Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
34 #include "amdgpu_drm.h"
35 #include "amdgpu_internal.h"
37 static int parse_one_line(struct amdgpu_device *dev, const char *line)
48 /* ignore empty line and commented line */
49 if (strlen(line) == 0 || line[0] == '#')
57 s_did = strtok_r(buf, ",", &saveptr);
61 did = strtol(s_did, &endptr, 16);
65 if (did != dev->info.asic_id) {
71 s_rid = strtok_r(NULL, ",", &saveptr);
75 rid = strtol(s_rid, &endptr, 16);
79 if (rid != dev->info.pci_rev_id) {
85 s_name = strtok_r(NULL, ",", &saveptr);
89 /* trim leading whitespaces or tabs */
90 while (isblank(*s_name))
92 if (strlen(s_name) == 0)
95 dev->marketing_name = strdup(s_name);
96 if (dev->marketing_name)
107 void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
116 fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
118 fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
123 /* 1st valid line is file version */
124 while ((n = getline(&line, &len, fp)) != -1) {
125 /* trim trailing newline */
126 if (line[n - 1] == '\n')
129 /* ignore empty line and commented line */
130 if (strlen(line) == 0 || line[0] == '#') {
135 drmMsg("%s version: %s\n", AMDGPU_ASIC_ID_TABLE, line);
139 while ((n = getline(&line, &len, fp)) != -1) {
140 /* trim trailing newline */
141 if (line[n - 1] == '\n')
144 r = parse_one_line(dev, line);
152 fprintf(stderr, "Invalid format: %s: line %d: %s\n",
153 AMDGPU_ASIC_ID_TABLE, line_num, line);
154 } else if (r && r != -EAGAIN) {
155 fprintf(stderr, "%s: Cannot parse ASIC IDs: %s\n",
156 __func__, strerror(-r));