From patchwork Mon Oct 31 13:44:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 9405481 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 6391B60234 for ; Mon, 31 Oct 2016 13:44:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BC6E28E11 for ; Mon, 31 Oct 2016 13:44:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EF31292A2; Mon, 31 Oct 2016 13:44:16 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 D2AFB28E11 for ; Mon, 31 Oct 2016 13:44:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B13B46E304; Mon, 31 Oct 2016 13:44:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0C6D26E308 for ; Mon, 31 Oct 2016 13:44:13 +0000 (UTC) Received: by mail-qt0-x242.google.com with SMTP id m48so842537qta.2 for ; Mon, 31 Oct 2016 06:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=W01zOFz2zZcDvMq2TMxT4QybjRSCxBYqif0OYh8obHY=; b=Sfeygn7pZROl1BoNkXnYjwVsWyclCG9TjWq7P4+R7cupl4FVO1eAeezxo5tqUJYya6 JrNiF2A/vlOTOBa0kn6sWtvOFfXV3L7vlDymDtqnyopec1IIrHlcsCx7ycs9EvsTI1ek aQrC+8V0RpKntPcw7448OOp4q7aV9wY3sAoZKRilpAY/vj+fcvrb2jht56letNlC49Nw xpQ9KU/2COx7nk4vpcQ2DT1bTwUEV0Hi4oRTduHCXRaVjeL7YFId9VNJyn/UyqE1hK2f iNcQlODvBz7avRmIEOtm739K0MjYOuG9K5cBWzM4V5uqkaIbtVtg6310neZzw/IsgU2e lRcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=W01zOFz2zZcDvMq2TMxT4QybjRSCxBYqif0OYh8obHY=; b=EhTJJ4xTaSyufq90vdn7KPoV54VitYFXhUEaLw24eo6ItkXDDpPPwxgWeLMtsf3ZCC 4KE2djxv3oixogjLraoxS2AeiVCb0F2CEeRuxGK/G4g74q5VcgF7SGFj9oO95ZRB3yLe fYfJhLadZksA7vkKqDcrE2whN68GVreWfMGiwexZ7C/v8oHimqi5l0jAuTjuYsdzm4Ic JV7OApJFugHonSdDFP3gZeQw4a72fmQKHKkJeUEKUQi5qxZENk8gVIYUbbygMIysRt3A mw+FHHo8aLuzIM1T9tR71N8j+1qBJWUq8a2vujCmS/rV9cu0uvdNX0O1E92RHAcIsm00 HNyg== X-Gm-Message-State: ABUngvcvGBifLKksKNjreQ2pbSqrWpS0Ikwa33oh9bOrvZDSOw5UEOZwMrC8uq/JarZk/g== X-Received: by 10.200.51.38 with SMTP id t35mr7788986qta.124.1477921452117; Mon, 31 Oct 2016 06:44:12 -0700 (PDT) Received: from localhost (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id j127sm11027688qkf.19.2016.10.31.06.44.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 06:44:11 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm] add libsync.h helper Date: Mon, 31 Oct 2016 09:44:07 -0400 Message-Id: <1477921447-18532-1-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 2.7.4 Cc: Robert Foss , Emil Velikov , Rob Clark 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-Virus-Scanned: ClamAV using ClamSMTP From: Rob Clark Rather than cut/pasting these couple ioctl wrappers everywhere, just stuff them as static-inline into a header. Signed-off-by: Rob Clark --- This is probably mostly used from mesa, but some drivers, test apps, etc may also want to use it from libdrm. Makefile.sources | 1 + libsync.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 libsync.h diff --git a/Makefile.sources b/Makefile.sources index a57036a..10aa1d0 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -13,6 +13,7 @@ LIBDRM_FILES := \ util_math.h LIBDRM_H_FILES := \ + libsync.h \ xf86drm.h \ xf86drmMode.h diff --git a/libsync.h b/libsync.h new file mode 100644 index 0000000..fc23b7f --- /dev/null +++ b/libsync.h @@ -0,0 +1,74 @@ +/* + * sync abstraction + * Copyright 2015-2016 Collabora Ltd. + * + * Based on the implementation from the Android Open Source Project, + * + * Copyright 2012 Google, Inc + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _LIBSYNC_H +#define _LIBSYNC_H + +#include +#include +#include +#include + +// todo prob should just #include ? +struct sync_merge_data { + char name[32]; + int32_t fd2; + int32_t fence; + uint32_t flags; + uint32_t pad; +}; +#define SYNC_IOC_MAGIC '>' +#define SYNC_IOC_MERGE _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data) + + + +static inline int sync_wait(int fd, int timeout) +{ + struct pollfd fds; + + fds.fd = fd; + fds.events = POLLIN | POLLERR; + return poll(&fds, 1, timeout); +} + +static inline int sync_merge(const char *name, int fd1, int fd2) +{ + struct sync_merge_data data = {}; + int err; + + data.fd2 = fd2; + strncpy(data.name, name, sizeof(data.name) - 1); + data.name[sizeof(data.name) - 1] = '\0'; + + err = ioctl(fd1, SYNC_IOC_MERGE, &data); + if (err < 0) + return err; + + return data.fence; +} + +#endif