[PATCH] amdgpu: add env support for amdgpu.ids path
Sergio Costas Rodriguez
sergio.costas at canonical.com
Thu Feb 27 12:45:51 UTC 2025
In some cases, like when building a Snap application that uses
libdrm, the `amdgpu.ids` file isn't directly available at the
compiling place, but inside a mounted folder. This forces each
application to link/bind the file from the current place
(usually at the $SNAP/gnome-platform/usr/share/libdrm/amdgpu.ids)
which is cumbersome.
This patch allows to set an environment variable, called
AMDGPU_ASIC_ID_TABLE_PATH, where the file will be also searched
if it isn't located in the default, meson-configured, path.
This patch is also available in the MESA gitlab:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/273
---
README.rst | 9 +++++++++
amdgpu/amdgpu_asic_id.c | 14 ++++++++++----
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/README.rst b/README.rst
index 74608031..6532c12f 100644
--- a/README.rst
+++ b/README.rst
@@ -49,3 +49,12 @@ Then use ninja to build and install:
If you are installing into a system location you will need to run install
separately, and as root.
+
+AMDGPU ASIC table file
+----------------------
+
+The AMDGPU driver requires the `amdgpu.ids` file. It is usually located at
+`$PREFIX/share/libdrm`, but it is possible to specify an alternative path
+during runtime by setting the `AMDGPU_ASIC_ID_TABLE_PATH` environment
+variable with the full path (including the file name) of the alternative
+file.
diff --git a/amdgpu/amdgpu_asic_id.c b/amdgpu/amdgpu_asic_id.c
index a5007ffc..81a7cf7f 100644
--- a/amdgpu/amdgpu_asic_id.c
+++ b/amdgpu/amdgpu_asic_id.c
@@ -112,10 +112,16 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
ssize_t n;
int line_num = 1;
int r = 0;
+ const char *amdgpu_asic_id_table_path = getenv("AMDGPU_ASIC_ID_TABLE_PATH");
+
+ if (amdgpu_asic_id_table_path == NULL || amdgpu_asic_id_table_path[0] == '\0') {
+ amdgpu_asic_id_table_path = AMDGPU_ASIC_ID_TABLE;
+ }
+
+ fp = fopen(amdgpu_asic_id_table_path, "r");
- fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
if (!fp) {
- fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
+ fprintf(stderr, "%s: %s\n", amdgpu_asic_id_table_path,
strerror(errno));
return;
}
@@ -132,7 +138,7 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
continue;
}
- drmMsg("%s version: %s\n", AMDGPU_ASIC_ID_TABLE, line);
+ drmMsg("%s version: %s\n", amdgpu_asic_id_table_path, line);
break;
}
@@ -150,7 +156,7 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
if (r == -EINVAL) {
fprintf(stderr, "Invalid format: %s: line %d: %s\n",
- AMDGPU_ASIC_ID_TABLE, line_num, line);
+ amdgpu_asic_id_table_path, line_num, line);
} else if (r && r != -EAGAIN) {
fprintf(stderr, "%s: Cannot parse ASIC IDs: %s\n",
__func__, strerror(-r));
--
2.45.2
More information about the amd-gfx
mailing list