From patchwork Fri Jan 11 12:38:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Mossberg X-Patchwork-Id: 13972 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 9283523E2E for ; Fri, 11 Jan 2013 12:38:54 +0000 (UTC) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by fiordland.canonical.com (Postfix) with ESMTP id 018D5A19B0A for ; Fri, 11 Jan 2013 12:38:53 +0000 (UTC) Received: by mail-vc0-f171.google.com with SMTP id n11so1370354vch.2 for ; Fri, 11 Jan 2013 04:38:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:date:message-id:x-mailer:in-reply-to :references:mime-version:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:content-type:content-transfer-encoding :sender:errors-to:x-gm-message-state; bh=kTgWFn7M5WoJo1I+Ug1sR2vcx4peJ5aQVxycKxLKmho=; b=CQK6LLmRAKQ5LfmEI+WL/1N5L4shVDligTm37CVZ45wzNwhhgd680vaQfpmqgZzPG4 ZkdFUuJOLdUlXy6G4JCIgqj40KDbclbndlda4tey2XRCc+aByukY+dCV8zw5lgIEZcv9 lOkzCKSsCbrv9F7ucHXq1pFEy1C7NQVo6We1+jpPpif47vGxh+NI1Or1lIFmZ2Malh9k A3rVD7DGadfzrOcDjA/421ay/SsPUMuCGRdkrxgmQm9pylliY0REflLFMU8TLuBQ31BD arfI2k1D4SExb4btX9lR1ur9JcoNVYWJdJq41arJPuGxe6vQh5suaXH2kFmcl6orwq4/ jlqA== X-Received: by 10.52.88.168 with SMTP id bh8mr80144263vdb.51.1357907933457; Fri, 11 Jan 2013 04:38:53 -0800 (PST) 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.58.145.101 with SMTP id st5csp109737veb; Fri, 11 Jan 2013 04:38:52 -0800 (PST) X-Received: by 10.204.149.86 with SMTP id s22mr36779140bkv.57.1357907931378; Fri, 11 Jan 2013 04:38:51 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id hu3si8055592bkc.122.2013.01.11.04.38.48; Fri, 11 Jan 2013 04:38:51 -0800 (PST) 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 1Ttdsg-0007cW-WB; Fri, 11 Jan 2013 12:38:43 +0000 Received: from eu1sys200aog118.obsmtp.com ([207.126.144.145]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Ttdsf-0007Xz-5R for linaro-mm-sig@lists.linaro.org; Fri, 11 Jan 2013 12:38:41 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob118.postini.com ([207.126.147.11]) with SMTP ID DSNKUPAHz5wwjGCtc3RdLr7HTjl3A0FkrOpK@postini.com; Fri, 11 Jan 2013 12:38:41 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8F60EF2; Fri, 11 Jan 2013 12:38:38 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EED0F4773; Fri, 11 Jan 2013 12:38:37 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 233FB24C2E7; Fri, 11 Jan 2013 13:38:31 +0100 (CET) Received: from steludxu2915.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server id 8.3.83.0; Fri, 11 Jan 2013 13:38:37 +0100 From: Johan Mossberg To: Date: Fri, 11 Jan 2013 13:38:13 +0100 Message-ID: <1357907893-3885-1-git-send-email-johan.mossberg@stericsson.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1355394294-4721-1-git-send-email-johan.mossberg@stericsson.com> References: <1355394294-4721-1-git-send-email-johan.mossberg@stericsson.com> MIME-Version: 1.0 Cc: linaro-mm-sig@lists.linaro.org Subject: [Linaro-mm-sig] [PATCHv3] gpu: ion: Add support for sharing buffers with dma buf kernel handles 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: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkswDT2OgzdH4ohWDd/gOpfhT/39qIw5T8JmhUmztTfEVYhczjuU8wUMn9e1OF9xVlD7XIo Currently ion can only share buffers with dma buf fd:s. Fd:s can not be used inside the kernel as they are process specific so support for sharing buffers with dma buf kernel handles is needed to support kernel only use cases. An example use case could be a GPU driver using ion that wants to share its output buffers with a 3d party display controller driver supporting dma buf. Signed-off-by: Johan Mossberg --- drivers/gpu/ion/ion.c | 26 ++++++++++++++++++++------ include/linux/ion.h | 12 ++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c index 0fc02fd..8fd61b3 100644 --- a/drivers/gpu/ion/ion.c +++ b/drivers/gpu/ion/ion.c @@ -949,19 +949,19 @@ struct dma_buf_ops dma_buf_ops = { .kunmap = ion_dma_buf_kunmap, }; -int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) +struct dma_buf *ion_share_dma_buf(struct ion_client *client, + struct ion_handle *handle) { struct ion_buffer *buffer; struct dma_buf *dmabuf; bool valid_handle; - int fd; mutex_lock(&client->lock); valid_handle = ion_handle_validate(client, handle); mutex_unlock(&client->lock); if (!valid_handle) { WARN(1, "%s: invalid handle passed to share.\n", __func__); - return -EINVAL; + return ERR_PTR(-EINVAL); } buffer = handle->buffer; @@ -969,15 +969,29 @@ int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) dmabuf = dma_buf_export(buffer, &dma_buf_ops, buffer->size, O_RDWR); if (IS_ERR(dmabuf)) { ion_buffer_put(buffer); - return PTR_ERR(dmabuf); + return dmabuf; } + + return dmabuf; +} +EXPORT_SYMBOL(ion_share_dma_buf); + +int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle) +{ + struct dma_buf *dmabuf; + int fd; + + dmabuf = ion_share_dma_buf(client, handle); + if (IS_ERR(dmabuf)) + return PTR_ERR(dmabuf); + fd = dma_buf_fd(dmabuf, O_CLOEXEC); if (fd < 0) dma_buf_put(dmabuf); return fd; } -EXPORT_SYMBOL(ion_share_dma_buf); +EXPORT_SYMBOL(ion_share_dma_buf_fd); struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) { @@ -1086,7 +1100,7 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (copy_from_user(&data, (void __user *)arg, sizeof(data))) return -EFAULT; - data.fd = ion_share_dma_buf(client, data.handle); + data.fd = ion_share_dma_buf_fd(client, data.handle); if (copy_to_user((void __user *)arg, &data, sizeof(data))) return -EFAULT; if (data.fd < 0) diff --git a/include/linux/ion.h b/include/linux/ion.h index a55d11f..e2503e9 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -214,11 +214,19 @@ void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle); void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); /** - * ion_share_dma_buf() - given an ion client, create a dma-buf fd + * ion_share_dma_buf() - share buffer as dma-buf * @client: the client * @handle: the handle */ -int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle); +struct dma_buf *ion_share_dma_buf(struct ion_client *client, + struct ion_handle *handle); + +/** + * ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd + * @client: the client + * @handle: the handle + */ +int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle); /** * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle