msm: kgsl: Don't access context memory after it's freed

Context memory was potentially accessed after being freed. Fix this
by incrementing the context's refcount at strategic places.

Change-Id: I31049bdd3eb9ac52160ca593619fcc8a32d4ddee
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
msm: kgsl: Add NULL check for next_event hook

KGSL driver needs to check that the function pointer
is not NULL before calling the hook. next_event
is an optional function not implemented by the 2d
core. This fix ensures that optional and unimplemented
function will not invoked by the driver.

Change-Id: I687b028260e3ec304d973c6a5bded0a8fdbfb73b
Signed-off-by: Hareesh Gundu <hareeshg@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>
gpu: msm: Allow retries for 0 order allocation

When allocating order 0 pages we allow the allocator to retry
the allocation to ensure we can take advantage of pages that
are being reclaimed. This will help avoid unnecessary out
of memory errors from kgsl clients.

Change-Id: Iec2a0a1fe10302c320a58cef90ae1ee7e35d71ee
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>