msm: kgsl: Print the nearest active GPU buffers to a faulting address

Print the two active GPU memory entries that bracket a faulting GPU
address. This will help diagnose premature frees and buffer ovverruns.

Check if the faulting GPU address was freed by the same process.

Change-Id: Ic0dedbadebf57be9abe925a45611de8e597447ea
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
msm: kgsl: Remove an uneeded register write for A3XX GPUs

A3XX doesn't have the MH block and so the register at 0x40 points
somewhere else. Luckily the write was harmless but remove it anyway.

Change-Id: Ic0dedbadd1e043cd38bbaec8fcf0c490dcdedc8c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: clean up iommu/gpummu protflag handling

Make kgsl_memdesc_protflags() return the correct type of flags
for the type of mmu being used. Query the memdesc with this
function in kgsl_mmu_map(), rather than passing in the
protflags. This prevents translation at multiple layers of
the code and makes it easier to enforce that the mapping matches
the allocation flags.

Change-Id: I2a2f4a43026ae903dd134be00e646d258a83f79f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: remove kgsl_mem_entry.flags

The two flags fields in kgsl_memdesc should be enough for
anyone.  Move the only flag using kgsl_mem_entry, the
FROZEN flag for snapshot procesing, to use kgsl_memdesc.priv.

Change-Id: Ia12b9a6e6c1f5b5e57fa461b04ecc3d1705f2eaf
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: map the guard page readonly on the iommu

The guard page needs to be readable by the GPU, due to
a prefetch range issue, but it should never be writable.
Change the page fault message to indicate if nearby
buffers have a guard page.

Change-Id: I3955de1409cbf4ccdde92def894945267efa044d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Add support for VBIF and VBIF_PWR performance counters

These 2 counter groups are also "special cases" that require
different programming sequences.

Change-Id: I73e3e76b340e6c5867c0909b3e0edc78aa62b9ee
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Only allow two counters for VBIF performance counters

There are only two VBIF counter groups so validate that the user
doesn't pass in > 1 and clean up the if/else clause.

Change-Id: Ic0dedbad3d5a54e4ceb1a7302762d6bf13b25da1
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Avoid an array overrun in the perfcounter API

Make sure the passed group is less than the size of the list of
performance counters.

Change-Id: Ic0dedbadf77edf35db78939d1b55a05830979f85
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Don't go to slumber if active_count is non zero

If active_cnt happens to be set when we go into
kgsl_early_suspend_driver() then don't go to SLUMBER.  This
avoids trouble if we come back and and try to access the
hardware while it is off.

Change-Id: Ic0dedbadb13514a052af6199c8ad1982d7483b3f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Enable HLSQ registers in snapshot when available

Reading the HLSQ registers during a GPU hang recovery might cause
the device to hang depending on the state of the HLSQ block.
Enable the HLSQ register reads when we know that they will
succeed.

Change-Id: I69f498e6f67a15328d1d41cc64c43d6c44c54bad
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: snapshot: Don't keep parsing indirect buffers on failure

Stop parsing an indirect buffer if an error is encountered (such as
a missing buffer). This is a pretty good indication that the buffers
are not reliable and the further the parser goes with a unreliable
buffer the more likely it is to get confused.

Change-Id: Ic0dedbadf28ef374c9afe70613048d3c31078ec6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: snapshot: Only push the last IB1 and IB2 in the static space

Some IB1 buffers have hundreds of little IB2 buffers and only one of them
will actually be interesting enough to push into the static space.  Only
push the last executed IB1 and IB2 into the static space.

Change-Id: Ic0dedbad26fb30fb5bf90c37c29061fd962dd746
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Save the last active context in snapshot

Save the last active context that was executing when the hang happened
in snapshot.

Change-Id: I2d32de6873154ec6c200268844fee7f3947b7395
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: In snapshot track a larger object size if address is same

If the object being tracked has the same address as a previously
tracked object then only track a single object with larger size
as the smaller object will be a part of the larger one anyway.

Change-Id: I0e33bbaf267bc0ec580865b133917b3253f9e504
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Track memory address from 2 additional registers

Add tracking of memory referenced by VS_OBJ_START_REG and FS_OBJ_START_REG
registers in snapshot. This makes snapshot more complete in terms of
tracking data that is used by the GPU at the time of hang.

Change-Id: I7e5f3c94f0d6744cd6f2c6413bf7b7fac4a5a069
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Loop till correct index on type0 packets

When searching for memory addresses in type0 packet we were looping
from start of the type0 packet till it's end, but the first DWORD
is a header so we only need to loop till packet_size - 1. Fix this.

Change-Id: I278446c6ab380cf8ebb18d5f3ae192d3d7e7db62
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Add global timestamp information to snapshot

Make sure that we always add global timestamp information to
snapshot. This is needed in playbacks for searching whereabouts
of last executed IB.

Change-Id: Ica5b3b2ddff6fd45dbc5a911f42271ad5855a86a
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Skip cff dump for certain functions when its disabled

Certain functions were generating CFF when CFF was disabled. Make
sure these functions do not dump CFF when it is disabled.

Change-Id: Ib5485b03b8a4d12f190f188b80c11ec6f552731d
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Fix searching of memory object

Make sure that at least a size of 1 byte is searched when locating
the memory entry of a region. If size is 0 then a memory region
whose last address is equal to the start address of the memory being
searched will be returned which is wrong.

Change-Id: I643185d1fdd17296bd70fea483aa3c365e691bc5
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: If adreno start fails then restore state of device

Restore the state of the device back to what it was at the
start of the adreno_start function if this function fails to
execute successfully.

Change-Id: I5b279e5186b164d3361fba7c8f8d864395b794c8
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>