From patchwork Mon Dec 10 16:44:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Mossberg X-Patchwork-Id: 13458 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 8272223E1F for ; Mon, 10 Dec 2012 16:45:26 +0000 (UTC) Received: from mail-ia0-f170.google.com (mail-ia0-f170.google.com [209.85.210.170]) by fiordland.canonical.com (Postfix) with ESMTP id 0F0A4A1982D for ; Mon, 10 Dec 2012 16:45:25 +0000 (UTC) Received: by mail-ia0-f170.google.com with SMTP id i1so4563283iaa.29 for ; Mon, 10 Dec 2012 08:45:25 -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: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=elj87829nwjrNxb0unkQbtITSDob1EOcGWrTgROjzF0=; b=loUWNjK0A16V8ctjbNX3Y+p1BNwGnDW6VU60H9LUZOHBFEcdLrUeHzfQ0ISrOViZh+ JzGaPtFX6mU7eee+nRWQT8m7a9ss67Gm9BHo0pWxGCfpJ7BT80FmvyHl/b0GltLNwaoI LemHHv3MYxgCW17zxgRMXUgo/AhxOTdkqA7Osai7HBxdAUsL3dmcnFOFljFu5romf+AN g2Ozw/8DqG3lE2u9zwzyR8JZ5IzjcUXZvfxpz31hmauLfl+jupiRS2hyWZvTNa3l+fzs dxgMjgn1SK+WiF5foGFJk8hM7wUNfqV73nWVE6s0015VWfz6nP+PtzYvXznU0lYxOmr2 x7qg== Received: by 10.50.152.137 with SMTP id uy9mr7014988igb.62.1355157925226; Mon, 10 Dec 2012 08:45:25 -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 n20csp78242igt; Mon, 10 Dec 2012 08:45:24 -0800 (PST) Received: by 10.14.206.197 with SMTP id l45mr51466237eeo.17.1355157924139; Mon, 10 Dec 2012 08:45:24 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id i42si48415275eem.124.2012.12.10.08.45.21; Mon, 10 Dec 2012 08:45:24 -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 1Ti6Tj-0003S1-7x; Mon, 10 Dec 2012 16:45:15 +0000 Received: from eu1sys200aog113.obsmtp.com ([207.126.144.135]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Ti6Th-0003Ra-O1 for linaro-mm-sig@lists.linaro.org; Mon, 10 Dec 2012 16:45:14 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob113.postini.com ([207.126.147.11]) with SMTP ID DSNKUMYRmWYaw9AsZkN0CGIxEiWHw7tKfE1b@postini.com; Mon, 10 Dec 2012 16:45:13 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 E501A1B7 for ; Mon, 10 Dec 2012 16:45:12 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9A88951A8 for ; Mon, 10 Dec 2012 16:45:12 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id E72C5A8065 for ; Mon, 10 Dec 2012 17:45:05 +0100 (CET) Received: from steludxu2915.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server id 8.3.83.0; Mon, 10 Dec 2012 17:45:11 +0100 From: Johan Mossberg To: Date: Mon, 10 Dec 2012 17:44:57 +0100 Message-ID: <1355157897-24290-1-git-send-email-johan.mossberg@stericsson.com> X-Mailer: git-send-email 1.8.0 MIME-Version: 1.0 Subject: [Linaro-mm-sig] [PATCH] 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: ALoCoQkzeg30rIihFOohjxAxH+iLoTfUElds/2G6cTh8cWdynpsr/Hg5XrMQRJsIphGzxQxrGpA8 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 | 18 ++++++++++++++++-- include/linux/ion.h | 8 ++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c index 748ff7d..31bb5e1 100644 --- a/drivers/gpu/ion/ion.c +++ b/drivers/gpu/ion/ion.c @@ -991,12 +991,12 @@ 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); @@ -1013,6 +1013,20 @@ int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) ion_buffer_put(buffer); return PTR_ERR(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 3ccc75a..cfb831d 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -210,6 +210,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