msm: kgsl: Retry hard reset more than once on failure

It has been observed that if hard reset is tried again after failure
then it succeeds, so add a loop to retry hard reset a few times
before considering it a failure.

Change-Id: I46dd8a420d5fd49941d096168aafd2eab693bebb
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Wake up threads after context detach

After context has detached wake up threads that might be
waiting to submit commands for the detached context.

Change-Id: I16eca443354bc5f77a2d26ef4759d0a41014250e
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Add a generic IB parser

Add generic IB parser to parse adreno IB's and find the objects
that are required to execute the IB. This generic parser can
be used from snapshot and other places like CFF to get the
list of objects that are required for an IB to execute
Use the generic parser from snapshot to find the objects in IB's that
need to be dumped during snapshot and implement IB object list in
snapshot so that the amount of time to take snapshot does not increase.

Change-Id: I7c1383392d04387027afe95aba9a94d0347c8f99
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Save snapshot IB data in queued work item

Queue a work item after taking snapshot. The work item saves
the data placed in frozen objects into a separate allocated memory.
The data in frozen objects can change after snapshot is taken and
before the snapshot is dumped or pulled from the system. This work
item in between helps in getting the actual data in the objects by
saving the data in memory. Data can change in the time the work item
executes and snapshot is taken but this time gap is much smaller
compared to snapshot being pulled and snapshot being taken so it
avoids incorrect data in most known cases.

Change-Id: I77d065a5f50517440fd249101b9f0f764125bfdd
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: A4XX GPU support

Support for A4XX GPU family. A4xx shares a lot of code with
A3xx, reuse the common functions whenever possible.

Change-Id: If10eac6ad71c92bf699a8874c1f189afc74db914
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Unmap memory after using it in CFF capture

Unmap memory from kernel space after it is used in CFF capture
function. The kernel mapping is not used frequently and code
sections that use it will always remap it in kernel.

Change-Id: I7909f11de928b5a5c881a3e693fb54aecd681bd3
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Set up address ranges for CFF capture

CFF capture runs on virtual platforms that cannot access address
beyond a certain range. Set the address ranges during CFF capture
to keep the addresses within that limit.

Change-Id: I6aaabe23af8e212e34738fe7e2dceb619a957118
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Fix memory entry leak when calling adreno_convertaddr

When adreno_convertaddr is called the memory searched in this function
may have a memory entry associated with it if this allocation belongs
to user space. A reference to this memory entry is taken when
this function is called which should be returned when the caller is
done using the memory. Made changes to return a reference to the
entry when calling this function which is returned when caller is
done using the memory.

Change-Id: I610553fd4b119d3c47cbfcec970d50046dbb2863
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Do not hold active count during CFF

When CFF is enabled active count on device was held which prevented
device from clocking off. This was done because simulator could not
handle device restarts. Instead of fixing this problem here the
post processing script can be modified to discard CFF data before
every starting opcode of CFF. Hence, there is no longer a requirement
to hold active count during CFF.

Change-Id: I7c23f90f2fe0deb8cfba10a067765a54c305bcef
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Add VBIF register programming for A4XX

Add VBIF register programming for a420 core during start up of
this device.

Change-Id: I1bd79f72dabdc8c4e9403bb2788b3ea53d8ba04c
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Count user and kernel performance counters seperately

Rather than just storing if the performance counter was referenced by the
kernel in a flag, keep track of user space and kernel space references
seperately.  This allows finer grained manipulations on the performance
counters (ie when allowed to be released).  This is needed to be able to
turn off certain performance counters when fault tolerance is disabled
at runtime.

Change-Id: I7b5593459e64557dabd594aeb6532a0c9af6a9c5
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Restructure performance counters

Restructure the performance counter mechanism by combining the two
structures declared for it. The 2 structures can only refer to a
single counter hence it is easier to manage by having them
under a single structure.

Change-Id: I19d13cf5aa619b85a332b383b464c2af65ad38c9
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Fix reading of special case counters

VBIF, VBIF power and power performance counters are special case
counters that are stopped by using a different set of registers.
Handle the case to read these counters in separate functions.

Change-Id: Ia89ba44d1031496ac7742b435c28ea2f3b2177fa
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Init log levels in device init

Device log levels should be initialized during device initialization,
removing this from debugfs init because customer could disable
debugfs.

Change-Id: Ie1222be1d421405e0d7481c799045cb9876c2a91
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Return -ENOTTY for legacy waittimestamp calls

Return -ENOTTY Instead of returning -EINVAL for depcreated
legacy waittimestamp so the userspace caller understands that
the functionality no longer exists.

Change-Id: Ic0dedbad49faf4b85d7a2939ba83169ededc9eff
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: remove KGSL_STATE_DUMP_AND_FT

This state is not used anymore.

Change-Id: I96e057b336d70618718c2f493024aaefa900d12d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Re-add the irq_last functionality

irq_last is a flag to indicate kgsl should busy wait in an
attempt to NAP because the GPU is likely done with its last
batch of processing.

The setting and clearing of the irq_last variable was removed
with the dispatcher.  Although there are no visable instances
of trouble getting to NAP in current builds, re-add the functionality
until it can be fully replaced.

Change-Id: I8b4d2b72aec8948919fbeed9939684a09cb4f7f9
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
msm: kgsl Check NULL return from kgsl_get_device_from_dev

The function kgsl_get_device_from_dev() might return NULL, which
was not checked in a few places. Check the return value wherever
it is called.

Change-Id: I764b23a7b13acd692ce0e1bf4bd040c7e180c7d8
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
msm: kgsl: Remove drawctxt_active from setstate default

drawctxt_active is cleared after the old context is removed
during context switch.  Unfortunately, the context restore calls
adreno_use_default_setstate() which always returns true if
drawctxt_active is NULL, effectively always forcing us down the
software path.

Remove the check - adreno_use_default_setstate() already checks to see
if the GPU is idle and that is a more reliable verification that the
software path is worth going down.

Change-Id: Ic0dedbad57d7783bc23dd925a277a63cd2d78a7e
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Move validation of user data after copy_from_user

Move validation of user supplied group id's after they've been copied
to kernel memory with copy_from_user.

Change-Id: Idce2b8df6faf018c3d2e41f3c3057d07b4e11535
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>