From patchwork Thu Oct 13 09:04:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9374573 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 BE81360839 for ; Thu, 13 Oct 2016 09:04:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADF8A29E7C for ; Thu, 13 Oct 2016 09:04:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A298D29E72; Thu, 13 Oct 2016 09:04:22 +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 2A79329E72 for ; Thu, 13 Oct 2016 09:04:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC7806E9C4; Thu, 13 Oct 2016 09:04:20 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-lf0-x243.google.com (mail-lf0-x243.google.com [IPv6:2a00:1450:4010:c07::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id C0B7B6E3E3 for ; Thu, 13 Oct 2016 09:04:18 +0000 (UTC) Received: by mail-lf0-x243.google.com with SMTP id b75so11439403lfg.3 for ; Thu, 13 Oct 2016 02:04:18 -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=JT88cyBpiuLcaQvUdWSKdEIUINotxEUxCuHKysgAmdg=; b=ywsp/Dp7gKtE2wWsHLd6guoKxxiuwB59o9I7/DGiZTIw/QH3/sHy/AHoADWygd+YA/ c0a8WZwaNU0jE0eF3ks1Yi1nUQX7XMMo0xy+AK+XLcDB8hhHCCy7ReaPeQdc1SUbfr35 NISQpXBBwtlGJnxqLA85dk9SKlU+UJGwqlI6MB/DDCIKUNNN9JBD7q69iSQSvVMyQ6Dq E9TWEQ+Z3qhcag8N4+SKd++a7bsR1Rka9SzxOIuh7NszE9GRpqvK6mGPHYQXzoNniP8U 0DGbJHa7qJfcbToSBSMm9kT6+XrRX8jUJIAb4fUIeh3mH6a04MSaY8jtTKQZv9S7LZMq HB5A== 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=JT88cyBpiuLcaQvUdWSKdEIUINotxEUxCuHKysgAmdg=; b=HWZobrjPt90rwKGsNsSivi4+LNCwrmEp5N52MD60k9bVcL0MhwOV7LCYroegZJx1S/ CKHReJ/hJJsORvbIRQ3Qb/CtXoVSi/tE4KUWt0QB+aa3sn27XE2CWEgec/jp2GpIM4eF EiOeY5GhuZoAMQ4JZKuYqHG89YXVf06MKZY+GLPLnNHY42UuU1Z9aEgBpQ71JfCAqAaF QOFmKL/BbSwLVrtuQ62akCrTLAaSrqoVgFtMrLbp/8aw/04Oof5yIplFx1kcegXJRLVv AcvpLXMyRTon3QgTvi04Vvy6xChbHN+bIyMTQTuMixQKFGbLQbcsU01sUoAIRxhUhpGa Jwnw== X-Gm-Message-State: AA6/9RnJwAslRUwS4an8bsSmfxuaEP64tRYiiYC3sl7sNkFhilk9CNqsjodvpWIID4F8iQ== X-Received: by 10.28.91.149 with SMTP id p143mr1371399wmb.20.1476349456982; Thu, 13 Oct 2016 02:04:16 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Oct 2016 02:04:16 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Thu, 13 Oct 2016 10:04:00 +0100 Message-Id: <1476349444-7331-4-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 3/7] drm/i915: Use i915_sg_create for partial views 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 Simplify the partial view creation loop by using the newly introduced helpers. It also allows the list to be coalesced when possbile. New i915_sg_add_dma helper was added to allow adding just the DMA address entries to the list. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem.c | 38 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.c | 34 ++++++++------------------------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index e226794ffc1b..641a1dbc87b8 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -4019,6 +4019,7 @@ struct i915_sg_create_state { struct i915_sg_create_state *i915_sg_create(unsigned int page_count); void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page); +void i915_sg_add_dma(struct i915_sg_create_state *state, dma_addr_t addr); struct sg_table *i915_sg_complete(struct i915_sg_create_state *state); void i915_sg_abort(struct i915_sg_create_state *state); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 1c1aa3bbde8a..05dc2af1a89e 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2268,6 +2268,8 @@ struct i915_sg_create_state *i915_sg_create(unsigned int page_count) * page which needs to be added to the sg list. * Function manages the internal state which can be read (only!) by the caller * where appropriate. + * + * MUST NOT be mixed with i915_sg_add_dma! */ void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page) { @@ -2291,6 +2293,42 @@ void i915_sg_add_page(struct i915_sg_create_state *state, struct page *page) } /** + * i915_sg_add_dma - adds a dma address to the sg list being built + * @state: state created with i915_sg_create + * @addr: dma address to add + * + * Intended to be called under the i915_sg_for_each_page iterator once for each + * page which needs to be added to the sg list. + * Function manages the internal state which can be read (only!) by the caller + * where appropriate. + * + * MUST NOT be mixed with i915_sg_add_page! + */ +void i915_sg_add_dma(struct i915_sg_create_state *state, dma_addr_t addr) +{ + struct scatterlist *sg = state->sg; + + if (!state->idx || + sg->length >= state->max_segment || + addr != state->last_pfn + PAGE_SIZE) { + if (state->idx) + sg = sg_next(sg); + state->st->nents++; + sg_set_page(sg, NULL, PAGE_SIZE, 0); + sg_dma_address(sg) = addr; + sg_dma_len(sg) = PAGE_SIZE; + } else { + sg->length += PAGE_SIZE; + if (IS_ENABLED(CONFIG_NEED_SG_DMA_LENGTH)) + sg_dma_len(sg) += PAGE_SIZE; + } + + state->last_pfn = addr; + state->sg = sg; + state->idx++; +} + +/** * i915_sg_complete - completes the sg list building * @state: state created with i915_sg_create * diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 2d846aa39ca5..f0c70e7c8daa 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -3559,41 +3559,23 @@ static struct sg_table * intel_partial_pages(const struct i915_ggtt_view *view, struct drm_i915_gem_object *obj) { - struct sg_table *st; - struct scatterlist *sg; + struct i915_sg_create_state *state; struct sg_page_iter obj_sg_iter; - int ret = -ENOMEM; - st = kmalloc(sizeof(*st), GFP_KERNEL); - if (!st) - goto err_st_alloc; - - ret = sg_alloc_table(st, view->params.partial.size, GFP_KERNEL); - if (ret) - goto err_sg_alloc; + state = i915_sg_create(view->params.partial.size); + if (IS_ERR(state)) + return ERR_CAST(state); - sg = st->sgl; - st->nents = 0; for_each_sg_page(obj->pages->sgl, &obj_sg_iter, obj->pages->nents, - view->params.partial.offset) + view->params.partial.offset) { - if (st->nents >= view->params.partial.size) + if (state->idx >= view->params.partial.size) break; - sg_set_page(sg, NULL, PAGE_SIZE, 0); - sg_dma_address(sg) = sg_page_iter_dma_address(&obj_sg_iter); - sg_dma_len(sg) = PAGE_SIZE; - - sg = sg_next(sg); - st->nents++; + i915_sg_add_dma(state, sg_page_iter_dma_address(&obj_sg_iter)); } - return st; - -err_sg_alloc: - kfree(st); -err_st_alloc: - return ERR_PTR(ret); + return i915_sg_complete(state); } static int