From patchwork Fri Feb 17 15:07:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9580073 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 915286042F for ; Fri, 17 Feb 2017 15:07:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81643283EE for ; Fri, 17 Feb 2017 15:07:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7556B286FE; Fri, 17 Feb 2017 15:07:27 +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 DE929283EE for ; Fri, 17 Feb 2017 15:07:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3445D6E037; Fri, 17 Feb 2017 15:07:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id B66696E037 for ; Fri, 17 Feb 2017 15:07:24 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id c4so5587659wrd.1 for ; Fri, 17 Feb 2017 07:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=nquJXgKnALdQ+rrKCMg8c3BbWiQ8Z/GF0wtWWztvFts=; b=XmtKeA1YBPF5m1OqFCG9AeQU3n5J/D+F/NgCGw9N0L0UcOm6zH3zZzKayIhBNHptCj X2KlFABTQzSFqdUEyHWQ0clVnwf7eonx/XEgqTwxKK/2CUcssCPZQkNZc6JGqTakfwCG JbER60VqbJ+M1sBDhHk/CQZIKkKGiHzysm/H2I5GRdV78uG4SUUQd4r2nnvgDD4eKZoj TFwttFPXWuUpATscdDpWzSgM+OuXlSWlhtGIK9ccTWE/xpow2elf7u2OvqLTqfOg4v30 8g0V9JcMgC528kLyTI4TvFanvngJQL8Zic6r/MfVgd5GS+rbv91e8N4j0lEQVj1RLn9C YqIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=nquJXgKnALdQ+rrKCMg8c3BbWiQ8Z/GF0wtWWztvFts=; b=A3HftpfIWIKEObOyAcNa27wgmnczQVlw8SQO9ozOumH9ueeLilQ51Z6AuQ7WuS1VK0 yKxCLLQQPbGVAxhD3ZurIjT7FwbZBhlGi+dF+zSpHjEzLW0B9DiagurZdicwxz2hY/Aj 4qfCOkDMDP8Ou/fZko0aEMInxrqIO31HKqUzFHbMpVUVIWaabSzXbWk1lavErf+7IpHH Swu1ZJG+IJOypbc0nOebwAUvkrVL4EYA1X4ItketR2m3zZ/Ac7QOwzgQ14kmCtgaZBl7 qD9xVU2eGfPnKmL8QyDyVIZvCFjpuzj+ohsxmT3aYoEUkR6k2CzcpXEm5DJ7Wpcd+GAQ q+DA== X-Gm-Message-State: AMke39n+M5lxiz15PYKDvobCto7qym9NAhW4R1rSa3d62KHEVRGhTgf6Xb65ZZc20/V0wA== X-Received: by 10.223.144.176 with SMTP id i45mr1741466wri.51.1487344041726; Fri, 17 Feb 2017 07:07:21 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id d29sm2023172wmi.19.2017.02.17.07.07.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 07:07:21 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 17 Feb 2017 15:07:19 +0000 Message-Id: <20170217150719.29555-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 Subject: [Intel-gfx] [PATCH] drm/i915: Remove temporary allocation of dma addresses when rotating 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 The object already stores (computed on the fly) the index to dma address so use it instead of reallocating a large temporary array every time we bind a rotated framebuffer. Signed-off-by: Chris Wilson Cc: Matthew Auld Cc: Joonas Lahtinen Cc: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_gem_gtt.c | 77 ++++++++++++------------------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 47a38272f54c..848dbb926fd1 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -3043,27 +3043,32 @@ void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv) } static struct scatterlist * -rotate_pages(const dma_addr_t *in, unsigned int offset, - unsigned int width, unsigned int height, - unsigned int stride, +rotate_pages(struct drm_i915_gem_object *obj, + const struct intel_rotation_plane_info *p, struct sg_table *st, struct scatterlist *sg) { unsigned int column, row; - unsigned int src_idx; - for (column = 0; column < width; column++) { - src_idx = stride * (height - 1) + column; - for (row = 0; row < height; row++) { - st->nents++; + for (column = 0; column < p->width; column++) { + unsigned long src_idx = + p->stride * (p->height - 1) + column + p->offset; + for (row = 0; row < p->height; row++) { + struct scatterlist *src; + unsigned int n; + + src = i915_gem_object_get_sg(obj, src_idx, &n); + src_idx -= p->stride; + /* We don't need the pages, but need to initialize * the entries so the sg list can be happily traversed. * The only thing we need are DMA addresses. */ sg_set_page(sg, NULL, PAGE_SIZE, 0); - sg_dma_address(sg) = in[offset + src_idx]; + sg_dma_address(sg) = sg_dma_address(src) + n*PAGE_SIZE; sg_dma_len(sg) = PAGE_SIZE; - sg = sg_next(sg); - src_idx -= stride; + sg = __sg_next(sg); + + st->nents++; } } @@ -3074,62 +3079,30 @@ static noinline struct sg_table * intel_rotate_pages(struct intel_rotation_info *rot_info, struct drm_i915_gem_object *obj) { - const unsigned long n_pages = obj->base.size / PAGE_SIZE; - unsigned int size = intel_rotation_info_size(rot_info); - struct sgt_iter sgt_iter; - dma_addr_t dma_addr; - unsigned long i; - dma_addr_t *page_addr_list; - struct sg_table *st; + const unsigned int size = intel_rotation_info_size(rot_info); struct scatterlist *sg; + struct sg_table *st; + unsigned long i; int ret = -ENOMEM; - /* Allocate a temporary list of source pages for random access. */ - page_addr_list = drm_malloc_gfp(n_pages, - sizeof(dma_addr_t), - GFP_TEMPORARY); - if (!page_addr_list) - return ERR_PTR(ret); - - /* Allocate target SG list. */ st = kmalloc(sizeof(*st), GFP_KERNEL); if (!st) - goto err_st_alloc; + goto err; ret = sg_alloc_table(st, size, GFP_KERNEL); if (ret) - goto err_sg_alloc; - - /* Populate source page list from the object. */ - i = 0; - for_each_sgt_dma(dma_addr, sgt_iter, obj->mm.pages) - page_addr_list[i++] = dma_addr; + goto err; - GEM_BUG_ON(i != n_pages); st->nents = 0; sg = st->sgl; - - for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) { - sg = rotate_pages(page_addr_list, rot_info->plane[i].offset, - rot_info->plane[i].width, rot_info->plane[i].height, - rot_info->plane[i].stride, st, sg); - } - - DRM_DEBUG_KMS("Created rotated page mapping for object size %zu (%ux%u tiles, %u pages)\n", - obj->base.size, rot_info->plane[0].width, rot_info->plane[0].height, size); - - drm_free_large(page_addr_list); + for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) + sg = rotate_pages(obj, &rot_info->plane[i], st, sg); + GEM_BUG_ON(st->nents != size); return st; -err_sg_alloc: +err: kfree(st); -err_st_alloc: - drm_free_large(page_addr_list); - - DRM_DEBUG_KMS("Failed to create rotated mapping for object size %zu! (%ux%u tiles, %u pages)\n", - obj->base.size, rot_info->plane[0].width, rot_info->plane[0].height, size); - return ERR_PTR(ret); }