msm: board-msm7x27a: Increase Idle timeout

For 7x27a and 7x27, clocks are controlled by modem. To improve stability,
reduce number of interactions to modem to turn on and off GPU clocks.

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

Conflicts:

	arch/arm/mach-msm/board-qrd7627a.c
	arch/arm/mach-msm/devices-msm7x2xa.h

Change-Id: I65503fcb6b2949a3a5925cd6190486b6e17116d6
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
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: 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: 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: increase valid timestamp range

The existing timestamp_cmp function returns a different
result depending on the order of the input parameters due to
having an asymetric valid window. When no rollover is
detected the window is 2^31 but when a rollover is detected
the window is 25000. This change makes the rollover window
symmetric at 2^31.

CRs-fixed: 347631
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
(cherry picked from commit beb4a64b08ac49d4e01f4dd0c911c14ed6939f6d)

Conflicts:

	drivers/gpu/msm/kgsl.h

Change-Id: I22dcc773438df32f105dc8bd069051c48fde5018
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: Allocate physical pages instead of using vmalloc

Replace vmalloc allocation with physical page allocation. For most
allocations we do not need a kernel virual address. vmalloc uses up
the kernel virtual address space. By replacing vmalloc with physical
page alloction and mapping that allocation to kernel space only
when it is required prevents the kgsl driver from using unnecessary
vmalloc virtual space.

CRs-Fixed: 346921

Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
(cherry picked from commit 8cb835b656ae2c3faa79af4f374563d344b46d4a)

Conflicts:

	drivers/gpu/msm/kgsl_sharedmem.c

Change-Id: I88e1eb282cc4822970811728d00b1096188f64e9
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@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)
gpu: ion: Add support for IOMMU in CP heap

ION clients allocating from a content protection
heap (cp heap) must be able to map the memory to
an IOMMU when IOMMU are being used.

Add callbacks to CP heap to support IOMMU mapping.

(cherry picked from commit 1c94f7be2d3fcd48978bd5276532beec184f5d74)

Change-Id: I81e726e98b8cc4b12fe8f4734c0da18a15968aee
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
gpu: ion: Allow smaller mappings

Clients using ION must be able to mmap a smaller
set of pages than what was allocated from the
IOMMU heap.

Add check that we don't try to map a page passed
the end of the vma.

(cherry picked from commit dbec7db15ddbf7d9b529077ffa61b9b2c30b33a0)

Change-Id: Iaf63a1099510ec4cdbcd294762b451037fe7784a
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 9c2eabefcb4e745b0c8f3bd90ee5fed742fc0e93)
gpu: ion: Add cache operations to IOMMU heap

The IOMMU heap must support cache operations so that clients
can do cached allocations from the heap.

Add function to perform cache operations on memory
allocated from IOMMU heap.

(cherry picked from commit ef0107124e052b86ce883ee6b0c1488d26de0775)

Change-Id: I59a6c6949432cc783b4bd3d7bd212da35bfe73ff
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
gpu: ion: Add map_dma support in IOMMU heap

IOMMU is missing support for ion_map_dma.
ION clients need support for this api.

Add functions to implement ion_map_dma and
ion_unmap_dma in the IOMMU heap.

(cherry picked from commit ab804b883a58c44df40e92940ac4dae3a91e7beb)

Change-Id: I2f2664b07d7a8c42ff8c915fa23ce159a84899ed
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
gpu: ion: Map a range into the IOMMU

Instead of mapping 1 4K page at a time into the IOMMU create a
scatterlist and map everything at once. This will be more efficient.

(cherry picked from commit 16cdb41acb58dc352994e9b27a9344b1337b0c46)

Change-Id: I8488cc8e6d013d1e62c6ea5fcfc2425384daefe9
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
iommu: Fix flags passed to iommu map functions.

iommu map functions requires clients to specify whether
the mappings should be read only or read-write (write only
is not supported). Ensure clients specify the appropriate
flags when calling map functions.

Change-Id: If42b4b0367b4311aa36d3063979ef04af3a43fc6
Signed-off-by: Olav Haugan <ohaugan@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: 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>

Conflicts:
	drivers/gpu/msm/kgsl.c
(cherry picked from commit c9559e461e3df1b828218421430a38c9d7a38ca4)

Change-Id: Ie1639fe75718038c8149e519952f7085dede4c0a
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>
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>

Conflicts:
	drivers/gpu/msm/adreno.h
	drivers/gpu/msm/adreno_pm4types.h
	drivers/gpu/msm/adreno_ringbuffer.c
(cherry-picked from commit d0ab6adeeae7dd039069fd93e6649777aff23668)

Change-Id: If7c93596d0228792002868a56cdf61dc9d34dd5c
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>
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.

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

Conflicts:
	drivers/gpu/msm/kgsl_sharedmem.h

Change-Id: I6b676b4d72f20b43a4cbf3a51099aaa2e8aa8b66
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>
msm: kgsl: fix 2d IB processing

The 2d hardware handles ringbuffer and IB commands as
a series of gotos. At the end of each IB, there must
be a goto command back to the ringbuffer, which must
be "monkey patched" into the IB by the driver.
Fix this code to use a proper kernel mapping.

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

(cherry-picked from commit d27b09f388bab25f7e15ed9c5ca5eb1203c85492)

Change-Id: Ib61d612e9f6f38be147e620eaf6086396ec86228
Signed-off-by: Jeremy Gebben <jgebben@quicinc.com>