[Intel-gfx] [RFCv3 06/15] drm/i915: let __i915_gem_context_create() takes context creation params
Zhi Wang
zhi.a.wang at intel.com
Fri Mar 11 10:59:37 UTC 2016
Let the core logic of context creation service creates 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 <zhi.a.wang at intel.com>
---
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..e7415b1a 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_global_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_global_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_global_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_global_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_global_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);
--
1.9.1
More information about the Intel-gfx
mailing list