From patchwork Thu Apr 12 03:55:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foss X-Patchwork-Id: 10337819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7035603B5 for ; Thu, 12 Apr 2018 03:56:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9D24285A3 for ; Thu, 12 Apr 2018 03:56:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E394285A7; Thu, 12 Apr 2018 03:56:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AF60285A3 for ; Thu, 12 Apr 2018 03:56:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0378B6E067; Thu, 12 Apr 2018 03:56:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 066346E031 for ; Thu, 12 Apr 2018 03:56:21 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a02:8109:9280:1d42:d4f1:433b:992c:3811]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: robertfoss) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 755312794A2; Thu, 12 Apr 2018 04:56:19 +0100 (BST) From: Robert Foss To: dri-devel , John Stultz , Emil Velikov , Tomasz Figa , Stefan Schake , Chih-Wei Huang , Daniel Stone Subject: [RFC 1/1] xf86drm: Add drmHandleMatch func Date: Thu, 12 Apr 2018 05:55:54 +0200 Message-Id: <20180412035554.30874-2-robert.foss@collabora.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180412035554.30874-1-robert.foss@collabora.com> References: <20180412035554.30874-1-robert.foss@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Robert Foss , Tomeu Vizoso MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drmHandleMatch is intended to allow for userspace to filter out devices that it does not want to open. Opening specific devices using paths alone is not a reliable due to probing order. This function intends to provide a mechanism for filtering out devices that don't fit what you need using the already existing drmVersion and drmDevice structs. Most fields of drmVersion and drmDevice can be used for comparing between the target device and the actual FD that has been provided. Signed-off-by: Robert Foss --- xf86drm.h | 2 ++ xf86drmMode.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/xf86drm.h b/xf86drm.h index 7773d71a8030..7ef1e2818301 100644 --- a/xf86drm.h +++ b/xf86drm.h @@ -863,6 +863,8 @@ extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_device extern int drmDevicesEqual(drmDevicePtr a, drmDevicePtr b); +extern int drmHandleMatch(int fd, drmVersionPtr ver, drmDevicePtr dev); + extern int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle); extern int drmSyncobjDestroy(int fd, uint32_t handle); extern int drmSyncobjHandleToFD(int fd, uint32_t handle, int *obj_fd); diff --git a/xf86drmMode.c b/xf86drmMode.c index 9a15b5e78dda..e403515a94b7 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -946,6 +946,75 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx) return 0; } +#define matchCmpInt(ver, ver_fd, element) \ + if (ver->element > 0 && ver->element != ver_fd->element) \ + goto fail; + +#define matchCmpStr(ver, ver_fd, element) \ + if (ver->element != NULL && !strcmp(ver->element, ver_fd->element)) \ + goto fail; + +static int drmMatchVersion(int fd, drmVersionPtr ver) +{ + drmVersionPtr ver_fd = NULL; + + if (!ver) + goto success; + + ver_fd = drmGetVersion(fd); + if (!ver_fd) + goto fail; + + matchCmpInt(ver, ver_fd, version_major); + matchCmpInt(ver, ver_fd, version_minor); + matchCmpInt(ver, ver_fd, version_patchlevel); + + matchCmpStr(ver, ver_fd, name); + matchCmpStr(ver, ver_fd, date); + matchCmpStr(ver, ver_fd, desc); + +success: + drmFreeVersion(ver_fd); + return 1; +fail: + drmFreeVersion(ver_fd); + return 0; +} + +static int drmMatchDevice(int fd, drmDevicePtr dev) +{ + drmDevicePtr dev_fd = NULL; + + if (!dev) + goto success; + + if (drmGetDevice2(fd, 0, &dev_fd) != 0) { + goto fail; + } + + matchCmpInt(dev, dev_fd, available_nodes) + matchCmpInt(dev, dev_fd, bustype) + + drmDevicesEqual(dev, dev_fd); + +success: + drmFreeDevice(&dev_fd); + return 1; +fail: + drmFreeDevice(&dev_fd); + return 0; +} + +int drmHandleMatch(int fd, drmVersionPtr ver, drmDevicePtr dev) +{ + int ret = 1; + + ret &= drmMatchVersion(fd, ver); + ret &= drmMatchDevice(fd, dev); + + return ret; +} + int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id, uint32_t flags, void *user_data) {