Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Lin <PingLei.Lin@amd.com>
To: <igt-dev@lists.freedesktop.org>
Cc: <alex.hung@amd.com>, <sunpeng.li@amd.com>,
	<chiahsuan.chung@amd.com>, <Pinglei.lin@amd.com>,
	James Lin <PingLei.Lin@amd.com>
Subject: [PATCH i-g-t] tests/amdgpu: Discover amdgpu backlight device dynamically instead of hardcoding amdgpu_bl0
Date: Fri, 26 Jun 2026 11:21:59 +0800	[thread overview]
Message-ID: <20260626032211.38353-1-PingLei.Lin@amd.com> (raw)

[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


             reply	other threads:[~2026-06-26  3:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  3:21 James Lin [this message]
2026-06-26  4:12 ` ✓ Xe.CI.BAT: success for tests/amdgpu: Discover amdgpu backlight device dynamically instead of hardcoding amdgpu_bl0 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260626032211.38353-1-PingLei.Lin@amd.com \
    --to=pinglei.lin@amd.com \
    --cc=alex.hung@amd.com \
    --cc=chiahsuan.chung@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=sunpeng.li@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox