From patchwork Wed Jun 12 13:16:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonyoung Shim X-Patchwork-Id: 2710081 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 67F7AC1459 for ; Wed, 12 Jun 2013 13:18:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87DB020212 for ; Wed, 12 Jun 2013 13:18:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 41E4420209 for ; Wed, 12 Jun 2013 13:18:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D237E6437 for ; Wed, 12 Jun 2013 06:18:32 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTP id A4C2AE643F for ; Wed, 12 Jun 2013 06:16:16 -0700 (PDT) Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MOA00E8J7IP6VD0@mailout2.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 12 Jun 2013 22:16:14 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.115]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 06.31.11618.E9478B15; Wed, 12 Jun 2013 22:16:14 +0900 (KST) X-AuditID: cbfee691-b7fef6d000002d62-a9-51b8749eb277 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id D5.00.21068.E9478B15; Wed, 12 Jun 2013 22:16:14 +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 <0MOA00DQL7J1H550@mmp1.samsung.com>; Wed, 12 Jun 2013 22:16:14 +0900 (KST) From: Joonyoung Shim To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm/cma: add low-level hook functions to use prime helpers Date: Wed, 12 Jun 2013 22:16:18 +0900 Message-id: <1371042979-14633-2-git-send-email-jy0922.shim@samsung.com> X-Mailer: git-send-email 1.8.1.2 In-reply-to: <1371042979-14633-1-git-send-email-jy0922.shim@samsung.com> References: <1371042979-14633-1-git-send-email-jy0922.shim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsWyRsSkWHdeyY5Ag4erNCx6z51ksrjy9T2b RefEJewOzB6zO2ayemz/9oDV4373caYA5igum5TUnMyy1CJ9uwSujI896QXLpCvuPHjN2sA4 U7yLkZNDQsBE4u+S5YwQtpjEhXvr2boYuTiEBJYySnxf3sEEU9Q97TYriC0ksIhR4t41JYii ViaJL9u7wbrZBPQk7mw7DtYgIqAs8XfiKrA4s4C5xP4rEDXCAv4SnY0X2EBsFgFViR2/e9lB bF4Bd4mTiz5DLVOQ+Hn5BFgNp4CHxKKLc6EWu0sc/DGVHWSxhMBrNomHu76zQwwSkPg2+RBL FyMHUEJWYtMBZog5khIHV9xgmcAovICRYRWjaGpBckFxUnqRqV5xYm5xaV66XnJ+7iZGYKie /vds4g7G+wesDzEmA42byCwlmpwPDPW8knhDYzMjC1MTU2Mjc0sz0oSVxHnVW6wDhQTSE0tS s1NTC1KL4otKc1KLDzEycXBKNTCKh4hdcmje6WYyL+3IL12+J20s/yffSn59rUjiiZHs2U9X 6h+x3U6Xvt8gfXPB8eatwgfPyRu+3ctzLvRWSf+XU7Okg99UBiRXv/1TZKgRxrx9mpxxc+uG E5Xz7govnX7R8NitO68+JiofW1hqPLVHKr18hpXeit3nts2YnXy9nrGnaqlOyc2jSizFGYmG WsxFxYkA7Ww3t2sCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRmVeSWpSXmKPExsVy+t9jAd15JTsCDY60KFr0njvJZHHl63s2 i86JS9gdmD1md8xk9dj+7QGrx/3u40wBzFENjDYZqYkpqUUKqXnJ+SmZeem2St7B8c7xpmYG hrqGlhbmSgp5ibmptkouPgG6bpk5QKuUFMoSc0qBQgGJxcVK+naYJoSGuOlawDRG6PqGBMH1 GBmggYQ1jBkfe9ILlklX3HnwmrWBcaZ4FyMnh4SAiUT3tNusELaYxIV769lAbCGBRYwS964p dTFyAdmtTBJftnczgiTYBPQk7mw7zgRiiwgoS/yduAoszixgLrH/CkSNsIC/RGfjBbBBLAKq Ejt+97KD2LwC7hInF31mglimIPHz8gmwGk4BD4lFF+eyQix2lzj4Yyr7BEbeBYwMqxhFUwuS C4qT0nON9IoTc4tL89L1kvNzNzGCI+GZ9A7GVQ0WhxgFOBiVeHgPJO0IFGJNLCuuzD3EKMHB rCTCmxgPFOJNSaysSi3Kjy8qzUktPsSYDHTVRGYp0eR8YJTmlcQbGpuYGVkamRtaGBmbkyas JM57sNU6UEggPbEkNTs1tSC1CGYLEwenVANjWrcFwzOJTQrvbFsmeHYu4mVb8M3SnylUS5G5 QGiN7n7VKYbMkhdP1Mh2OF79yCr0dVPsB9Vt/Y+2xxh7azqHf125q7lFeq7XczepeTsXfXh1 RmWumbqujv/iuR/Obtu5eQ+32aTLDdaaJrX/GqtPb97wnvfO3XdPdp56UevnsWKzTvebqRsS lFiKMxINtZiLihMBjgV2t8gCAAA= 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=-4.4 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 | 76 ++++++++++++++++++++++++++++++++++++ include/drm/drm_gem_cma_helper.h | 9 +++++ 2 files changed, 85 insertions(+) diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 9efabce..41a4635 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -599,3 +599,79 @@ 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; + int ret; + + ret = drm_gem_mmap_obj(obj, obj->size, vma); + 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__ */