From patchwork Thu Dec 13 10:24:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Mossberg X-Patchwork-Id: 13523 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 B99F723FC0 for ; Thu, 13 Dec 2012 10:25:34 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id B5086A19BD1 for ; Thu, 13 Dec 2012 10:25:33 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so3722360ieb.11 for ; Thu, 13 Dec 2012 02:25:33 -0800 (PST) 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-mailer:in-reply-to:references:mime-version :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=9ckkknswr2Nsf4V1hEezTe4WANfPMyYGa8ezWy7EFL0=; b=pYCredqWK6ykJn28f4OYcPusyP7c8TT75X4zpJQixWx15b1RPKhSKSeErMiZHwlSO1 1IGuFFPnai5oHk3RNJcFXDOPFu3gu8h7oEDx9teuMIrp/Az/9Je7ggyWoXg/01QOV0Dz LaYbPO8geMxy60bkMaRwr0fROfmAa58Mtpy7YKpWTyeH0BRFPAVzs1dHkcg6yOiRoU8D sWnjzICx96H7vY+C/FlVinITyg9Ezax8MKK0xi1A0J1N3f1/IJ5Ff2u+ddzxvoMQuqwn 9s64QaSYbJU9g/Gr6goGUkqLsaovfoiAhc+QUoO79G59U1xIBvLj13VQbo24X6fC3gTd 9KJA== Received: by 10.50.36.164 with SMTP id r4mr1089372igj.57.1355394332884; Thu, 13 Dec 2012 02:25:32 -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.50.67.148 with SMTP id n20csp2150igt; Thu, 13 Dec 2012 02:25:32 -0800 (PST) Received: by 10.194.179.34 with SMTP id dd2mr7205126wjc.1.1355394331273; Thu, 13 Dec 2012 02:25:31 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id cu9si8814594wib.3.2012.12.13.02.25.28; Thu, 13 Dec 2012 02:25:31 -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 1Tj5yo-0006Yw-Cf; Thu, 13 Dec 2012 10:25:26 +0000 Received: from eu1sys200aog105.obsmtp.com ([207.126.144.119]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tj5yn-0006Yi-0y for linaro-mm-sig@lists.linaro.org; Thu, 13 Dec 2012 10:25:25 +0000 Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob105.postini.com ([207.126.147.11]) with SMTP ID DSNKUMmtE/kyz+YnVxiVwahyjTjCWEAMirmt@postini.com; Thu, 13 Dec 2012 10:25:24 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id D7286148 for ; Thu, 13 Dec 2012 10:17:08 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 47A57E91 for ; Thu, 13 Dec 2012 10:25:20 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 4781D24CB97 for ; Thu, 13 Dec 2012 11:25:14 +0100 (CET) Received: from steludxu2915.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server id 8.3.83.0; Thu, 13 Dec 2012 11:25:19 +0100 From: Johan Mossberg To: Date: Thu, 13 Dec 2012 11:24:54 +0100 Message-ID: <1355394294-4721-1-git-send-email-johan.mossberg@stericsson.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1355157897-24290-1-git-send-email-johan.mossberg@stericsson.com> References: <1355157897-24290-1-git-send-email-johan.mossberg@stericsson.com> MIME-Version: 1.0 Subject: [Linaro-mm-sig] [PATCHv2] gpu: ion: Add ion_share_dma_buf_kernel 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: ALoCoQlT65KJwZpi2CDJOhw9kXiBcGQNFGCPkgQs35Nk10OtqfvsCk3pSyQ+z2PXzqVutJZBHGCE ion_share_dma_buf_kernel enables you to share ion buffers via dma buf for kernel only use cases. Useful for example when a GPU driver using ion 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 | 22 ++++++++++++++++++---- include/linux/ion.h | 8 ++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c index 3872095..e7b0d0b 100644 --- a/drivers/gpu/ion/ion.c +++ b/drivers/gpu/ion/ion.c @@ -955,19 +955,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_kernel(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; @@ -975,8 +975,22 @@ 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_kernel); + +int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) +{ + struct dma_buf *dmabuf; + int fd; + + dmabuf = ion_share_dma_buf_kernel(client, handle); + if (IS_ERR(dmabuf)) + return PTR_ERR(dmabuf); + fd = dma_buf_fd(dmabuf, O_CLOEXEC); if (fd < 0) dma_buf_put(dmabuf); diff --git a/include/linux/ion.h b/include/linux/ion.h index a7d399c..8720e9b 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -205,6 +205,14 @@ 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_kernel() - share buffer as dma-buf + * @client: the client + * @handle: the handle + */ +struct dma_buf *ion_share_dma_buf_kernel(struct ion_client *client, + struct ion_handle *buf); + +/** * ion_share_dma_buf() - given an ion client, create a dma-buf fd * @client: the client * @handle: the handle