msm: kgsl: Synchronize access to IOMMU cfg port

Add a software based spinlock between CPU and GPU.
This spinlock is used to grant mutually exclusive access to
SMMU configuration between CPU and GPU. This mutual exclusion
is required to prevent deadlock in the system.

CRs-Fixed: 409198
Change-Id: Ic375beaaf4c5505b41d3fabc4adf15965d71b13a
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: pass mmu pointer into address space query functions

This allows address space and pagetable configuration to be
set from data in the mmu, such as devtree settings.

Change-Id: I811b2d8bbac2613a0ea51795f7cd4b121ec203da
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Add in-stream support for IOMMU-v1

Add support to perform in-stream pagetable updates and tlb
flushes for IOMMU-v1. This is only supported if the IOMMU
hardware includes halt lock supprt. The IOMMU halt lock is
held when writing to TTBR0 register of IOMMU unit from the GPU.
This prevents the GPU pre-fetcher from using the IOMMU
while TTBR0 is being updated.

Change-Id: I43dab204d9f10a97fc1db53d120dcab1f5e9a5af
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Use increasing delays to transition to NAP

When active count goes down to zero, the GPU is about
to be idle.  Wait for it to go fully idle and transition
to the NAP state.

Change-Id: I06ed7bc07125e757ae2d665b2fd4135a6e0296fe
CRs-Fixed: 436977
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Do not store timestamp for null context in pagefault handler

If the pagefault happened in a NULL context do not try to store
global timestamp information, this change prevents null pointer access
and kernel panic.

Change-Id: I42a8824adf33ad8eecceed0801146d6aefab4924
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Turn on timestamp based IOMMU clocking for IOMMU-v1

Turn on timestamp based clocking for IOMMU-v1. This was turned
off due to global timestamps not being updated correctly. Since,
global timestamp updates are now fixed turn this feature on.

Change-Id: I26a0b10b4b3982882ef304bae68b24b1d876bc7d
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Report cff dump virtual address range correctly

When IOMMU is used then the vitual address can range from the base
address used when per process pagetable is disabled upto the last
address that can be assigned to a kgsl allocated memory region.
Report this range correctly in CFF.

Change-Id: Ib1798434b60f1e3cd4c0570456bf4b075ffa2afd
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: reduce iommu pagefault logging

Remove duplicate log messages that were happening for
every iommu page fault.

Change-Id: I13bebcd3e93165d1b22ca859c39d0b169d3a53eb
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Print out page fault memory usage info

Add the memory usage info in the GPU page fault error message.
This help GPU page fault debug

Change-Id: I40988e7572781a2935a099046163560edcab9432
Signed-off-by: Alex Wong <waiw@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Use the correct flag when checking for cpu map

Report whether cpu mapping can be used or not by checking for
this flag instead of per process flag.

Change-Id: I554e93c3ad551a69fd385415d1757bfd866c9255
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Restrict GPU virtual address when using CFF

If CFF is enabled then the GPU virtual address range needs
to be restricted to 512MB. This is a requirement of the virtual
platform on which the CFF vectors are replayed.

Change-Id: I77663edee942c26206e4a058f2bf47369e2348e6
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Fix checking of validity of process private pointer

When walking through the list of process private pointers if the
right pointer is not found then process private pointer may not be
NULL. Hence, checking the validity of process private pointer based
on it being NULL is incorrect. Fixed this.

Change-Id: I79bec9dc3fb80342dfc771d427a0f5bad805295f
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Get an active count during CFF

When CFF is running we cannot restart the device. This is because the
simulator cannot handle device restarts in playback. Get an active
count when CFF is enabled so that device is always up.

Change-Id: I3214237e165e0cc23ada12f8a52361155b3c3ec1
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Remove earlysuspend code

The earlysuspend API is gone now that proper wakelocks are
upstream. Remove earlysuspend code from the kgsl driver.

Change-Id: I8d264beb63b9ac92de2b25fa77916278d8882c6d
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Add fault count to snapshot debugfs

Additional faults can occur between when a snapshot is frozen
and the snapshot is read.  Keep track of the total number of
faults encountered to keep track of how the GPU is actually
doing on multi-hour test cases.

Change-Id: I392fce74e7d215aa7bd0e1a7ce5c9f340413cd53
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
gpu: msm: Allow retries for 0 order allocation

When allocating order 0 pages we allow the allocator to retry
the allocation to ensure we can take advantage of pages that
are being reclaimed. This will help avoid unnecessary out
of memory errors from kgsl clients.

Change-Id: Iec2a0a1fe10302c320a58cef90ae1ee7e35d71ee
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Add support for coresight

Adding support for Coresight debug bus to work with the GPU,
including registering graphics core with Coresight and a coresight
interface to GPU through sysfs.

Change-Id: I9508659ca7d7d67e8a8becba41d06be76360c570
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Fail if sysfs or debugfs initialization fails

While creating a new process struct for kgsl, clean up resources
and bail if sysfs or debugfs initialization fails. This prevents
errors further down the line.

CRs-fixed: 509931
Change-Id: If0857628a56eecf4855013aaf313de28ac9ad108
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Provide a sysfs interface to force GPU clocks/bus on

Simplify debugging by providing an unambigious means for keeping
the clocks and/or bus permanently enabled.

Change-Id: Id537a70992f4e07e6b59de80daffdd116649229e
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: Check pagetable pointer before dereferencing it

Make sure that pagetable pointer is valid before dereferencing the
pointer. The pagetable pointer may be invalid if a new process is
added to the process private list and its pagetable is not yet
initialized. This can happen because a process private pointer is
added to the list and this list is guarded by kgsl driver mutex,
but the initialization of the process private pointer happens
later after the kgsl driver mutex is unlocked. So this can cause a
situation where a process private pointer is on the list but its
pagetable is not yet initialized.

CRs-Fixed: 490374
Change-Id: I2807ac557d9b640b2ca1e02f88f245cc87abcff4
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>