Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [RFC PATCH] lib/kms: Get pipe enum from debugfs
@ 2023-03-20  6:00 Bhanuprakash Modem
  2023-03-20  6:47 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/kms: Get pipe enum from debugfs (rev3) Patchwork
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bhanuprakash Modem @ 2023-03-20  6:00 UTC (permalink / raw)
  To: igt-dev; +Cc: Jani Nikula

The pipe may not be the same as crtc index if pipes are fused off.
For testing purposes, IGT needs to know the pipe. There's already
a I915_GET_PIPE_FROM_CRTC_ID IOCTL for this. However, the upcoming
Xe driver won't have that IOCTL.

Add IGT support to read the pipe from debugfs. For i915, still
fallback to ioctl method to support older kernels.

V2: Fix kmstest_get_pipe_from_crtc_id() (Bhanu)

Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem@intel.com>
---
 lib/igt_kms.c | 80 +++++++++++++++++++++++++++++++++++----------------
 1 file changed, 56 insertions(+), 24 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 562d60bff..b3135ad7a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1067,6 +1067,53 @@ void kmstest_dump_mode(drmModeModeInfo *mode)
 		 aspect ? aspect : "", aspect ? ")" : "");
 }
 
+/*
+ * With non-contiguous pipes display, crtc mapping is not always same
+ * as pipe mapping, In i915 pipe is enum id of i915's crtc object.
+ * hence allocating upper bound igt_pipe array to support non-contiguos
+ * pipe display and reading pipe enum for a crtc using GET_PIPE_FROM_CRTC_ID
+ * ioctl for a pipe to do pipe ordering with respect to crtc list.
+ */
+static int __intel_get_pipe_from_crtc_id(int fd, int crtc_id, int crtc_idx)
+{
+	char buf[2];
+	int debugfs_fd, res;
+
+	/*
+	 * No GET_PIPE_FROM_CRTC_ID ioctl support for XE. Instead read
+	 * from the debugfs "i915_pipe".
+	 *
+	 * This debugfs is applicable for both i915 & XE. For i915, still
+	 * we can fallback to ioctl method to support older kernels.
+	 */
+	debugfs_fd = igt_debugfs_pipe_dir(fd, crtc_idx, O_RDONLY);
+	igt_assert(debugfs_fd >= 0);
+
+	res = igt_debugfs_simple_read(debugfs_fd, "i915_pipe", buf, sizeof(buf));
+	close(debugfs_fd);
+
+	if (res <= 0) {
+		/* Fallback to older ioctl method. */
+		if (is_i915_device(fd)) {
+			struct drm_i915_get_pipe_from_crtc_id get_pipe;
+
+			get_pipe.pipe = 0;
+			get_pipe.crtc_id =  crtc_id;
+
+			do_ioctl(fd, DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID,
+				 &get_pipe);
+
+			return get_pipe.pipe;
+		} else
+			igt_assert_f(false, "XE: Failed to read the debugfs i915_pipe.\n");
+	} else {
+		int pipe;
+
+		igt_assert_eq(sscanf(buf, "%d", &pipe), 1);
+		return pipe;
+	}
+}
+
 /**
  * kmstest_get_pipe_from_crtc_id:
  * @fd: DRM fd
@@ -1100,7 +1147,8 @@ int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id)
 
 	drmModeFreeResources(res);
 
-	return i;
+	return is_intel_device(fd) ?
+		__intel_get_pipe_from_crtc_id(fd, crtc_id, i) : i;
 }
 
 /**
@@ -2558,14 +2606,14 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	drmModeRes *resources;
 	drmModePlaneRes *plane_resources;
 	int i;
-	bool is_i915_dev;
+	bool is_intel_dev;
 
 	memset(display, 0, sizeof(igt_display_t));
 
 	LOG_INDENT(display, "init");
 
 	display->drm_fd = drm_fd;
-	is_i915_dev = is_i915_device(drm_fd);
+	is_intel_dev = is_intel_device(drm_fd);
 
 	drmSetClientCap(drm_fd, DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1);
 
@@ -2593,34 +2641,18 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	if (is_xe_device(drm_fd))
 		xe_device_get(drm_fd);
 
-	/*
-	 * With non-contiguous pipes display, crtc mapping is not always same
-	 * as pipe mapping, In i915 pipe is enum id of i915's crtc object.
-	 * hence allocating upper bound igt_pipe array to support non-contiguos
-	 * pipe display and reading pipe enum for a crtc using GET_PIPE_FROM_CRTC_ID ioctl
-	 * for a pipe to do pipe ordering with respect to crtc list.
-	 */
 	display->n_pipes = IGT_MAX_PIPES;
 	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
 	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
 
 	for (i = 0; i < resources->count_crtcs; i++) {
 		igt_pipe_t *pipe;
+		int pipe_enum = (is_intel_dev)?
+			__intel_get_pipe_from_crtc_id(drm_fd,
+						      resources->crtcs[i], i) : i;
 
-		if (is_i915_dev) {
-			struct drm_i915_get_pipe_from_crtc_id get_pipe;
-
-			get_pipe.pipe = 0;
-			get_pipe.crtc_id =  resources->crtcs[i];
-			do_ioctl(display->drm_fd,
-					DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID, &get_pipe);
-			pipe = &display->pipes[get_pipe.pipe];
-			pipe->pipe = get_pipe.pipe;
-		}
-		else {
-			pipe = &display->pipes[i];
-			pipe->pipe = i;
-		}
+		pipe = &display->pipes[pipe_enum];
+		pipe->pipe = pipe_enum;
 
 		/* pipe is enabled/disabled */
 		pipe->enabled = true;
-- 
2.40.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [igt-dev] [RFC PATCH] lib/kms: Get pipe enum from debugfs
@ 2023-03-17 16:50 Bhanuprakash Modem
  0 siblings, 0 replies; 5+ messages in thread
From: Bhanuprakash Modem @ 2023-03-17 16:50 UTC (permalink / raw)
  To: igt-dev; +Cc: Jani Nikula

The pipe may not be the same as crtc index if pipes are fused off.
For testing purposes, IGT needs to know the pipe. There's already
a I915_GET_PIPE_FROM_CRTC_ID IOCTL for this. However, the upcoming
Xe driver won't have that IOCTL.

Add IGT support to read the pipe from debugfs. For i915, still
fallback to ioctl method to support older kernels.

Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem@intel.com>
---
 lib/igt_kms.c | 53 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 562d60bff..d7b46cd44 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -2558,7 +2558,7 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	drmModeRes *resources;
 	drmModePlaneRes *plane_resources;
 	int i;
-	bool is_i915_dev;
+	bool is_i915_dev, is_intel_dev;
 
 	memset(display, 0, sizeof(igt_display_t));
 
@@ -2566,6 +2566,7 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 
 	display->drm_fd = drm_fd;
 	is_i915_dev = is_i915_device(drm_fd);
+	is_intel_dev = is_intel_device(drm_fd);
 
 	drmSetClientCap(drm_fd, DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1);
 
@@ -2607,17 +2608,47 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	for (i = 0; i < resources->count_crtcs; i++) {
 		igt_pipe_t *pipe;
 
-		if (is_i915_dev) {
-			struct drm_i915_get_pipe_from_crtc_id get_pipe;
+		/*
+		 * No GET_PIPE_FROM_CRTC_ID ioctl support for XE. Instead read
+		 * from the debugfs "i915_pipe".
+		 *
+		 * This debugfs is applicable for both i915 & XE. For i915, still
+		 * we can fallback to ioctl method to support older kernels.
+		 */
+		if (is_intel_dev) {
+			char buf[2];
+			int debugfs_fd, res;
 
-			get_pipe.pipe = 0;
-			get_pipe.crtc_id =  resources->crtcs[i];
-			do_ioctl(display->drm_fd,
-					DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID, &get_pipe);
-			pipe = &display->pipes[get_pipe.pipe];
-			pipe->pipe = get_pipe.pipe;
-		}
-		else {
+			debugfs_fd = igt_debugfs_pipe_dir(drm_fd, i, O_RDONLY);
+			igt_assert(debugfs_fd >= 0);
+
+			res = igt_debugfs_simple_read(debugfs_fd, "i915_pipe", buf, sizeof(buf));
+			close(debugfs_fd);
+
+			if (res <= 0) {
+				/* Fallback to older ioctl method. */
+				if (is_i915_dev) {
+					struct drm_i915_get_pipe_from_crtc_id get_pipe;
+
+					get_pipe.pipe = 0;
+					get_pipe.crtc_id =  resources->crtcs[i];
+
+					do_ioctl(drm_fd,
+						 DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID,
+						 &get_pipe);
+
+					pipe = &display->pipes[get_pipe.pipe];
+					pipe->pipe = get_pipe.pipe;
+				} else
+					igt_assert_f(false, "XE: Failed to read the debugfs i915_pipe.\n");
+			} else {
+				int p;
+
+				igt_assert_eq(sscanf(buf, "%d", &p), 1);
+				pipe = &display->pipes[p];
+				pipe->pipe = p;
+			}
+		} else {
 			pipe = &display->pipes[i];
 			pipe->pipe = i;
 		}
-- 
2.40.0

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

end of thread, other threads:[~2023-03-20 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-20  6:00 [igt-dev] [RFC PATCH] lib/kms: Get pipe enum from debugfs Bhanuprakash Modem
2023-03-20  6:47 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/kms: Get pipe enum from debugfs (rev3) Patchwork
2023-03-20  8:02 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-03-20 12:49 ` [igt-dev] [RFC PATCH] lib/kms: Get pipe enum from debugfs Jani Nikula
  -- strict thread matches above, loose matches on Subject: below --
2023-03-17 16:50 Bhanuprakash Modem

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