msm: kgsl: Use the kmalloc/vmalloc trick for the sharedmem page array

It was previously assumed that most GPU memory allocations would be
small enough to allow us to fit the array of page pointers into one
or two pages allocated via kmalloc.  Recent reports have proven
those assumptions to be wrong - allocations on the order of 32MB will
end up trying to get 8 pages from kmalloc and 8 contiguous pages
on a busy system are a rare beast indeed.

So use the usual kmalloc/vmalloc trick instead - use kmalloc for the
page array when we can and vmalloc if we can't.

CRs-fixed: 513469
Change-Id: Ic0dedbad0a5b14abe6a8bd73342b3e68faa8c8b7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Use the correct length when looking for address collision

Use the right length of allocation from the aligned base address of
CPU virtual map to look for collision in the GPU vitual map. This
prevents discarding of usable address ranges due to false collision
hits.

CRs-Fixed: 492041
Change-Id: I370e6a31f98803e8ca6858a5562f47afeeaa157e
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Prevent race conditions when freeing memory

Multiple threads can call an ioctl to free a memory region.
Only one of these threads must be allowed to free memory and
the rest can return without freeing. Add a new pending flag
which is tested and set in a critical section guarded by
spinlock to prevent multiple ioctl threads from freeing the
same memory.
Also, a thread could be freeing a memory region that is
in use by another thread. Ensure that the detachment of the
memory from the process list and freeing of the memory always
happens in the same thread. This will prevent a situation where
the memory is being used by a thread which is detached from the
process list and is yet to be freed.
Seperate the selection of gpuaddr and mapping into pagetable. The
gpuaddr assignment needs to be done with process memory lock held
in a critical section but the mapping into pagetable can be done
separately without holding memory lock.

CRs-Fixed: 495144
Change-Id: Idf85fbd4bca29c18597f4b0e737c207f002ab266
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Only reference the rb_node after taking spinlock

Derefernce the rb node after taking spinlock since the root
node can change and is supposed to be guarded by the spinlock

CRs-Fixed: 495129
Change-Id: I63de7755cf9d5fb548c082f43403000bcef5721b
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Only initialize process structure once

If the debug root of the process structure is initialized
then it means that the remaining fields will also be
initialized. Check this field at the beginning of the
initialization routine and skip to end of the function. This
also by-passes the reinitialization of some fields because
of errorneous NULL pointer check of rb node. The rb node is
always initialized to NULL so checking if it is NULL to
determine whether the pointer is initialized or not is wrong.

CRs-Fixed: 498014
Change-Id: I73b2124c037187bc96942714dac62c0a72c26372
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Do not hold memory spinlock when calling find region function

The function kgsl_sharedmem_find_region holds the memory spinlock
at the beginning of the function so we do not need to hold the lock
before calling the function

Change-Id: I20ee32e0ed6aee6ed61cdd4fb7a9cc08a876fc84
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Add a missing mutex unlock

Adding a missing mutex unlock where we return from
kgsl_late_resume_driver if we fail to wake up the device.

CRs-fixed: 500422
Change-Id: I26b56d95a9427798719fb162d1b1edaf641ae57b
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Skip perf counters and Sync lock for A2xx.

Fix includes two changes:

- Skip Perf counters for A2xx since these are intended only for A3xx.
- Don't use GPU-CPU sync lock for A2xx to avoid bootup failure.

Change-Id: I9e1d349b95dd0f6470ab507167b53540f1f1acf7
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
msm: kgsl: Always resume the GPU regardless of its state

Make sure we resume the GPU regardless of its current
state. If the device is not in suspend state restart the
device and  print an error message.

Change-Id: I9e71cbe27d360dc06513c54f3a734aaea5b10d2b
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: generate descriptive names for kgsl-timeline

Generate names for kgsl-timelines using the following format:
<device>-<thread name>(<tid>)-<proc name>(<pid>)-<context id>

This makes it possible to identify the context of a timeline in the
sync dump, which makes it much easier to identify which context has
a GPU timeout.

Change-Id: I0ce0614a53a93fd81094d92c9bef7053e6d416d2
Git-commit: e3348f389f715cb2143a708ec6796d3f65e03821
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: show timestamp in sync dump

Improve the debug information printed for kgsl points and timelines.

kgsl_sync_pt_value_str:
  - show timestamp passed to kgsl_add_fence_event()
kgsl_sync_timeline_value_str:
  - show most recent timestamp passed to kgsl_sync_timeline_signal()
  - show last retired timestamp according to kgsl_sync_get_timestamp()

Change-Id: I93fe408b06de054b11e05784cd7175ed3fcb76ad
Git-commit: 595e213985f63d6aa484c966a4f4a710b31ca209
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
gpu: msm: Fix context name

Change-Id: I591a98a6e22658342530141efbb0c68961674e81
msm: kgsl: Map sync lock variables to every pagetable

Map sync lock variables to every pagetable since we don't
use TTBR1 anymore.

Change-Id: If2d43c4c57d0cdcf6076229dfad32c0375e74df4
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
msm: kgsl: Add a check to free the kgsl_timeline object.

Add a check to free the kgsl_timeline object only after
destroy flag is set. This is to avoid further references to timeline
from kgsl if it is already freed and also to catch any unbalanced
kref count.

Change-Id: I8017b9a928a26b703eb92b17ab6a361e4b479e5a
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
msm: kgsl: Wake up gpu on kgsl_ioctl_timestamp_event only if necessary

Any call of kgsl_ioctl_timestamp_event wakes up gpu. In some cases
(like retired timestamp) it's not necessary. Wake up gpu only if it's
necessary.

Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
Change-Id: I845faf6e9c6e4c9882a68489b64223919be3d21c
msm: kgsl: Do not try to resume the device from INIT state

If the device is still in INIT state there are no open instances
of it running.  Resume calls should be no-ops.  Do not attempt
to start the device at this point.

Change-Id: I1cb6d60581b0b5b0a2ab1b13418adc4ae3983c5e
Signed-off-by: Lucille Sylvester <lsylvest@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>
msm: kgsl: Properly record the size of the sglist in the memdesc

It was possible to fail out of kgsl_sharedmem_alloc after a sglist was
allocated but before we saved the size of the allocation which caused
problems when the sglist was freed during cleanup.

CRs-fixed: 464289
Change-Id: Ic0dedbadd57ec4d9422b5e3a873243d0ffed51f7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>