Slim_msm: Wait for reconfig sequence to complete

Wait for current reconfiguration to complete during
reconfigure_now sequnce. Earlier we are not waiting
for reconfiguration done interrupt after sending the
reconfiguration message to the slimus hardware. This
may lead to hardware synchronization issues in lower
slimbus clock frequencies.

In this patch we are waiting for the reconfiguration
done interrupt from slimbus hardware.

CRs-Fixed: 490022
Change-Id: If0126dac9a1ad2d931e9a0e345d19559fe36f67a
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
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>
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>

Conflicts:
	arch/arm/mach-msm/clock-8974.c
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>

Conflicts:
	drivers/misc/qseecom.c
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>

Conflicts:
	drivers/misc/qseecom.c
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>
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>
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>
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>
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>
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>
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>

Conflicts:
	drivers/misc/qseecom.c
qseecom: Fix kernel panic

There exist a  possibility for "handle" input being NULL.  We need
to check for this before dereferencing it.

Change-Id: I50c1c6855ad303e05b52e6e37d774551d9db4fc4
Signed-off-by: Mona Hossain <mhossain@codeaurora.org>
msm:qseecom: Add validation checks for memory cleanup for qseecom

Add validation checks to handle memory freeing &
prevent NULL pointer access.

Change-Id: I7383b10037ca0ce3f049de060dc70f3ad4b9ca55
Signed-off-by: Hariprasad Dhalinarasimha <hnamgund@codeaurora.org>
qseecom: fix memory leak in qseecom_start_app()

Fixes the incorrect reurn path in qseecom_start_app() function with
proper clean-up. With out this patch, there are lot of memory leaks.

Change-Id: Ib9f7b08dd86952c1b0a1572d9a7d81517c3b2189
CRs-fixed: 509111
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
qseecom: Fix error handling path in receive_req()

This patch fixes the error handling path in receive_req() function
called from userspace. Issue seen if user is calling the receive_req
function without calling the listener registration. qseecom_find_svc()
should return NULL if there are no services found.

Change-Id: Id51d8f48d7266b5acbc845f7b9ac0068d16b1ede
CRs-fixed: 496927
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
qseecom: Fix QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ kernel crash

Fixes the kernel crash occuring with IOCTL_UNLOAD_EXTERNAL_ELF_REQ
ioctl by adding unavailable client type to qseecom_client_handle_type
enum, which is required in the driver during qseecom_release().

Change-Id: I73b817255149ffc4a808852feb2954a0ba3c317f
CRs-fixed: 508253
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
qseecom: Add NULL pointer check in qseecom_ioctl

NULL pointer check is added to the qseecom driver in qseecom_ioctl,
which is required to validate the data pointer before executing any
other code from ioctl's.

Change-Id: I6fecf13769b4d7e94eebd4dc075a5ece79b18e1b
Signed-off-by: AnilKumar Chimata <anilc@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: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Update HELLO message processing

When IPC Router receives a HELLO message from a remote IPC Router, the
protocol is to send a list of servers registered locally and registered
outside the mesh network where the HELLO message is received. Currently
the implementation does not follow this protocol strictly and hence
correct the implementation.

CRs-Fixed: 414147
Change-Id: I75aa089b152baea0925d127b1d9deb6684677cfa
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>