From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751875AbcAEM5P (ORCPT ); Tue, 5 Jan 2016 07:57:15 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:60850 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751434AbcAEM5M (ORCPT ); Tue, 5 Jan 2016 07:57:12 -0500 X-AuditID: cbfee690-f79646d000001316-37-568bbda65103 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: [PATCH] staging/ion: Add support to get ion handle from dma buf Date: Tue, 05 Jan 2016 18:33:02 +0530 Message-id: <1451998982-15654-1-git-send-email-rohit.kr@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAAzWSbUhTYRiGe885OztKwsm0XqeGriQTtPx+QzN/RL31qwgG9qVLD2q6OTYV gwpzFDppLDNXa9MsCj9ZDFuSU+fsA0xKman4iVmGmIhNbVqTXKN/93Nf98P943kY0reDEjC5 0kJOLhXnC2lvqsUv7nrk885K0aEhcxBack3TaN52AC1sailk6d/go7myFYCUT400arQ4CWR/ rafRrK6WRiNTR1FrnZlGw53vSaT+1ctHa4vjfLRgcgH0XXmLQhNfjTxUOaukkOGNg0Z9kw4+ qlZPglR/bO4w87BdfYfAU129FFYtDhF4YthC425DCx+Xj5Xy8MrMH4CXv41ReECVh5e6PtPY peumsLqtCWCHaQ82tr0ks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gbDGJC/fWs3UxcnEICcxilNh2 +xczhNPEJPF34XWwKjYBDYkDh74wgSREBFYyS2z4+I0dJMEsECnxsPMzM4gtLOAhsb9rDVCc g4NFQFXi4NpckDCvgIvE758HGEHCEgIKEnMm2Uxg5F7AyLCKUSK1ILmgOCk91zAvtVyvODG3 uDQvXS85P3cTIzgZPJPawXhwl/shRgEORiUeXo6XXWFCrIllxZW5hxglOJiVRHidl3SHCfGm JFZWpRblxxeV5qQWH2I0BVo/kVlKNDkfmKjySuINjU3MTY1NLU0sTMwslcR5ay9FhgkJpCeW pGanphakFsH0MXFwSjUwRuyfxCCsG8M08cnWGvfP99mKheKmnVJ2cq9b+HSORfEyF8H5UcuP HTf+4b9o55NFcx7F/ytz5f1wzmpVF9M80QO60+35lrh8/rG3dWlJtuxWsxsb3xWqFv29llL1 aF9u6bmdsyNiwp8yWm/+ImCwbYdvoID8/fMHXovqzj7R+eW4/f1w1pq8w0osxRmJhlrMRcWJ ABZ/YvgcAwAA 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. Signed-off-by: Rohit kumar --- Currently, ION is the memory manager for graphics in android. However, in other linux platforms such as Tizen, 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. drivers/staging/android/ion/ion.c | 21 +++++++++++++++------ drivers/staging/android/ion/ion.h | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index e237e9f..5509716 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -1151,16 +1151,13 @@ 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) { @@ -1199,6 +1196,18 @@ end: } EXPORT_SYMBOL(ion_import_dma_buf); +struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd) +{ + struct dma_buf *dmabuf; + + dmabuf = dma_buf_get(fd); + if (IS_ERR(dmabuf)) + return ERR_CAST(dmabuf); + + return ion_import_dma_buf(client, dmabuf); +} +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 +1315,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