From patchwork Wed May 25 14:04:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9135429 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 871C66075C for ; Wed, 25 May 2016 14:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A38228164 for ; Wed, 25 May 2016 14:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CB92282DC; Wed, 25 May 2016 14:05:57 +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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CA4C28164 for ; Wed, 25 May 2016 14:05:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 09B586E95E; Wed, 25 May 2016 14:05:56 +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 AB92D6E959 for ; Wed, 25 May 2016 14:05:20 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id q62so15847404wmg.3 for ; Wed, 25 May 2016 07:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dw8S4sndYKl48gaGZOf0z2ERkdvtbXkmQd09WrBdavo=; b=uN2o1VYdcZvb8LO5s/0ARwNJ5CwXEopGDh0thHf7nLcAmir2do7QbxLWwR6umzESSV HekZ5L1YHduHlksuzRZhJPIY443y5eZo/Wv7d8VU/YCMyARoeCbBtKW9pGf56syHaCib +Ll1OdndaCi6h8UFyWO2ztI2IjvDbqNXqZK9g0dgRbIBpvSc7LO318YGGkgzeyDQJ3oX tAFjW8STBDwmdwvSPOh2VtCIZrTKvhtMBOza0rPuR1lOsdOxlMMQJk61M+wdo+qckvlV p76gCgT7x1v/tF4BIm8URxUHx2DTd2PQ07PAeWJ9qjzuIlQpMJsn8FcGIBdgZQBbHqLt PDaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dw8S4sndYKl48gaGZOf0z2ERkdvtbXkmQd09WrBdavo=; b=IGKCcjxrvTVD5rljB/pAHrB9KSZH8oaPJRySASvAo2kflj1Sr3KPv+/ASUpoyeS6/r bGWIdnFJij5/Au64HRHNBdkAsUdWwf63JpSCNHtaorlgQ0ThELDNpZXHyGs3ctpzKJ0i 79/IJ4qbieJZYPHPlgxjObwr7OZVAw5lyHxwQzTxqcU7bm248CYuNWoLxDE1+eC+6+a8 Xkt/F4OtHM3Q+m7Z3pdaFj5DEbCvdmWDPEo0aRwq6cwkwC6d97x3fy3anjCtxQ6TRAEz 1oL9JFiso3NlTlxMFL9314tsuSkKBl/rnzCzayGipLFLwDyWhRuPnXlFCsQVcfE5TC1J S1mw== X-Gm-Message-State: ALyK8tKLXocTliYe6HwlRtWBP4IJS8k8Xe16rt8FBde7nY7rOCYcy2vUf1ct/K6AKmiiBQ== X-Received: by 10.28.73.198 with SMTP id w189mr3930886wma.32.1464185101014; Wed, 25 May 2016 07:05:01 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id 63sm25111800wmz.5.2016.05.25.07.04.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 May 2016 07:05:00 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 25 May 2016 15:04:49 +0100 Message-Id: <1464185093-21196-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464185093-21196-1-git-send-email-chris@chris-wilson.co.uk> References: <1464176933-31067-1-git-send-email-chris@chris-wilson.co.uk> <1464185093-21196-1-git-send-email-chris@chris-wilson.co.uk> Cc: Mika Kuoppala Subject: [Intel-gfx] [PATCH v2 2/6] drm/i915: Move legacy kernel context pinning to intel_ringbuffer.c 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 This is so that we have symmetry with intel_lrc.c and avoid a source of if (i915.enable_execlists) layering violation within i915_gem_context.c - that is we move the specific handling of the dev_priv->kernel_context for legacy submission into the legacy submission code. This depends upon the init/fini ordering between contexts and engines already defined by intel_lrc.c, and also exporting the context alignment required for pinning the legacy context. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_gem_context.c | 27 +++------------------------ drivers/gpu/drm/i915/intel_ringbuffer.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index e4c8e341655c..19d0194c728f 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -867,6 +867,8 @@ struct i915_gem_context { u32 user_handle; #define CONTEXT_NO_ZEROMAP (1<<0) + u32 ggtt_alignment; + struct intel_context { struct drm_i915_gem_object *state; struct intel_ringbuffer *ringbuf; diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index a3b11aac23a4..c620fe6c9d96 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -268,6 +268,8 @@ __create_hw_context(struct drm_device *dev, list_add_tail(&ctx->link, &dev_priv->context_list); ctx->i915 = dev_priv; + ctx->ggtt_alignment = get_context_alignment(dev_priv); + if (dev_priv->hw_context_size) { struct drm_i915_gem_object *obj = i915_gem_alloc_context_obj(dev, dev_priv->hw_context_size); @@ -413,26 +415,6 @@ int i915_gem_context_init(struct drm_device *dev) return PTR_ERR(ctx); } - if (!i915.enable_execlists && ctx->engine[RCS].state) { - int ret; - - /* We may need to do things with the shrinker which - * require us to immediately switch back to the default - * context. This can cause a problem as pinning the - * default context also requires GTT space which may not - * be available. To avoid this we always pin the default - * context. - */ - ret = i915_gem_obj_ggtt_pin(ctx->engine[RCS].state, - get_context_alignment(dev_priv), 0); - if (ret) { - DRM_ERROR("Failed to pinned default global context (error %d)\n", - ret); - i915_gem_context_unreference(ctx); - return ret; - } - } - dev_priv->kernel_context = ctx; DRM_DEBUG_DRIVER("%s context support initialized\n", @@ -469,9 +451,6 @@ void i915_gem_context_fini(struct drm_device *dev) lockdep_assert_held(&dev->struct_mutex); - if (!i915.enable_execlists && dctx->engine[RCS].state) - i915_gem_object_ggtt_unpin(dctx->engine[RCS].state); - i915_gem_context_unreference(dctx); dev_priv->kernel_context = NULL; @@ -721,7 +700,7 @@ static int do_rcs_switch(struct drm_i915_gem_request *req) /* Trying to pin first makes error handling easier. */ ret = i915_gem_obj_ggtt_pin(to->engine[RCS].state, - get_context_alignment(engine->i915), + to->ggtt_alignment, 0); if (ret) return ret; diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index 8d35a3978f9b..4e0aa7e9d5da 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -2244,6 +2244,8 @@ static int intel_init_ring_buffer(struct drm_device *dev, struct intel_engine_cs *engine) { struct drm_i915_private *dev_priv = to_i915(dev); + struct i915_gem_context *kctx = dev_priv->kernel_context; + struct intel_context *ce = &kctx->engine[engine->id]; struct intel_ringbuffer *ringbuf; int ret; @@ -2260,6 +2262,25 @@ static int intel_init_ring_buffer(struct drm_device *dev, init_waitqueue_head(&engine->irq_queue); + if (ce->state) { + i915_gem_context_reference(kctx); + + /* We may need to do things with the shrinker which + * require us to immediately switch back to the default + * context. This can cause a problem as pinning the + * default context also requires GTT space which may not + * be available. To avoid this we always pin the default + * context. + */ + ret = i915_gem_obj_ggtt_pin(ce->state, + kctx->ggtt_alignment, + 0); + if (ret) + goto error; + + ce->initialised = false; + } + ringbuf = intel_engine_create_ringbuffer(engine, 32 * PAGE_SIZE); if (IS_ERR(ringbuf)) { ret = PTR_ERR(ringbuf); @@ -2300,6 +2321,8 @@ error: void intel_cleanup_engine(struct intel_engine_cs *engine) { struct drm_i915_private *dev_priv; + struct i915_gem_context *kctx; + struct intel_context *ce; if (!intel_engine_initialized(engine)) return; @@ -2327,6 +2350,14 @@ void intel_cleanup_engine(struct intel_engine_cs *engine) i915_cmd_parser_fini_ring(engine); i915_gem_batch_pool_fini(&engine->batch_pool); + + kctx = dev_priv->kernel_context; + ce = &kctx->engine[engine->id]; + if (ce->state) { + i915_gem_object_ggtt_unpin(ce->state); + i915_gem_context_unreference(kctx); + } + engine->i915 = NULL; }