msm: kgsl: GPU fault tolerance timer

GPU fault tolerance timer with a 50ms interval is introduced to detect
the condition where GPU is stalled, when GPU state is active we check
for GPU stall and if a stall is detected fault tolerance is triggered.
Using a timer is a better design because this removes dependency
on userspace to call waittimestamp.

CRs-Fixed: 477979
Change-Id: I22b1316ad3edb271c1241b93e7a36373dfc70234
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno_ringbuffer.c
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl.h
	drivers/gpu/msm/kgsl_device.h
msm: kgsl: GPU soft reset

Soft reset GPU when GPU power rail is not turned off.
In hard reset we reload full microcode but in soft reset
since the memory powerrail is not turned off we only
load jump tables part of microcode, this reduces GPU
reset time from 10ms to 200us.

Change-Id: Ibbc36e97cc95425e13856fd5d847eed742743723
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>

Conflicts:
	drivers/gpu/msm/adreno.c
msm: kgsl: embed kgsl_context struct in adreno_context struct

Having a separate allocated struct for the device specific context
makes ownership unclear, which could lead to reference counting
problems or invalid pointers. Also, duplicate members were
starting to appear in adreno_context because there wasn't a safe
way to reach the kgsl_context from some parts of the adreno code.
This can now be done via container_of().

This change alters the lifecycle of the context->id, which is
now freed when the context reference count hits zero rather
than in kgsl_context_detach().

It also changes the context creation and destruction sequence.
The device specific code must allocate a structure containing
a struct kgsl_context and passes a pointer it to kgsl_init_context()
before doing any device specific initialization. There is also a
separate drawctxt_detach() callback for doing device specific
cleanup. This is separate from freeing memory, which is done
by the drawctxt_destroy() callback.

Change-Id: I7d238476a3bfec98fd8dbc28971cf3187a81dac2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
(cherry picked from commit f1ce0f462572fe5c5e8f1dbc2f10d3b1a944af11)

Conflicts:
	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_a2xx.c
	drivers/gpu/msm/adreno_a3xx.c
	drivers/gpu/msm/adreno_drawctxt.c
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_cffdump.c
	drivers/gpu/msm/kgsl_cffdump.h
	drivers/gpu/msm/kgsl_device.h
	drivers/gpu/msm/kgsl_iommu.c
	drivers/gpu/msm/kgsl_sync.c
msm: kgsl: convert cffdump stub functions to inlines

Since cffdump is not often enabled in Kconfig, it is helpful
to at least catch compiler errors and warnings when it is off.

Change-Id: Ic0dedbad41b0faac6e0a2514e694f8e369c61f7f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 4025519b7eb7adb4b2065677b80e77ea2d83038c)

Conflicts:
	drivers/gpu/msm/kgsl_cffdump.h
msm: kgsl: Make cff capture a device specific property

Make CFF capture a device specific property. This allows the control
of CFF for a particular device without CFF interferance from another
device. This will be useful when we have a virtual device and need to
only capture CFF for the virtual device. CFF capture can only be
turned on for one device at a time.

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

Conflicts:
	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_a2xx.c
	drivers/gpu/msm/adreno_a3xx.c
	drivers/gpu/msm/adreno_drawctxt.c
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_cffdump.c
	drivers/gpu/msm/kgsl_cffdump.h
msm: kgsl: Use a read/lock for the context idr

Everybody loves a rcu but in this case we are dangerously mixing rcus and
atomic operations.  Add a read/write lock to explicitly protect the idr.
Also fix a few spots where the idr was used without protection.

Change-Id: Ic0dedbad517a9f89134cbcf7af29c8bf0f034708
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 4dc1193af601748c95d990956fadfb8a03f4dcd3)

Conflicts:
	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_iommu.c
	drivers/gpu/msm/kgsl_snapshot.c
	drivers/gpu/msm/kgsl_sync.c
Cherry-pick'in clean up

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

Conflicts:
	drivers/gpu/msm/kgsl.c
	drivers/gpu/msm/kgsl_cffdump.c
	drivers/gpu/msm/kgsl_cffdump.h
msm: kgsl: Convert all physical address to type phys_addr_t

Future chipsets may not define phys_addr_t to 32 bits hence convert
all physical address variables to this type.

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

Conflicts:
	drivers/gpu/msm/kgsl_iommu.c
msm: kgsl: Prevent race conditions when freeing memory

Multiple threads can call an ioctl to free a memory region.
Only one of these threads must be allowed to free memory and
the rest can return without freeing. Add a new pending flag
which is tested and set in a critical section guarded by
spinlock to prevent multiple ioctl threads from freeing the
same memory.

Also, a thread could be freeing a memory region that is
in use by another thread. Ensure that the detachment of the
memory from the process list and freeing of the memory always
happens in the same thread. This will prevent a situation where
the memory is being used by a thread which is detached from the
process list and is yet to be freed.

Seperate the selection of gpuaddr and mapping into pagetable. The
gpuaddr assignment needs to be done with process memory lock held
in a critical section but the mapping into pagetable can be done
separately without holding memory lock.

CRs-Fixed: 495144
Change-Id: Idf85fbd4bca29c18597f4b0e737c207f002ab266
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl.c
msm: kgsl: Fix context reference counting

Get rid of kgsl_find_context. Use instead kgsl_context_get that does
correct RCU read locking around the itr_find and increases the
reference count on the context before returning it.  This eliminates
the chance that a context will be destroyed while somebody is still
using it.  Of course increased use of kgsl_context_get is accompanied
by kgsl_context_put in all the right places.

Change-Id: Ic0dedbad73d497fd9b451aefad8e5b28d33b829d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
(cherry picked from commit 220ad7d0539b087c7fe308b636596f14ab053e38)

Conflicts:
	drivers/gpu/msm/adreno.c
	drivers/gpu/msm/adreno_postmortem.c
	drivers/gpu/msm/kgsl_device.h
	drivers/gpu/msm/kgsl_snapshot.c
msm: kgsl: show timestamp in sync dump

Improve the debug information printed for kgsl points and timelines.

kgsl_sync_pt_value_str:
  - show timestamp passed to kgsl_add_fence_event()
kgsl_sync_timeline_value_str:
  - show most recent timestamp passed to kgsl_sync_timeline_signal()
  - show last retired timestamp according to kgsl_sync_get_timestamp()

Change-Id: I93fe408b06de054b11e05784cd7175ed3fcb76ad
Git-commit: 595e213985f63d6aa484c966a4f4a710b31ca209
Git-repo: https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git
Signed-off-by: Fred Fettinger <fred.fettinger@motorola.com>
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>

Conflicts:
	drivers/gpu/msm/kgsl_sync.c