From patchwork Thu Oct 13 09:04:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9374581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E3A2560839 for ; Thu, 13 Oct 2016 09:04:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D39A829E6B for ; Thu, 13 Oct 2016 09:04:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C86C829E7C; Thu, 13 Oct 2016 09:04:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 82DF429E6B for ; Thu, 13 Oct 2016 09:04:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E48F76E9CE; Thu, 13 Oct 2016 09:04:24 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-lf0-x244.google.com (mail-lf0-x244.google.com [IPv6:2a00:1450:4010:c07::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1AF206E9CA for ; Thu, 13 Oct 2016 09:04:21 +0000 (UTC) Received: by mail-lf0-x244.google.com with SMTP id x79so11606697lff.2 for ; Thu, 13 Oct 2016 02:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y7+1jWiRqy7vqYt/7XviYkS5f8pjiV1b83cvCWNLUL0=; b=nJIKplVRDu9sNGKC5BYhUfefKu5V46gFaSHhigMvnYwjmQyVDJ0dpydGbgvwUGzX4E qpYkc2lRDfouIWw3KcDoQXnTykhyWXCD/vBazt6dB2osLYB9Rq/u3/FjlXvTwyTs2YP0 3xZ1dOKIvDafpMQY3tHsc1M4oVeVOUD3gUOtMss+ya6q2ayEEzTlbrgJbgO+t/t8tvaJ GOT9dFsPBfcRPHGdppFGhcvOjLD8qSq7ps7jQCGEOeVw+oeqegnZzaKvV0mNkYSnTmjy pAHkPaQsKq3y3RBpgjdMc7eBauAAFF6vk+2I9pcZLkmsgwKXOpezCe0OZgmiplVIVYIN cjtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y7+1jWiRqy7vqYt/7XviYkS5f8pjiV1b83cvCWNLUL0=; b=VCG+OYd7XQjQJjpAi/pTZH00tcdVuQDyaRV8CCuBf5mJcjxsgNc33q5cNPZg0NKgir SWr3EfF4Om7adPuCmto0AxbF19Q5ZDlh2Tbbzk9lNzi115UQ81E9ENXg0KwcH+IAEmsZ b4yIUgq1bgkzioL9O2NdLV0O4zYy1GtuXIF0O8ycN8eogKoOBIdCN4JHXXr6OSXADB1d SGhwRIxX1LdpGfHLorJFh3MrecesAarxCG+D+tXxXibINfcV+ZOIIs+vNgbthkPONWwu IAsSU0ZAb7hA5rKyi5DA2YrC/SJe1MRCbzovx1mByR42VHmbJLFaGdp+2znK6fYF8++A d6kA== X-Gm-Message-State: AA6/9RmuW8CVWi7RHYY0E6V/NCnbNOv/h+Q7YMuLp6jkJWFWsw3mg47jsiM7u9NWHL/hLQ== X-Received: by 10.28.103.70 with SMTP id b67mr1385277wmc.74.1476349459208; Thu, 13 Oct 2016 02:04:19 -0700 (PDT) Received: from localhost.localdomain ([2a02:c7d:9b6d:e300:916a:6cab:ac67:71c2]) by smtp.gmail.com with ESMTPSA id y2sm20776894wjx.20.2016.10.13.02.04.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Oct 2016 02:04:18 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Thu, 13 Oct 2016 10:04:02 +0100 Message-Id: <1476349444-7331-6-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476349444-7331-1-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1476349444-7331-1-git-send-email-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [RFC 5/7] drm/i915: Use i915_sg_create for dmabuf X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin As for the earlier ones, it simplifies the loop and enables entry colaescing. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 45 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index 97c9d68b45df..5df1dfdeec66 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -40,11 +40,13 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme enum dma_data_direction dir) { struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf); - struct sg_table *st; - struct scatterlist *src, *dst; - int ret, i; + struct drm_device *dev = obj->base.dev; + struct i915_sg_create_state *state; + struct sgt_iter sgt_iter; + struct page *page; + int ret; - ret = i915_mutex_lock_interruptible(obj->base.dev); + ret = i915_mutex_lock_interruptible(dev); if (ret) goto err; @@ -55,40 +57,33 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme i915_gem_object_pin_pages(obj); /* Copy sg so that we make an independent mapping */ - st = kmalloc(sizeof(struct sg_table), GFP_KERNEL); - if (st == NULL) { - ret = -ENOMEM; + state = i915_sg_create(obj->pages->nents); + if (IS_ERR(state)) { + ret = PTR_ERR(state); goto err_unpin; } - ret = sg_alloc_table(st, obj->pages->nents, GFP_KERNEL); - if (ret) - goto err_free; - - src = obj->pages->sgl; - dst = st->sgl; - for (i = 0; i < obj->pages->nents; i++) { - sg_set_page(dst, sg_page(src), src->length, 0); - dst = sg_next(dst); - src = sg_next(src); - } + for_each_sgt_page(page, sgt_iter, obj->pages) + i915_sg_add_page(state, page); - if (!dma_map_sg(attachment->dev, st->sgl, st->nents, dir)) { + i915_sg_complete(state); + + if (!dma_map_sg(attachment->dev, + state->st->sgl, state->st->nents, dir)) { ret =-ENOMEM; goto err_free_sg; } - mutex_unlock(&obj->base.dev->struct_mutex); - return st; + mutex_unlock(&dev->struct_mutex); + + return state->st; err_free_sg: - sg_free_table(st); -err_free: - kfree(st); + i915_sg_abort(state); err_unpin: i915_gem_object_unpin_pages(obj); err_unlock: - mutex_unlock(&obj->base.dev->struct_mutex); + mutex_unlock(&dev->struct_mutex); err: return ERR_PTR(ret); }