msm: kgsl: Add cache flush for A20x

Adding extra cache flush command to make sure that CP block
gets event from RB all the time to avoid race conditions because of
clock switches. this is to improve stability on 8x25 target.

Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
(cherry picked from commit f4537cf8dd50a78d78ab1664d623c9b6ecf3f240)

Conflicts:

	drivers/gpu/msm/adreno_ringbuffer.c

Change-Id: Ie08148847d33cd3e526e9bf23bf357a55b048e1b
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: kgsl: Log retired timestamps on device wake

Knowing the retired timestamp on wake-up is useful to debug hangs that
are caused due to clock instability. When we request for clock ON, the
clock may/may-not be turned ON, but we go ahead assuming it is ON. This
can be caught by printing the timestamp on wake. The timestamp we print,
can be compared against the timestamp in postmortem dump (assuming a
hang happens).

If there is a difference, we can say that GPU has run for sometime after
wake. So, we needn't suspect clocks.

If there is no difference, we can say that GPU has hung immediately after
wake. So, we can positively suspect the clocks.

Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>
(cherry picked from commit d0348f1644a21ae73982f94c442bdf9f17584ebe)

Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
(cherry picked from commit 0184185f274762462738621282dc50815313339d)

Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
(cherry picked from commit 9e5af757c0902544113bba8ac5296d4a5f15aaf7)

Change-Id: I3c02b3a27486073a31b21bc0a49114d1a668ff1d
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
Revert "msm: kgsl: Update pagetable on context destruction for A20x"

This reverts commit f0d1c9b79e05972816b92bd43b29e98f764826ea.

Reverting this change since it corrupts Bin Base Offset between
two draws of a Binning pass, resulting in GPU hang.

(cherry picked from commit 3ec5d2db139d0941ec8360f6cc399223b18469e5)

Change-Id: Ie1853075533e15e6c8020a00e57b1695df81c9ba
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
msm: kgsl: Fix hang detection to be 50ms or more

In current design waittimestamp can trigger hang detection
in less than 50ms. Check if hang detection was called less than
50ms ago, if true do no attempt hang detection.

(cherry picked from commit 2518e02e85f50338dc1f5708c03edabd4215d099)

Change-Id: I97fd14df2c5288810950a33ea305b05b8ad0faa4
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: kgsl: Remove duplicate code for checking timestamps

Event based as well as interruptible based timestamp checks
use the same code, they differ on if the mutex is held or not.
Separate the common code out to avoid confusion.

Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Rajeev Kulkarni <krajeev@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno.c

Signed-off-by: Vikram Orre <quic_vorre@quicinc.com>

Change-Id: I343379b6daac24b4e6f7c7ea4c4031671ae150e5
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_ringbuffer.c
	drivers/gpu/msm/adreno_ringbuffer.h
msm: kgsl: Don't silently ignore events that have a retired timestamp

After all the current events are processed in the main loop, the next
pending event is marked to fire an interrupt to start the cycle anew.
When the event is marked, we check the timestamp again to make sure that
we are always caught up with the GPU.  If the timestamp for the next
event happens to be retired when we get to this point, we silently leave
the function.

If there are no other subsequent events or waittimestamp requests, then
it is possible that another interrupt might never be fired for that context
and then the event gets missed.  Return a 1 in this case all the way back
up the stack and make the event code keep processing events until we are
positive that none are past.

CRs-fixed: 447655
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit f64ee0494159e61dbac2868162878d5e9a618587)

Change-Id: I0c83d8370098357fdc28d8b995a132593bab2ebd
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: kgsl: Use the correct units for ADRENO_IDLE_TIMEOUT

In a few spots the ADRENO_IDLE_TIMEOUT value (measured in milliseconds)
was used directly for jiffy calculations resulting in timeouts that were
1000/HZ times longer than they should have been.  Use msecs_to_jiffies
for these situations.

CRs-Fixed: 448226
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 0bcdb735fb0ffa524638ab75acf76d3ddfe38616)

Change-Id: Ic2cd7eaf949d5c69c803fd109f206629de56ef9f
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: kgsl: Don't change the sglen of the memdesc if allocation fails

If the page_alloc loop fails, we changed the length of the scatterlist
for the memdesc to the last good page so we could have an efficient
loop through kgsl_sharedmem_free.  Unfortunately, we were also using
the sglen to decide between using kmem or vmalloc memory for the sg
list in the first place. There is a chance that one could start out
with a large sg list from vmalloc, but if it failed early, then we
could truncate the size and attempt to kfree it.

Zero the stlist at init time and use a length == 0 as an indicator
that the list might be truncated.
CRs-Fixed: 443441

Signed-off-by: Dhivya Subramanian <dthiru@codeaurora.org>
(cherry picked from commit 24866eefe7db32ab8f32ba69518f65f1c74c66c2)

Change-Id: Id1d2052ae034db78f42cc5fe6bb742ae8130f391
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: kgsl: Move events to context specific lists

