[Mesa-dev] [PATCH 1/2] mesa:amd get device name from kernel
Jiang, Sonny
Sonny.Jiang at amd.com
Tue Sep 3 22:33:42 UTC 2019
Signed-off-by: Sonny Jiang <sonny.jiang at amd.com>
---
src/amd/common/ac_gpu_info.c | 72 ++++++++++++++++++++++++++++++++----
1 file changed, 64 insertions(+), 8 deletions(-)
diff --git a/src/amd/common/ac_gpu_info.c b/src/amd/common/ac_gpu_info.c
index 5fb1e26376a..c8bc398319e 100644
--- a/src/amd/common/ac_gpu_info.c
+++ b/src/amd/common/ac_gpu_info.c
@@ -106,6 +106,7 @@ bool ac_query_gpu_info(int fd, void *dev_p,
int r, i, j;
amdgpu_device_handle dev = dev_p;
drmDevicePtr devinfo;
+ drmVersionPtr version;
/* Get PCI info. */
r = drmGetDevice2(fd, 0, &devinfo);
@@ -304,18 +305,73 @@ bool ac_query_gpu_info(int fd, void *dev_p,
info->pci_id = amdinfo->asic_id; /* TODO: is this correct? */
info->vce_harvest_config = amdinfo->vce_harvest_config;
- switch (info->pci_id) {
+ static struct ac_chip_mapping {
+ const char *kernel_name;
+ enum radeon_family family;
+ const char *mesa_name;
+ } table[] = {
+ {"TAHITI", CHIP_TAHITI, "TAHITI"},
+ {"PITCAIRN", CHIP_PITCAIRN, "PITCAIRN"},
+ {"VERDE", CHIP_VERDE, "VERDE"},
+ {"OLAND", CHIP_OLAND, "OLAND"},
+ {"HAINAN", CHIP_HAINAN, "HAINAN"},
+ {"BONAIRE", CHIP_BONAIRE, "BONAIRE"},
+ {"KAVERI", CHIP_KAVERI, "KAVERI"},
+ {"KABINI", CHIP_KABINI, "KABINI"},
+ {"HAWAII", CHIP_HAWAII, "HAWAII"},
+ {"MULLINS", CHIP_KABINI, "KABINI"},
+ {"TOPAZ", CHIP_ICELAND, "ICELAND"},
+ {"TONGA", CHIP_TONGA, "TONGA"},
+ {"FIJI", CHIP_FIJI, "FIJI"},
+ {"CARRIZO", CHIP_CARRIZO, "CARRIZO"},
+ {"STONEY", CHIP_STONEY, "STONEY"},
+ {"POLARIS10", CHIP_POLARIS10, "POLARIS10"},
+ {"POLARIS11", CHIP_POLARIS11, "POLARIS11"},
+ {"POLARIS12", CHIP_POLARIS12, "POLARIS12"},
+ {"VEGAM", CHIP_VEGAM, "VEGAM"},
+ {"VEGA10", CHIP_VEGA10, "VEGA10"},
+ {"VEGA12", CHIP_VEGA12, "VEGA12"},
+ {"VEGA20", CHIP_VEGA20, "VEGA20"},
+ {"RAVEN", CHIP_RAVEN, "RAVEN"},
+ {"ARCTURUS", CHIP_ARCTURUS, "ARCTURUS"},
+ {"RENOIR", CHIP_RENOIR, "RENOIR"},
+ {"NAVI10", CHIP_NAVI10, "NAVI10"},
+ {"NAVI14", CHIP_NAVI14, "NAVI14"},
+ {"NAVI12", CHIP_NAVI12, "NAVI12"}
+ };
+
+ version = drmGetVersion(fd);
+ if (!version) {
+ fprintf(stderr, "amdgpu: drmGetVersion failed.\n");
+ return false;
+ }
+
+ if (version->desc_len && version->desc) {
+ for (unsigned i = 0; i < ARRAY_SIZE(table); i++) {
+ if (strcmp(version->desc, table[i].kernel_name) == 0) {
+ info->family = table[i].family;
+ info->name = table[i].mesa_name;
+ break;
+ }
+ }
+ }
+
+ drmFreeVersion(version);
+
+ if (!info->name) {
+ switch (info->pci_id) {
#define CHIPSET(pci_id, cfamily) \
- case pci_id: \
- info->family = CHIP_##cfamily; \
- info->name = #cfamily; \
- break;
+ case pci_id: \
+ info->family = CHIP_##cfamily; \
+ info->name = #cfamily; \
+ break;
#include "pci_ids/radeonsi_pci_ids.h"
#undef CHIPSET
- default:
- fprintf(stderr, "amdgpu: Invalid PCI ID.\n");
- return false;
+ default:
+ fprintf(stderr, "amdgpu: Invalid PCI ID.\n");
+ return false;
+ }
}
/* Raven2 uses the same PCI IDs as Raven1, but different revision IDs. */
--
2.17.1
More information about the mesa-dev
mailing list