msm: kgsl: Add ION as an external memory source (CodeAurora)

Allow ION buffers to be attached via IOCTL_KGSL_MAP_USER_MEM

Change-Id: Ic0dedbada34d12fb70b528f3a93dd21805a4c8a4
msm: kgsl: Create ion client in the probe function

Move the call for creating the ion client from kgsl_setup_ion to
kgsl_device_platform_probe. Keeping the create ion client call linked to
kgsl_ioctl_map_user_mem made the user process which first used this
ioctl be forever visible as an ion client in debugfs, even when the
process itself had terminated. Creating ion client in probe ensures that
kgsl appears as the ion client in debugfs and avoids confusion.

CRs-fixed: 349112
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
(cherry picked from commit f48af7f2fc1f2c863c48b6d4c65f83ef65228eb7)

Change-Id: I193cd495939210274c7e5d7a6910c319355f3205
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: call sysfs_notify when a hang snapshot is made

/sys/class/kgsl/kgsl-3d0/snapshot/timestamp will have sysfs_notify()
called when a hang happens, so that a userspace process can
poll(2) on this file to detect a hang.

CRs-Fixed: 354385
Change-Id: I0a3c8fcbe3fb09256bcd12f6e63c107536734485
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 90812c8eac42b5ce7bb48e35897537021e01e6de)
msm_rotator: add rotator ref count to cleanup code

Perform cleanup of rotator sessions only if reference count reaches 0,
this avoids closing rotator sessions from sibling threads.

Change-Id: I83add90cc04faa90c372dde09a096c7a07be528a
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
(cherry picked from commit cea80ac8448ded8bbba56f1eb219857526270874)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: rotator: update user session parameters for all rotator start calls

Session parameters hold the dst format of rotator output, this is
currently passed to userspace only on new session, if session is reused
with different format session not updated and can cause incorrect
display output configuration.

CRs-Fixed: 349903
Change-Id: I5dd3f277b0d5fac145c805f4898c799ef4fb1b94
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
(cherry picked from commit c56399542e5a015f2f10cdc443365167a5f17f2a)
msm: rotator: codes clean up
msm: kgsl: Write the retired timestamp on resume

Write the retired timestamp into the expected location. This fixes
userspace crashes after resume when the retired timestamp is read
as 0 instead of the expected last timestamp.

CRs-Fixed: 350556
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
(cherry picked from commit 68dba7b544a9f2351d61dff7f7c47aaff96d0413)

Change-Id: Ib57e7d59b5481357ab6f23b460ea435462192065
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm_fb: display: add YUV444 MDP format support
msm: vidc: fix klockwork issue from HTC
msm: kgsl: release the wakelock when going to suspend

This change is needed only if slumber is disabled
CRs-Fixed: 355216
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
(cherry picked from commit 48e727689b8fabbb44f20e86f1ad6a04b8111e0a)

Change-Id: Iedcfce9b422c4441442d2a8b667e7ed2ad189348
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: disable early suspend and late resume for 2d cores.

The powerrail off during slumber is causing a GPU hang

CRs-Fixed: 355216
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
(cherry picked from commit 2bd5c33b0c7a47fffc089ced6d14efc0369a5bdc)

Change-Id: I6582aa2fb428f87f5b16975b747e147c673731bb
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: Do not dereference pointer before checking against NULL

The pagetable pointer was checked against NULL after being used.
Check against NULL first and then dereference it.

Change-Id: I714de9e3b153f212cb92502a21c7d720dd4e1e37
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: convert timestamp_cmp logic to use unsigned logic

The meaning of timestamps becomes difficult to understand when
converting between unsigned and signed values. Values that
were seperated by 0x80000000 also returned inconsistent
results.

CRs-Fixed: 355752

Conflicts:

	drivers/gpu/msm/kgsl.h

Change-Id: I5d5d1ad64ef120da8769d72ac69dde37f8f5c6ae
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
msm: kgsl: fix cleanup code in kgsl_ioctl_map_user_mem()

ion handles need to be handled differently than pmem or
ashmem handles.

