msm: kgsl: Allow tasks to signal pending events

Add a type parameter to event callbacks to give tasks a way to
communicate error conditions to the callback. Current type values
are KGSL_EVENT_TIMESTAMP_RETIRED for normal timestamp expiry and
KGSL_EVENT_CANCELLED if the event is cancelled prematurely.

Change-Id: Ic0dedbad9907cd50642a604a3af562e01a4b4a3b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl.h
msm: kgsl: Add memfree_history debug feature

A kgsl user can free up an allocation of GPU memory with
kgsl_ioctl_sharedmem_free() function, but the GPU address
might still be in use resulting in a GPU page fault.
A bug of this kind is hard to find because the driver keeps
no trace of kgsl_ioctl_sharedmem_free calls.
This change implements a "memfree history" debug feture that
allows to see an information about a last couple of hundred
memory free calls in kernel/debug/kgsl/kgsl-3d0/memfree_history
file.

Change-Id: I12e0e3702db56d99d5de644739b364dea4cc37b1
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
msm: kgsl: Update required timestamps during command submission

Update all the required timestamps when submitting commands to the
GPU ringbuffer for execution. The global timestamp was not being
updated in all the required cases. Now the global timestamp and
per context timestamp are updated if following conditions are met:
	1. A valid non global context is passed
	2. The context passed supports per context timestamps
	3. The command submission is not from kgsl
If 3 conditions above are not met then only the global timestamp is
updated.

Change-Id: Ib4fe6fbd2ac57fbc5306377f09072f9e4c09d442
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_ringbuffer.c
msm: kgsl: Lock ringbuffer translation in TLB

Lock ringbuffer virtual address translation in TLB of IOMMU. This
is required to prevent a hardware table walk from happening when
GPU executes commands that program the IOMMU registers. If a hardware
table walk happens when GPU is programming IOMMU register then it
can cause a deadlock on the bus.

Change-Id: I99428be7879a5210ba816f5f96864f94714649d7
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_iommu.c
	drivers/gpu/msm/kgsl_iommu.h
msm: kgsl: Add a barrier after writing to V2PUR register

Add a memory barrier after writing to V2PUR register of IOMMU. Without
this barrier the CPU core can stall because of multiple outstanding IOMMU
register transactions happening in parallel. This barrier synchronizes
the multiple IOMMU register transactions and prevents the CPU from
stalling.

Change-Id: I1d715e9fb8287b1f0b009b39b11b5469ab8861c8
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Print additional registers on IOMMU pagefault

Print more IOMMU registers when a IOMMU pagefault happens which
report whether the pagefault is a read or write fault.

Change-Id: I27acafa9dcfd0c7de9056151ed1baef7dd2346df
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_iommu.c
msm: kgsl: Always fire an interupt if requested

Even if the event code specifies a dummy interupt it might still
get wrapped with the conditional check.  Make sure that all forced
interrupts from the event code get fired.

Change-Id: Ic0dedbadc4599efcbca65ad93cc27943bad2ca79
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add device init function

Some device specific parameters need to be setup only once during
device initialization. Create an init function for this purpose
rather than re-doing this init everytime the device is started.

Change-Id: I45c7fcda8d61fd2b212044c9167b64f793eedcda
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
msm: kgsl: use kgsl_mmu_device_setstate() if the GPU is already idle

Use the default setstate function, which directly reprograms the IOMMU,
to change IOMMU pagetables or flush the TLB if the GPU is already idle.
This condition often occurs when the GPU is being powered down. In this
case it is desirable to avoid the overhead of issuing commands, waiting
for idle and firing events that results from using the GPU
command stream to reprogram the IOMMU.

Change-Id: I633002ac49c8fe58df3f1f6a1fd1ddf705fc1733
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: improve active_cnt and ACTIVE state management

