From patchwork Thu Dec 22 10:56:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484685 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 85B99601D3 for ; Thu, 22 Dec 2016 10:57:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80B552818E for ; Thu, 22 Dec 2016 10:57:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7596E28324; Thu, 22 Dec 2016 10:57:03 +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 1C3782818E for ; Thu, 22 Dec 2016 10:57:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43F4F6F214; Thu, 22 Dec 2016 10:56:58 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wj0-x241.google.com (mail-wj0-x241.google.com [IPv6:2a00:1450:400c:c01::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 301446E261 for ; Thu, 22 Dec 2016 10:56:36 +0000 (UTC) Received: by mail-wj0-x241.google.com with SMTP id j10so35718212wjb.3 for ; Thu, 22 Dec 2016 02:56:36 -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:in-reply-to:references; bh=NVKLOpMyeEg6sOo8KX3I3zO3KoDr0bOEXhFLf3zQg3E=; b=keaNoJRXrO40PGqOmPuPUUdmW1rVx4G2AA8ADLdjSk9NcLcqfKDRSBXKuVC5OtM5pm FOAQ+wvTZJmtnT3L0vUXJ0SpMsIlFZrEXgWYMUkW57tMyXdSHWi9gqQoBWZIkSiYSnvS Yli45IdXmbKyg0trQUTTBIPxYC5Et2SJXucqYoORftqAvwrmPfDlw1U59aKjRfol//ij 339t8lvO4n76dZpmZvy90TBkPbApGWxseaBclUSZdQt9B7OvkozXEh9zNTAGRJ/mnBFJ +8XHra8EIu2zZeYduRF7fHxt1GAVU/s1dEf7nCyOtOLdB0L4gQdB+gj1s/UqSXOsgIa0 HrNw== 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 :in-reply-to:references; bh=NVKLOpMyeEg6sOo8KX3I3zO3KoDr0bOEXhFLf3zQg3E=; b=KNCsR/cnVmxkYcgZAkaRYDnM3qR+RV+ab1VVpE8q/QZ5/HOTozxp0helI953AUgmLl X7Uy03aTtNRmRDXpP+BS69sBBvebEOvOXPkG1qMCcp3Zrm4UoqI0bLEZQ+mA+mMMWmM6 cw8bDeUgvkW3Dfk1V19mbdG9I3rzMcQaO+70K1RrlUavckiwfDQQjR4SEiIfB9gdf8vs R7fJzfMpv4CDBw9qIQKPZnewaqwPKrgZRcmJNSBtOCm/YNVeQbKfGbpNJ6cC+Wkc9ZMf 9BXRzB3NbIQgehyb4XNEqmfplSrU4jLACO93QdGqk0pxUvKIq2ooI2ShNjAMBVgXPrdk 4Pkg== X-Gm-Message-State: AIkVDXK+mgWEsUmKIL3t7E0I+rRXIpc5aIJFeStt4sL9FVgfEF12HQcqy1gL7JAxB3LcQg== X-Received: by 10.194.86.67 with SMTP id n3mr9534096wjz.105.1482404193856; Thu, 22 Dec 2016 02:56:33 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id u78sm31553040wma.11.2016.12.22.02.56.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 02:56:33 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 22 Dec 2016 10:56:25 +0000 Message-Id: <20161222105625.10832-5-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161222105625.10832-1-chris@chris-wilson.co.uk> References: <20161222105625.10832-1-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 5/5] drm/i915: Extact compute_partial_view() 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 In order to reuse the partial view for selftesting, extract the common function for computing the view. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_gem.c | 48 +++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 62719124840a..2ce53fec9ef9 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1778,6 +1778,32 @@ int i915_gem_mmap_gtt_version(void) return 1; } +static inline struct i915_ggtt_view +compute_partial_view(struct drm_i915_gem_object *obj, + struct vm_area_struct *area, + pgoff_t page_offset, + unsigned int chunk_size) +{ + struct i915_ggtt_view view; + + if (i915_gem_object_is_tiled(obj)) + chunk_size = roundup(chunk_size, tile_row_pages(obj)); + + view.type = I915_GGTT_VIEW_PARTIAL; + view.partial.offset = rounddown(page_offset, chunk_size); + view.partial.size = + min_t(unsigned int, chunk_size, + vma_pages(area) - view.partial.offset); + + /* If the partial covers the entire object, just create a + * normal VMA. + */ + if (chunk_size >= obj->base.size >> PAGE_SHIFT) + view.type = I915_GGTT_VIEW_NORMAL; + + return view; +} + /** * i915_gem_fault - fault a page into the GTT * @area: CPU VMA in question @@ -1855,26 +1881,10 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf) /* Now pin it into the GTT as needed */ vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, flags); if (IS_ERR(vma)) { - struct i915_ggtt_view view; - unsigned int chunk_size; - /* Use a partial view if it is bigger than available space */ - chunk_size = MIN_CHUNK_PAGES; - if (i915_gem_object_is_tiled(obj)) - chunk_size = roundup(chunk_size, tile_row_pages(obj)); - - memset(&view, 0, sizeof(view)); - view.type = I915_GGTT_VIEW_PARTIAL; - view.partial.offset = rounddown(page_offset, chunk_size); - view.partial.size = - min_t(unsigned int, chunk_size, - vma_pages(area) - view.partial.offset); - - /* If the partial covers the entire object, just create a - * normal VMA. - */ - if (chunk_size >= obj->base.size >> PAGE_SHIFT) - view.type = I915_GGTT_VIEW_NORMAL; + struct i915_ggtt_view view = + compute_partial_view(obj, area, + page_offset, MIN_CHUNK_PAGES); /* Userspace is now writing through an untracked VMA, abandon * all hope that the hardware is able to track future writes.