msm: kgsl: Dereference pagetable pointer after checking it's not NULL

The pt pointer was being checked against NULL value after it was
dereferenced

Change-Id: Ifbdeb7bec5e3f28396196d8f55356e5dbf1a2e55
CRs-Fixed: 336516
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit c0f21b6bc1fcb73900ea845e05a42a2de6fd8dde)
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: 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>
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>
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: 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>
msm: kgsl: fix size checking in adreno_find_region

This function is supposed to return the memdesc that
contains the range gpuaddr to gpuaddr + size. One of the
lookups was using sizeof(unsigned int) instead of size,
which could cause false positive results from this function
and possibly kernel panics in the snapshot or postmortem
code, which rely on it to do bounds checking for them.

Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit 1ab51045b57edc5af3079599cfc9b843b03843f9)

Change-Id: I818c603f5b301865a87ec6bd84e6a6922c7c3234
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>