Require any code path which intends to touch the hardware
to take a reference on active_cnt with kgsl_active_count_get()
and release it with kgsl_active_count_put() when finished.
These functions now do the wake / sleep steps that were
previously handled by kgsl_check_suspended() and
kgsl_check_idle().

Additionally, kgsl_pre_hwaccess() will no longer turn on
the clocks, it just enforces via BUG_ON that the clocks
are enabled before a register is touched.

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

Conflicts:
	drivers/gpu/msm/kgsl.c
msm: kgsl: Sync memory with CFF from places where it was missing

Before submitting any indirect buffer to GPU via the ringbuffer,
the indirect buffer memory should be synced with CFF so that the
CFF capture will be complete. Add the syncing of memory with CFF
in places where this was missing

Change-Id: I18f506dd1ab7bdfb1a68181016e6f661a36ed5a2
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Export some kgsl-core functions to EXPORT_SYMBOLS

Export some functions in the KGSL core driver so they can
be seen by the leaf drivers.

Change-Id: Ic0dedbad5dbe562c2e674f8e885a3525b6feac7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Send the right IB size to adreno_find_ctxtmem

adreno_find_ctxtmem expects byte lengths and we were sending it
dword lengths which was about as effective as you would expect.

Change-Id: Ic0dedbad536ed377f6253c3a5e75e5d6cb838acf
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Add 8974 default GPR0 & clk gating values

Add correct clock gating values for A330, A305 and A320.
Add generic function to return the correct default clock
gating values for the respective gpu. Add default GPR0
value for A330.

Change-Id: I039e8e3622cbda04924b0510e410a9dc95bec598
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
msm: kgsl: Move A3XX VBIF settings decision to a table

The vbif selection code is turning into a long series of if/else
clauses. Move the decision to a look up table that will be easier
to update and maintain when when we have eleventy A3XX GPUs.

Change-Id: Ic0dedbadd6b16734c91060d7e5fa50dcc9b8774d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Update settings for the A330v2 GPU in 8972v2

The new GPU spin in 8974v2 has some slightly different settings
then the 8974v1: add support for identifying a v2 spin, add a new
table of VBIF register settings and update the clock gating
registers.

Change-Id: Ic0dedbad22bd3ed391b02f6327267cf32f17af3d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Fix compilation errors when CFF is turned on

Fix the compilation errors when option MSM_KGSL_CFF_DUMP option
is turned on.

Change-Id: I59b0a7314ba77e2c2fef03338e061cd503e88714
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Convert the Adreno GPU cycle counters to run free

In anticipation of allowing multiple entities to share access to the
performance counters; make the few performance counters that KGSL
uses run free.

Change-Id: Ic0dedbadbefb400b04e4f3552eed395770ddbb7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno.h
	drivers/gpu/msm/adreno_a3xx.c
msm: kgsl: Handle a possible ringbuffer allocspace error

In the GPU specific start functions, account for the possibility
that ringbuffer allocation routine might return NULL.

Change-Id: Ic0dedbadf6199fee78b6a8c8210a1e76961873a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_a3xx.c
msm: kgsl: Add a new API to allow sharing of GPU performance counters

Adreno uses programmable performance counters, meaning that while there
are a limited number of physical counters each counter can be programmed
to count a vast number of different measurements (we refer to these as
countables).  This could cause problems if multiple apps want to use
the performance counters, so this API and infrastructure allows the
counters to be safely shared.

The kernel tracks which countable is selected for each of the physical
counters for each counter group (where groups closely match hardware
blocks). If the desired countable is already in use, or there is an
open physical counter, then the process is allowed to use the counter.

The get ioctl reserves the counter and returns the dword offset of the
register associated with that physical counter.  The put ioctl
releases the physical counter.  The query ioctl gets the countables
used for all of the counters in the block - up to 8 values can be
returned.  The read ioctl gets the current hardware value in the counter

Change-Id: Ic0dedbadae1dedadba60f8a3e685e2ce7d84fb33
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_a3xx.c