msm: Add null pointer checks

Add null pointer checks to ensure subsystem API calls
do not dereferences null pointers and cause system
crash.

Change-Id: I5d5efc21b346ac5b9f6ddb2e42354aaf40fb56a7
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/subsystem_map.c
msm: cpufreq: fix a race between hotplug and cpufreq

When msm_cpufreq_target() is called without holding the policy
semaphore, there is a rare chance that the cpu gets hotplugged in
the acpuclk_set_rate. The probability of this issue increases
when cross-calling is used or using interactive governor which
tries to set all cpu frequencies from a single thread.

Add a hotplug notifier and set the device_suspended flag holding
the suspend mutex, when cpu is going down. This mutex is always
held when frequency changes are done.

Change-Id: Ide3aa6927ad60d2512d63761c51bb15117461250
Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>
(cherry picked from commit 56f5a6de7f2ab48ed0538da727ad52673fb801a2)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: cpufreq: increase priority of thread that increases frequencies

When the cpufreq governors request for increase in frequency from kworker
threads, there is chance that the kworker thread is cpu starved due to
other high priority threads, leading to undesirable increase in frequency
ramp-up latency. Add the calling thread to SCHED_FIFO policy when
requesting for increase in frequency and restore back to original policy
after ramp-up is completed.

Change-Id: Ie4fa199b7f9087717cb94dfcc2eddea27cc0012b
Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/cpufreq.c
msm: acpuclock: Support tracing of CPU frequency changes

Utilize the cpu_frequency traces to profile CPU frequency switching.

Change-Id: I5f7b5ea9ab0bd70deb3d64c9361c4b56ab63466d
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
(cherry picked from commit 7c57b5dfc88a77a7d0c1d7820cf0baa3c37210fc)
(cherry picked from commit e759493b08da1c1d39e68849b6092b3dac3928aa)
trace: power: add cpu_frequency_switch_{start, end}

It is sometimes useful to profile how long CPU frequency switches
take, since they often involve variable overhead (PLL lock times,
voltage increase time, etc.). Add additional traces to to make this
possible.

Since the overhead involved may differ based on the frequencies
being switched between, record both the start and the end frequencies
as part of the trace.

Change-Id: I2de743fc357dad3590fd4980f65f38f6073d426e
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
(cherry picked from commit 0fe22de09613ce497561f51151b2c50b6c4a1c3e)
(cherry picked from commit 9ab0adbcac4df4d681617a8368329d2f4cad4171)
msm: 8960: Remove pre-silicon support

Support for RUMI and simulation are no longer required.

Change-Id: I49cdbc463a8484d18696eceae9a2a2d7aa9b2b85
Signed-off-by: Syed Rameez Mustafa <rameezmustafa@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8960-display.c
	arch/arm/mach-msm/board-8960-pmic.c
	arch/arm/mach-msm/board-8960.c
	arch/arm/mach-msm/msm-krait-l2-accessors.c
msm: hotplug/platsmp: Fix cpu invaldation pointer arithmetic

These functions take two void pointers indicating where to start
and end the invalidation and cache flush. The pointer arithmetic
is considering the pen_release pointer as an int pointer so
adding sizeof(pen_release) is adding 16 bytes to the pointer and
specifying that as the end. This inadvertently invalidates data
next to the pen_release variable which could be bad. Fix the
pointer math to only invalidate or clean the region for the
pen_release variable.

Change-Id: If0cf0e5de7c9f4b8c70662b29957a1f347809124
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/hotplug.c
msm: hotplug: Change the pen variable in one place

Other WFI based hotplug implementations set the pen variable to
-1 in C code and do the appropriate flushing operations in one
location. They also don't try to invalidate the cache on a
spurious wakeup and report how many spurious wakeups there were.
Let's do the same in our code so that we can remove our
dependence on the dmac_{inv,flush}_range() functions (which are
no longer upstream) and easily report spurious wakeups to the
kernel logs.

This does delay the time we set the pen back to its default
value, but that doesn't actually matter because generic ARM
hotplug code already waits for a completion before continuing.

Change-Id: Ic36fbf744fe8abeda20ad9859a207b5e37c5e63c
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/hotplug.c
msm: 8064: Remove pre-silicon support

Support for RUMI and simulation  are no longer required.

Change-Id: Id73f9f40340062c73f9180c59d3f4a525979ca86
Signed-off-by: Syed Rameez Mustafa <rameezmustafa@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/board-8064-pmic.c
	arch/arm/mach-msm/board-8064-storage.c
	arch/arm/mach-msm/board-8064.c
msm: platsmp: Support the full boot chain for 8974

With the full boot chain, the secondary CPUs are held in
reset until the primary CPU explicitly releases them from
reset.

Change-Id: Ie2a9f235386133d570dc826fe1cf5b44587a0706
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
msm: platsmp: Update Krait release sequence for 8960AB.

The Krait CPU in the MSM8960AB target requires a slightly
modified sequence to bring the secondary cores out of
reset.

Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
(cherry picked from commit 121f75f4ec8a1cd05688e66d959e55d1c5c2f327)

Change-Id: I5b909ba7980263a9fa2d01846814f9c1ce114400
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/platsmp.c
msm: scm-boot: Clarify types for scm_set_boot_addr()

The boot address is a physical address (even if the secure
monitor only considers it to be 32 bits). Move to using
phys_addr_t to clarify this is a physical address and to ease
any support of LPAE in the future. Also make the flags unsigned
so that we can use the highest bit if necessary.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
(cherry picked from commit efadd5b002a819d0e0213ac10a1e3d1c9463a07b)

Change-Id: I06c5af4093b6fa947a8705364425de2c54464cde
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/scm-boot.c
msm: platsmp: Update Krait reset sequence

The SMP CPU initialization code incorrectly applied the
KPSS 2.x CPU reset sequence to Krait Pass 3, even on
targets using KPSS 1.x. Modify the SMP code to apply the
KPSS 1.x reset sequence where appropriate, regardless of
the CPU version. Also incorporate updated register settings
to avoid having to later reconfigure the Krait PLL clamps.

CRs-Fixed: 431744

Change-Id: I41b07fa96e95bdc23ba742f6f4a9fcea70a10a7a
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
Signed-off-by: Neha Pandey <nehap@codeaurora.org>

Conflicts:
	arch/arm/mach-msm/platsmp.c
msm: Export some iommu domain management functions

Several of the iommu virtual address space functions may
need to be accessed by modules. Export the symbol.

Change-Id: Ief99cbb63f729943b6d8b45ce9aed071d84decd1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
(cherry picked from commit 33b30bee472264ecf5b7d06d842349bbe593d0fc)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
(cherry picked from commit 67c19b8a6c2a8a4e27df324516ecddbf758c379c)
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>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
Merge remote-tracking branch 'codeaurora/jb_2.6'
Revert "vsprintf: ignore %n again"

This reverts commit 6aa1415be536d39b771d5bfc79b82b2308bb6559.