msm: Fix correct topology for qseecom bus scaling.

Currently, bus scaling topology for qseecom is incorrect.
 -Added the correct topology paths for accessing Crypto
  Engine which is controlled by QSEE.
 -Removed setting the clock frequency of DFAB. This is
  done by the bus driver.
 -Removed references to the dfab clock instance defined
  in clocks file.

Change-Id: Ib6953ea3bf5721d458bfe2aa06c54be329a8fdb9
Signed-off-by: Ramesh Masavarapu <rameshm@codeaurora.org>
(cherry picked from commit 1e8c7242fd3f32ade703484d2113f4a6f442a0e8)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: include msm-specific ion header

All msm_ion clients need to use <linux/msm_ion.h> instead of
<linux/ion.h>

Change-Id: If78e8a3aa66209b93449569cc9bd670b8d21008c
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom:Fix race condition while voting for clocks

In the current functionality, if DFAB clock is already on and a
request is made to turn on SFPB clock, the DFAB clock is turned
off and SFPB clock is turned on and vice-versa.

The above situation can lead to unexpected errors. The current fix
makes sure that clocks that are on are not voted to be off without
explicit request.

Change-Id: I6c3230e23b105c049cdb0aace579b8a176328c84
Signed-off-by: Ramesh Masavarapu <rameshm@codeaurora.org>
(cherry picked from commit 8d7565828aca6023ca968d2e5350737bd6d86215)

Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Add SFAB clock voting.

Add SFAB voting in  QSEECOM_IOCTL_PERF_ENABLE_REQ.
The SFAB clock needs to be bumped up to its optimal
value when opearting in high bandwidth mode (for max
crypto performance)

Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
(cherry picked from commit 8e2d73a0ade94ffd27882043d562c7ee825d9f7c)

Conflicts:

	drivers/misc/qseecom.c

Change-Id: I281e544756304f19969afbab7196a227dad0e2b1
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Enable clocks for the Crypto Engine used by Trustzone.

All interactions with secure applications on TZ by non-secure
apps on HLOS need the crypto clocks on.
Without this, simple operations as loading secure apps in
Trust zone fail.

Change-Id: I37097cb401508f7582de014e502f3709170ca6b2
Signed-off-by: Ramesh Masavarapu <rameshm@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Add kernel space client support

Add support for kernel space client:
    - add support for starting secure app by kernel client
    - add support for shutting down secure app by kernel client
    - add support for sending command to secure app loaded by
      kernel space client(s)

The above is needed for allowing kernel modules to communicate
with app running in secure domain.

Change-Id: I3ae3a7648714eb7d7f4801b2f8e7cd94b5c64bdf
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: mako compatibility fixup

Signed-off-by: faux123 <reioux@gmail.com>
qseecom: Vote for CE clk before loading image

Add support for setting the Crypto HW to operate in
high bandwidth mode before issuing a request to load
image.

This is needed for better performance when using crypto
HW to authenticate the image before loading it.

Change-Id: Ib976d8227e605b9aad8191c6fe8f1dcc5d28e90e
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Add API to set bandwidth for CE HW

Add API to allow kernel space clients to bump up
CE clks for improved performance

Change-Id: Iecd13cf4efe9b2b1415be56d3ec9e4dc040918f8
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Remove mutex lock in load_fw API

Loading of app is stuck waiting for lock on app_access_lock
being released.  This mutex is already locked prior to invoking
load_fw.
Removing the mutex lock (already called before invoking load_fw),
in load_fw, fixes the issue with the loading getting stuck.

Change-Id: Ia095bf268c6c1c08dfe1544280567ba4bd4661d6
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Fix the kernel_qseecom_client send_cmd fucntionality

Give the correct address of shared virtual buffer
address to be used during start_app.

Change-Id: Iebe10304c9c295c34eb3e1aeba9255e7c91609cc
CRs-fixed: 434753
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>

Conflicts:
	drivers/misc/qseecom.c

Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Add SFAB clock voting in set_bandwidth request

Vote for SFAB clock when requesting to set to crypto high
performance mode.
The SFAB clock needs to be bumped up to its optimal
value when operating in high bandwidth mode (for max
crypto performance)

Change-Id: Ifea68a15d48f737a855acd05e59ac20d4438a9cd
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Remove extra call to disable clock.

Currently the qseecom driver calls qsee_disable_clock_vote() in
the release function. This reduces the reference count during
disabling of the clock and results in turning off the bus clocks
inconsistently.
This change fixes the inconsistency.

Change-Id: I37d048928373f0539da9fee0910fc9a20239c307
Signed-off-by: Ramesh Masavarapu <rameshm@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Fix failure to release qseecom handle

qseecom_release() returns a failure, if it is unable to find
app_id of zero, associated with the handle in the app list.

