Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] tests/amdgpu: Discover amdgpu backlight device dynamically instead of hardcoding amdgpu_bl0
@ 2026-06-26  3:21 James Lin
  2026-06-26  4:12 ` ✓ Xe.CI.BAT: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: James Lin @ 2026-06-26  3:21 UTC (permalink / raw)
  To: igt-dev; +Cc: alex.hung, sunpeng.li, chiahsuan.chung, Pinglei.lin, James Lin

[Why]
amd_abm builds the backlight sysfs path assuming the amdgpu backlight
device is amdgpu_bl0. The amdgpu backlight device is named amdgpu_bl<N>
where N is derived from the DRM primary node index (see
amdgpu_dm_backlight.c). On systems where the amdgpu DRM node is not
card0 (e.g. simpledrm takes card0 and amdgpu comes up as card1), the
backlight device is amdgpu_bl1, not amdgpu_bl0. The hardcoded
"/sys/class/backlight/amdgpu_bl0" path does not exist, so
backlight_read_max_brightness() and backlight_write_brightness() fail
before any test logic runs, preventing dpms_cycle and the other abm
subtests from executing.

[How]
Add find_backlight_device() to scan /sys/class/backlight for the first
entry beginning with "amdgpu_bl" and store its full path in a
file-scope buffer. Call it from igt_fixture and route the brightness
and max_brightness accessors through the discovered path instead of the
hardcoded amdgpu_bl0 macro. Use igt_require_f() so a machine with no
amdgpu backlight skips cleanly rather than asserting.

Signed-off-by: James Lin <PingLei.Lin@amd.com>
---
 tests/amdgpu/amd_abm.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/tests/amdgpu/amd_abm.c b/tests/amdgpu/amd_abm.c
index ba90344d3..7992dfd87 100644
--- a/tests/amdgpu/amd_abm.c
+++ b/tests/amdgpu/amd_abm.c
@@ -31,13 +31,44 @@
 #include <string.h>
 #include <fcntl.h>
 #include <time.h>
+#include <dirent.h>
 
 #define DEBUGFS_CURRENT_BACKLIGHT_PWM "amdgpu_current_backlight_pwm"
 #define DEBUGFS_TARGET_BACKLIGHT_PWM "amdgpu_target_backlight_pwm"
-#define BACKLIGHT_PATH "/sys/class/backlight/amdgpu_bl0"
+#define BACKLIGHT_DIR "/sys/class/backlight"
 #define PANEL_POWER_SAVINGS_ATTR "amdgpu/panel_power_savings"
 #define MK_COLOR(r, g, b)	((0 << 24) | (r << 16) | (g << 8) | b)
 
+/*
+ * The amdgpu backlight device is named amdgpu_bl<N> where N is derived from
+ * the DRM primary node index (see amdgpu_dm_backlight.c). On systems where
+ * the amdgpu DRM node is not card0 (e.g. card1), the device is amdgpu_bl1,
+ * not amdgpu_bl0. Discover it at runtime instead of hardcoding the name.
+ */
+static char backlight_path[PATH_MAX];
+
+static void find_backlight_device(void)
+{
+	DIR *dir;
+	struct dirent *ent;
+
+	dir = opendir(BACKLIGHT_DIR);
+	igt_require_f(dir, "Cannot open %s\n", BACKLIGHT_DIR);
+
+	while ((ent = readdir(dir))) {
+		if (strncmp(ent->d_name, "amdgpu_bl", 9) == 0) {
+			snprintf(backlight_path, sizeof(backlight_path),
+				 "%s/%s", BACKLIGHT_DIR, ent->d_name);
+			break;
+		}
+	}
+	closedir(dir);
+
+	igt_require_f(backlight_path[0] != '\0',
+		      "No amdgpu_bl* backlight device found in %s\n",
+		      BACKLIGHT_DIR);
+}
+
 typedef struct data {
 	igt_display_t display;
 	igt_plane_t *primary;
@@ -234,7 +265,7 @@ static int backlight_write_brightness(int value)
 	char src[64];
 	int len;
 
-	igt_assert(snprintf(full, PATH_MAX, "%s/%s", BACKLIGHT_PATH, "brightness") < PATH_MAX);
+	igt_assert(snprintf(full, PATH_MAX, "%s/%s", backlight_path, "brightness") < PATH_MAX);
 	fd = open(full, O_WRONLY);
 	if (fd == -1)
 		return -errno;
@@ -288,7 +319,7 @@ static int backlight_read_max_brightness(int *result)
 	char dst[64];
 	int r, e;
 
-	igt_assert(snprintf(full, PATH_MAX, "%s/%s", BACKLIGHT_PATH, "max_brightness") < PATH_MAX);
+	igt_assert(snprintf(full, PATH_MAX, "%s/%s", backlight_path, "max_brightness") < PATH_MAX);
 
 	fd = open(full, O_RDONLY);
 	if (fd == -1)
@@ -528,6 +559,8 @@ int igt_main()
 
 		igt_display_require(&data.display, data.drm_fd);
 
+		find_backlight_device();
+
 		test_init(&data);
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-26  5:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26  3:21 [PATCH i-g-t] tests/amdgpu: Discover amdgpu backlight device dynamically instead of hardcoding amdgpu_bl0 James Lin
2026-06-26  4:12 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-06-26  4:28 ` ✓ i915.CI.BAT: " Patchwork
2026-06-26  5:36 ` [PATCH i-g-t] " Tom Chung
2026-06-26  5:50 ` ✗ Xe.CI.FULL: failure for " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox