msm: kgsl: remove readl/writel use for dma memory

For dma_alloc_coherent() you don't need writel/readl because
it's just a plain old void *. Linux tries very hard to make a
distinction between io memory (void __iomem *) and memory
(void *) so that drivers are portable to architectures that
don't have a way to access registers via pointer dereferences.
You can see http://lwn.net/Articles/102232/ and the Linus rant
http://lwn.net/Articles/102240/ here for more details behind
the motivation.

Change-Id: I3da075c30304e4adf321cfb3edb1baa4a93fc2ce
Signed-off-by: Jeremy Gebben <jgebben@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 kmemleak tool does not report incorrect mem leak.

Certain memory allocations are not properly tracked by kmemleak tool,
which makes it to incorrectly detect memory leak. Notify the tool by using
kmemleak_not_leak() to ignore the memory allocation so that incorrect leaks
report are avoided.

CRs-Fixed: 334294
Signed-off-by: Anshuman Dani <adani@codeaurora.org>
(cherry picked from commit eecd52061a50325db02d2396bfd455b306a04f34)

Change-Id: If2c955f95c650a73a04aca01977dc7ac13319878
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: Do not BUG in GPU recovery if a valid context can't be found

Don't BUG() if we can't find a valid context to recover to; just fail and
go into a zombie state. This usually happens after a first hang goes bad
and the system keeps hanging while trying to find its way. The problem with
a BUG() in this case is that the system goes down and we can't recover the
snapshot or other debug information.

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

Change-Id: I68581017f6e78a866a6d91033f980ecd06d96360
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>
msm: kgsl: set the dma_address field of scatterlists

Ion carveout and content protect heap buffers do not
have a struct page associated with them. Thus
sg_phys() will not work reliably on these buffers.
Set the dma_address field on physically contiguous
buffers.  When mapping a scatterlist to the gpummu
use sg_dma_address() first and if it returns 0
then use sg_phys().

Change-Id: Ie5f19986446be4383dfbfffa2534136b592e8e46
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 582fe31d2719b45fd0accf85bf2351f1a15b97b7)
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: flush outer cache for alloc_page() pages

The outer cache needs to be flushed for these pages
after they are allocated so that the GPU and CPU
have a consistent view of them.

CRs-Fixed: 346921
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 7018a21bf2b52f1296557d1f6ec9ed64e9169de7)

Change-Id: Id5c11ab8d856fc270330fd3258baa51b8efca192
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>

Conflicts:
	drivers/gpu/msm/kgsl_sharedmem.c
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: 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)

Conflicts:
	drivers/gpu/msm/kgsl.c
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>
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: Change name of vmalloc allocator

Change the vmalloc allocation name to something more appropriate since
we do not allocate memory using vmalloc for userspace driver. We
directly allocate physical pages and map that to user address space. The
name is changed to page_alloc instead of vmalloc. Add sysfs files to
track memory usage via both vmalloc and page_alloc.

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

Conflicts:

	drivers/gpu/msm/kgsl_drm.c

Change-Id: Ia31c4ca61a699896689c3ad0c877659e21efd09c
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_sharedmem.c
msm: kgsl: Only return tlb flush flag if bit is set for given device

We should only return the tlb flush flag if the bit corresponding
to the given device is set in the tlb flags. Earlier we were returning
the flush flag always if the tlb flags had the flush bit set for any
device.

Change-Id: Ia598694b295e650ce97dde83ccd89c99e5811d06
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Check whether the ops pointer is valid.

Check that the ops pointer is valid before using it, otherwise we
may fault.

CRs-fixed: 360810
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit be9799810e79340362978979ce1ff2d9f185904e)

Conflicts:

	drivers/gpu/msm/kgsl.h

Change-Id: I59d5ee123c66b044e8d9c502ed6e641e51bf62fa
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>