Move the event accounting from a master list on the device to individual
context lists. This makes the management code more simple and reduces
the amount of extra cycles taken trying to walk a single largish list.
The new added code makes the event code slightly bigger than kgsl.c can
bear. As events become more commonplace this code will be more important
and it will be easier to maintain in a dedicated file so move all the event
related code into kgsl_events.c

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit ef3456c4552ab55e8b5882afe0c58062bcbeeba5)

Conflicts:

	drivers/gpu/msm/kgsl.c

Change-Id: If8109ebf81e542e952e14581a30d034ed4d53596
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

Conflicts:

	drivers/gpu/msm/kgsl_events.c
msm: kgsl: Increase IDLE_TIMEOUT for 2D core to 20secs

Increasing the hang detection time for 2D core from
10 secs to 20 secs to avoid False GPU Hangs.
Some c2d test cases are taking more than 10 secs
to process which results in a False GPU Hang.

Change-Id: Ice5e4b719adb44cd13fb8164bafedce1049416f7
CRs-Fixed: 454439
Signed-off-by: Vikram Orre <vorre@codeaurora.org>
msm: kgsl: Replace 10secs timeout with Z180_IDLE_TIMEOUT for 2D.

Use Z180_IDLE_TIMEOUT macro for 2D hang detection instead
of hardcoded value of 10 secs.

Change-Id: I39f9d3ff9ef00df2f3d399454279045fe68e471a
CRs-Fixed: 454439
Signed-off-by: Vikram Orre <vorre@codeaurora.org>
msm: kgsl: Add CP_WAIT_FOR_IDLE packet before updating timestamp

HW workaround to resolve MMU pagefault caused by memory
freeing early before GPU completes it.

This is race condition where timestamp is getting updated
and the event handler runs before the GPU actually got done
with the timestamp, hence freeing the buffer early while GPU
still not completed with it.

Signed-off-by: Anshuman Dani <adani@codeaurora.org>
(cherry picked from commit faf69cfeeede0883b9556e532d720ab4dc95b01d)

Signed-off-by: Gopal Goberu <ggober@codeaurora.org>
(cherry picked from commit 03c88f958a62e4bcea0640faef0766d6d10e787a)

Change-Id: Id4553255322a5e6eb729f1790fcc09d654da01e3
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm:kgsl: Remove NORETRY flag in memory allocations

With NORETRY flag kernel will not try to reclaim memory
incase of memory allocation failures.With NORETRY flag
being removed, kernel makes mutliple attempts in order to make memory
allocation sucessfull, before returning failure.

Change-Id: I7d71954eba723ce6a8a79b63f54bea1e5b6618f1
Signed-off-by: Rajeev Kulkarni <krajeev@codeaurora.org>
msm: kgsl: Delete the context event while the context is still valid

Make sure that the context is freed only after the event is deleted
from the list to avoid accessing invalid list pointers. This makes
sure that the context memory is not accessed after being freed.

Change-Id: I9196219f1472396c0063dbeaa5351f66e6e5648f
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
Signed-off-by: Uma Maheshwari Bhiram <ubhira@codeaurora.org>
msm: kgsl: Remove invalid context_id logging

Remove printing of "invalid context_id" messages and
replace those with simply returning with -EINVAL. The
messages serve little purpose and their removal alleviates
kernel log spamming.

CRs-fixed: 449050
Change-Id: Id0d6538d228e7dc928a628bdffde8c952ec5d6fe
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Properly record the size of the sglist in the memdesc

It was possible to fail out of kgsl_sharedmem_alloc after a sglist was
allocated but before we saved the size of the allocation which caused
problems when the sglist was freed during cleanup.

CRs-fixed: 464289
Change-Id: Ic0dedbadd57ec4d9422b5e3a873243d0ffed51f7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Don't do intensive memory recovery when allocating big pages

We don't want to incur too much overhead when allocating big pages
so don't attempt to retry, perform reclaim, or run memory compaction
on high-order allocations.

Change-Id: Ic0dedbadb354c6faea34abec36aee268ac0f2c34
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
msm: kgsl: Don't access context memory after it's freed

Context memory was potentially accessed after being freed. Fix this
by incrementing the context's refcount at strategic places.

Change-Id: I31049bdd3eb9ac52160ca593619fcc8a32d4ddee
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
msm: kgsl: Add NULL check for next_event hook

KGSL driver needs to check that the function pointer
is not NULL before calling the hook. next_event
is an optional function not implemented by the 2d
core. This fix ensures that optional and unimplemented
function will not invoked by the driver.

Change-Id: I687b028260e3ec304d973c6a5bded0a8fdbfb73b
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
msm: kgsl: Don't consider active count if not in active state

Don't consider active_cnt variable if not already in ACTIVE state.
The active count variable does not necessarily exactly indicate the
number of open handles to GPU for switching power state. Hence,
only wait for active count to reach zero before switching to SUSPEND
state if, the current state is ACTIVE.

CRs-fixed: 483154
Change-Id: Ie025a1873cfb9237bdfba89204f4c2116549eba4
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>