From 3a919bd7603c04cc077d28691d0a19341d86e9b0 Mon Sep 17 00:00:00 2001
From: Tarun Karra <tkarra@codeaurora.org>
Date: Mon, 22 Sep 2014 15:01:19 -0700
Subject: [PATCH] msm: kgsl: Prevent adreno stop after gpu is power collapsed

When GPU is power collapsed GPU is already stopped. If kgsl release
gets called do not try to stop the GPU again. Trying to stop
already stopped GPU can lead to errors.

When content protection is enabled we cannot write to VBIF
registers with iommu detached. With this limitation if
adreno stop gets called twice, the second adreno stop will
cause NOC errors/XPU violations because trustzone will
XPU lock down all VBIF registers after first adreno stop.

Prevent adreno stop getting called twice by checking if device
is started, only if device is started go ahead with adreno
stop.

CRs-fixed: 726670
Change-Id: I4e3c7a9b37eb88d458d65763ed6818a4fd96bd06
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
---
 drivers/gpu/msm/adreno.c | 6 ++++--
 drivers/gpu/msm/kgsl.c   | 2 --
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/msm/adreno.c b/drivers/gpu/msm/adreno.c
index 45b6c0aeee72..12da1c4076e1 100644
--- a/drivers/gpu/msm/adreno.c
+++ b/drivers/gpu/msm/adreno.c
@@ -1798,8 +1798,10 @@ static int adreno_stop(struct kgsl_device *device)
 {
 	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
 
-	if (adreno_dev->drawctxt_active)
-		kgsl_context_put(&adreno_dev->drawctxt_active->base);
+	if (!test_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv))
+		return 0;
+
+	kgsl_pwrctrl_enable(device);
 
 	adreno_dev->drawctxt_active = NULL;
 
diff --git a/drivers/gpu/msm/kgsl.c b/drivers/gpu/msm/kgsl.c
index efc4c69210a0..a4986a75b626 100644
--- a/drivers/gpu/msm/kgsl.c
+++ b/drivers/gpu/msm/kgsl.c
@@ -961,8 +961,6 @@ int kgsl_close_device(struct kgsl_device *device)
 		/* Fail if the wait times out */
 		BUG_ON(atomic_read(&device->active_cnt) > 0);
 
-		/* Force power on to do the stop */
-		kgsl_pwrctrl_enable(device);
 		result = device->ftbl->stop(device);
 		kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT);
 	}
-- 
GitLab