/** * i915_gem_context_create_gvt - create a GVT GEM context * @dev: drm device * * * This function is used to create a GVT specific GEM context. * * Returns: * pointer to i915_gem_context on success, error pointer if failed * */ struct i915_gem_context * i915_gem_context_create_gvt(struct drm_device *dev) { struct i915_gem_context *ctx; int ret; if (!IS_ENABLED(CONFIG_DRM_I915_GVT)) return ERR_PTR(-ENODEV); ret = i915_mutex_lock_interruptible(dev); if (ret) return ERR_PTR(ret); ctx = __create_hw_context(to_i915(dev), NULL); if (IS_ERR(ctx)) goto out; ctx->file_priv = ERR_PTR(-EBADF); i915_gem_context_set_closed(ctx); /* not user accessible */ i915_gem_context_clear_bannable(ctx); i915_gem_context_set_force_single_submission(ctx); if (!i915.enable_guc_submission) ctx->ring_size = 512 * PAGE_SIZE; /* Max ring buffer size */ GEM_BUG_ON(i915_gem_context_is_kernel(ctx)); out: mutex_unlock(&dev->struct_mutex); return ctx; }
void mock_context_close(struct i915_gem_context *ctx) { i915_gem_context_set_closed(ctx); i915_ppgtt_close(&ctx->ppgtt->base); i915_gem_context_put(ctx); }
static void context_close(struct i915_gem_context *ctx) { i915_gem_context_set_closed(ctx); if (ctx->ppgtt) i915_ppgtt_close(&ctx->ppgtt->base); ctx->file_priv = ERR_PTR(-EBADF); i915_gem_context_put(ctx); }
struct i915_gem_context * mock_context(struct drm_i915_private *i915, const char *name) { struct i915_gem_context *ctx; int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return NULL; kref_init(&ctx->ref); INIT_LIST_HEAD(&ctx->link); ctx->i915 = i915; ctx->vma_lut.ht_bits = VMA_HT_BITS; ctx->vma_lut.ht_size = BIT(VMA_HT_BITS); ctx->vma_lut.ht = kcalloc(ctx->vma_lut.ht_size, sizeof(*ctx->vma_lut.ht), GFP_KERNEL); if (!ctx->vma_lut.ht) goto err_free; ret = ida_simple_get(&i915->context_hw_ida, 0, MAX_CONTEXT_HW_ID, GFP_KERNEL); if (ret < 0) goto err_vma_ht; ctx->hw_id = ret; if (name) { ctx->name = kstrdup(name, GFP_KERNEL); if (!ctx->name) goto err_put; ctx->ppgtt = mock_ppgtt(i915, name); if (!ctx->ppgtt) goto err_put; } return ctx; err_vma_ht: kvfree(ctx->vma_lut.ht); err_free: kfree(ctx); return NULL; err_put: i915_gem_context_set_closed(ctx); i915_gem_context_put(ctx); return NULL; }