From patchwork Thu Feb 18 11:42:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Zhi A" X-Patchwork-Id: 8349111 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B6FCE9F399 for ; Thu, 18 Feb 2016 11:45:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B759F2022D for ; Thu, 18 Feb 2016 11:45:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C13452022A for ; Thu, 18 Feb 2016 11:45:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 207D66EB6D; Thu, 18 Feb 2016 11:45:05 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 084706EB6D for ; Thu, 18 Feb 2016 11:45:02 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 18 Feb 2016 03:45:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,465,1449561600"; d="scan'208";a="654959813" Received: from dev-inno.bj.intel.com ([10.238.135.69]) by FMSMGA003.fm.intel.com with ESMTP; 18 Feb 2016 03:45:01 -0800 From: Zhi Wang To: intel-gfx@lists.freedesktop.org, igvt-g@lists.01.org Date: Thu, 18 Feb 2016 19:42:13 +0800 Message-Id: <1455795741-3487-7-git-send-email-zhi.a.wang@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455795741-3487-1-git-send-email-zhi.a.wang@intel.com> References: <1455795741-3487-1-git-send-email-zhi.a.wang@intel.com> Cc: daniel.vetter@ffwll.ch, david.j.cowperthwaite@intel.com, zhiyuan.lv@intel.com Subject: [Intel-gfx] [RFCv2 06/14] drm/i915: let __i915_gem_context_create() takes context creation params 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let the core logic of context creation service creats the GEM context by context creation params. Now it provides following options for context creation: - Need to create legacy context for this GEM context? - Need to create PPGTT instance for this GEM context? - Need to treat this context as the global default context? And for all the assumptions in the original implementation, we keep them in the upper-level wrapper. Signed-off-by: Zhi Wang --- drivers/gpu/drm/i915/i915_gem_context.c | 71 ++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 5516346..cda09f7 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -223,6 +223,13 @@ static int __create_legacy_hw_context(struct drm_device *dev, return 0; } +struct i915_gem_context_create_params { + struct drm_i915_file_private *file_priv; + bool has_legacy_ctx; + bool has_ppgtt; + bool is_default_ctx; +}; + static struct intel_context * __create_hw_context(struct drm_device *dev, struct drm_i915_file_private *file_priv) @@ -249,44 +256,43 @@ __create_hw_context(struct drm_device *dev, static struct intel_context * __i915_gem_create_context(struct drm_device *dev, - struct drm_i915_file_private *file_priv) + struct i915_gem_context_create_params *params) { - struct drm_i915_private *dev_priv = to_i915(dev); - const bool is_global_default_ctx = file_priv == NULL; - const bool is_legacy_ctx = !!dev_priv->hw_context_size; struct intel_context *ctx; int ret = 0; BUG_ON(!mutex_is_locked(&dev->struct_mutex)); - ctx = __create_hw_context(dev, file_priv); + ctx = __create_hw_context(dev, params->file_priv); if (IS_ERR(ctx)) return ctx; - if (is_legacy_ctx) { + if (params->has_legacy_ctx) { ret = __create_legacy_hw_context(dev, ctx); if (ret) goto err_destroy; - } - if (is_global_default_ctx && is_legacy_ctx) { - /* 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->legacy_hw_ctx.rcs_state, - get_context_alignment(dev), 0); - if (ret) { - DRM_DEBUG_DRIVER("Couldn't pin %d\n", ret); - goto err_destroy; + if (params->is_default_ctx) { + /* 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->legacy_hw_ctx.rcs_state, + get_context_alignment(dev), 0); + if (ret) { + DRM_DEBUG_DRIVER("Couldn't pin %d\n", ret); + goto err_destroy; + } } } - if (USES_FULL_PPGTT(dev)) { - struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev, file_priv); + if (params->has_ppgtt) { + struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev, + params->file_priv); if (IS_ERR_OR_NULL(ppgtt)) { DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n", @@ -303,7 +309,7 @@ __i915_gem_create_context(struct drm_device *dev, return ctx; err_unpin: - if (is_global_default_ctx && is_legacy_ctx) + if (params->is_default_ctx && params->has_legacy_ctx) i915_gem_object_ggtt_unpin(ctx->legacy_hw_ctx.rcs_state); err_destroy: i915_gem_context_unreference(ctx); @@ -311,12 +317,12 @@ err_destroy: } static inline int alloc_context_idr(struct drm_device *dev, - struct intel_context *ctx) + struct intel_context *ctx, + struct i915_gem_context_create_params *params) { int ret; - /* Default context will never have a file_priv */ - if (ctx->file_priv != NULL) { + if (params->is_default_ctx) { ret = idr_alloc(&ctx->file_priv->context_idr, ctx, DEFAULT_CONTEXT_HANDLE, 0, GFP_KERNEL); if (ret < 0) @@ -338,14 +344,23 @@ static struct intel_context * i915_gem_create_context(struct drm_device *dev, struct drm_i915_file_private *file_priv) { + struct drm_i915_private *dev_priv = to_i915(dev); + struct i915_gem_context_create_params params; struct intel_context *ctx; int ret; - ctx = __i915_gem_create_context(dev, file_priv); + memset(¶ms, 0, sizeof(params)); + + params.file_priv = file_priv; + params.has_legacy_ctx = !!dev_priv->hw_context_size; + params.has_ppgtt = USES_FULL_PPGTT(dev); + params.is_default_ctx = (file_priv == NULL); + + ctx = __i915_gem_create_context(dev, ¶ms); if (IS_ERR(ctx)) return ctx; - ret = alloc_context_idr(dev, ctx); + ret = alloc_context_idr(dev, ctx, ¶ms); if (ret < 0) { i915_gem_context_unreference(ctx); return ERR_PTR(ret);