msm: kgsl: Fix adreno idle detection during hang

Adreno idle detection during a hang was being obstructed when
called from adreno_waittimestamp(). The variable active_cnt which
was meant to protect the device from going into suspend while
doing a waittimestamp was being set and was preventing the
check of rbbm_status register which was leading to a false hang
detection, where, if the rbbm_status register value had been
probed the device would have been found to be idle. We fix this by
having a separate function is_adreno_rbbm_status_idle() which checks
this register and report whether the core is idle or not. And we call
this function instead of the generic adreno_isidle() inside
adreno_hang_detect(). Doing this fixes at least one scenario of false
hang detection.
CRs-fixed: 406631

Change-Id: I44b5446769eaa361cca63674f700153ee3faff45
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Rajeev Kulkarni <krajeev@codeaurora.org>
msm: kgsl: Check the current interrupt status before power operations

Sometimes the core will go idle before the interrupt can be handled on
the GPU. If that happens then we could go to a lower power state before
cleaning up the pending interrupt and various entities that might be
waiting for it. Consider the current interrupt status when checking
for idle.

CRS-fixed: 449813
Change-Id: Ic0dedbadfd2d40e4411cf3b05e1eb4c4eecf7841
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_a2xx.c
msm: kgsl: Remove invalid context_id logging

Remove printing of "invalid context_id" messages and
replace those with simply returning with -EINVAL. The
messages serve little purpose and their removal alleviates
kernel log spamming.

CRs-fixed: 449050
Change-Id: Id0d6538d228e7dc928a628bdffde8c952ec5d6fe
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Don't consider active count if not in active state

Don't consider active_cnt variable if not already in ACTIVE state.
The active count variable does not necessarily exactly indicate the
number of open handles to GPU for switching power state. Hence,
only wait for active count to reach zero before switching to SUSPEND
state if, the current state is ACTIVE.

CRs-fixed: 483154
Change-Id: Ie025a1873cfb9237bdfba89204f4c2116549eba4
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: clean up use of memdesc->hostptr

Some external memory types were using hostptr to store
a userspace virtual address, but other code assumes it is a
kernel virtual address. Make memdesc->hostpr always
be the kernel virtual address and add a useraddr
field for the userspace virtual address.

Change-Id: Id4580a2ff34aeb15f2c1b26a7134f0fd4ec52a6e
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Use ERR_PTR to return errors from kgsl_create_context()

Normally kgsl_create_context() returns a pointer to a new context.
In case of errors it just returns NULL pointer, and that doesn't allow
to propagate the right error code back to the user via
kgsl_ioctl_drawctxt_create()
This fix modifies kgsl_create_context to use ERR_PTR macro for passing
error codes to its caller.

Change-Id: I447c1765828912b0994bcae67a73864e62eef9b6
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>