[Intel-gfx] [RFCv2 05/14] drm/i915: factor out __create_legacy_hw_context()
Zhi Wang
zhi.a.wang at intel.com
Thu Feb 18 11:42:12 UTC 2016
As creating the legacy HW context has become into an option in GEM context
creating service (__i915_gem_create_context()), we factor out __create_
legacy_hw_context() from the __create_hw_context().
After the re-factor, the __create_hw_context() is only responsible for
allocating and initializing the basic members of intel_context data
structure, like list head... in addition to these very basic members, the
legacy context alloction is moved into __create_legacy_hw_context(), which
becomes a function block of the GEM context creating service.
Signed-off-by: Zhi Wang <zhi.a.wang at intel.com>
---
drivers/gpu/drm/i915/i915_gem_context.c | 43 ++++++++++++++++++---------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 38e9fe1..5516346 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -209,13 +209,26 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size)
return obj;
}
+static int __create_legacy_hw_context(struct drm_device *dev,
+ struct intel_context *ctx)
+{
+ struct drm_i915_private *dev_priv = to_i915(dev);
+ struct drm_i915_gem_object *obj =
+ i915_gem_alloc_context_obj(dev, dev_priv->hw_context_size);
+
+ if (IS_ERR(obj))
+ return PTR_ERR(obj);
+
+ ctx->legacy_hw_ctx.rcs_state = obj;
+ return 0;
+}
+
static struct intel_context *
__create_hw_context(struct drm_device *dev,
struct drm_i915_file_private *file_priv)
{
struct drm_i915_private *dev_priv = dev->dev_private;
struct intel_context *ctx;
- int ret;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (ctx == NULL)
@@ -224,37 +237,23 @@ __create_hw_context(struct drm_device *dev,
kref_init(&ctx->ref);
list_add_tail(&ctx->link, &dev_priv->context_list);
ctx->i915 = 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);
- if (IS_ERR(obj)) {
- ret = PTR_ERR(obj);
- goto err_out;
- }
- ctx->legacy_hw_ctx.rcs_state = obj;
- }
-
ctx->file_priv = file_priv;
/* NB: Mark all slices as needing a remap so that when the context first
* loads it will restore whatever remap state already exists. If there
* is no remap info, it will be a NOP. */
ctx->remap_slice = (1 << NUM_L3_SLICES(dev)) - 1;
-
ctx->hang_stats.ban_period_seconds = DRM_I915_CTX_BAN_PERIOD;
return ctx;
-
-err_out:
- i915_gem_context_unreference(ctx);
- return ERR_PTR(ret);
}
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);
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;
@@ -264,7 +263,13 @@ __i915_gem_create_context(struct drm_device *dev,
if (IS_ERR(ctx))
return ctx;
- if (is_global_default_ctx && ctx->legacy_hw_ctx.rcs_state) {
+ if (is_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
@@ -298,7 +303,7 @@ __i915_gem_create_context(struct drm_device *dev,
return ctx;
err_unpin:
- if (is_global_default_ctx && ctx->legacy_hw_ctx.rcs_state)
+ if (is_global_default_ctx && is_legacy_ctx)
i915_gem_object_ggtt_unpin(ctx->legacy_hw_ctx.rcs_state);
err_destroy:
i915_gem_context_unreference(ctx);
--
1.9.1
More information about the Intel-gfx
mailing list