cma: Make locking finer grained

CMA locking is currently very coarse. The cma_mutex protects both
the bitmap and avoids concurrency with alloc_contig_range. There
are several situations which may result in a deadlock on the CMA
mutex currently, mostly involving AB/BA situations with alloc and
free. Fix this issue by protecting the bitmap with a mutex per CMA
region and use the existing mutex for protecting against concurrency
with alloc_contig_range.

Change-Id: I6863ba7ab7fae07c68fee23b0aa4c869244fe2a1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
dt: introduce for_each_available_child_of_node, of_get_next_available_child

Macro for_each_child_of_node() makes it easy to iterate over all of the
children for a given device tree node, including those nodes that are
marked as unavailable (i.e. status = "disabled").

Introduce for_each_available_child_of_node(), which is like
for_each_child_of_node(), but it automatically skips unavailable nodes.
This also requires the introduction of helper function
of_get_next_available_child(), which returns the next available child
node.

Change-Id: I811ff03886518989373a69240c35a9d7de23a2c6
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
staging: ion: msm: Only parse available dt nodes

ION is currently ignoring the status property of device tree
heap nodes. Make ION aware of the status of the ION heap nodes making
it possible to disable certain heaps.

Change-Id: I96e6af97df6bbd1c24ace9aa476baae28409ea96
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
ion: secure_buffer: fix iteration of sg_table

We're currently re-using the `i' loop counter to iterate over the chunk
list within our iteration of the secure sg_table. This causes the
iteration of the sg_table to get all messed up and results in crashes
when we walk off the end of the list. Fix it.

Change-Id: I09c84015f8c3cbcb2cea60886241457bb829003c
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: cma_secure_heap: validate buffer length

The secure CMA heap only supports buffers lengths that are multiples of
1MB. Currently, we simply crash if a bad length is requested. Rather
than crashing, log an error and return a failure.

Change-Id: I0387ee9f2900e44c817d3a7497e9b0528dd8c33b
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: fix remaining instances of sg_dma_len

Recently, [ec6c8a8f443: "ion: convert sg_dma_len(sg) to sg->length"]
moved Ion away from using sg_dma_len. However, a few instances were left
over from MSM-specific code. Fix these instances so that we're using
sg->length everywhere.

Change-Id: I76b07f5589ba3867e1584b129a0ccd9f3ef00ad7
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
msm: ipc: Migrate to wakeup sources from wake locks

Wakelock usage has been deprected. Update IPC Router to use wakeup
sources.

Change-Id: I7cf67a2f24241ec96e558478d532fe174abf17d9
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
ASoC: msm: Do not set volume to zero during session open

Setting stream volume to 0 will cause problem when user
starts playback from aplay. The previous volume which is
set gets overwritten with 0 when the playback starts. To
avoid this user space can control the volume setting at
the start of the playback.

Change-Id: I3776bb7ffd390ff0cfb56462bebb60a9163a7796
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
ASoC: msm: Add check for NULL pointer and buffer overflow

Changes to add check for NULL pointer before they
get dereferenced and check for buffer overflows
to ensure out of bound indexes of arrays are not
accessed.

CRs-fixed: 628847 628850
Change-Id: I3fcebe07a7f9e7ff480857480fa0df2ada017c69
Signed-off-by: Aravind Kumar <akumark@codeaurora.org>
PM / devfreq: Rewrite devfreq_update_status() to fix multiple bugs

The current devfreq_update_status() has the following bugs:
- When the new frequency doesn't have a valid level, the time spent in the
  new frequency is counted towards the next valid frequency switch instead
  of being ignored.
- The time spent on the previous frequency is added to the new frequency's
  stats instead of the previous frequency's stats.

This patch fixes all of this.

Change-Id: I7bbdafca78d1565cdbf815356556fe6d6cca9e3f
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
cma: Drop the right mutex

The lock that was locked was cma->lock not cma_mutex. Drop
the right one when breaking out of the loop.

Change-Id: I0a1831b23613c5220795fe2a63f9db7439268c3f
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
PM / devfreq: Check for GPU busy time before sending the sample

Sometimes GPU busy time is very low during sampling. Accumulate
the statistics and send them with the next sample.

