arm: Add ARCH_RANDOM Kconfig

Some boards may support architecture generated random numbers. Add
the appropriate Kconfig.

Change-Id: I0077a982c9bb6d3a35435cc27fe40b7e0596ca84
CRs-Fixed: 498392
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Kconfig: Add config option to support vmalloc savings

The virtual space belonging to any subsystem which is
expected to have a lifetime of the entire system can be
reclaimed. Adding config option to enable or disable
this feature.

Change-Id: I56faef4b71c948185fdfe336054a5951dfa8d011
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
Kconfig: Add menu choice option to reclaim virtual memory

Add menu choice options for selecting the method of reclaiming
virtual memory, either by mapping around the largest hole or
reclaiming virtual memory belonging to any subsystem expected to
have a lifetime of the entire system. By default virtual memory
is not reclaimed.

Change-Id: I1b8a1492062bb9532700122878618989e5148647
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
msm: acpuclock: Fix acpuclk_data null pointer dereference

If acpuclk_data is null, dereferencing it in acpuclk_get_switch_time
causes a kernel panic.  Add pointer check to fix that.

Change-Id: I69b92671c8cf26cb45ec8f1193c147be2ebe4c16
Signed-off-by: Junjie Wu <junjiew@codeaurora.org>
msm: cpufreq: Move cpu_frequency_* trace points from acpuclock to cpufreq

acpuclock is not used on newer targets, so move the trace points
in it up to the generic msm cpufreq driver. Also drop the use of
the 'trace_cpu_frequency' entirely, since it's already present in
generic cpufreq code.

As a side effect of this change, these trace events will no longer
track cpu frequency changes from the power-collapse path. Only
frequency changes coming from cpufreq will be tracked.

CRs-Fixed: 535512
Change-Id: Ib69d92f5d3209a7e36be678997b79bcdac92f953
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
smp: Relax irqs_disable() warning in smp_call_function_single()

The change that long-ago added the interrupts-disabled warning in
smp_call_function_single() cited the following deadlock as the reason:
	CPU A				CPU B
	Disable interrupts
					smp_call_function()
					Take call_lock
					Send IPIs
					Wait for all cpus to acknowledge IPI
					CPU A has not responded, spin waiting
					for cpu A to respond, holding call_lock
	smp_call_function()
	Spin waiting for call_lock
	Deadlock			Deadlock

Such a deadlock is not possible however, in the event that
smp_call_function_single() is called for the currently-executing CPU.
While not a common usecase, relaxing the warning may simplify some
driver implementations.

The 'acpuclock-krait' driver in the MSM ARM sub-architecture provides
one example, where smp_call_function_single() is sometimes called from
a cpuidle path with interrupts disabled, but only ever from the target
CPU. Other callers of that same function may cross-call, but only do so
when interrupts are enabled.

Change-Id: I647b3b46fe6aa4dfb06f7750396986b80b92d700
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
msm: Add null-pointer checks for domains

Add check for null-pointer before passing domain pointer
into map and unmap api to avoid null-pointer deferences.

CRs-fixed: 493503
Change-Id: I185deb9f2878ef62601eb4ca1d2b71f892ca0185
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
msm: Fix race condition in domain lookup

During lookup of domains we take a pointer to the root node
of the rb tree before taking the mutex to protect the rb tree.
However, the rb root node might change if another process updates
the rb tree after we take the pointer to the root node. This can
cause us to not find the entry that we are looking for.
Fix this by ensuring we have taken the mutex before getting the
root node pointer.

CRs-fixed: 493503
Change-Id: I4702740e486fda0cd92df0401d8e4706598a899b
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
msm: ipc_logging: Add ipc logging context destroy API

If IPC logging gets used by other drivers and modules, then those
drivers/modules may need to destroy the logging context for dynamic
modules that get unloaded.

Add a function called ipc_log_context_destroy() that will destroy a
logging context created by ipc_log_context_create().

Change-Id: I0f927235e51bd17b82bb2bd2eea198fc681e03cd
Signed-off-by: Arun Kumar Neelakantam <aneela@codeaurora.org>
msm: ipc_logging: move deserialize function

To enable testing using dynamically-loaded kernel modules, the
deserialization function is needed which requires it to be exported.

Rename function, move it to the main driver file and export it.

Change-Id: I5f49ebf9e9268c9e2c04fc61703a9beb6ec5f242
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
msm: ipc: Fix potential AB-BA deadlock

