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.

Change-Id: I239087435f4599b62b7da71ecea0a5878cda5037
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Pass correct datatype to kgsl_mmu_ptpool_destroy()

This fixes a crash due to NULL pointer access when allocation of DMA
Coherent memory fails.

Change-Id: I7ea7405713682aaa7cd660ef341a968342dc0880
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>
msm: kgsl: Follow reverse sequence of init procedure during exit

Fixes kernel warnings about sysfs entries being unavailable when they
are removed during exit.

Change-Id: I6caaaff935b31d3f39a3610cdd2b048baf2f1a97
Signed-off-by: Ranjhith Kalisamy <ranjhith@codeaurora.org>
msm: kgsl: Modify kgsl_core_exit to release resources carefully.

kgsl_core_exit() should not call kgsl_sharedmem_uninit_sysfs() and
device_unregister() if those resources have not been allocated.
We check this by seeing if kgsl_driver.virtdev has been
populated or not.

CRs-fixed: 359477
Change-Id: Ic040667b29bd4e006e6f29a50809d94a2bb4b469
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Add CP_WAIT_FOR_IDLE packet before updating
 timestamp

HW workaround to resolve MMU pagefault caused by memory
freeing early before GPU completes it.

This is race condition where timestamp is getting updated
and the event handler runs before the GPU actually got done
with the timestamp, hence freeing the buffer early while GPU
still not completed with it.

Signed-off-by: Anshuman Dani <adani@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno_ringbuffer.c
Change-Id: I6d338d7dca680f57f2c39ed5a14381b261bf8bce

Signed-off-by: Vikram Orre <vorre@codeaurora.org>
msm: kgsl: Add cache flush for A20x

Adding extra cache flush command to make sure that CP block
gets event from RB all the time to avoid race conditions because of
clock switches. this is to improve stability on 8x25 target.

Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno_ringbuffer.c
Change-Id: Ie411be46fa166864073d35c50085a8f2506d0eb8

Signed-off-by: Vikram Orre <vorre@codeaurora.org>
msm: kgsl: Map a guard page on the back of GPU MMU regions

Add a guard page on the backside of page_alloc MMU mappings to protect
against an over zealous GPU pre-fetch engine that sometimes oversteps the
end of the mapped region. The same phsyical page can be re-used for each
mapping so we only need to allocate one phsyical page to rule them all
and in the darkness bind them.

Change-Id: Ic0dedbad01e1eae5832bb79cc1446353656cf0af
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Optimize page_alloc allocations

User memory needs to be zeroed out before it is sent to the user.
To do this, the kernel maps the page, memsets it to zero and then
unmaps it.  By virtue of mapping it, this forces us to flush the
dcache to ensure cache coherency between kernel and user mappings.
Originally, the page_alloc loop was using GFP_ZERO (which does a
map, memset, and unmap for each individual page) and then we were
additionally calling flush_dcache_page() for each page killing us
on performance.  It is far more efficient, especially for large
allocations (> 1MB), to allocate the pages without GFP_ZERO and
then to vmap the entire allocation, memset it to zero, flush the
cache and then unmap. This process is slightly slower for very
small allocations, but only by a few microseconds, and is well
within the margin of acceptability. In all, the new scheme is
faster than the default for all sizes greater than 16k, and is
almost 4X faster for 2MB and 4MB allocations which are common for
textures and very large buffer objects.

The downside is that if there isn't enough vmalloc room for the
allocation that we are forced to fallback to a slow page by
page memset/flush, but this should happen rarely (if at all) and
is only included for completeness.

CRs-Fixed: 372638
Change-Id: Ic0dedbadf3e27dcddf0f068594a40c00d64b495e
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add new sysfs node to list GPU clock frequencies

Add a new sysfs node to communicate available GPU clock frequencies
to userspace for the power daemons.

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

Conflicts:

	drivers/gpu/msm/kgsl_pwrctrl.c

Change-Id: I21fd05aec3a633f82d3dc396240f6e91bcdb8425
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
msm: kgsl: Return error if the user allocates a buffer size of zero

Instead of calling BUG_ON if the user passes a zero length via
IOCTL_KGSL_GPUMEM_ALLOC to kgsl_sharedmem_alloc_user, return
-EINVAL instead and propegate the error back up to the user.

CRs-fixed: 389886
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 611fd265950cfa1daaa0adf08500b79901cd56d6)

Change-Id: I1fe9de717cc708b509f1d577b910b7a80e2a681b
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
Merge changes I1fe9de71,I21fd05ae,Ic0dedbad,Ic0dedbad,I7f0d7683,I102f897d,Ic040667b,I6caaaff9,I7ea74057,I23908743 into jb_chocolate

* changes:
  msm: kgsl: Return error if the user allocates a buffer size of zero
  msm: kgsl: Add new sysfs node to list GPU clock frequencies
  msm: kgsl: Optimize page_alloc allocations
  msm: kgsl: Map a guard page on the back of GPU MMU regions
  msm: kgsl: Add cache flush for A20x
  msm: kgsl: Add CP_WAIT_FOR_IDLE packet before updating  timestamp
  msm: kgsl: Modify kgsl_core_exit to release resources carefully.
  msm: kgsl: Follow reverse sequence of init procedure during exit
  msm: kgsl: Pass correct datatype to kgsl_mmu_ptpool_destroy()
  msm: kgsl: Change name of vmalloc allocator