From patchwork Thu Jun 10 21:09:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12313949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E9E1C48BE5 for ; Thu, 10 Jun 2021 21:09:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C11D613E9 for ; Thu, 10 Jun 2021 21:09:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C11D613E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=jlekstrand.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DCFC36EDF0; Thu, 10 Jun 2021 21:09:51 +0000 (UTC) Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by gabe.freedesktop.org (Postfix) with ESMTPS id D93CE6EDF0 for ; Thu, 10 Jun 2021 21:09:48 +0000 (UTC) Received: by mail-pj1-x1036.google.com with SMTP id k5so4432515pjj.1 for ; Thu, 10 Jun 2021 14:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=07rjFAS53OMENHNy2p9Y4md9eEuMc5d3z32QsAn1VH0=; b=hKegitAhnQFI7BkhN4rPvK+RsJ7qTH1v8UfAT4+BFkqj6EmNy+0H5YegJVAZiYZBEE sn3oQAxk5tpvmLWcYQ2tQw46YKEKA3eGH7Sc8i7DY/1IK31CCUQ2N5X66zTQXTUP+Uoc SogXZAv6cl7dvfYRangfKSQhGfa+jRFynqc4LyfxzNLNkq+b0NIp4K9DWmA2l0IL/wu7 r8IvZ/gmXvukk6kxBuED2ivHRWO36dcJik3I1yz0HnOsqubfNvcn+TAG19PCf8ImbgBV nZ3bx6UF7bnsTY200eomUvoeoQ03aRHidnWAckVv8xUR2F4BGXbrQEaCf30NmJHN2AJP jxcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=07rjFAS53OMENHNy2p9Y4md9eEuMc5d3z32QsAn1VH0=; b=YTCHilFcJonm8XDaZw9sJwpBPAI9BPvWrkFtjYm4Noi6NKxh3nUD6S5RIiBzb30gVp Ehst+aaYAXA7lbYLICtDjR8PzAoKFsKqeg8H4oCH1NdIqAiiqYEE3HghsYX9AH5Fgmj3 YJ+nAxQJSiIlc5wOQZ0NtursZmJAX0Rhwf+swI7jxzeipdPOVfRv5byRCZktU1inGhfC 0rdEh5eB2/uIrTbXjA18DOYFFOmW/IUslEdApY1GNGBxLXZqvdrkAZR47yJF7x17gc1Y h+Kj5gq8kH7HFjPWzyYZzEEmJw6wcsSfgB2NmtoHh/M8CkxJ2x02U7/ZKetwuOZ4q7ii RAcA== X-Gm-Message-State: AOAM530DySGNwmp1GjxI4KOnpbhTjS4HKFluwH3ArvtF4ZOzznyDI5+I 4Yvg50qtNiE7QWME6QQvmkNV7Pjv5ULL3w== X-Google-Smtp-Source: ABdhPJxfnqTfKyzkOHS1LJAtEcWyVp+4PgnYwvworSgybNREuYlZlS9sGT4ETV9nYNBSW7Whe5vnZg== X-Received: by 2002:a17:90a:6404:: with SMTP id g4mr5292379pjj.155.1623359388052; Thu, 10 Jun 2021 14:09:48 -0700 (PDT) Received: from omlet.lan (jfdmzpr03-ext.jf.intel.com. [134.134.139.72]) by smtp.gmail.com with ESMTPSA id o16sm3145288pfu.75.2021.06.10.14.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 14:09:47 -0700 (PDT) From: Jason Ekstrand To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/6] dma-buf: Document DMA_BUF_IOCTL_SYNC (v2) Date: Thu, 10 Jun 2021 16:09:22 -0500 Message-Id: <20210610210925.642582-4-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610210925.642582-1-jason@jlekstrand.net> References: <20210610210925.642582-1-jason@jlekstrand.net> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , Jason Ekstrand Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This adds a new "DMA Buffer ioctls" section to the dma-buf docs and adds documentation for DMA_BUF_IOCTL_SYNC. v2 (Daniel Vetter): - Fix a couple typos - Add commentary about synchronization with other devices - Use item list format for describing flags Signed-off-by: Jason Ekstrand Cc: Daniel Vetter Cc: Christian König Cc: Sumit Semwal Acked-by: Christian König --- Documentation/driver-api/dma-buf.rst | 8 +++++ include/uapi/linux/dma-buf.h | 46 +++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Documentation/driver-api/dma-buf.rst b/Documentation/driver-api/dma-buf.rst index 7f21425d9435a..0d4c13ec1a800 100644 --- a/Documentation/driver-api/dma-buf.rst +++ b/Documentation/driver-api/dma-buf.rst @@ -88,6 +88,9 @@ consider though: - The DMA buffer FD is also pollable, see `Implicit Fence Poll Support`_ below for details. +- The DMA buffer FD also supports a few dma-buf-specific ioctls, see + `DMA Buffer ioctls`_ below for details. + Basic Operation and Device DMA Access ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -106,6 +109,11 @@ Implicit Fence Poll Support .. kernel-doc:: drivers/dma-buf/dma-buf.c :doc: implicit fence polling +DMA Buffer ioctls +~~~~~~~~~~~~~~~~~ + +.. kernel-doc:: include/uapi/linux/dma-buf.h + Kernel Functions and Structures Reference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h index 7f30393b92c3b..1c131002fe1ee 100644 --- a/include/uapi/linux/dma-buf.h +++ b/include/uapi/linux/dma-buf.h @@ -22,8 +22,52 @@ #include -/* begin/end dma-buf functions used for userspace mmap. */ +/** + * struct dma_buf_sync - Synchronize with CPU access. + * + * When a DMA buffer is accessed from the CPU via mmap, it is not always + * possible to guarantee coherency between the CPU-visible map and underlying + * memory. To manage coherency, DMA_BUF_IOCTL_SYNC must be used to bracket + * any CPU access to give the kernel the chance to shuffle memory around if + * needed. + * + * Prior to accessing the map, the client must call DMA_BUF_IOCTL_SYNC + * with DMA_BUF_SYNC_START and the appropriate read/write flags. Once the + * access is complete, the client should call DMA_BUF_IOCTL_SYNC with + * DMA_BUF_SYNC_END and the same read/write flags. + * + * The synchronization provided via DMA_BUF_IOCTL_SYNC only provides cache + * coherency. It does not prevent other processes or devices from + * accessing the memory at the same time. If synchronization with a GPU or + * other device driver is required, it is the client's responsibility to + * wait for buffer to be ready for reading or writing. If the driver or + * API with which the client is interacting uses implicit synchronization, + * this can be done via poll() on the DMA buffer file descriptor. If the + * driver or API requires explicit synchronization, the client may have to + * wait on a sync_file or other synchronization primitive outside the scope + * of the DMA buffer API. + */ struct dma_buf_sync { + /** + * @flags: Set of access flags + * + * DMA_BUF_SYNC_START: + * Indicates the start of a map access session. + * + * DMA_BUF_SYNC_END: + * Indicates the end of a map access session. + * + * DMA_BUF_SYNC_READ: + * Indicates that the mapped DMA buffer will be read by the + * client via the CPU map. + * + * DMA_BUF_SYNC_WRITE: + * Indicates that the mapped DMA buffer will be written by the + * client via the CPU map. + * + * DMA_BUF_SYNC_RW: + * An alias for DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE. + */ __u64 flags; };