[PATCH] amdgpu: add env support for amdgpu.ids path
authorSergio Costas Rodriguez <sergio.costas@canonical.com>
Wed, 2 Nov 2022 14:48:07 +0000 (15:48 +0100)
committerTimo Aaltonen <tjaalton@debian.org>
Thu, 27 Feb 2025 12:57:25 +0000 (14:57 +0200)
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.

Gbp-Pq: Name amdgpu-add-env-support-for-amdgpu-ids.patch

README.rst
amdgpu/amdgpu_asic_id.c

index 746080319414bef9981dea1a34e007f233379ce1..6532c12ff87fb0492cf10763b95952a7c76b8076 100644 (file)
@@ -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.
index a5007ffc80a74e517b6a85b49a7c0ffd6fb5ccb8..81a7cf7f415de4822300cb962673cb9ae7e5f5a1 100644 (file)
@@ -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));