From patchwork Fri Jul 27 13:40:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 10334 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9A09C23F08 for ; Fri, 27 Jul 2012 13:40:18 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 698A5A1913F for ; Fri, 27 Jul 2012 13:40:18 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so3166515ghb.11 for ; Fri, 27 Jul 2012 06:40:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:subject:to :from:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=Shgkkf67L0JcditAHau0vS5EW2qdKBTGTfvtpc406Xg=; b=GloSthsIsK3fiT6P1l7S+lIEk4TluRKFo2X6mSBP5uY1+O9ObnBHV+uiFiQXh8eZ3n TSxoQ77lrYwmrz2tRYaWsfI1af2M/ge8pTfXSA/kKuUuno4d/Fu+Vp01ogulWRbV8WPN dWjORD5JzoFlXk8g78GBI/jnbGpGzyVtmacTcobcq9sPVRluur+6+dwKy4PN0rnkfbgj RSOPjyv+xfpc3SS3AHLJrKPcZFo3brGYyLmnXt8mzNY4MQXHEDsUNfcoYy5VC4ulq+um OIRguD7zOI25wggYxu2KCYZMbaE9My8Zw+gh+AUJFXexRYljU+fHWY+HcnoZXzXkDvmD azng== Received: by 10.50.160.130 with SMTP id xk2mr1889959igb.66.1343396417929; Fri, 27 Jul 2012 06:40:17 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.43.93.3 with SMTP id bs3csp32622icc; Fri, 27 Jul 2012 06:40:17 -0700 (PDT) Received: by 10.216.66.149 with SMTP id h21mr1246459wed.151.1343396416701; Fri, 27 Jul 2012 06:40:16 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com. [91.189.90.139]) by mx.google.com with ESMTP id m10si2786832wee.96.2012.07.27.06.40.16; Fri, 27 Jul 2012 06:40:16 -0700 (PDT) Received-SPF: pass (google.com: domain of mlankhorst@lillypilly.canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mlankhorst@lillypilly.canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=mlankhorst@lillypilly.canonical.com Received: from lillypilly.canonical.com ([91.189.89.62]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Sukm8-0001nc-0P; Fri, 27 Jul 2012 13:40:16 +0000 Received: by lillypilly.canonical.com (Postfix, from userid 3489) id F201126C2514; Fri, 27 Jul 2012 13:40:15 +0000 (UTC) Subject: [RFC PATCH 3/3] dma-bikeshed-fence: Hardware dma-buf implementation of fencing To: linaro-mm-sig@lists.linaro.org, rob.clark@linaro.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org From: Maarten Lankhorst Cc: patches@linaro.org, linux-kernel@vger.kernel.org, sumit.semwal@linaro.org Date: Fri, 27 Jul 2012 15:40:13 +0200 Message-ID: <20120727134011.2036.58474.stgit@patser.local> In-Reply-To: <20120727133952.2036.61330.stgit@patser.local> References: <20120727133952.2036.61330.stgit@patser.local> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmyE7UuihR+drhKeTOa+ooRXQQOCuQfAj3kzkZYT4JQXM91bY5GjhIIAwgyjH/r2J42SU5A This type of fence can be used with hardware synchronization for simple hardware that can block execution until the condition dma_buf[offset] >= value has been met, accounting for wraparound. A software fallback still has to be provided in case the fence is used with a device that doesn't support this mechanism. It is useful to expose this for graphics cards that have an op to support this. Some cards like i915 can export those, but don't have an option to wait, so they need the software fallback. I extended the original patch by Rob Clark. Signed-off-by: Maarten Lankhorst --- drivers/base/Makefile | 2 - drivers/base/dma-bikeshed-fence.c | 44 +++++++++++++++++ include/linux/dma-bikeshed-fence.h | 92 ++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 drivers/base/dma-bikeshed-fence.c create mode 100644 include/linux/dma-bikeshed-fence.h diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 6e9f217..1e7723b 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -10,7 +10,7 @@ obj-$(CONFIG_CMA) += dma-contiguous.o obj-y += power/ obj-$(CONFIG_HAS_DMA) += dma-mapping.o obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o -obj-$(CONFIG_DMA_SHARED_BUFFER) += dma-buf.o dma-fence.o +obj-$(CONFIG_DMA_SHARED_BUFFER) += dma-buf.o dma-fence.o dma-bikeshed-fence.o obj-$(CONFIG_ISA) += isa.o obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o diff --git a/drivers/base/dma-bikeshed-fence.c b/drivers/base/dma-bikeshed-fence.c new file mode 100644 index 0000000..fa063e8 --- /dev/null +++ b/drivers/base/dma-bikeshed-fence.c @@ -0,0 +1,44 @@ +/* + * dma-fence implementation that supports hw synchronization via hw + * read/write of memory semaphore + * + * Copyright (C) 2012 Texas Instruments + * Author: Rob Clark + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include + +static int enable_signaling(struct dma_fence *fence) +{ + struct dma_bikeshed_fence *bikeshed_fence = to_bikeshed_fence(fence); + return bikeshed_fence->enable_signaling(bikeshed_fence); +} + +static void bikeshed_release(struct dma_fence *fence) +{ + struct dma_bikeshed_fence *f = to_bikeshed_fence(fence); + + if (f->release) + f->release(f); + dma_buf_put(f->sync_buf); +} + +struct dma_fence_ops dma_bikeshed_fence_ops = { + .enable_signaling = enable_signaling, + .release = bikeshed_release +}; +EXPORT_SYMBOL_GPL(dma_bikeshed_fence_ops); diff --git a/include/linux/dma-bikeshed-fence.h b/include/linux/dma-bikeshed-fence.h new file mode 100644 index 0000000..4f19801 --- /dev/null +++ b/include/linux/dma-bikeshed-fence.h @@ -0,0 +1,92 @@ +/* + * dma-fence implementation that supports hw synchronization via hw + * read/write of memory semaphore + * + * Copyright (C) 2012 Texas Instruments + * Author: Rob Clark + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef __DMA_BIKESHED_FENCE_H__ +#define __DMA_BIKESHED_FENCE_H__ + +#include +#include +#include + +struct dma_bikeshed_fence { + struct dma_fence base; + + struct dma_buf *sync_buf; + uint32_t seqno_ofs; + uint32_t seqno; + + int (*enable_signaling)(struct dma_bikeshed_fence *fence); + void (*release)(struct dma_bikeshed_fence *fence); +}; + +/* + * TODO does it make sense to be able to enable dma-fence without dma-buf, + * or visa versa? + */ +#ifdef CONFIG_DMA_SHARED_BUFFER + +extern struct dma_fence_ops dma_bikeshed_fence_ops; + +static inline bool is_bikeshed_fence(struct dma_fence *fence) +{ + return fence->ops == &dma_bikeshed_fence_ops; +} + +static inline struct dma_bikeshed_fence *to_bikeshed_fence(struct dma_fence *fence) +{ + if (WARN_ON(!is_bikeshed_fence(fence))) + return NULL; + return container_of(fence, struct dma_bikeshed_fence, base); +} + +/** + * dma_bikeshed_fence_init - Initialize a fence + * + * @fence: dma_bikeshed_fence to initialize + * @sync_buf: buffer containing the memory location to signal on + * @seqno_ofs: the offset within @sync_buf + * @seqno: the sequence # to signal on + * @priv: value of priv member + * @enable_signaling: callback which is called when some other device is + * waiting for sw notification of fence + * @release: callback called during destruction before object is freed. + */ +static inline void dma_bikeshed_fence_init(struct dma_bikeshed_fence *fence, + struct dma_buf *sync_buf, + uint32_t seqno_ofs, uint32_t seqno, void *priv, + int (*enable_signaling)(struct dma_bikeshed_fence *fence), + void (*release)(struct dma_bikeshed_fence *fence)) +{ + BUG_ON(!fence || !sync_buf || !enable_signaling); + + __dma_fence_init(&fence->base, &dma_bikeshed_fence_ops, priv); + + get_dma_buf(sync_buf); + fence->sync_buf = sync_buf; + fence->seqno_ofs = seqno_ofs; + fence->seqno = seqno; + fence->enable_signaling = enable_signaling; +} + +#else +// TODO +#endif /* CONFIG_DMA_SHARED_BUFFER */ + +#endif /* __DMA_BIKESHED_FENCE_H__ */