From patchwork Wed Jan 11 21:09:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9511445 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 7E2B060710 for ; Wed, 11 Jan 2017 21:11:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 710EA28655 for ; Wed, 11 Jan 2017 21:11:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65D0B28696; Wed, 11 Jan 2017 21:11:15 +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 000CD28655 for ; Wed, 11 Jan 2017 21:11:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A13846EA0F; Wed, 11 Jan 2017 21:10:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id D233C6EA0E for ; Wed, 11 Jan 2017 21:10:19 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id r126so798127wmr.3 for ; Wed, 11 Jan 2017 13:10:19 -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=P5RcnSU82G0vRqO6QhSwys4mDB4SufGhALtqGkVi444=; b=H1m739y9J7qNpoTgrDCqQH0CaNGnwoDhS1K5x34UyknV4+CbClJbv08iRIp7RE5br1 MWZ2n5ORrMYXvAks1FyA4Jkz0I40L+ozQuMzZa9Wa+Fv4Lb957AHHGVDiRPhDtn4ArUi 63yxtwB4/kNQfKhIdg6puWm2PB8/zFeViNDjXAUsXZxvXUxJ2ds0N8KnM7aiPv8igAWR IEwubUj+CUm1Fpoos3pttNLXnQ/D3HRMQjX0fVuBNuiPxrINlAesadm0oz+OjwvfYQMH SxR/xyH3tjknTF+/HnkmRtUW2CiZImU+whbeh6iogW5AQadq3oV6p9QtVCa0wet8YR/3 5Z+Q== 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=P5RcnSU82G0vRqO6QhSwys4mDB4SufGhALtqGkVi444=; b=LDwC601VX8YEyFcG3wV+3rsQot6wxzlfVyu1JCeEgnJrwqz4OP57MikEveSGQ3dDKT ucbQgon/OPnNN7KMj63uBSUHhfJPWwzexi3zNqFBpob/CYCvCBYQ3tWtegVY45KgBFST ftthRTgNhKXZ7zMaO4we9LXDSaCYbz/a5dugme/DJlFeVGPHihAuUXG9EjaXzwcUlmxc pzakdPEi2ZDJXyrJKNQUtKUwuUoj2hjWR/+pwsCHM1qCA+RKv2XUIlZvimoEpDy3vpqQ eSKBfjV080Xb+4znxE8cl9kPQiVRK3COZIk8lycWwuGp0CspvFzkZVvUc2+uTJgmbSpu ZqfA== X-Gm-Message-State: AIkVDXK+npDCgV2YckJXiOniDXH0QfyHnUywvnnkdRhZmZ+aRCs7zKGR4mrEniTDHDRY+Q== X-Received: by 10.28.98.66 with SMTP id w63mr4789068wmb.142.1484169018437; Wed, 11 Jan 2017 13:10:18 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id y4sm10354906wjp.0.2017.01.11.13.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 13:10:17 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 11 Jan 2017 21:09:34 +0000 Message-Id: <20170111210937.29252-35-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170111210937.29252-1-chris@chris-wilson.co.uk> References: <20170111210937.29252-1-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 34/37] drm/i915: Test creation of partial VMA 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 Mock testing to ensure we can create and lookup partial VMA. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/selftests/i915_vma.c | 179 ++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c b/drivers/gpu/drm/i915/selftests/i915_vma.c index 95c5db2b0881..7511f383868c 100644 --- a/drivers/gpu/drm/i915/selftests/i915_vma.c +++ b/drivers/gpu/drm/i915/selftests/i915_vma.c @@ -416,12 +416,191 @@ static int igt_vma_rotate(void *arg) return err; } +static bool assert_partial(struct drm_i915_gem_object *obj, + struct i915_vma *vma, + unsigned long offset, + unsigned long size) +{ + struct sgt_iter sgt; + dma_addr_t dma; + + for_each_sgt_dma(dma, sgt, vma->pages) { + dma_addr_t src; + + if (!size) { + pr_err("Partial scattergather list too long\n"); + return false; + } + + src = i915_gem_object_get_dma_address(obj, offset); + if (src != dma) { + pr_err("DMA mismatch for partial page offset %lu\n", + offset); + return false; + } + + offset++; + size--; + } + + return true; +} + +static int igt_vma_partial(void *arg) +{ + struct drm_i915_private *i915 = arg; + const unsigned int npages = 1021; /* prime! */ + struct drm_i915_gem_object *obj; + unsigned int sz, offset, loop; + struct i915_vma *vma; + int err = -ENOMEM; + + obj = i915_gem_object_create_internal(i915, npages*PAGE_SIZE); + if (IS_ERR(obj)) + goto err; + + for (loop = 0; loop <= 1; loop++) { /* exercise both create/lookup */ + unsigned int count, nvma; + + nvma = loop; + for_each_prime_number_from(sz, 1, npages) { + for_each_prime_number_from(offset, 0, npages - sz) { + struct i915_ggtt_view view; + + view.type = I915_GGTT_VIEW_PARTIAL; + view.partial.offset_size = + offset << INTEL_PARTIAL_SIZE_BITS | (sz - 1); + + if (sz == npages) + view.type = I915_GGTT_VIEW_NORMAL; + + vma = i915_gem_obj_lookup_or_create_vma(obj, &i915->ggtt.base, &view); + if (IS_ERR(vma)) { + err = PTR_ERR(vma); + goto err_object; + } + + if (!i915_vma_is_ggtt(vma)) { + pr_err("VMA is not in the GGTT!\n"); + err = -EINVAL; + goto err_object; + } + + err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL); + if (err) + goto err_object; + + if (vma->size != sz*PAGE_SIZE) { + pr_err("VMA is wrong size, expected %lu, found %llu\n", + sz*PAGE_SIZE, vma->size); + err = -EINVAL; + goto err_object; + } + + if (vma->node.size < vma->size) { + pr_err("VMA binding too small, expected %llu, found %llu\n", + vma->size, vma->node.size); + err = -EINVAL; + goto err_object; + } + + if (view.type != I915_GGTT_VIEW_NORMAL) { + if (memcmp(&vma->ggtt_view, &view, sizeof(view))) { + pr_err("VMA mismatch upon creation!\n"); + err = -EINVAL; + goto err_object; + } + + if (vma->pages == obj->mm.pages) { + pr_err("VMA using unrotated object pages!\n"); + err = -EINVAL; + goto err_object; + } + } + + if (!assert_partial(obj, vma, offset, sz)) { + pr_err("Inconsistent partial pages for (offset=%d, size=%d)\n", offset, sz); + err = -EINVAL; + goto err_object; + } + + i915_vma_unpin(vma); + nvma++; + } + } + + count = loop; + list_for_each_entry(vma, &obj->vma_list, obj_link) + count++; + if (count != nvma) { + pr_err("All partial vma were not recorded on the obj->vma_list: found %u, expected %u\n", + count, nvma); + err = -EINVAL; + goto err_object; + } + + /* Create a mapping for the entire object, just for extra fun */ + vma = i915_gem_obj_lookup_or_create_vma(obj, + &i915->ggtt.base, + NULL); + if (IS_ERR(vma)) { + err = PTR_ERR(vma); + goto err_object; + } + + if (!i915_vma_is_ggtt(vma)) { + pr_err("VMA is not in the GGTT!\n"); + err = -EINVAL; + goto err_object; + } + + err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL); + if (err) + goto err_object; + + if (vma->size != obj->base.size) { + pr_err("VMA is wrong size, expected %lu, found %llu\n", + sz*PAGE_SIZE, vma->size); + err = -EINVAL; + goto err_object; + } + + if (vma->node.size < vma->size) { + pr_err("VMA binding too small, expected %llu, found %llu\n", + vma->size, vma->node.size); + err = -EINVAL; + goto err_object; + } + + if (vma->ggtt_view.type != I915_GGTT_VIEW_NORMAL) { + pr_err("Not the normal ggtt view! Found %d\n", + vma->ggtt_view.type); + err = -EINVAL; + goto err_object; + } + + if (vma->pages != obj->mm.pages) { + pr_err("VMA not using object pages!\n"); + err = -EINVAL; + goto err_object; + } + + i915_vma_unpin(vma); + } + +err_object: + i915_gem_object_put(obj); +err: + return err; +} + int i915_vma_mock_selftests(void) { static const struct i915_subtest tests[] = { SUBTEST(igt_vma_create), SUBTEST(igt_vma_pin1), SUBTEST(igt_vma_rotate), + SUBTEST(igt_vma_partial), }; struct drm_i915_private *i915; int err;