msm: kgsl: Fix conditional GPU interrupts to fire only for waiting context

Conditional interrupts were not getting fired at the correct time when
using per context timestamps.  When a context was waiting on a timestamp,
the interrupt was being fired on the global timestamp rather than the per
context timestamp.  Now the interrupt is fired on the per context
timestamp.

Change-Id: Ib683c846f0639a1e44f5b39bb81ca2751b306ea1
CRs-Fixed: 340620
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno_drawctxt.c
	drivers/gpu/msm/adreno_ringbuffer.c
	drivers/gpu/msm/adreno_ringbuffer.h
msm: kgsl: Detect and avoid malformed ioctl codes

Because we were using _IO_NR, one could construct a malformed ioctl
code that would avoid allocating memory yet go to a function that
expected that memory. Still use _IO_NR to index the array of ioctls,
but check that the full values match before jumping to the helper
function.

CRs-fixed: 385592
Change-Id: Ic0dedbaded469035bd0a2bb0f20fecb2a3045ca5
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Hold pm_qos vote for active rendering

Differentiate between the screen off case where kgsl shouldn't
hold a pm_qos vote and the screen on case where power rails
may be turned off after a long idle.  restore_slumber now
corresponds to the screen on/off while strtstp_sleepwake covers
the power rail collapse.

CRs-Fixed: 386956
Change-Id: Id4318f1aa87d6ad0653fe5db18c5d33bda1cc8bb
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

Conflicts:

	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_pwrctrl.c
msm: kgsl: Allow the wait_timeout to be disabled

With the improved hang detection we don't technically need a upper
timeout bound for a process to wait in waitfortimestamp().  Allow
for a idle_timestamp of '0' to allow the loop to wait for ever.
The infrastructure for changing the idle_timeout still exists
so it can be changed to whatever value is appropriate for debugging
or testing.

CRs-fixed: 382366
CRs-fixed: 383999
Change-Id: Ic0dedbadf2c100eb56ed2338914575061776e725
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_ringbuffer.c
msm: kgsl: Add GPU clock statistics.

The GPU clock statistics show the amount of time the
GPU was busy in the last one second and the time spent
at each individual clock level while it was busy.

Change-Id: I16f8973ca0c683d55406a1f37c1395cdfe43ef5a
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c
Revert "msm: kgsl: implement sync compare callback"

This reverts commit 1ae85460046371f6fccec52590c3c975610b40ca.
Revert "msm: kgsl: Add support for Android's sync point"

This reverts commit 222acd4a5229fa3ce0aeb8770539a88229f0c76d.
msm: kgsl: Add support for Android's sync point framework

The Android sync point framework will replace the synchronization
previously implemented by genlock. This change implements the KGSL
component of the sync point framework by creating a fence that is
automatically signaled by KGSL when it's timestamp expires. The
fence FD is returned to the user driver so that another process
can wait for the sync point.

Change-Id: Ifee38dfde00e551f3524f7a37833938dcdb64905
Signed-off-by: Jeff Boody <jboody@codeaurora.org>

Conflicts:

	drivers/gpu/msm/Makefile
	drivers/gpu/msm/kgsl.c
	include/linux/msm_kgsl.h
msm: kgsl: implement sync compare callback

The compare callback is required to test the order that
sync pts will signal. Failing to implement the compare
callback results in kernel panics for some use cases.

Change-Id: Ibea1497c12fd8cc66087ff52d3709a07793f215f
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
msm: kgsl: remove unnecessary definitions for dup and has_signaled

The dup and has_signaled functions are not called outside kgsl_sync.c

Change-Id: I69d746f4e4acae9b4f5a3a2cac79ac812e5eff5c
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
msm: kgsl: Hold the pm_qos vote at all times when ACTIVE

The GPU needs access to the L2 cache while running.  If the
CPU is not also active using the cache can lead to stability
issues.  Keep the CPU out of idle power collapse at all times
while the GPU is running.

CRs-Fixed: 397489
Change-Id: Iab2d8c601e903aadc4060f7c6d67bc128840edbf
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c
msm: kgsl: fix idle reporting for the msm pwrscale policy

Report idle whenever we go to nap and sleep for the msm policy

Change-Id: I490d76812b6833acd1fe7394129ce2f42483d8c2
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c
	drivers/gpu/msm/kgsl_pwrscale.c
	drivers/gpu/msm/kgsl_pwrscale.h
	drivers/gpu/msm/kgsl_pwrscale_msm.c
msm: kgsl: Don't use 'wait_timeout' in the idle functions

There are two distinct parts of the code that may need to loop waiting
for the GPU to complete a task: waiting for a timestamp and waiting
for the entire core to go idle. Waiting for a timestamp technically
doesn't need a timeout since the only downside is a process that sleeps
forever with an interruptible timeout. Waiting for the core to go idle
is more problematic because it is a busy wait and it is the last point
we can safely detect a GPU hang.

Beacuse we can (and will) not use a timeout in wait for timestamp, we
need to institute a new timeout value to be used in idle. Nowhere the
idle function is called uses a custom value for the timeout, so remove
that parameter from the calls and use a static timeout value in the
core specific functions.

Change-Id: Ic0dedbad9ecd2044c34e4cec551dc7f53b253f3d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_a3xx.c
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_gpummu.c
	drivers/gpu/msm/kgsl_iommu.c
	drivers/gpu/msm/kgsl_pwrctrl.c
	drivers/gpu/msm/z180.c