[Intel-gfx] [PATCH] Add new drm_intel_get_pipe_from_crtc_id function.

Carl Worth cworth at cworth.org
Wed Apr 29 23:43:55 CEST 2009


This wraps the new DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID ioctl,
allowing applications to discover the pipe number corresponding
to a given CRTC ID. This is necessary for doing pipe-specific
operations such as waiting for vblank on a given CRTC.
---

 I intentionally made this silent on any error from the ioctl so that
 the code will still run against old kernels, (with best-effort
 behavior of always returning pipe 0). This will be better than the
 old behavior of the driver which was getting a random value for the
 pipe.

 But should I be trying harder to catch any real errors from new
 kernels? I suppose the kernel will already log the error at least.

 libdrm/intel/intel_bufmgr.h     |    2 ++
 libdrm/intel/intel_bufmgr_gem.c |   23 +++++++++++++++++++++++
 shared-core/i915_drm.h          |   10 ++++++++++
 3 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/libdrm/intel/intel_bufmgr.h b/libdrm/intel/intel_bufmgr.h
index 542dc06..e228c8a 100644
--- a/libdrm/intel/intel_bufmgr.h
+++ b/libdrm/intel/intel_bufmgr.h
@@ -118,6 +118,8 @@ int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo);
 int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo);
 void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable);
 
+int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id);
+
 /* drm_intel_bufmgr_fake.c */
 drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd,
 					     unsigned long low_offset,
diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c
index e48778c..dda352e 100644
--- a/libdrm/intel/intel_bufmgr_gem.c
+++ b/libdrm/intel/intel_bufmgr_gem.c
@@ -805,6 +805,29 @@ drm_intel_gem_bo_subdata (drm_intel_bo *bo, unsigned long offset,
     return 0;
 }
 
+int
+drm_intel_get_pipe_from_crtc_id (drm_intel_bufmgr *bufmgr, int crtc_id)
+{
+    drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bufmgr;
+    struct drm_i915_get_pipe_from_crtc_id get_pipe_from_crtc_id;
+    int ret;
+
+    get_pipe_from_crtc_id.crtc_id = crtc_id;
+    ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID,
+		 &get_pipe_from_crtc_id);
+    if (ret != 0) {
+	/* We're intentionally silent here so that there is no
+	 * complaint when simply running with an older kernel that
+	 * doesn't have the GET_PIPE_FROM_CRTC_ID ioctly. In that
+	 * case, we just punt and try to sync on pipe 0, which is
+	 * hopefully the right pipe in some cases at least.
+	 */
+	return 0;
+    }
+
+    return get_pipe_from_crtc_id.pipe;
+}
+
 static int
 drm_intel_gem_bo_get_subdata (drm_intel_bo *bo, unsigned long offset,
 			      unsigned long size, void *data)
diff --git a/shared-core/i915_drm.h b/shared-core/i915_drm.h
index 5456e91..c8fec5f 100644
--- a/shared-core/i915_drm.h
+++ b/shared-core/i915_drm.h
@@ -205,6 +205,7 @@ typedef struct drm_i915_sarea {
 #define DRM_I915_GEM_GET_TILING	0x22
 #define DRM_I915_GEM_GET_APERTURE 0x23
 #define DRM_I915_GEM_MMAP_GTT	0x24
+#define DRM_I915_GET_PIPE_FROM_CRTC_ID	0x25
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -242,6 +243,7 @@ typedef struct drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_SET_TILING	DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_SET_TILING, struct drm_i915_gem_set_tiling)
 #define DRM_IOCTL_I915_GEM_GET_TILING	DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling)
 #define DRM_IOCTL_I915_GEM_GET_APERTURE	DRM_IOR  (DRM_COMMAND_BASE + DRM_I915_GEM_GET_APERTURE, struct drm_i915_gem_get_aperture)
+#define DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GET_PIPE_FROM_CRTC_ID, struct drm_i915_get_pipe_from_crtc_id)
 
 /* Asynchronous page flipping:
  */
@@ -769,4 +771,12 @@ struct drm_i915_gem_get_aperture {
 	uint64_t aper_available_size;
 };
 
+struct drm_i915_get_pipe_from_crtc_id {
+	/** ID of CRTC being requested **/
+	uint32_t crtc_id;
+
+	/** pipe of requested CRTC **/
+	uint32_t pipe;
+};
+
 #endif				/* _I915_DRM_H_ */
-- 
1.6.2.1




More information about the Intel-gfx mailing list