From patchwork Thu May 17 10:31:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Airlie X-Patchwork-Id: 8712 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 162DC23E49 for ; Thu, 17 May 2012 10:35:53 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id A8D1CA18B0F for ; Thu, 17 May 2012 10:35:52 +0000 (UTC) Received: by ggnf1 with SMTP id f1so1976794ggn.11 for ; Thu, 17 May 2012 03:35:52 -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:from:to :date:message-id:x-scanned-by:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=HMOjFm6tjJ1rYqeMe0fE876+N9gg+pt3lcvoWC/IimY=; b=isG75KUe7Au0KU/9H9qTy33VON99tiphNwB7ZkqMEawcxzKWLfh3vHxdjPIEOqqSKM k4A7MWlEMlal7SGxN4R7YKehlEobccCR81G2caZtrrHsJM11IB3FOYzZ/GyDxn+7FDQo KuYFUADm15P6EnoXhH+q1rMvPeLqgLbFH0gz/wAr1e+64DYMR/m3BuzNjl943YCVItyb vIyidywWSf2fZApTy/9DNE/S4a8ArcrVGCttRCtubODoJpnlkZAaz+YAqYKp8Pitvb8p kaoJyKJwVaMNA4hffOS12laopX5ulJfkzmx6sg5F7eWtom1pw4yZ/mGXEmdR8sX20sSU orNg== Received: by 10.50.195.234 with SMTP id ih10mr4842230igc.0.1337250952026; Thu, 17 May 2012 03:35:52 -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.231.35.72 with SMTP id o8csp18619ibd; Thu, 17 May 2012 03:35:50 -0700 (PDT) Received: by 10.180.78.233 with SMTP id e9mr17146017wix.5.1337250950205; Thu, 17 May 2012 03:35:50 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id r56si6741535weq.107.2012.05.17.03.35.48; Thu, 17 May 2012 03:35:50 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SUy3c-0007Ox-5X; Thu, 17 May 2012 10:35:44 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SUy3a-0007Or-EI for linaro-mm-sig@lists.linaro.org; Thu, 17 May 2012 10:35:42 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4HAZeef001558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 May 2012 06:35:40 -0400 Received: from optimus.redhat.com (vpn1-5-207.ams2.redhat.com [10.36.5.207]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q4HAZcc1001741; Thu, 17 May 2012 06:35:39 -0400 From: Dave Airlie To: linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org Date: Thu, 17 May 2012 11:31:50 +0100 Message-Id: <1337250710-31113-1-git-send-email-airlied@gmail.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Subject: [Linaro-mm-sig] [PATCH] dma-buf: add vmap interface (v2) X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQmEoYtewD8Bic5nejNqB00SwrkryE11JTuhUIQkXuYRDJw+hxH14M3s/poTF3diUMIQb6VN From: Dave Airlie The main requirement I have for this interface is for scanning out using the USB gpu devices. Since these devices have to read the framebuffer on updates and linearly compress it, using kmaps is a major overhead for every update. v2: fix warn issues pointed out by Sylwester Nawrocki. Signed-off-by: Dave Airlie --- drivers/base/dma-buf.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 14 ++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 07cbbc6..750f92c 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -406,3 +406,37 @@ void dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long page_num, dmabuf->ops->kunmap(dmabuf, page_num, vaddr); } EXPORT_SYMBOL_GPL(dma_buf_kunmap); + +/** + * dma_buf_vmap - Create virtual mapping for the buffer object into kernel address space. The same restrictions as for vmap and friends apply. + * @dma_buf: [in] buffer to vmap + * + * This call may fail due to lack of virtual mapping address space. + * These calls are optional in drivers. The intended use for them + * is for mapping objects linear in kernel space for high use objects. + * Please attempt to use kmap/kunmap before thinking about these interfaces. + */ +void *dma_buf_vmap(struct dma_buf *dmabuf) +{ + if (WARN_ON(!dmabuf)) + return NULL; + + if (dmabuf->ops->vmap) + return dmabuf->ops->vmap(dmabuf); + return NULL; +} +EXPORT_SYMBOL(dma_buf_vmap); + +/** + * dma_buf_vunmap - Unmap a vmap obtained by dma_buf_vmap. + * @dma_buf: [in] buffer to vmap + */ +void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) +{ + if (WARN_ON(!dmabuf)) + return; + + if (dmabuf->ops->vunmap) + dmabuf->ops->vunmap(dmabuf, vaddr); +} +EXPORT_SYMBOL(dma_buf_vunmap); diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 3efbfc2..b92b6de 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -92,6 +92,9 @@ struct dma_buf_ops { void (*kunmap_atomic)(struct dma_buf *, unsigned long, void *); void *(*kmap)(struct dma_buf *, unsigned long); void (*kunmap)(struct dma_buf *, unsigned long, void *); + + void *(*vmap)(struct dma_buf *); + void (*vunmap)(struct dma_buf *, void *vaddr); }; /** @@ -167,6 +170,9 @@ void *dma_buf_kmap_atomic(struct dma_buf *, unsigned long); void dma_buf_kunmap_atomic(struct dma_buf *, unsigned long, void *); void *dma_buf_kmap(struct dma_buf *, unsigned long); void dma_buf_kunmap(struct dma_buf *, unsigned long, void *); + +void *dma_buf_vmap(struct dma_buf *); +void dma_buf_vunmap(struct dma_buf *, void *vaddr); #else static inline struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, @@ -248,6 +254,14 @@ static inline void dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long pnum, void *vaddr) { } + +static inline void *dma_buf_vmap(struct dma_buf *) +{ +} + +static inline void dma_buf_vunmap(struct dma_buf *, void *vaddr); +{ +} #endif /* CONFIG_DMA_SHARED_BUFFER */ #endif /* __DMA_BUF_H__ */