In kernel QMI, while receiving responses continuously, there is a
classic out-of-order(AB-BA) deadlock scenario between IPC router and
Kernel QMI interface. The scenario is as below:

  1) IPC Router receives the message for kernel QMI port and acquires the
     corresponding port's port_rx_q_lock and then calls the notify
     function for that port which tries to acquire the handle_lock of the
     port.

  2) Kernel QMI interface, that runs independent of IPC Router activities,
     tries to send a message and acquires handle_lock for the port and
     tries to acquire the port's port_rx_q_lock to read the response from
     the port.

  3) This creates a classic AB-BA deadlock because port_rx_q_lock is
     locked at step 1 and handle_lock is acquired at step 2.

Fix the deadlock.

Change-Id: I532cff30b445e11baa715a570e5e853d9b71bab3
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Make the kernel-space read operation as non-blocking

Update the read operations of kernel space to be non-blocking and
return -ENOMSG when there is no message to read.

Change-Id: I92f55d8829755078f34ff3cbe2dc9b16ed7988df
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Serialize SMD XPRT CLOSE and OPEN events

When a remote subsystem resets, IPC Router's SMD XPRT Layer queues a CLOSE
event. When the concerned subsytem powers up and the channel is reopened,
SMD XPRT Layer queues a OPEN event. When the remote subsytem resets and
powers up quickly, the following race condition exists:
a) IPC Router is scheduled out while handling the CLOSE event, leaving a
   stale XPRT
b) IPC Router's SMD XPRT Layer queues a OPEN event
c) IPC Router's SMD XPRT Layer reads a HELLO message, finds a stale
   XPRT and queues a DATA event on the stale XPRT
This race condition causes a kernel panic.

Fix this race condition, by not handling any other SMD XPRT event until
the CLOSE event is complete.

CRs-Fixed: 488331
Change-Id: I2283e163413d1896bd6842530b8a6a2b537e22de
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Handle the Resume_Tx events from remote endpoints

To prevent the QMI clients from flooding the remote services, IPC Router
transport supports a flow control mechanism. When the IPC Router
transport returns -EAGAIN during message transmission, queue the packet
into client's pending transaction queue for transmission during later
time. In addition, handle RESUME_TX events from the remote services and
use that event to transmit the packets in pending transaction queue.

Change-Id: Ib24256fd0dbeecb9d96ea03ffd86afe2b4cc1483
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: smem: Update SMEM log dump_sym to indicate QMI modules

SMEM Log dump_sym file indicates log information from QCCI/QCSI modules
as ONCRPC and log information from IPC Router as ROUTER which is
misleading.

Update the code so that dump_sym indicates correct module names.

Change-Id: I8e67ccce60780ec935cfc71d0854f156f3e922b8
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: qmi: Update the wait-for-response to UNINTERRUPTIBLE

Currently once a QMI request is sent, the wait for the response is
interruptible. Sometimes the wait returns -ERESTARTSYS due to signals or
for reasons other than response reception. Since the interface to send
a QMI request is restricted completely within the kernel-space, the
kernel QMI client is not able to handle -ERESTARTSYS gracefully.

Update the wait-for-response in the interface API to uninterruptible.

CRs-Fixed: 504771
Change-Id: I91262e6a7057b5387adfd4728ba9a6ea7002e5d9
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Return error value on send failure

msm_ipc_router_send_msg() returns 0 instead of the error code when the
send helper function fails.

Return error code from helper function in failure cases.

Change-Id: Idef1ceef261945e30b57cd5e99fcb0b2651b31ab
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Clean-up code redundancy

The receive message operation for the socket interface and the kernel
interface has redundant code.

Clean-up redundant code.

Change-Id: Ibe52816f5b567feab4d6247a3dba1945e209c626
Signed-off-by: Arun Kumar Neelakantam <aneela@codeaurora.org>
msm: ipc: Initialize unused elements of control message to 0

Initialize the entire control message to 0, so that unused elements of
a control message are initialized to 0. This will prevent any uninitialized
elements from leaking information to the remote subsystems.

Change-Id: I910f3956e8f282e614216c45f7af92d741d887f8
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Send Resume_Tx from the client/server context

Resume_tx is passed by IPC Router as soon as it detects confirm_rx
field being set in received message. In a scenario where the local port
towards which the confirm_rx is directed is not in a state of accepting
messages, this behavior of IPC Router makes the remote port send more
data towards the local port. In addition, in a multi-hop scenario the
resume_tx message holds the destination node_id as the value of the
neighbouring node_id which is incorrect.

Pass Resume_Tx from the context of the thread to which the local port is
associated. Pass the right node_id as destination node_id in the
Resume_Tx message.

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