msm: kgsl: Handle a possible ringbuffer allocspace error

In the GPU specific start functions, account for the possibility
that ringbuffer allocation routine might return NULL.

Change-Id: Ic0dedbadf6199fee78b6a8c8210a1e76961873a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add a new API to allow sharing of GPU performance counters

Adreno uses programmable performance counters, meaning that while there
are a limited number of physical counters each counter can be programmed
to count a vast number of different measurements (we refer to these as
countables).  This could cause problems if multiple apps want to use
the performance counters, so this API and infrastructure allows the
counters to be safely shared.

The kernel tracks which countable is selected for each of the physical
counters for each counter group (where groups closely match hardware
blocks). If the desired countable is already in use, or there is an
open physical counter, then the process is allowed to use the counter.

The get ioctl reserves the counter and returns the dword offset of the
register associated with that physical counter.  The put ioctl
releases the physical counter.  The query ioctl gets the countables
used for all of the counters in the block - up to 8 values can be
returned.  The read ioctl gets the current hardware value in the counter

Change-Id: Ic0dedbadae1dedadba60f8a3e685e2ce7d84fb33
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
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>