Ejemplo n.º 1
0
int i915_gem_context_init(struct drm_i915_private *dev_priv)
{
	struct i915_gem_context *ctx;

	/* Init should only be called once per module load. Eventually the
	 * restriction on the context_disabled check can be loosened. */
	if (WARN_ON(dev_priv->kernel_context))
		return 0;

	if (intel_vgpu_active(dev_priv) &&
	    HAS_LOGICAL_RING_CONTEXTS(dev_priv)) {
		if (!i915.enable_execlists) {
			DRM_INFO("Only EXECLIST mode is supported in vgpu.\n");
			return -EINVAL;
		}
	}

	/* Using the simple ida interface, the max is limited by sizeof(int) */
	BUILD_BUG_ON(MAX_CONTEXT_HW_ID > INT_MAX);
	ida_init(&dev_priv->context_hw_ida);

	if (i915.enable_execlists) {
		/* NB: intentionally left blank. We will allocate our own
		 * backing objects as we need them, thank you very much */
		dev_priv->hw_context_size = 0;
	} else if (HAS_HW_CONTEXTS(dev_priv)) {
		dev_priv->hw_context_size =
			round_up(get_context_size(dev_priv),
				 I915_GTT_PAGE_SIZE);
		if (dev_priv->hw_context_size > (1<<20)) {
			DRM_DEBUG_DRIVER("Disabling HW Contexts; invalid size %d\n",
					 dev_priv->hw_context_size);
			dev_priv->hw_context_size = 0;
		}
	}

	ctx = i915_gem_create_context(dev_priv, NULL);
	if (IS_ERR(ctx)) {
		DRM_ERROR("Failed to create default global context (error %ld)\n",
			  PTR_ERR(ctx));
		return PTR_ERR(ctx);
	}

	/* For easy recognisablity, we want the kernel context to be 0 and then
	 * all user contexts will have non-zero hw_id.
	 */
	GEM_BUG_ON(ctx->hw_id);

	i915_gem_context_clear_bannable(ctx);
	ctx->priority = I915_PRIORITY_MIN; /* lowest priority; idle task */
	dev_priv->kernel_context = ctx;

	GEM_BUG_ON(!i915_gem_context_is_kernel(ctx));

	DRM_DEBUG_DRIVER("%s context support initialized\n",
			i915.enable_execlists ? "LR" :
			dev_priv->hw_context_size ? "HW" : "fake");
	return 0;
}
Ejemplo n.º 2
0
int i915_gem_context_init(struct drm_device *dev)
{
    struct drm_i915_private *dev_priv = dev->dev_private;
    struct intel_context *ctx;
    int i;

    /* Init should only be called once per module load. Eventually the
     * restriction on the context_disabled check can be loosened. */
    if (WARN_ON(dev_priv->ring[RCS].default_context))
        return 0;

    if (i915.enable_execlists) {
        /* NB: intentionally left blank. We will allocate our own
         * backing objects as we need them, thank you very much */
        dev_priv->hw_context_size = 0;
    } else if (HAS_HW_CONTEXTS(dev)) {
        dev_priv->hw_context_size = round_up(get_context_size(dev), 4096);
        if (dev_priv->hw_context_size > (1<<20)) {
            DRM_DEBUG_DRIVER("Disabling HW Contexts; invalid size %d\n",
                             dev_priv->hw_context_size);
            dev_priv->hw_context_size = 0;
        }
    }

    ctx = i915_gem_create_context(dev, NULL);
    if (IS_ERR(ctx)) {
        DRM_ERROR("Failed to create default global context (error %ld)\n",
                  PTR_ERR(ctx));
        return PTR_ERR(ctx);
    }

    for (i = 0; i < I915_NUM_RINGS; i++) {
        struct intel_engine_cs *ring = &dev_priv->ring[i];

        /* NB: RCS will hold a ref for all rings */
        ring->default_context = ctx;
    }

    DRM_DEBUG_DRIVER("%s context support initialized\n",
                     i915.enable_execlists ? "LR" :
                     dev_priv->hw_context_size ? "HW" : "fake");
    return 0;
}