diff mbox

drm: Implement drmHandleEvent2()

Message ID 1429795950-8368-1-git-send-email-tjakobi@math.uni-bielefeld.de (mailing list archive)
State New, archived
Headers show

Commit Message

Tobias Jakobi April 23, 2015, 1:32 p.m. UTC
Basically this is an extended version of drmHandleEvent().

drmHandleEvent() only handles core events (like e.g. page flips),
but since kernel DRM drivers might use vendor-specific events
to signal userspace the completion of pending jobs, etc., its
desirable to provide a way to handle these without putting
vendor-specific code in the core libdrm.

To use this you provide drmHandleEvent2() with a function that
handles your non-core events (and some opaque pointer).

The signature of that function looks like this:
void vendor(int fd, struct drm_event *e, void *custom_data);

'fd' is the DRM file descriptor, 'e' the non-core event, and
'custom_data' the aforementioned opaque pointer.

This way we don't have to maintain a copy of drmHandleEvent()
in the vendor code.

Signed-off-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
---
 xf86drm.h     | 13 +++++++++++++
 xf86drmMode.c | 10 +++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

Comments

Tobias Jakobi April 23, 2015, 2:32 p.m. UTC | #1
Hello,

since it might not be entirely clear how to use this, here's how the 
Exynos libdrm would use it:
https://patchwork.kernel.org/patch/6263151/

With best wishes,
Tobias



On 2015-04-23 15:32, Tobias Jakobi wrote:
> Basically this is an extended version of drmHandleEvent().
> 
> drmHandleEvent() only handles core events (like e.g. page flips),
> but since kernel DRM drivers might use vendor-specific events
> to signal userspace the completion of pending jobs, etc., its
> desirable to provide a way to handle these without putting
> vendor-specific code in the core libdrm.
> 
> To use this you provide drmHandleEvent2() with a function that
> handles your non-core events (and some opaque pointer).
> 
> The signature of that function looks like this:
> void vendor(int fd, struct drm_event *e, void *custom_data);
> 
> 'fd' is the DRM file descriptor, 'e' the non-core event, and
> 'custom_data' the aforementioned opaque pointer.
> 
> This way we don't have to maintain a copy of drmHandleEvent()
> in the vendor code.
> 
> Signed-off-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
> ---
>  xf86drm.h     | 13 +++++++++++++
>  xf86drmMode.c | 10 +++++++++-
>  2 files changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/xf86drm.h b/xf86drm.h
> index 40c55c9..ad0ae1c 100644
> --- a/xf86drm.h
> +++ b/xf86drm.h
> @@ -741,8 +741,21 @@ typedef struct _drmEventContext {
> 
>  } drmEventContext, *drmEventContextPtr;
> 
> +typedef void (*drmEventVendorHandler)(int fd, struct drm_event *e,
> +	void *custom_data);
> +
>  extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
> 
> +/*
> + * drmHandleEvent2() is an extended variant of drmHandleEvent() which
> + * allows handling of vendor-specific/non-core events.
> + * The function pointer 'vendorhandler' is used (if non-zero) to
> + * process non-core events. The opaque pointer 'data' is passed as
> + * the 'custom_data' argument.
> + */
> +extern int drmHandleEvent2(int fd, drmEventContextPtr evctx,
> +	drmEventVendorHandler vendorhandler, void *data);
> +
>  extern char *drmGetDeviceNameFromFd(int fd);
>  extern int drmGetNodeTypeFromFd(int fd);
> 
> diff --git a/xf86drmMode.c b/xf86drmMode.c
> index 1333da4..e68e3e2 100644
> --- a/xf86drmMode.c
> +++ b/xf86drmMode.c
> @@ -857,7 +857,8 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id,
> uint32_t size,
>  	return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETGAMMA, &l);
>  }
> 
> -int drmHandleEvent(int fd, drmEventContextPtr evctx)
> +int drmHandleEvent2(int fd, drmEventContextPtr evctx,
> +			drmEventVendorHandler vendorhandler, void *data)
>  {
>  	char buffer[1024];
>  	int len, i;
> @@ -900,6 +901,8 @@ int drmHandleEvent(int fd, drmEventContextPtr 
> evctx)
>  						 U642VOID (vblank->user_data));
>  			break;
>  		default:
> +			if (vendorhandler)
> +				vendorhandler(fd, e, data);
>  			break;
>  		}
>  		i += e->length;
> @@ -908,6 +911,11 @@ int drmHandleEvent(int fd, drmEventContextPtr 
> evctx)
>  	return 0;
>  }
> 
> +int drmHandleEvent(int fd, drmEventContextPtr evctx)
> +{
> +	return drmHandleEvent2(fd, evctx, NULL, NULL);
> +}
> +
>  int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
>  		    uint32_t flags, void *user_data)
>  {
diff mbox

Patch

diff --git a/xf86drm.h b/xf86drm.h
index 40c55c9..ad0ae1c 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -741,8 +741,21 @@  typedef struct _drmEventContext {
 
 } drmEventContext, *drmEventContextPtr;
 
+typedef void (*drmEventVendorHandler)(int fd, struct drm_event *e,
+	void *custom_data);
+
 extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
 
+/*
+ * drmHandleEvent2() is an extended variant of drmHandleEvent() which
+ * allows handling of vendor-specific/non-core events.
+ * The function pointer 'vendorhandler' is used (if non-zero) to
+ * process non-core events. The opaque pointer 'data' is passed as
+ * the 'custom_data' argument.
+ */
+extern int drmHandleEvent2(int fd, drmEventContextPtr evctx,
+	drmEventVendorHandler vendorhandler, void *data);
+
 extern char *drmGetDeviceNameFromFd(int fd);
 extern int drmGetNodeTypeFromFd(int fd);
 
diff --git a/xf86drmMode.c b/xf86drmMode.c
index 1333da4..e68e3e2 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -857,7 +857,8 @@  int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETGAMMA, &l);
 }
 
-int drmHandleEvent(int fd, drmEventContextPtr evctx)
+int drmHandleEvent2(int fd, drmEventContextPtr evctx,
+			drmEventVendorHandler vendorhandler, void *data)
 {
 	char buffer[1024];
 	int len, i;
@@ -900,6 +901,8 @@  int drmHandleEvent(int fd, drmEventContextPtr evctx)
 						 U642VOID (vblank->user_data));
 			break;
 		default:
+			if (vendorhandler)
+				vendorhandler(fd, e, data);
 			break;
 		}
 		i += e->length;
@@ -908,6 +911,11 @@  int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	return 0;
 }
 
+int drmHandleEvent(int fd, drmEventContextPtr evctx)
+{
+	return drmHandleEvent2(fd, evctx, NULL, NULL);
+}
+
 int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
 		    uint32_t flags, void *user_data)
 {