From patchwork Wed Jun 19 06:03:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonyoung Shim X-Patchwork-Id: 2747191 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 5E36CC0AB1 for ; Wed, 19 Jun 2013 06:03:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47B8220202 for ; Wed, 19 Jun 2013 06:03:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 379BB20201 for ; Wed, 19 Jun 2013 06:03:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 46814E62C4 for ; Tue, 18 Jun 2013 23:03:09 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by gabe.freedesktop.org (Postfix) with ESMTP id AB7B7E6138 for ; Tue, 18 Jun 2013 23:02:57 -0700 (PDT) Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MOM009A2M3OG810@mailout1.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 19 Jun 2013 15:02:56 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.113]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 7F.67.11618.09941C15; Wed, 19 Jun 2013 15:02:56 +0900 (KST) X-AuditID: cbfee691-b7fef6d000002d62-1d-51c14990f6a9 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id EB.14.28381.09941C15; Wed, 19 Jun 2013 15:02:56 +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 <0MOM00E88M4UU4O0@mmp1.samsung.com>; Wed, 19 Jun 2013 15:02:56 +0900 (KST) From: Joonyoung Shim To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/prime: support to cache mapping Date: Wed, 19 Jun 2013 15:03:05 +0900 Message-id: <1371621785-21749-1-git-send-email-jy0922.shim@samsung.com> X-Mailer: git-send-email 1.8.1.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsWyRsSkUHeC58FAgwM/xS1OXF/EZPFhqYvF la/v2Sw6Jy5hd2Dx2DnrLrvH7I6ZrB73u48zefQ2v2MLYInisklJzcksSy3St0vgyni+4i5L wXTpiktv/zA1MG4U62Lk5JAQMJE4uOwVO4QtJnHh3nq2LkYuDiGBpYwSfb86WGGKeu/OZYVI LGKU+LPyKzOE08oksfnDXWaQKjYBPYk7244zgdgiAsoSfyeuYgSxmQX8JNqvXWMDsYWBJp2+ tRNsHYuAqsSn2Q1gvbwC7hJdZ58xQWxTkPh5+QTYGRICz9kkvj4+xQTRICDxbfIhli5GDqCE rMSmA8wQ9ZISB1fcYJnAKLiAkWEVo2hqQXJBcVJ6kalecWJucWleul5yfu4mRmBAnv73bOIO xvsHrA8xJgONm8gsJZqcDwzovJJ4Q2MzIwtTE1NjI3NLM9KElcR51VusA4UE0hNLUrNTUwtS i+KLSnNSiw8xMnFwSjUw7ite/HxN206v7njXUxsfxDyd9MNKb+thn9A1N5r/t2xuM3zPwj7H SaC2+/4akzaJHxXmokU3bt+ap974TWbjkrkH3fOzZu70URRZJ8XlclE364KEaVLf3TdMaakv p6VVzdxRyH1Zzd5fcXLdKrFKjcSFLPv/XL3XLH6pNHpLDNuqzc7PnZdcUGIpzkg01GIuKk4E AErMVIVeAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRmVeSWpSXmKPExsVy+t9jAd0JngcDDS4eELA4cX0Rk8WHpS4W V76+Z7PonLiE3YHFY+esu+wesztmsnrc7z7O5NHb/I4tgCWqgdEmIzUxJbVIITUvOT8lMy/d Vsk7ON453tTMwFDX0NLCXEkhLzE31VbJxSdA1y0zB2inkkJZYk4pUCggsbhYSd8O04TQEDdd C5jGCF3fkCC4HiMDNJCwhjHj+Yq7LAXTpSsuvf3D1MC4UayLkZNDQsBEovfuXFYIW0ziwr31 bF2MXBxCAosYJf6s/MoM4bQySWz+cJcZpIpNQE/izrbjTCC2iICyxN+JqxhBbGYBP4n2a9fY QGxhoKmnb+1kB7FZBFQlPs1uAOvlFXCX6Dr7jAlim4LEz8sn2CYwci9gZFjFKJpakFxQnJSe a6hXnJhbXJqXrpecn7uJERzuz6R2MK5ssDjEKMDBqMTD27DyQKAQa2JZcWXuIUYJDmYlEV49 h4OBQrwpiZVVqUX58UWlOanFhxiTgbZPZJYSTc4HxmJeSbyhsYmZkaWRuaGFkbE5acJK4rwH Wq0DhQTSE0tSs1NTC1KLYLYwcXBKNTDmPhVrFUywMNPIX8K2YXVE+H1jpRXHzxUufMt9TZHv Vql3S1rn63TrmtZVOSc1/vTV8076b1OrffakDPOtSMspHJmL2ud31TupGu1fzBtpK2LIlJHu 5ZiRfvDGlrkOkpyTVl6/eyxaWX7Bfr/ayY3PXz48dT3C8fY327i1sgmOl549P3h2X6wSS3FG oqEWc1FxIgAMsz6yuwIAAA== 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 The drm prime also can support it like GEM CMA supports to cache mapping. It doesn't allow multiple mappings for one attachment. Signed-off-by: Joonyoung Shim --- drivers/gpu/drm/drm_prime.c | 54 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index d92853e..ac48038 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -62,15 +62,29 @@ struct drm_prime_member { struct dma_buf *dma_buf; uint32_t handle; }; + +struct drm_prime_attachment { + struct sg_table *sgt; + enum dma_data_direction dir; +}; + static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle); static int drm_gem_map_attach(struct dma_buf *dma_buf, struct device *target_dev, struct dma_buf_attachment *attach) { + struct drm_prime_attachment *prime_attach; struct drm_gem_object *obj = dma_buf->priv; struct drm_device *dev = obj->dev; + prime_attach = kzalloc(sizeof(*prime_attach), GFP_KERNEL); + if (!prime_attach) + return -ENOMEM; + + prime_attach->dir = DMA_NONE; + attach->priv = prime_attach; + if (!dev->driver->gem_prime_pin) return 0; @@ -80,25 +94,59 @@ static int drm_gem_map_attach(struct dma_buf *dma_buf, static void drm_gem_map_detach(struct dma_buf *dma_buf, struct dma_buf_attachment *attach) { + struct drm_prime_attachment *prime_attach = attach->priv; struct drm_gem_object *obj = dma_buf->priv; struct drm_device *dev = obj->dev; + struct sg_table *sgt; if (dev->driver->gem_prime_unpin) dev->driver->gem_prime_unpin(obj); + + if (!prime_attach) + return; + + sgt = prime_attach->sgt; + + if (prime_attach->dir != DMA_NONE) + dma_unmap_sg(attach->dev, sgt->sgl, sgt->nents, + prime_attach->dir); + + sg_free_table(sgt); + kfree(sgt); + kfree(prime_attach); + attach->priv = NULL; } static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, enum dma_data_direction dir) { + struct drm_prime_attachment *prime_attach = attach->priv; struct drm_gem_object *obj = attach->dmabuf->priv; struct sg_table *sgt; + if (WARN_ON(dir == DMA_NONE || !prime_attach)) + return ERR_PTR(-EINVAL); + + /* return the cached mapping when possible */ + if (prime_attach->dir == dir) + return prime_attach->sgt; + + /* + * two mappings with different directions for the same attachment are + * not allowed + */ + if (WARN_ON(prime_attach->dir != DMA_NONE)) + return ERR_PTR(-EBUSY); + mutex_lock(&obj->dev->struct_mutex); sgt = obj->dev->driver->gem_prime_get_sg_table(obj); - if (!IS_ERR_OR_NULL(sgt)) + if (!IS_ERR_OR_NULL(sgt)) { dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir); + prime_attach->sgt = sgt; + prime_attach->dir = dir; + } mutex_unlock(&obj->dev->struct_mutex); return sgt; @@ -107,9 +155,7 @@ static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, struct sg_table *sgt, enum dma_data_direction dir) { - dma_unmap_sg(attach->dev, sgt->sgl, sgt->nents, dir); - sg_free_table(sgt); - kfree(sgt); + /* nothing to be done here */ } static void drm_gem_dmabuf_release(struct dma_buf *dma_buf)