From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761301AbcALDzY (ORCPT ); Mon, 11 Jan 2016 22:55:24 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:54962 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761240AbcALDzV (ORCPT ); Mon, 11 Jan 2016 22:55:21 -0500 X-AuditID: cbfee68d-f79646d000001355-0d-569479270f2d From: Rohit kumar To: 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, rohit.kr@samsung.com, vishnu.ps@samsung.com Cc: sreenathd@samsung.com, pintu_agarwal@yahoo.com, me.rohit@live.com, cpgs@samsung.com Subject: [PATCHv3 1/1] staging/ion: Add support to get ion handle from dma buf Date: Tue, 12 Jan 2016 09:31:46 +0530 Message-id: <1452571306-1470-1-git-send-email-rohit.kr@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1451998982-15654-1-git-send-email-rohit.kr@samsung.com> References: <1451998982-15654-1-git-send-email-rohit.kr@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0hTYRjHfc85O9tM4TBdvS3SEtKSvF96LbWggvdLIUSWQdmaBxXnHJuK fjBEC2vm8JbS8BYW3psNFdOlc0pFN0RNy1veUsobokwLL+00+vZ7/s/l/8DzCEjRECURxCuS WZVCKnej7alG58AML4/04kjfypkQtLrznUY/zSfQ4m4phYwf//DRfNYGQNnVehrVGbcINNhR RqNZXQWNRibPoqbKNhoNv35LIu1mLx9Zlsf4aNGwA9BC9n0Kjc/peSh3NptC5X3rNHo/sc5H xdoJcE6M2z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PgK5bZg4wBJQUyhJzSoFCAYnFxUr6dpgmhIa46VrANEbo+oYEwfUY GaCBhDWMGQu+XWIvWKxWMe//NdYGxj3yXYycHBICJhLPl+9ihrDFJC7cW8/WxcjFISQwi1Hi 8JFzrBBOE5PEjx1/mECq2AQ0JA4c+sIEkhARWMksseHjN3aQBLNApMTDzs9go4QF/CSmP58F ZrMIqEr8v9nOCGLzCjhLLD1yAsjmAFqnIDFnkg1ImFPAVeLdm0fMIGEhAReJZys5JzDyLmBk WMUokVqQXFCclJ5rmJdarlecmFtcmpeul5yfu4kRnD6eSe1gPLjL/RCjAAejEg/vQc4pYUKs iWXFlbmHGCU4mJVEeJ2CgEK8KYmVValF+fFFpTmpxYcYTYHOmsgsJZqcD0xteSXxhsYm5qbG ppYmFiZmlkrivLWXIsOEBNITS1KzU1MLUotg+pg4OKUaGKc+PBR4Uk8u+lzwvvVpXz8eU0vb Vxr1mv+nimb+r5/6LmqK5+RTVeWvFM9l0m6fy3VVYe+Udysl445ySO3WMJ22//rV/AhzxaTl Z37w+lbPu/bU3l+0jqsg1embqGpgo+Zns3mv1Hqn6l+K+PSNP2DVtX7lTSL1ae9Ts07s2tnK wmH4+wpvkxJLcUaioRZzUXEiAEho7yo1AwAA 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 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 */ -- 1.7.9.5