msm: clock-8974: Allow measurement of clocks in the WCNSS

For debugging reasons, it is required that WLAN drivers
be able to measure clocks in the WCNSS subsystem. It is
assumed that the WCNSS debug mux is already programmed
by the WCNSS firmware.

Change-Id: Ia1bc054f8dd8bd51e62046c9ea71624a22bc890e
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Enable protected mode for A3XX

Enable protected register mode for A3XX with these commits from
msm-3.10:

msm: kgsl: Enable protected register mode for A3XX
msm: kgsl: Print the register that causes a protected mode error
msm: kgsl: Unprotect the VBIF performance counters

Change-Id: Ic0dedbad950ffbd063fd861d9440bb5dce8d5fb1
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Protect SMMU registers from being written by the GPU

Put the SMMU register range in protected mode to shield them from
IB1/IB2 writes from userspace.

CRs-Fixed: 599971
Change-Id: Ic0dedbad8c03fc1c54ff73221231e2440d3c34dd
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: get pm_qos_latency from device tree

pm_qos_latency parameter can be configured from
device tree as well. Will set to default value if
entry not found in target device tree.

Signed-off-by: Prakash Kamliya <pkamliya@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: change pm_qos_latency to pm-qos-latency

Use hyphen symbol instead of underscore for pm-qos-latency
property name. Hyphen should be used instead of underscore
in device tree property name.

Signed-off-by: Prakash Kamliya <pkamliya@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Remove unused legacy IB timeout variables

Remove unused variables from legacy IB timeout detection.

Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Dump snapshot for long IB timeout

Dump snapshot when long IB timeout is detected. The GPU
command processor is halted on long IB timeout detection,
this will halt the GPU pipeline, dumping the snapshot at
this point is safe and gives us information to debug
long IB timeout.

Change-Id: I51bb73b66e11c3b6945c3dfe92af03e21e3c0e62
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: use %pK to restrict printing GPU / memory addresses

Use %pK in the output for the per-process memory dump to keep from
printing the GPU and user memory addresses for the GPU memory
objects own by the process.  This allows us to make the 'mem' file
world readable without exposing any really dangerous information.

[neo: This is already merged. Only required part. Not complete commit.]

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Sunil Khatri <sunilkh@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: don't use sscanf()

Friends do not let friends use sscanf().

[neo: Modify to fix compatibility with Chaos Kernel.]

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Don't update devfreq if the device is in slumber

There is no need to notify devfreq with the device statistics
if the device is power collapsed.

Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Enhance GFT to avoid hang->recover->hang cycle

If GFT recovered more than X times in Y ms invalidate the context
and do not attempt recovery. this is to prevent the case where GFT keeps
recovering continuously.

Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Return HI offset from kgsl_perfcounter_get

Previously, kgsl_perfcounter_get only returned the offset
of the LO perf counter register. This assumed that the HI
register would always be adjacent to the LO register. With
VBIF 2.0, this assumption has now been broken, so both the
HI and LO register offsets must be returned.

Conflicts:

        drivers/gpu/msm/a4xx_reg.h
        drivers/gpu/msm/adreno_a3xx.c
        drivers/gpu/msm/adreno_a4xx.c
        include/uapi/linux/msm_kgsl.h

CRs-fixed: 578771
Change-Id: Ie74da5d797e58a143b89a61aba7ebaf1ed42ed5e
Signed-off-by: Kevin Matlage <kmatlage@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Add hang interrupt and change HW fault generation

Add a sysfs property to dynamically control HW hang interrupt.
HW fault is generated for hang interrupt only.

Change-Id: Ib50c57476e54cccfef0ae18a0cbb42fce29457c1
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Increase the timeout value for fault detection

Increment the timeout value for detecting faults from 50ms to
200ms. The fault detection mechanism is a backup to hardware
fault detection. 50ms is small since it has been observed that
this mechanism triggers false positives with 50ms.

CRs-Fixed: 630776
Change-Id: I8f382051e06bdc47f152309a2868092e1980604e
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Enable hang interrupt by setting right bits for A330V2

A330V2 hang interrupt bit is at a different location compared to
other A3XX cores. Set the right hang interrupt bit for A330V2.

Change-Id: I702f1653ed31907a708b19c7b2288644e2d45220
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Enable hang interrupt for a330v2

Enable hang interrupt for a330v2 by default during
GPU initialization.

Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Fix derp

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Remove the "global" locking from the ioctl path

Remove the lock code from the generic ioctl handler and move the
mutex lock/unlock code to the places that really need it.  In
particular try not to hold a lock while doing user memory functions
(copy_to_user/copy_from_user) to avoid the potential of a deadlock
with the memory semaphore.

CRs-Fixed: 671080
Change-Id: Ic0dedbad6f7325b53d71a5dbbed50f92483871c8
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Protect CP_STATE_DEBUG_INDEX

Put CP_STATE_DEBUG_INDEX and CP_STATE_DEBUG_DATA under protection
to keep it from being written from an IB1. Doing so however opens
up a subtle "feature" in the microcode: memory read opcodes turn off
protected mode in the microcode to do the read and then turns it
back on regardless of the initial state. This is a problem if the
memory read happens while protected mode is turned off and then we
try to access a protected register which then complains and goes boom.

To account for this irregularity explicitly turn back off protected
mode in all the places where we know this will be a problem.

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: kgsl: Skip the entire command during fault recovery

During fault recovery the algorithm may choose to skip the faulting
command. To skip just one indirect buffer we have to rely on
CP_IB1_BASE but depending on where the fault happened the base could
already be pointing to the next buffer. This causes the code to skip
over the wrong buffer. There is no advantage to skipping just one
buffer vs the entire submission.

Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>