CRs-Fixed: 359268
Change-Id: I20637644f247859245fbba80e5bc6b50fd896403
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 53d4dd028583c3d0a97233d3dff4336ae086ca91)
base: genlock: allow synchronization with a single gralloc handle

In order to support synchronization in a process with a single
gralloc handle we require the ability to write lock a buffer
while it is already read locked by the same handle. This change
extends the concept of an exclusive write lock or recursive read
locks to a genlock handle (rather than the genlock lock).
Genlock cannot provide deadlock protection because the same
handle can be used simultaneously by a producer and consumer.
In practice an error will still be generated when the timeout
expires.

CRs-fixed: 356263

Signed-off-by: Jeff Boody <jboody@codeaurora.org>
(cherry picked from commit 6d9076fe46bcba71986a25cf357e71a4d83958c1)

Change-Id: I5d02591586023f4b622915522e2e038c16c9f2f2
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: Add a new property to IOCTL_KGSL_DEVICE_GETPROPERTY

Return the reset status of the GPU unit when
IOCTL_KGSL_DEVICE_GETPROPERTY is called with
type KGSL_PROP_GPU_RESET_STAT

(cherry picked from commit 2dfe5dd0c53c8f9abc83bc6a9671d499c8135f68)

Change-Id: I6109b2d161e1c5a82363b582e2c1f106e2753742
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: kgsl: Make sure that gpu clock goes to turbo after wake

Change-Id: I11348ac36a81ca2bdaf708d2340f2589b88a7d45
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

msm: kgsl: Stop the device during sleep

For 7x27, 7x27A and 7x25A, stop the kgsl device during sleep.This
improved PDT stability results and 72hrs stability on customer devices.

CRs-Fixed: 339805
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
Signed-off-by: Sudhakara Rao Tentu <srtentu@codeaurora.org>
(cherry picked from commit fe4bede74b7c767412467f53c827528e3ad6bea4)

Conflicts:

	arch/arm/mach-msm/devices-msm7x27a.c
	drivers/gpu/msm/kgsl_pwrctrl.c

Change-Id: I7953947e8b9c8b5109e52b8af49857b7c9e941c0
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
msm: kgsl: Store process mem entries in a rbtree

The list of memory objects attached to a process gets searched quite
a lot during normal operation of the driver.  For processes with a
lot of memory allocations, the linear search through the list is O(N)
and uses a lot more CPU during critical loops than it should. Change
the mem entry list to a rbtree for faster search speeds.

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

(cherry picked from commit c9559e461e3df1b828218421430a38c9d7a38ca4)

(cherry picked from commit 33bceb148eaadf18ea91378dd9b9ac5861b36a09)

Change-Id: Ic769e0d2bb52cb4d14955942ce6bd8744d8a5995
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: rework ib checking

Separate ib parse checking from cffdump as it is useful
in other situations. This is controlled by a new debugfs
file, ib_check. All ib checking is off (0) by default,
because parsing and mem_entry lookup can have a performance
impact on some benchmarks. Level 1 checking verifies the
IB1's. Level 2 checking also verifies the IB2.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>

CRs-Fixed: 351811
(cherry-picked from commit d0ab6adeeae7dd039069fd93e6649777aff23668)

(cherry picked from commit f6924037a5d56f2934ef7d2b2cafb5ab3e49c94e)

Change-Id: Iebf462c29021cf0b7a830a8ff2d4cebcc3a39d43
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: Use kzalloc to allocate scatterlists of 1 page or less

The majority of the scatterlist allocations used in KGSL are under 1
page (1 page of struct scatterlist is approximately 1024 entries
equalling 4MB of allocated buffer).  In these cases using vmalloc
for the sglist is undesirable and slow.  Add functions to check the
size of the allocation and favor kzalloc for 1 page allocations and
vmalloc for larger lists.

CRs-Fixed: 351811
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry-picked from commit a652a07b0d719c4925ca45c018432888dd2388a4)

(cherry picked from commit 157ce2805727972f48881b37ba1ffe192b1801c6)

Change-Id: I54ff7011cfcbe8128e93063d2b43bc0688902a8f
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>