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.

Conflicts:

    drivers/gpu/msm/adreno.c
    drivers/gpu/msm/kgsl_pwrctrl.c

CRs-Fixed: 477979
Change-Id: I22b1316ad3edb271c1241b93e7a36373dfc70234
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
msm: kgsl: Check long IB only for valid context

Do not check for long IB if the hang is detected in a NULL context,
hang in NULL context can happen when we are switching from NULL to
active context and hang is detected in commands that write an
active context to memstore, long IB in this scenario is not possible.

Change-Id: I7711c86b91c6c2ce0b4aa0543572c26d10c83030
Signed-off-by: Tarun Karra <tkarra@codeaurora.org>
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
msm-camera: Added the  NULL check in gemini driver.

Adding NULL check for ionhandle and y_off in gemini driver files.

CRs-Fixed: 504159

Change-Id: I6d20298183bec0c3c2c16088a936ac6f7d307da4
Signed-off-by: Katta Santhisindhu <kattas@codeaurora.org>
msm: kgsl: Fix long IB time calculation problem.

Remove unnecessary addition of GPU used time to calculate
IB duration.

Change-Id: Ic7e18882038f21a087a2348d6f4fab5aed2bb8cf
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
ASoC: wcd9310: Fix DMIC current leakage after disable

Observed after disabling DMIC path, some DMICs observe
power leakage of around 2mA and affecting power numbers.
This happens due to the DMIC clock runs off MCLK. 2 Stage
of Dividers are used to  generate various DMIC Clock Freq.
Since the SW Enable/Disabling is async to MCLK, the Divider
will either hold the last stage 0 or 1.
Manually force the digital mic clock pin to GPIO mode from
functional mode through the TLMM mux option and force the value
of DMIC voltage to 0V. This will avoid any current leakage.

CRs-Fixed: 504468
Change-Id: I720fadda77b59454feb1a64d0c4951a6c09de66c
Signed-off-by: Laxminath Kasam <lkasam@codeaurora.org>
msm: kgsl: Set alignment to 0 when low on mapped memory

If CPU map returns error due to low memory then we need to set
the alignment to 0 and instead of setting it to PAGE_OFFSET. This
is because we then simply search of a free memory gap at page
boundary and disrerard alignment requirement since memory is
low.

Change-Id: I828f5d0120d6d530e0e8857bcd96c9d5f266da10
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
msm: kgsl: Set proper pagetable address immediately after recovery

Update the MMU with proper pagetable address immediately after
recovery to avoid any translations with old pagetable.

Change-Id: Ib929598363e48a42b8ae174ed9718402541f5b09
Signed-off-by: Rajesh Kemisetti <rajeshk@codeaurora.org>
msm: kgsl: Use the kmalloc/vmalloc trick for the sharedmem page array

It was previously assumed that most GPU memory allocations would be
small enough to allow us to fit the array of page pointers into one
or two pages allocated via kmalloc.  Recent reports have proven
those assumptions to be wrong - allocations on the order of 32MB will
end up trying to get 8 pages from kmalloc and 8 contiguous pages
on a busy system are a rare beast indeed.

So use the usual kmalloc/vmalloc trick instead - use kmalloc for the
page array when we can and vmalloc if we can't.

CRs-fixed: 513469
Change-Id: Ic0dedbad0a5b14abe6a8bd73342b3e68faa8c8b7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
gpu: ion: Free the sgtable for CMA based heaps

When an sgtable is allocated with sg_alloc_table, the table needs
to be destroyed in addition to being freed. Destroy the sgtable
when freeing the associated memory.

Change-Id: Iedba81146ba453070790f071848f86826f7eec9c
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Srinivasarao P <spathi@codeaurora.org>
msm: ipc: IPC Router updates to support QMI in the kernel

1) Move the kernel interface APIs to a separate header file.
2) Use platform device to indicate the arrival/exit of service.
3) Add kernel APIs to send and receive messages through IPC Router.
4) Clean up unused Macros, enums, header inclusion.

Change-Id: I1541e9815d104f7ea46d19c10b57c77d967bd065
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
lib: qmi: Introduce QMI Encode/Decode library

Introduce Encode/Decode Library to perform QMI message marshaling.
The QMI Encode/Decode Library encodes the kernel C data structures into
QMI wire format and decodes the messages in QMI wire format into kernel
C structures.

Change-Id: Ib443e697dafedeac8a790de9a3a8ed4a8444082f
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Update the wakelock naming format for the local ports

Update the wakelock names to "ipc<local_port_id>_<port_owner>". This
enables easier identification of the wakelock owners.

Change-Id: Ife2bcbea5f4ab27269749123475065b6ec7b7f0b
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Add support for IPC Logging

Enhance IPC Router to log information pertaining to the messages
exchanged between user-space and other systems.

Change-Id: I8ef3e793a85bcdb14c69eb96278ce2ea8a47df96
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Add IPC Logging support to IPC Router

IPC Router to log debug & Router-to-Router messages onto the IPC Log
buffer. This will enable debugging the IPC Router initialization
issues and Router-to-Router communication issues, using debugfs without
logging to the kernel logs.

Change-Id: I90d968baf355f2f9abe95ea53d8b059781e8fbc6
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Change IPC log file name for IPC Router

Change the name of the files that contain the IPC log information
from the IPC Router. This change is done to reflect the module name
as a part of the IPC log file name.

Change-Id: I541aa5866251348b472eba6d1b3d1840500387f9
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Update recvmsg operation to be non-blocking by default

Update the IPC Router recvmsg operation to be non-blocking by default
and return 0 when there is no data to read.

CRs-Fixed: 464634
Change-Id: I1f43e3a36d72312372a3ac141d506c81a613c408
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc_router: Fix potential leaks and null dereferences

Added null pointer checks to avoid potential null pointer dereferences
and free statements to avoid potential memory leaks

Change-Id: I0553dfe6c61260a700a9dc6a411dcec6483e0eb8
Signed-off-by: Brent Hronik <bhronik@codeaurora.org>
msm: ipc: Pass RESUME_TX events to the endpoints

IPC Message Router blocks the endpoints from transmission if the transmit
message count for the destination endpoint reaches the quota count. This
will cause the asynchronous message transfer to block, which violates the
defintion of asynchronous behavior.

Return -EAGAIN when the transmit message count for the destination
endpoint reaches the quota count. In addition, after receiving the
resume_tx event from the remote endpoints notify all the local endpoints
that are waiting on the remote endpoint's resume_tx event.

CRs-Fixed: 473573
Change-Id: I82b49d268394bb8c064d88fd6a2799a5e9ec566f
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Do not broadcast remove client messages, if possible

Remove client message is broadcast to all subsystems within the system.
If a client has never communicated over any link, then do not send the
remove client message over any link. If a client has been communicating
only over a specific link, then send the remove client message only over
that link. If a client has been communicating over multiple links, then
broadcast the remove client message.

CRs-Fixed: 454809
Change-Id: I007c7f1ace66191ce9cbf0bad033381c4f3b750f
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Return -ENODEV when remote port is not found

Current implementation returns -ENOMEM when look up for a remote port
fails.

Return -ENODEV instead of -ENOMEM.

Change-Id: I7022e760631b3faaf7f1ba7952c8569905c4ee5a
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>