There exists scenarios where the handle may not have the
app_id initialized and remain to be 0.  In these scenarios,
once the uninitialized zero app_id is not found in the list,
it returns a failure.

Fix to this is look for non-zero valid app_id in the app_list when
releasing the handle.

Change-Id: I7b6489526da57cd2106f4aae9fdc0547e7a5fe86
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
qseecom: Check if app exists before loading the app

There is a chance of send a request to QSEE to load an app that
is already previously loaded. Requesting QSEE to load an app
that is already loaded will result in a failure.

Issuing a request to QSEE to check if app already exists before
issuing a request to load it, all within the same app_access_lock
mutex, fixes this issue.

CRs-Fixed: 420473
Change-Id: I5dfb02c7b0f0144d142fc70084ec1e096ada0439
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
msm: boards: Enable Krait Retention.

Add SPM sequences to do Krait retention for 8960,8930
and 8064. Also added a new rpmrs level containing the
latencies and power measurements for this new low power
state.

CRs-Fixed: 369864
Change-Id: Ib30a9a978cf38b35037810a4001c9277837acd4c
Signed-off-by: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
msm: Fix correct topology for qseecom bus scaling.

Currently, bus scaling topology for qseecom is incorrect.
 -Added the correct topology paths for accessing Crypto
  Engine which is controlled by QSEE.
 -Removed setting the clock frequency of DFAB. This is
  done by the bus driver.
 -Removed references to the dfab clock instance defined
  in clocks file.

Change-Id: Ib6953ea3bf5721d458bfe2aa06c54be329a8fdb9
Signed-off-by: Ramesh Masavarapu <rameshm@codeaurora.org>
(cherry picked from commit 1e8c7242fd3f32ade703484d2113f4a6f442a0e8)

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

Conflicts:

	arch/arm/mach-msm/board-8064.c
	arch/arm/mach-msm/board-8930.c
	arch/arm/mach-msm/board-8960.c
	drivers/misc/qseecom.c

Signed-off-by: Seongmin Park <r_data@naver.com>
msm: clock: Move voltage scaling to prepare/unprepare

Move the voltage calls to a sleepable context so we can avoid
spinning for hundreds of microseconds with interrupts disabled
waiting for a regulator to increase. This change also paves the
way to making the clock driver into a real regulator consumer
that uses the proper regulator APIs instead of the MSM specific
rpm_vreg API.

Doing this also requires us to make clk_set_rate() a sleeping
call so that concurrent clk_prepare() and clk_set_rate() calls
are synchronized. Making clk_set_rate() sleepable also
necessitates moving the clk_set_rate() call in clock-voter.c to a
sleepable context. Do that by having clock-voter aggregate and
update the rate in prepare/unprepare instead of enable/disable
(note that enable/disable of voter clocks implicitly calls
enable/disable on the parent via generic clock code).

Now that clk_set_rate() is sleeping, call clk_prepare() and
clk_unprepare() in the clock-local code when a rate change
requires reparenting the clock. This cleans up a problem we have
where sources may be left unprepared by a clock rate switch
(hence the default true warned flag for PLLs and crystals).

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

Conflicts:

	arch/arm/mach-msm/clock-local2.c

Change-Id: Ie5bbb17537d5b33de92f8ea1c2da6070b18c14f1
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
msm: clock-local: Add PXO rates for LPASS clocks on 8660, 8960, 8930, 8064

LPASS clock are enabled out of reset on these SoCs, with PXO selected
as their undivided source. Because PXO rates are not present in the
frequency tables however, these clocks fail to handoff with reason
'HANDOFF_UNKNOWN_RATE'. As a result, clock_late_init() does not attempt
to disable these clocks in lateinit.

Add PXO rates to the LPASS frequency tables so that handoff succeeds
and, in lateinit, disables them if they are not used.

(cherry picked from commit ac15a37fd85089a2aef16624140a5d0a6cd1d71b)

Signed-off-by: Matt Wagantall <mattw@codeaurora.org>

Change-Id: Id8d674bfa3d41316be8aa14c5cc84baa77078d23

Signed-off-by: Neha Pandey <nehap@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>
msm: clock-8960: Lower frequency requirements of fpb active votes

We have an active set vote for the multimedia fpb and chip fpb so
that the registers are accessible whenever the processor is
awake. Unfortunately these requests are at the highest rate
supported which is not really necessary to ensure that the buses
are clocking. Lower the rate requests to the fastest speed that
doesn't require increasing voltages to allow the chip to hit low
voltages when the processor is awake.

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

Change-Id: I3ee4926da0d953e7e31c3c64dffd11f6ee5edb72
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
Signed-off-by: Seongmin Park <r_data@naver.com>