amdgpu: Read model name from /proc/cpuinfo for APUs

The correct marketing name is encoded in the model name field
that is read from the hardware on an APU.  Try to read from /proc/cpuinfo
when an APU is found to identify such hardware.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
This commit is contained in:
Mario Limonciello 2025-10-14 11:54:41 -05:00 committed by Mario Limonciello (AMD)
parent f7013effc3
commit 2c1d39eff8

View file

@ -104,6 +104,45 @@ out:
return r; return r;
} }
static void amdgpu_parse_proc_cpuinfo(struct amdgpu_device *dev)
{
const char *search_key = "model name";
char *line = NULL;
size_t len = 0;
FILE *fp;
fp = fopen("/proc/cpuinfo", "r");
if (fp == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
return;
}
while (getline(&line, &len, fp) != -1) {
char *saveptr;
char *value;
if (strncmp(line, search_key, strlen(search_key)))
continue;
/* get content after colon and strip whitespace */
value = strtok_r(line, ":", &saveptr);
value = strtok_r(NULL, ":", &saveptr);
if (value == NULL)
continue;
while (*value == ' ' || *value == '\t')
value++;
saveptr = strchr(value, '\n');
if (saveptr)
*saveptr = '\0';
dev->marketing_name = strdup(value);
break;
}
free(line);
fclose(fp);
}
void amdgpu_parse_asic_ids(struct amdgpu_device *dev) void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
{ {
FILE *fp; FILE *fp;
@ -113,6 +152,12 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
int line_num = 1; int line_num = 1;
int r = 0; int r = 0;
if (dev->info.ids_flags & AMDGPU_IDS_FLAGS_FUSION) {
amdgpu_parse_proc_cpuinfo(dev);
if (dev->marketing_name != NULL)
return;
}
fp = fopen(AMDGPU_ASIC_ID_TABLE, "r"); fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
if (!fp) { if (!fp) {
fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE, fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,