Change-Id: I77e568b48afc3a4922c7c341d9478705b7ae3a30
Signed-off-by: Suman Tatiraju <sumant@codeaurora.org>
msm: spm-v2: Store voltage levels into PMIC_DATA3

On certain targets, where the SPM controls the power supply for each
core, the SPM power down sequence takes care of restoring the Voltage
level after a power collapse to the appropriate sleep level. The active
voltage level is stored in the PMIC_DATA_3 register and SPM state
machine uses the data in this register to restore the voltage to the
current active level.

Change-Id: I4a25440e818abdefec8cdfd3491fe9a7d772aab4
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
msm: spm-v2: Flush the PMIC_DATA registers

Different versions of SAW use different PMIC_DATA registers to
save the current voltage, which is used to restore voltage when
exiting low power modes. Flush the appropriate PMIC_DATA registers
depending on the SAW versions.

Change-Id: I7b421ed7e60ebde7c1f9ef32ce1a047ca361c32c
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
msm: spm-v2: Use proper register offsets for SAW2_v3.0

Current code get the register offsets for SAW2 based
on hardcode macros. Use SAW2 major, minor numbers to
get the proper register offsets to different versions
of SAW2 controllers(i.e: SAW2_v2.1 and SAW2_v3.0) and
this patch remove the SAW2_v1.1 controller related code.

Change-Id: Ib80e06caab7d999bfec3ba94b786de2f5ef2074c
Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>
msm: spm: set pc mode bit for SAW2_3.0

Set the power collapse bitin SAW2_SPM_CTL register.
This bit is used to differentiate other low power modes
from power collapse mode. This information is used for
contolling DBGWRDUP input signal. If PC_MODE is set DBGPWRDUP
signal is de-asserted as soon as SPM_WAIT_ACK becomes HIGH.
When the PC mode is not set it will help in early exit from
clock gating.

Change-Id: I74c44d3bb2b02bec449c809a5868ff944436eb09
Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>
msm: spm: Update msm_spm_turn_on_cpu_rail() to use new SAW2 base address

Update the msm_spm_turn_on_cpu_rail() to use SAW2 base addresses passed
from the release_secondary to turn on the cpu rail, before bringing back
the cpu online.

Change-Id: Ic57d3995c42291d9d2f28f03591823056bf0ff41
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
arm: dts: msm: update SPM sequences for krait v2.x

KPSS v2 implemented HW Sequencer to switch Krait power gate
modes. SPM toggle one power control signal to switch to RET/PC sleep.
If the SPM power control for the h/w sequencer is asserted for only
3 AHB clocks, a single cycle pulse is generated which latches the
newMode. The newMode is latched even though the h/w sequencer is
not idle. This causes the state machine to get stuck in LDO_PD state.

Update the retention SPM sequence as recommended by cpu design team
to avoid the issue. Power collapse sequences are already up to date.

CRs-fixed: 566952
Change-Id: I8fe74acf06d67b490f927b504e3aba266667cf9f
Signed-off-by: Venkat Devarasetty <vdevaras@codeaurora.org>
arm: arch_timer: set memory mapped timer interrupt as IRQF_TIMER

The memory mapped timer is used as a broadcast timer to wake the core for
timer interrupts when the arch timer might not be functional. When interrupt
is not marked as IRQF_NO_SUSPEND, the interrupt gets disabled during the
suspend_device_irqs() callback in the suspend path. If a core were to enter a
idle low power mode which relies on broadcast timer to process the interrupt,
the core is never woken up for timer interrupts.

Mark the interrupt with IRQF_TIMER which marks this interrupt as a timer
interrupt and also marks it as IRQF_NO_SUSPEND

CRs-fixed: 636712
Change-Id: I0484e92a9d05f66a0c5b3c00c584a3dd3fe6ae85
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
misc: qfpfuse: Fix overflow condition

Fix potential integer overflow for ioctl command to avoid incorrect
buffer allocation. Use the stack for data buffering to avoid the
small buffer allocation for improved performance. Increase the fuse
blow timeout in the driver to cover all QFPROM implementations.

CRs-Fixed: 550574,550575

Change-Id: Iee3cc1d38aa5dbf8ef693a43a0ca716fc8724c62
Acked-by: Radhakrishna Popuri <c_rpopur@qti.qualcomm.com>
Signed-off-by: Venkatesh Yadav Abbarapu <quicvenkat@codeaurora.org>
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>