msm: kgsl: Fix gpu idle check

Fix the mask being used to check whether gpu has a pending
irq or not and check whether gpu status is idle before checking
for a pending irq. If pending irq is checked before the gpu
status then there is a possibility of the irq being set after
it has been checked but before the gpu status is checked which
will result in the logic detecting that gpu is idle with a
pending irq.

Change-Id: I5f97b6f3f4c6b58c95e91604ae87330d06685962
CRs-Fixed: 647176
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

msm: kgsl: Change check for gpu idle

Check whether gpu is idle by checking if any of its bits in
RBBM_STATUS is set except for AHB and HI bits.

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

msm: kgsl: Clean-up unneeded power code

No platforms with direct ebi1 connections exist, nor
is idling before changing the frequency needed.

Change-Id: I80911c81ef7303e229494ce6ba3df57ee25b24a5
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

msm: kgsl: Set the GX rail voltage before enabling it

Make sure the rail turns on with a consistent voltage.  Also
this sequence moves an RPM call from after the rail is on to
before it is powered up which saves a bit of power.

Change-Id: Ided5f9777879fa48fd594c84b31cec9cdf513098
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

msm: kgsl: Add traces for the constraints API

This interface helps with debugging when an application
requests for a pwrlevel constraint to be set/unset. It
also traces when the constraints actually come into affect
and when they could be revoked.

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

Conflicts:
	drivers/gpu/msm/kgsl_pwrctrl.h

msm: kgsl: fix MIN power constraints in non-trivial cases

Switching from a MAX to a MIN power constraint in the same
context is broken.  So is switching from a MAX context constraint
to a MIN constraint on a different context.  Clarify constraint
ownership, update the timestamps accordingly, and reset constraints
when changed by the context.

Change-Id: Id27dbc20e2aac994101817af3857451c1703219e
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

msm: kgsl: Remove the busy waiting loop from idle_check

Previously there were issues with extra long GPU sequences
running during the idle_check NAP attempt thwarting the
transition to NAP.  With the dispatcher architecture this
is much less likely to occur.  In addition the dispatcher
increases chances of a very short pause between a command
coming in and being submitted increasing the occurence of
"micro-NAPs" being caught by this loop.  These extremely
short NAP periods are actually a power loss on the CX rail.
Given that hw clock gating will take care of any long GPU
command tails remove the busy wait loop for power savings.

Change-Id: I4efc6215689c42ab03d4e478ad97839208d04004
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

gpu: msm: Add missing trace include

Change-Id: Iefaa252a8cef43e5037f4bf3232560a44b11cb3f

msm: kgsl: Wait for dispatcher on adreno idle

When waiting for the adreno device to become idle wait for
the dispatcher to complete processing commands that are
already submitted to the ringbuffer and prevent dispatcher
from submitting more commands while a thread is waiting for
dispatcher to become idle. This is required to support mutiple
ringbuffers where it is not sufficient to just wait for current
ringbuffer to become idle. All ringbuffers need to be idle and
to do that dispatcher needs to run without submitting more
commands but retiring commands that have been submitted.

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

Conflicts:
	drivers/gpu/msm/adreno_dispatch.c

msm: kgsl: Add CFF capture for IBs

If CFF is enabled, when an IB is submitted to hardware
parse it to find all objects in it and dump them.

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

msm: kgsl: Use the correct method for exporting trace event functions

Use EXPORT_TRACEPOINT_SYMBOL instead of my lazy "trace" wrappers for
trace_kgsl_regwrite and trace_kgsl_issueibcmds thus saving lots of
code and a shred or two of dignity along the way.

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

Conflicts:
	drivers/gpu/msm/adreno_ringbuffer.c
	drivers/gpu/msm/kgsl.h

msm: kgsl: Idle the dispatcher before writing perfcounter select

The GPU must be idle before writing to the perfcounter select
registers to avoid an AHB timeout. Idle the GPU before writing
to the register.

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

Conflicts:
	drivers/gpu/msm/adreno.c

msm: kgsl: Avoid race conditions with GPU halt variable

1. Take the device mutex before we check for GPU halt.
It's quite possible that after checking gpu halt this
thread might be preempted by kernel, other thread can
update the gpu halt. This will lead to a situation
where other thread has requested to stop sending cmds
and this thread might be sending cmds to ringbuffer.

2. Handle multiple threads changing the halt variable.
It's possible that one thread has set the halt value
and other thread clears that value.

3. init_completion() cannot be used to reinitialize
completion when reusing completion object,
INIT_COMPLETION macro should be used instead.

CRs-Fixed: 667179
Change-Id: Ie41c69be35bfd3ca14f3ce782ab45efb70aaf46a
Signed-off-by: Prakash Kamliya <pkamliya@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_dispatch.c

msm: kgsl: Avoid another race condition with GPU halt

A race condition may occur while clearing GPU halt
from _adreno_start() in one thread and at the same
time decrementing it inside adreno_put_gpu_halt()
from adreno_dispatcher_idle_unsafe() in the other
thread. This can cause BUG_ON as "halt" value would
become negative.

Clearing GPU halt inside _adreno_start() should not
be required explicitly for below reasons:
1. "halt" is member of static global variable, so it
would be initialized to zero at the beginning.
2. Commands submission to GPU from the thread executing
_adreno_start() should be blocked until "halt" is reset
back to zero from adreno_dispatcher_idle_unsafe().

CRs-Fixed: 678633
Change-Id: I06bbf4ad751a72b2e943365c1ac1952f67ac299c
Signed-off-by: Prabhat Awasthi <pawasthi@codeaurora.org>