From: Kunal Joshi <kunal1.joshi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Kunal Joshi <kunal1.joshi@intel.com>, Sowmiya S <sowmiya.s@intel.com>
Subject: [PATCH i-g-t 11/13] lib/igt_dp: add DPCD read helpers
Date: Thu, 1 Oct 2026 13:07:01 +0530 [thread overview]
Message-ID: <20261001073703.5067-12-kunal1.joshi@intel.com> (raw)
In-Reply-To: <20261001073703.5067-1-kunal1.joshi@intel.com>
Add igt_dp_aux_open() for opening the AUX channel device of a
connector, and igt_dp_dpcd_read() and igt_dp_dpcd_read_byte() for
reading DPCD through it. We'll be adding a user in follow-up.
Only add reads, as DPCD writes from userspace would race with the
driver. The AUX device only exists with
CONFIG_DRM_DISPLAY_DP_AUX_CHARDEV=y, so return errors instead of
asserting, and let the callers decide what to do.
kms_dp_aux_dev, amd_assr, amd_replay and amd_multidisplay_modeset have
local copies of the same, which could be converted later.
Assisted-by: GitHub_Copilot:claude-opus-5
Signed-off-by: Kunal Joshi <kunal1.joshi@intel.com>
Reviewed-by: Sowmiya S <sowmiya.s@intel.com>
---
lib/igt_dp.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_dp.h | 9 +++++
2 files changed, 117 insertions(+)
diff --git a/lib/igt_dp.c b/lib/igt_dp.c
index 9f71c9e72..0b1fe73de 100644
--- a/lib/igt_dp.c
+++ b/lib/igt_dp.c
@@ -6,7 +6,13 @@
* Louis Chauvet <louis.chauvet@bootlin.com>
*/
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
#include "drmtest.h"
#include "i915/i915_dp.h"
@@ -173,3 +179,105 @@ void igt_dp_wait_pending_retrain(int drm_fd, igt_output_t *output)
}
igt_assert_f(false, "Timeout waiting for pending retrain to complete\n");
}
+
+/**
+ * igt_dp_aux_open: Open the AUX channel device of a display port
+ * @drm_fd: DRM file descriptor
+ * @output: igt_output_t object representing the display port
+ *
+ * The AUX channel of a connector is exposed as a character device when the
+ * kernel is built with CONFIG_DRM_DISPLAY_DP_AUX_CHARDEV. The device is
+ * parented to the connector, so it is the connector's own sysfs directory
+ * which is scanned here and not /dev, and there is at most one entry in it to
+ * match. /dev is only where the matched entry is then opened from.
+ *
+ * Returns:
+ * A file descriptor for the AUX channel device, or a negative error code on
+ * failure.
+ */
+int igt_dp_aux_open(int drm_fd, igt_output_t *output)
+{
+ struct dirent *entry;
+ int aux_fd = -ENOENT;
+ int dir_fd;
+ DIR *dir;
+
+ dir_fd = igt_connector_sysfs_open(drm_fd, output->config.connector);
+ if (dir_fd < 0)
+ return -ENOENT;
+
+ dir = fdopendir(dir_fd);
+ if (!dir) {
+ /* Save the error before close() gets a chance to overwrite it. */
+ int err = -errno;
+
+ close(dir_fd);
+ return err;
+ }
+
+ errno = 0;
+
+ while ((entry = readdir(dir))) {
+ char path[NAME_MAX + sizeof("/dev/")];
+
+ if (strncmp(entry->d_name, "drm_dp_aux", strlen("drm_dp_aux")))
+ continue;
+
+ snprintf(path, sizeof(path), "/dev/%s", entry->d_name);
+
+ aux_fd = open(path, O_RDONLY);
+ if (aux_fd < 0)
+ aux_fd = -errno;
+
+ break;
+ }
+
+ /* readdir() reports both the end of the directory and an error as NULL. */
+ if (!entry && errno)
+ aux_fd = -errno;
+
+ closedir(dir);
+
+ return aux_fd;
+}
+
+/**
+ * igt_dp_dpcd_read: Read from the DPCD of a display port
+ * @aux_fd: AUX channel device file descriptor from igt_dp_aux_open()
+ * @offset: DPCD offset to read from
+ * @buf: Buffer to read into
+ * @size: Number of bytes to read
+ *
+ * Returns:
+ * The number of bytes read, or a negative error code on failure.
+ */
+int igt_dp_dpcd_read(int aux_fd, unsigned int offset, void *buf, size_t size)
+{
+ ssize_t ret;
+
+ ret = pread(aux_fd, buf, size, offset);
+ if (ret < 0)
+ return -errno;
+
+ return ret;
+}
+
+/**
+ * igt_dp_dpcd_read_byte: Read a single byte from the DPCD of a display port
+ * @aux_fd: AUX channel device file descriptor from igt_dp_aux_open()
+ * @offset: DPCD offset to read from
+ * @val: Location to store the value read
+ *
+ * Returns:
+ * 0 on success, or a negative error code on failure.
+ */
+int igt_dp_dpcd_read_byte(int aux_fd, unsigned int offset, uint8_t *val)
+{
+ int ret;
+
+ ret = igt_dp_dpcd_read(aux_fd, offset, val, sizeof(*val));
+ if (ret < 0)
+ return ret;
+
+ return ret == 1 ? 0 : -EIO;
+}
diff --git a/lib/igt_dp.h b/lib/igt_dp.h
index 0c56ad2ec..44f3b11a1 100644
--- a/lib/igt_dp.h
+++ b/lib/igt_dp.h
@@ -9,6 +9,9 @@
#ifndef _IGT_DP_H_
#define _IGT_DP_H_
+#include <stddef.h>
+#include <stdint.h>
+
#include "igt_kms.h"
int igt_dp_get_current_link_rate(int drm_fd, igt_output_t *output);
@@ -27,4 +30,10 @@ int igt_dp_get_pending_retrain(int drm_fd, igt_output_t *output);
void igt_dp_wait_pending_retrain(int drm_fd, igt_output_t *output);
+int igt_dp_aux_open(int drm_fd, igt_output_t *output);
+
+int igt_dp_dpcd_read(int aux_fd, unsigned int offset, void *buf, size_t size);
+
+int igt_dp_dpcd_read_byte(int aux_fd, unsigned int offset, uint8_t *val);
+
#endif
--
2.25.1
next prev parent reply other threads:[~2026-10-01 7:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 7:36 [PATCH i-g-t 00/13] Expand kms_dp_link_training coverage Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 01/13] lib/i915/i915_dp: add helpers for the allowed link configs debugfs Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 02/13] tests/intel/kms_dp_link_training: use i915_dp_is_uhbr_rate() Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 03/13] tests/intel/kms_dp_link_training: extract train_link_config() Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 04/13] tests/intel/kms_dp_link_training: detect links that failed training Kunal Joshi
2026-10-01 9:05 ` S, Sowmiya
2026-10-01 7:36 ` [PATCH i-g-t 05/13] tests/intel/kms_dp_link_training: use the lowest pixel clock mode Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 06/13] tests/intel/kms_dp_link_training: train all allowed link configs Kunal Joshi
2026-10-01 9:05 ` S, Sowmiya
2026-10-01 7:36 ` [PATCH i-g-t 07/13] lib/i915/i915_dp: add i915_dp_get_tc_mode() Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 08/13] tests/intel/kms_dp_link_training: log the DP link inventory Kunal Joshi
2026-10-01 7:36 ` [PATCH i-g-t 09/13] tests/intel/kms_dp_link_training: train each MST topology only once Kunal Joshi
2026-10-01 7:37 ` [PATCH i-g-t 10/13] tests/intel/kms_dp_link_training: add tbt-alt and direct link subtests Kunal Joshi
2026-10-01 7:37 ` Kunal Joshi [this message]
2026-10-01 7:37 ` [PATCH i-g-t 12/13] lib/igt_dp: add DPCD link status and channel coding checks Kunal Joshi
2026-10-01 7:37 ` [PATCH i-g-t 13/13] tests/intel/kms_dp_link_training: check the link from the sink side Kunal Joshi
2026-10-01 13:13 ` ✓ i915.CI.BAT: success for Expand kms_dp_link_training coverage (rev2) Patchwork
2026-10-01 16:42 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-01 21:02 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-10-05 16:06 ` Joshi, Kunal1
2026-10-02 17:18 ` ✗ i915.CI.Full: " Patchwork
2026-10-05 16:04 ` Joshi, Kunal1
-- strict thread matches above, loose matches on Subject: below --
2026-09-16 4:47 [PATCH i-g-t 00/13] Expand kms_dp_link_training coverage Kunal Joshi
2026-09-16 4:47 ` [PATCH i-g-t 11/13] lib/igt_dp: Add DPCD read helpers Kunal Joshi
2026-09-23 13:34 ` S, Sowmiya
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=20261001073703.5067-12-kunal1.joshi@intel.com \
--to=kunal1.joshi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=sowmiya.s@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.