2017-08-05 08:15:15 -06:00
|
|
|
/*
|
|
|
|
* Copyright © 2017 Advanced Micro Devices, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xf86drm.h"
|
|
|
|
#include "amdgpu_drm.h"
|
|
|
|
#include "amdgpu_internal.h"
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
static int parse_one_line(struct amdgpu_device *dev, const char *line)
|
2017-08-05 08:15:15 -06:00
|
|
|
{
|
|
|
|
char *buf, *saveptr;
|
|
|
|
char *s_did;
|
2018-02-16 19:24:37 -07:00
|
|
|
uint32_t did;
|
2017-08-05 08:15:15 -06:00
|
|
|
char *s_rid;
|
2018-02-16 19:24:37 -07:00
|
|
|
uint32_t rid;
|
2017-08-05 08:15:15 -06:00
|
|
|
char *s_name;
|
|
|
|
char *endptr;
|
2018-02-16 19:24:37 -07:00
|
|
|
int r = -EINVAL;
|
|
|
|
|
|
|
|
/* ignore empty line and commented line */
|
|
|
|
if (strlen(line) == 0 || line[0] == '#')
|
|
|
|
return -EAGAIN;
|
2017-08-05 08:15:15 -06:00
|
|
|
|
|
|
|
buf = strdup(line);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* device id */
|
|
|
|
s_did = strtok_r(buf, ",", &saveptr);
|
2018-02-16 19:24:37 -07:00
|
|
|
if (!s_did)
|
2017-08-05 08:15:15 -06:00
|
|
|
goto out;
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
did = strtol(s_did, &endptr, 16);
|
|
|
|
if (*endptr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (did != dev->info.asic_id) {
|
|
|
|
r = -EAGAIN;
|
2017-08-05 08:15:15 -06:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* revision id */
|
|
|
|
s_rid = strtok_r(NULL, ",", &saveptr);
|
2018-02-16 19:24:37 -07:00
|
|
|
if (!s_rid)
|
2017-08-05 08:15:15 -06:00
|
|
|
goto out;
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
rid = strtol(s_rid, &endptr, 16);
|
|
|
|
if (*endptr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (rid != dev->info.pci_rev_id) {
|
|
|
|
r = -EAGAIN;
|
2017-08-05 08:15:15 -06:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* marketing name */
|
|
|
|
s_name = strtok_r(NULL, ",", &saveptr);
|
2018-02-16 19:24:37 -07:00
|
|
|
if (!s_name)
|
2017-08-05 08:15:15 -06:00
|
|
|
goto out;
|
2018-02-16 19:24:37 -07:00
|
|
|
|
2017-08-05 08:15:15 -06:00
|
|
|
/* trim leading whitespaces or tabs */
|
|
|
|
while (isblank(*s_name))
|
|
|
|
s_name++;
|
2018-02-16 19:24:37 -07:00
|
|
|
if (strlen(s_name) == 0)
|
2017-08-05 08:15:15 -06:00
|
|
|
goto out;
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
dev->marketing_name = strdup(s_name);
|
|
|
|
if (dev->marketing_name)
|
|
|
|
r = 0;
|
|
|
|
else
|
|
|
|
r = -ENOMEM;
|
2017-08-05 08:15:15 -06:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
|
2017-08-05 08:15:15 -06:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char *line = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
ssize_t n;
|
|
|
|
int line_num = 1;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
|
|
|
|
if (!fp) {
|
|
|
|
fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
|
|
|
|
strerror(errno));
|
2018-02-16 19:24:37 -07:00
|
|
|
return;
|
2017-08-05 08:15:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 1st valid line is file version */
|
|
|
|
while ((n = getline(&line, &len, fp)) != -1) {
|
|
|
|
/* trim trailing newline */
|
|
|
|
if (line[n - 1] == '\n')
|
|
|
|
line[n - 1] = '\0';
|
|
|
|
|
|
|
|
/* ignore empty line and commented line */
|
|
|
|
if (strlen(line) == 0 || line[0] == '#') {
|
|
|
|
line_num++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
drmMsg("%s version: %s\n", AMDGPU_ASIC_ID_TABLE, line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((n = getline(&line, &len, fp)) != -1) {
|
|
|
|
/* trim trailing newline */
|
|
|
|
if (line[n - 1] == '\n')
|
|
|
|
line[n - 1] = '\0';
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
r = parse_one_line(dev, line);
|
|
|
|
if (r != -EAGAIN)
|
|
|
|
break;
|
2017-08-05 08:15:15 -06:00
|
|
|
|
|
|
|
line_num++;
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:24:37 -07:00
|
|
|
if (r == -EINVAL) {
|
|
|
|
fprintf(stderr, "Invalid format: %s: line %d: %s\n",
|
|
|
|
AMDGPU_ASIC_ID_TABLE, line_num, line);
|
|
|
|
} else if (r) {
|
|
|
|
fprintf(stderr, "%s: Cannot parse ASIC IDs: %s\n",
|
|
|
|
__func__, strerror(-r));
|
|
|
|
}
|
2017-08-05 08:15:15 -06:00
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(fp);
|
|
|
|
}
|