Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 446882ee authored by Jordan Crouse's avatar Jordan Crouse
Browse files

msm: kgsl: Reorganize draw context validation



Verify the incoming draw context flags are correct *before* bothering
to initalize the memory. This saves us from having to jump through
hoops to take it down later.

Change-Id: Ic0dedbada00fc63752d2763ec18e1bfc3bb6410f
Signed-off-by: default avatarJordan Crouse <jcrouse@codeaurora.org>
parent e1b6fe17
Loading
Loading
Loading
Loading
+30 −33
Original line number Diff line number Diff line
@@ -324,21 +324,9 @@ adreno_drawctxt_create(struct kgsl_device_private *dev_priv,
	struct adreno_context *drawctxt;
	struct kgsl_device *device = dev_priv->device;
	int ret;
	unsigned long local;

	drawctxt = kzalloc(sizeof(struct adreno_context), GFP_KERNEL);

	if (drawctxt == NULL)
		return ERR_PTR(-ENOMEM);

	ret = kgsl_context_init(dev_priv, &drawctxt->base);
	if (ret != 0) {
		kfree(drawctxt);
		return ERR_PTR(ret);
	}

	drawctxt->timestamp = 0;

	drawctxt->base.flags = *flags & (KGSL_CONTEXT_PREAMBLE |
	local = *flags & (KGSL_CONTEXT_PREAMBLE |
		KGSL_CONTEXT_NO_GMEM_ALLOC |
		KGSL_CONTEXT_PER_CONTEXT_TS |
		KGSL_CONTEXT_USER_GENERATED_TS |
@@ -350,17 +338,38 @@ adreno_drawctxt_create(struct kgsl_device_private *dev_priv,
		KGSL_CONTEXT_IFH_NOP |
		KGSL_CONTEXT_SECURE);

	/*
	 * If content protection is not enabled and secure context
	 * is requested return error.
	 */
	/* Check for errors before trying to initialize */

	/* We no longer support legacy context switching */
	if ((local & KGSL_CONTEXT_PREAMBLE) == 0 ||
		(local & KGSL_CONTEXT_NO_GMEM_ALLOC) == 0) {
		KGSL_DEV_ERR_ONCE(device,
			"legacy context switch not supported\n");
		return ERR_PTR(-EINVAL);
	}

	/* Make sure that our target can support secure contexts if requested */
	if (!kgsl_mmu_is_secured(&dev_priv->device->mmu) &&
			(drawctxt->base.flags & KGSL_CONTEXT_SECURE)) {
		dev_WARN_ONCE(device->dev, 1, "Secure context not supported");
		kfree(drawctxt);
			(local & KGSL_CONTEXT_SECURE)) {
		KGSL_DEV_ERR_ONCE(device, "Secure context not supported\n");
		return ERR_PTR(-EINVAL);
	}

	drawctxt = kzalloc(sizeof(struct adreno_context), GFP_KERNEL);

	if (drawctxt == NULL)
		return ERR_PTR(-ENOMEM);

	ret = kgsl_context_init(dev_priv, &drawctxt->base);
	if (ret != 0) {
		kfree(drawctxt);
		return ERR_PTR(ret);
	}

	drawctxt->timestamp = 0;

	drawctxt->base.flags = local;

	/* Always enable per-context timestamps */
	drawctxt->base.flags |= KGSL_CONTEXT_PER_CONTEXT_TS;
	drawctxt->type = (drawctxt->base.flags & KGSL_CONTEXT_TYPE_MASK)
@@ -378,15 +387,6 @@ adreno_drawctxt_create(struct kgsl_device_private *dev_priv,
	 */
	plist_node_init(&drawctxt->pending, drawctxt->base.priority);

	if ((drawctxt->base.flags & KGSL_CONTEXT_PREAMBLE) == 0 ||
		  (drawctxt->base.flags & KGSL_CONTEXT_NO_GMEM_ALLOC) == 0) {
		KGSL_DEV_ERR_ONCE(device,
				"legacy context switch not supported\n");
		ret = -EINVAL;
		goto err;

	}

	kgsl_sharedmem_writel(device, &device->memstore,
			KGSL_MEMSTORE_OFFSET(drawctxt->base.id, soptimestamp),
			0);
@@ -399,9 +399,6 @@ adreno_drawctxt_create(struct kgsl_device_private *dev_priv,
	/* copy back whatever flags we dediced were valid */
	*flags = drawctxt->base.flags;
	return &drawctxt->base;
err:
	kgsl_context_detach(&drawctxt->base);
	return ERR_PTR(ret);
}

/**