From patchwork Tue Sep 22 15:54:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Jakobi X-Patchwork-Id: 7240251 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 558599F44C for ; Tue, 22 Sep 2015 15:54:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5DB2420840 for ; Tue, 22 Sep 2015 15:54:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 351A120835 for ; Tue, 22 Sep 2015 15:54:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 906846EAB6; Tue, 22 Sep 2015 08:54:06 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.math.uni-bielefeld.de (smtp.math.uni-bielefeld.de [129.70.45.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id 76CC36EAB6 for ; Tue, 22 Sep 2015 08:54:05 -0700 (PDT) Received: from chidori.entropy (unknown [5.147.63.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client did not present a certificate) by smtp.math.uni-bielefeld.de (Postfix) with ESMTPSA id 56EDC61149; Tue, 22 Sep 2015 17:54:03 +0200 (CEST) From: Tobias Jakobi To: linux-samsung-soc@vger.kernel.org Subject: [PATCH 01/13] drm: Implement drmHandleEvent2() Date: Tue, 22 Sep 2015 17:54:50 +0200 Message-Id: <1442937302-8211-2-git-send-email-tjakobi@math.uni-bielefeld.de> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1442937302-8211-1-git-send-email-tjakobi@math.uni-bielefeld.de> References: <1442937302-8211-1-git-send-email-tjakobi@math.uni-bielefeld.de> Cc: emil.l.velikov@gmail.com, dri-devel@lists.freedesktop.org, Tobias Jakobi , gustavo.padovan@collabora.co.uk X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. The signature of that function looks like this: void vendor(int fd, struct drm_event *e, void *ctx); 'fd' is the DRM file descriptor, 'e' the non-core event and 'ctx' the event context (casted to void). This way we don't have to maintain a copy of drmHandleEvent() in the vendor code. v2: Remove the opaque pointer, since this can be better handled with a container approach. Signed-off-by: Tobias Jakobi --- xf86drm.h | 21 +++++++++++++++++++++ xf86drmMode.c | 10 +++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/xf86drm.h b/xf86drm.h index 481d882..1e474a3 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -750,8 +750,29 @@ typedef struct _drmEventContext { } drmEventContext, *drmEventContextPtr; +typedef void (*drmEventVendorHandler)(int fd, struct drm_event *e, void *ctx); + 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. Users of have to prepare a container struct + * in the following way: + * + * struct vendor_event_context { + * drmEventContext base; + * int vendor_specific_data[num]; + * }; + * + * And then call: + * struct vendor_event_context ctx = {0}; + * drmHandleEvent2(fd, &ctx.base, handler); + */ +extern int drmHandleEvent2(int fd, drmEventContextPtr evctx, + drmEventVendorHandler vendorhandler); + extern char *drmGetDeviceNameFromFd(int fd); extern int drmGetNodeTypeFromFd(int fd); diff --git a/xf86drmMode.c b/xf86drmMode.c index ab6b519..89698da 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -867,7 +867,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) { char buffer[1024]; int len, i; @@ -910,6 +911,8 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx) U642VOID (vblank->user_data)); break; default: + if (vendorhandler) + vendorhandler(fd, e, evctx); break; } i += e->length; @@ -918,6 +921,11 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx) return 0; } +int drmHandleEvent(int fd, drmEventContextPtr evctx) +{ + return drmHandleEvent2(fd, evctx, NULL); +} + int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id, uint32_t flags, void *user_data) {