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
msm: mdss: remove YUV upscale limitation

Parameters check for YUV upscaling when doing chroma upsampling is not
required, hardware is able to support up to 40x up scaling for chroma
components so this check is not needed.

Change-Id: I700282c4627df5a630def6072b8deba38bb58b41
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>
msm8974: mhl: set hpd, tmds based on path_en bit

Set HPD and TMDS pass-through only after receiving
PATH_EN from the sink and reading all device
capability bytes from the sink.
Making MHL wait until the PATH_EN bit has been set by the
sink/dongle is in conformance with the MHL spec.
This change prevents incorrect behavior in usecases
such as meeting timing requirements in test 1A-02 HDCP
compliance test suite, disabling hpd when TV is powered off
with MHL cable connected to the TX.

CRs-Fixed: 504737
CRs-Fixed: 481930
Change-Id: Id2c1fb9d2dbe10b1310958021cca3533790e7394
Signed-off-by: Abhishek Kharbanda <akharban@codeaurora.org>
Signed-off-by: Manoj Rao <manojraj@codeaurora.org>
msm: mdss: Do not call set rate for handoff enabled clocks

When continuous splash screen is enabled, DSI branch clocks
are never turned off in the bootloader and are handed off
during kernel bootup. When the DSI controller is probed, it
needs to vote for keeping these clocks enabled. However,
calling set rate may result in a screen blink. Remove the
set rate call to fix this issue.

CRs-Fixed: 506037
Change-Id: I46074ff93456899de6b0e36a185d00d16f5f762e
Signed-off-by: Aravind Venkateswaran <aravindh@codeaurora.org>

Conflicts:
	drivers/video/msm/mdss/msm_mdss_io_8974.c
msm: mdss: Fix order of DSI clocks operations

For DSI branch clocks, set rate should be called
before calling the prepare and enable ops. This is
the recommended order for clock operations and is
required before moving the DSI pll enable sequences
to the prepare op.

Change-Id: I5f53f424a6665e2ce41076734eb6379596fa1d00
CRs-Fixed: 513361
Signed-off-by: Aravind Venkateswaran <aravindh@codeaurora.org>

Conflicts:
	drivers/video/msm/mdss/mdss_dsi_host.c
	drivers/video/msm/mdss/msm_mdss_io_8974.c
mdss: display: add edp aux channel support toward link training

Edp aux channel is the communication channel between host and
client (panel). Host reads edid back from panel and issues dpcd
command to panel through aux channel. This patch adds aux channel
support so that edp link training can be done.

CRs-Fixed: 486135
Change-Id: If29dc8257ecc555296c043f2ebcc6dc5cb400d49
Signed-off-by: Kuogee Hsieh <khsieh@codeaurora.org>
mdss: hdmi: Correct CEA format check

This change corrects the CEA format check to include all the supported
resolutions through which the audio should be routed to HDMI TV.

CRs-Fixed: 517950
Change-Id: Icd5c7503b2dc3a184bbf52205b0386eee9daca62
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
msm: mdss: Change the Aplha scaling type to bilinear

Currently, for Alpha plane the filter used is nearest due to which
there is an aliasing effect. Using the same filter as graphics core
which is bilinear, the aliasing effect is avoided.

CRs-fixed: 517627
Change-Id: Ifb4629ddcea1ac447d151469b1f56e3400b7fac0
Signed-off-by: Sree Sesha Aravind Vadrevu <svadrevu@codeaurora.org>
msm: mdss: keep reference of rotator output buffer

Change logic to free buffer for previous rotation call. This will make
sure to keep a ref count on the buffer secure lock before it's picked up
by MDP for displaying to panel. It will also allow for asynchronous calls
to rotator to be supported by not freeing the source and destination
buffers within same call.

Change-Id: I389d6a4523bdc79a5dfe76e3603e43325d63b82c
Signed-off-by: Adrian Salido-Moreno <adrianm@codeaurora.org>