msm: vidc: Add free buffer api to flush state

This change adds free buffer api to video
client's flushing state to allow buffer
freeing in flush state.

CRs-fixed: 430214
Change-Id: I970efbbd8cc503eab4b944e12630f1b1faa9069c
Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>
msm: mdm: Assert soft_reset_gpio in mdm_power_down_common

In cases where the external modem is powered up very early in the
boot up process, user space application is not loaded as a result
mdm2ap_status is never pulled high. In case where we need to shutdown
the phone for charging we leave the ap2mdm_soft_reset_gpio pulled
high which results in leakage. Assert the ap2mdm_soft-reset_gpio
irrespective of the state of mdm2ap_status gpio.

CRs-Fixed: 425684
Change-Id: Icd37ac8eec1a8b9259563f2627ee57340f4e9f59
Signed-off-by: Taniya Das <tdas@codeaurora.org>
mfd: wcd9xxx: fix multi channel payload calculation

When multiple channels are used for a session (Rx/Tx), all bits in the
Rx/Tx port multichannel register needs to be Set. If a bit corresponding
to any channel is missing, the channel will not be aware that the other
channel (corresponding to the missing bit) is also part of the same group.
This will create ambiguity among the channels in the same PCM group and
will lead to shifting of Phase/delay in data in those channels.

CRs-fixed: 425803
Change-Id: Ie78ba82eeeb494db73a781e96b835361ef589a67
Signed-off-by: Banajit Goswami <bgoswa@codeaurora.org>
msm: mdm: Fix for incorrect ramdump timeout and ssr ref count.

The SSR reference count now gets decremented only once during a SSR cycle.
Ramdump timeout is now set correctly for each mdm.

Change-Id: I3f1d577805d4a6cc5171a69107f8529a9d165b04
Signed-off-by: Ameya Thakur <ameyat@codeaurora.org>
msm: kgsl: Fix hang detection to be 50ms or more

In current design waittimestamp can trigger hang detection
in less than 50ms. Check if hang detection was called less than
50ms ago, if true do no attempt hang detection.

Change-Id: Iaeb2501316c4194957fbe211b6023eeb869bd0d5
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Locate index of recovery during initialization

When a hang happens locate the index in ringbuffer from where replay
of recovery needs to be re-tried during initialization of recevery.
If the hang detection is false then hang reported by postmortem and
snapshot may be different, but recovery will always start from the
index obtained during initialization. Also, this allows us to capture
data into the snapshot that is in line with the point from where
recovery occurred.

Change-Id: Ie3877f0c81dad2ede888db7cb7d3ff13e2761763
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Recovery policy change

Recovery algorithm is changed to
step 1: retry the same commands that hung the GPU
step 2: if step 1 fails, nop just the IB that hung the GPU
	and retry
step 3: if step 2 fails, skip commands in current context
        till end of frame and retry
step 4: if step 3 fails mark context as bad and execute
        the remaining commands from good contexts.

Previously we used to return -EDEADLK when recovery succeeds,
this is the same error code if the context is not recoverable.
With new policy if recovery succeeds we return -EAGAIN so that
userspace treats recovered context differently from the ones
that are not recoverable. If recovery fails we mark the context
as bad and return -EDEADLK.

Change-Id: I9fa3c40801964186866b6002e62f19cf6aa41361
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Renaming recovery to fault tolerance

Renaming recovery to fault tolerance and modifying
the functions and log messages accordingly.

Change-Id: I5f249806026ac514c4aff7da45c3a4e8cc2f8c34
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Store process id and name in context structure

Store process id and name in context structure, this
information is used to print the process name when
when we detect a error in the driver, example
GPU fault tolerance, commands from bad context
in issueibcmds.

Change-Id: I6acd63933754fdec80d8274d3e1380ff2c23770e
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Detect long running IBs

When expired global timestamp is not progressing,
check if an IB is talking more than 2 seconds
with no update in GPU read pointer, IB1 base
IB1 size, IB2 base, IB2 size and detect it as a
long running IB. Invalidate the context of the IB
and do not attempt fault tolerance on this context.

Change-Id: I7e9780f5aed73a5c8807069aa506bec16a1576b4
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Run GPU fault tolerance at max clock

GPU fault tolerance should take minimal time,
set the GPU clock to max freqency to acheive this.
When we set GPU clock to max freqency we vote for
high CPU clock and bus bandwidth.

Change-Id: I98a3f7c24f0939c08f9b12257817d17414e3f128
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Reduce postmortem logs by default

Full postmortem logs take 600ms to 1sec and this affects
fault tolerance time. Reduce postmortem logs and print
only necessary information. Full postmortem logs can
be enabled using debugfs.

Change-Id: I9039746bbdcf67ceebc02f21e84ab873531035a5
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Allow fault tolerance userspace control

Allow userspace to control fault tolerance policy,
this allows fault tolerance policy to be controlled
using panel file.

Change-Id: I991edf6f082384bc69454058fe5df3b5f535aa4c
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: No fault tolerance if userspace sets a flag

If userspace requests no fault tolerance using context flag
KGSL_CONTEXT_NO_FAULT_TOLERANCE, do not attempt denial of
service detection and do not attempt fault tolerance when
a hang is detected.

Change-Id: I5de0e4ae6e8407365725c30fcb0e00a601460ebc
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Limit pagefault logging to 1 per page

Log only one pagefault error per page. If we log all the
pagefault errors it causes lot of messages in kernel logs
and sometimes leads to watchdog timeouts.

Change-Id: If8ee4ee28f6289277eb98d4d8ba73dfda6fc1133
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Allow pagefault policy to be controlled by userspace

GPU pagefault policy can be set to below options:
   a) enable/disable GPU HALT on pagefaults
   b) log only one pagefault per page.
GPU pagefault policy can be controled using panel file
and debugfs.

Change-Id: I0613e0d087fc45eb5e519e1c834a33f32376672f
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Debugfs entity to switch on/off userspace FT policy control

When debugfs entity "ft_user_control" is set, it enables userspace to
control GPU fault tolerance policy. By default it is disabled.

Change-Id: Ia93ccf6d9595f6e7cda71863f9067819aaa0a68d
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
msm: kgsl: Make the snapshot dumper more tolerant of corrupted IBs

If there are a lot of sequential commands in the ringbuffer for the
same context there is a high probablity that some of the memory
for the older commands has been reused and so the contents may not
be reliable. Increase robustness by making sure we don't parse the
same IB over and over again and be more tolerant of errors and
strange sizes.

Change-Id: Ic0dedbade8504ea258ceea40593cb75e7d6211c8
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Make sure the last IB2 is in the static snapshot region

When taking a snapshot from a ramdump it is usually important that
we get the last IB2 that was executed so if we find it during
parsing put it in the static snapshot region as opposed to the
dynamic one.

Change-Id: Ic0dedbad878b961ebe29afe9145443e9bfd0bc6a
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
msm: kgsl: Use the correct timestamp for the snapshot

The snapshot timestamp is currently based on wall time which makes
it very difficult to debug against a kernel log based on boot time.
It doesn't help matters that the snapshot timestamp is output in
human unfriendly hex.  Use boot time instead of wall time for the
snapshot value and print it out in decimal.

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