From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751400AbcBAHwM (ORCPT ); Mon, 1 Feb 2016 02:52:12 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:59549 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750883AbcBAHwI (ORCPT ); Mon, 1 Feb 2016 02:52:08 -0500 X-AuditID: cbfee68d-f79646d000001355-21-56af0ea6c965 Date: Mon, 01 Feb 2016 13:29:16 +0530 From: Rohit To: Rohit kumar Cc: gregkh@linuxfoundation.org, arve@android.com, riandrews@android.com, labbott@redhat.com, dan.carpenter@oracle.com, gioh.kim@lge.com, sumit.semwal@linaro.org, mitchelh@codeaurora.org, paul.gortmaker@windriver.com, linux@rasmusvillemoes.dk, shawn.lin@rock-chips.com, sriram@marirs.net.in, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, pintu.k@samsung.com, vishnu.ps@samsung.com, sreenathd@samsung.com, pintu_agarwal@yahoo.com, me.rohit@live.com, cpgs@samsung.com Subject: Re: [PATCHv3 1/1] staging/ion: Add support to get ion handle from dma buf Message-id: <20160201132916.0d822f60@rohitk-ubuntu.sisodomain.com> In-reply-to: <1452571306-1470-1-git-send-email-rohit.kr@samsung.com> References: <1451998982-15654-1-git-send-email-rohit.kr@samsung.com> <1452571306-1470-1-git-send-email-rohit.kr@samsung.com> Organization: Samsung X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.10; i686-pc-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRjm2zk7m9Lyc2p+SRmOjJTSvPZFklGGByIJimH9SJcenKhTNpWC EtMEU5yZhjC120hMzcm0mXfdAiFNzFvhZUNMLS9ZzXubNbcC/z3v+1ze58fLJfjVbDduvCSV kUpEiQLKnqx1Drx7vHKvSnhCV3YYL5s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8WUvruMDqIe23ZvY/W4 3NfL5HFv32EWj663V5g87lzbw+axf+4ado+OWw2sHl8e/mH0+Pj0FovHha5sj/f7rrJ5/J21 n8Wjb8sqRo/Pm+Q81m/ZyuQxa9ZhpgCBqAZGm4zUxJTUIoXUvOT8lMy8dFsl7+B453hTMwND XUNLC3MlhbzE3FRbJRefAF23zBxgCCgplCXmlAKFAhKLi5X07TBNCA1x07WAaYzQ9Q0Jgusx MkADCWsYM1qecxRs16x4c+U2UwPjLsUuRk4OCQETidmtf1ghbDGJC/fWs3UxcnEICSxllNhw /y4zhNPEJHFv93oWkCoWAVWJ38dnMYLYbAJKEv9fzWUDsUUE1CQa10wE62YWeMUs0fuhmx0k ISwQInHp5xmwIl4BJ4lfi/4yg9icAi4Sf379BYsLCdRJ3P96CWwBv4CoxOGF25khTrKRWL1z HTNEr6DEj8n3wGqYBbQkNm9rYoWw5SU2r3nLPIFRcBaSsllIymYhKVvAyLyKUSK1ILmgOCk9 1zAvtVyvODG3uDQvXS85P3cTIzjRPZPawXhwl/shRgEORiUeXs6YdWFCrIllxZW5hxglOJiV RHj3fgUK8aYkVlalFuXHF5XmpBYfYjQFhs5EZinR5HxgEs4riTc0NjE3NTa1NLEwMbNUEud9 /B+oSSA9sSQ1OzW1ILUIpo+Jg1OqgVEzLP/oU3W3Van3RPJf1v7burlh7cpFKjULt4i+ZKjZ zeexepL/cc2mzQq/2eXrfVfL7Lg05dy+hH3TL7b/5NO4zHAl+l3WriM5VQrnJJae396wTVev QmCzXc6zBZdM7jTMfVUYd9bn85I/P7WffOP6x6MfbTuNtewwV15Jpo+FmtShplT24MdKLMUZ iYZazEXFiQDmiP0sigMAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kindly review the patch. Patchv2 had refcount issue which is fixed here. On Tue, 12 Jan 2016 09:31:46 +0530 Rohit kumar wrote: > Currently we can only import dma buf fd's to get ion_handle. > Adding support to import dma buf handles to support kernel > specific use cases. > > An example use case is in linux platforms such as Tizen, in which > DRM-GEM is used for buffer management for graphics. It has gem_handle > corresponding to a buffer and uses gem_name for sharing the buffer > with other processes. However,it also uses dma_buf fd for 3d > operations. For wayland, there are multiple calls for gem_handle to > dma_buf fd conversion. So, we store dma_buf associated with buffer. > But, there is no api for getting ion_handle from dma_buf. This patch > exposes api to retrieve the ion handle from dma_buf for similar use > cases. With this patch, we can integrate ION within DRM-GEM for > buffer management and dma_buf sharing. > > Signed-off-by: Rohit kumar > --- > v2: Updated commit message with use case explanation, as suggested by > Laura Abbott > v3: Fixed dmabuf refcount issue in ion_import_dma_buf. dma_buf_put() > was being called without dma_buf_get(), so moving it to > ion_import_dma_buf_fd(). > > drivers/staging/android/ion/ion.c | 26 ++++++++++++++++++-------- > drivers/staging/android/ion/ion.h | 20 ++++++++++++++++---- > 2 files changed, 34 insertions(+), 12 deletions(-) > > diff --git a/drivers/staging/android/ion/ion.c > b/drivers/staging/android/ion/ion.c index e237e9f..7e86e18 100644 > --- a/drivers/staging/android/ion/ion.c > +++ b/drivers/staging/android/ion/ion.c > @@ -1151,22 +1151,18 @@ int ion_share_dma_buf_fd(struct ion_client > *client, struct ion_handle *handle) } > EXPORT_SYMBOL(ion_share_dma_buf_fd); > > -struct ion_handle *ion_import_dma_buf(struct ion_client *client, int > fd) +struct ion_handle *ion_import_dma_buf(struct ion_client *client, > + struct dma_buf *dmabuf) > { > - struct dma_buf *dmabuf; > struct ion_buffer *buffer; > struct ion_handle *handle; > int ret; > > - dmabuf = dma_buf_get(fd); > - if (IS_ERR(dmabuf)) > - return ERR_CAST(dmabuf); > /* if this memory came from ion */ > > if (dmabuf->ops != &dma_buf_ops) { > pr_err("%s: can not import dmabuf from another > exporter\n", __func__); > - dma_buf_put(dmabuf); > return ERR_PTR(-EINVAL); > } > buffer = dmabuf->priv; > @@ -1194,11 +1190,25 @@ struct ion_handle *ion_import_dma_buf(struct > ion_client *client, int fd) } > > end: > - dma_buf_put(dmabuf); > return handle; > } > EXPORT_SYMBOL(ion_import_dma_buf); > > +struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, > int fd) +{ > + struct dma_buf *dmabuf; > + struct ion_handle *handle; > + > + dmabuf = dma_buf_get(fd); > + if (IS_ERR(dmabuf)) > + return ERR_CAST(dmabuf); > + > + handle = ion_import_dma_buf(client, dmabuf); > + dma_buf_put(dmabuf); > + return handle; > +} > +EXPORT_SYMBOL(ion_import_dma_buf_fd); > + > static int ion_sync_for_device(struct ion_client *client, int fd) > { > struct dma_buf *dmabuf; > @@ -1306,7 +1316,7 @@ static long ion_ioctl(struct file *filp, > unsigned int cmd, unsigned long arg) { > struct ion_handle *handle; > > - handle = ion_import_dma_buf(client, data.fd.fd); > + handle = ion_import_dma_buf_fd(client, data.fd.fd); > if (IS_ERR(handle)) > ret = PTR_ERR(handle); > else > diff --git a/drivers/staging/android/ion/ion.h > b/drivers/staging/android/ion/ion.h index b860c5f..a1331fc 100644 > --- a/drivers/staging/android/ion/ion.h > +++ b/drivers/staging/android/ion/ion.h > @@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct > ion_client *client, 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 > + * ion_import_dma_buf() - get ion_handle from dma-buf > + * @client: the client > + * @dmabuf: the dma-buf > + * > + * Get the ion_buffer associated with the dma-buf and return the > ion_handle. > + * If no ion_handle exists for this buffer, return newly created > ion_handle. > + * If dma-buf from another exporter is passed, return > ERR_PTR(-EINVAL) > + */ > +struct ion_handle *ion_import_dma_buf(struct ion_client *client, > + struct dma_buf *dmabuf); > + > +/** > + * ion_import_dma_buf_fd() - given a dma-buf fd from the ion > exporter get handle > * @client: the client > * @fd: the dma-buf fd > * > - * Given an dma-buf fd that was allocated through ion via > ion_share_dma_buf, > - * import that fd and return a handle representing it. If a dma-buf > from > + * Given an dma-buf fd that was allocated through ion via > ion_share_dma_buf_fd, > + * import that fd and return a handle representing it. If a dma-buf > from > * another exporter is passed in this function will return > ERR_PTR(-EINVAL) */ > -struct ion_handle *ion_import_dma_buf(struct ion_client *client, int > fd); +struct ion_handle *ion_import_dma_buf_fd(struct ion_client > *client, int fd); > #endif /* _LINUX_ION_H */