From patchwork Fri Jun 28 05:24:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonyoung Shim X-Patchwork-Id: 2797131 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B100FBF4A1 for ; Fri, 28 Jun 2013 05:27:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D0AD02012B for ; Fri, 28 Jun 2013 05:27:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E000D20125 for ; Fri, 28 Jun 2013 05:27:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D6E91E5F4B for ; Thu, 27 Jun 2013 22:27:32 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 8AFE2E5C94 for ; Thu, 27 Jun 2013 22:24:55 -0700 (PDT) Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MP3005138DEBAQ0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Fri, 28 Jun 2013 14:24:54 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.116]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 81.15.08825.62E1DC15; Fri, 28 Jun 2013 14:24:54 +0900 (KST) X-AuditID: cbfee68e-b7f276d000002279-bc-51cd1e2654bd Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 08.A5.28381.62E1DC15; Fri, 28 Jun 2013 14:24:54 +0900 (KST) Received: from localhost.localdomain ([10.89.53.198]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MP300FJD8DHYZD0@mmp1.samsung.com>; Fri, 28 Jun 2013 14:24:53 +0900 (KST) From: Joonyoung Shim To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/3] drm/cma: add low-level hook functions to use prime helpers Date: Fri, 28 Jun 2013 14:24:54 +0900 Message-id: <1372397095-23934-2-git-send-email-jy0922.shim@samsung.com> X-Mailer: git-send-email 1.8.1.2 In-reply-to: <1372397095-23934-1-git-send-email-jy0922.shim@samsung.com> References: <1372397095-23934-1-git-send-email-jy0922.shim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsWyRsSkRFdN7mygwdlLfBYnri9isrjy9T2b RefEJewOzB47Z91l95jdMZPV4373caYA5igum5TUnMyy1CJ9uwSujKmrogomy1SsXXeMpYHx p3gXIweHhICJxP2LBV2MnECmmMSFe+vZuhi5OIQEljJKXN6zlxUiYSJx+P4hFojEIkaJqf27 mCGcViaJd3+bmUGq2AT0JO5sO84EYosIKEv8nbiKEcRmFrCQ+DZzEguILSwQIjH1/hewOIuA qkTbrn6wel4Bd4lZ0zqYIbYpSPy8fIINxOYU8JDY9eUO2BVCQDWPd19mBFksIfCeTWLL2hVQ gwQkvk0GOQ/kHVmJTQeg5khKHFxxg2UCo/ACRoZVjKKpBckFxUnpRUZ6xYm5xaV56XrJ+bmb GIGhevrfs74djDcPWB9iTAYaN5FZSjQ5HxjqeSXxhsZmRhamJqbGRuaWZqQJK4nzqrVYBwoJ pCeWpGanphakFsUXleakFh9iZOLglGpgTEx0Pb03VNTn43HuSR+kb9dISYT6T1u1K/H+7zq+ 4g1xfWKnbfkTL6csOeI25emZR3t9mWUPiwtJP3sk8ji97v59B+u3P7v6J7ywvcahbK35LSxS QPpBnvr2npL+PHU5/qJ5fcELdi8Iu2wswezYPHOnI/fxLYaedw5YV3l98jJN6FG9c3upEktx RqKhFnNRcSIAGuAFKGsCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRmVeSWpSXmKPExsVy+t9jAV01ubOBBl/OsVucuL6IyeLK1/ds Fp0Tl7A7MHvsnHWX3WN2x0xWj/vdx5kCmKMaGG0yUhNTUosUUvOS81My89JtlbyD453jTc0M DHUNLS3MlRTyEnNTbZVcfAJ03TJzgFYpKZQl5pQChQISi4uV9O0wTQgNcdO1gGmM0PUNCYLr MTJAAwlrGDOmrooqmCxTsXbdMZYGxp/iXYycHBICJhKH7x9igbDFJC7cW8/WxcjFISSwiFFi av8uZginlUni3d9mZpAqNgE9iTvbjjOB2CICyhJ/J65iBLGZBSwkvs2cBDZJWCBEYur9L2Bx FgFVibZd/WD1vALuErOmdTBDbFOQ+Hn5BBuIzSngIbHryx1WEFsIqObx7suMExh5FzAyrGIU TS1ILihOSs811CtOzC0uzUvXS87P3cQIjoVnUjsYVzZYHGIU4GBU4uFtTDwTKMSaWFZcmXuI UYKDWUmE984CoBBvSmJlVWpRfnxRaU5q8SHGZKCrJjJLiSbnA+M0ryTe0NjEzMjSyNzQwsjY nDRhJXHeA63WgUIC6YklqdmpqQWpRTBbmDg4pRoY60UV/M5q3jvN+tjt53elhtwHl9OEHmpO T/TYYLs9aVbocYlp+2NO5bL6cJRwz9CUuGDqdXn7ov9yFy6q5dySufB0frC0vDZXyA3PYJUU OdFXV7qOv9o7J0OlYfbG/ccZ0g68dRZbajKp8bFxw9uPu8X7VvrPFv9z3sngmoX/k5MfxOsb DSdcVmIpzkg01GIuKk4EAL47u7rJAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: laurent.pinchart@ideasonboard.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using the dma_buf functionality for GEM CMA, we can use prime helpers if we can provide low-level hook functions for GEM CMA. Signed-off-by: Joonyoung Shim --- drivers/gpu/drm/drm_gem_cma_helper.c | 79 ++++++++++++++++++++++++++++++++++++ include/drm/drm_gem_cma_helper.h | 9 ++++ 2 files changed, 88 insertions(+) diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index ce06397..83a45e5 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -602,3 +602,82 @@ error_gem_free: return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(drm_gem_cma_dmabuf_import); + +/* low-level interface prime helpers */ +struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj) +{ + struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj); + struct sg_table *sgt; + int ret; + + sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) + return NULL; + + ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr, + cma_obj->paddr, obj->size); + if (ret < 0) + goto out; + + return sgt; + +out: + kfree(sgt); + return NULL; +} +EXPORT_SYMBOL_GPL(drm_gem_cma_prime_get_sg_table); + +struct drm_gem_object * +drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size, + struct sg_table *sgt) +{ + struct drm_gem_cma_object *cma_obj; + + if (sgt->nents != 1) + return ERR_PTR(-EINVAL); + + /* Create a CMA GEM buffer. */ + cma_obj = __drm_gem_cma_create(dev, size); + if (IS_ERR(cma_obj)) + return ERR_PTR(PTR_ERR(cma_obj)); + + cma_obj->paddr = sg_dma_address(sgt->sgl); + cma_obj->sgt = sgt; + + DRM_DEBUG_PRIME("dma_addr = 0x%x, size = %zu\n", cma_obj->paddr, size); + + return &cma_obj->base; +} +EXPORT_SYMBOL_GPL(drm_gem_cma_prime_import_sg_table); + +int drm_gem_cma_prime_mmap(struct drm_gem_object *obj, + struct vm_area_struct *vma) +{ + struct drm_gem_cma_object *cma_obj; + struct drm_device *dev = obj->dev; + int ret; + + mutex_lock(&dev->struct_mutex); + ret = drm_gem_mmap_obj(obj, obj->size, vma); + mutex_unlock(&dev->struct_mutex); + if (ret < 0) + return ret; + + cma_obj = to_drm_gem_cma_obj(obj); + return drm_gem_cma_mmap_obj(cma_obj, vma); +} +EXPORT_SYMBOL_GPL(drm_gem_cma_prime_mmap); + +void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj) +{ + struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj); + + return cma_obj->vaddr; +} +EXPORT_SYMBOL_GPL(drm_gem_cma_prime_vmap); + +void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr) +{ + /* Nothing to do */ +} +EXPORT_SYMBOL_GPL(drm_gem_cma_prime_vunmap); diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index 6e17251..9d39d2a 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -54,4 +54,13 @@ struct dma_buf *drm_gem_cma_dmabuf_export(struct drm_device *drm_dev, struct drm_gem_object *drm_gem_cma_dmabuf_import(struct drm_device *drm_dev, struct dma_buf *dma_buf); +struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj); +struct drm_gem_object * +drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size, + struct sg_table *sgt); +int drm_gem_cma_prime_mmap(struct drm_gem_object *obj, + struct vm_area_struct *vma); +void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj); +void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr); + #endif /* __DRM_GEM_CMA_HELPER_H__ */