From 8456ddc256dd40c9f80f4a8a9dd4f6cf0f27ddae Mon Sep 17 00:00:00 2001 From: Anmolpreet Kaur Date: Thu, 22 Sep 2022 17:53:28 +0530 Subject: [PATCH] securemsm-kernel: Add support for qseecom proxy module A new module named qseecom_proxy has been defined in kernel which acts as a forwarder for calls received from kernel clients of qseecom and smcinvoke. This change adds the support for calling that module from the vendor dlkm modules smcinvoke and qseecom. Change-Id: I0d1aa93b9cea9e6a6e1fee17c33c78e14deb8ecf Signed-off-by: Anmolpreet Kaur --- hdcp/hdcp_qseecom.c | 4 +++ linux/misc/qseecom_priv.h | 25 ++++++++++++++++ qseecom/qseecom.c | 58 ++++++++++++++++++++++++++++++++---- smcinvoke/smcinvoke.c | 15 +++++++++- smcinvoke/smcinvoke_kernel.c | 52 +++++++++++++++++++++++++++----- 5 files changed, 139 insertions(+), 15 deletions(-) create mode 100644 linux/misc/qseecom_priv.h diff --git a/hdcp/hdcp_qseecom.c b/hdcp/hdcp_qseecom.c index e1a9212276..2bd4f3111c 100644 --- a/hdcp/hdcp_qseecom.c +++ b/hdcp/hdcp_qseecom.c @@ -23,7 +23,11 @@ #include #include #include +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) +#include +#else #include "misc/qseecom_kernel.h" +#endif #define HDCP2P2_APP_NAME "hdcp2p2" #define HDCP1_APP_NAME "hdcp1" diff --git a/linux/misc/qseecom_priv.h b/linux/misc/qseecom_priv.h new file mode 100644 index 0000000000..f15115fa93 --- /dev/null +++ b/linux/misc/qseecom_priv.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __QSEECOM_PRIV_H_ +#define __QSEECOM_PRIV_H_ + +#include + +#if IS_ENABLED(CONFIG_QSEECOM) || IS_ENABLED(CONFIG_ARCH_SA8155) + +int qseecom_process_listener_from_smcinvoke(uint32_t *result, + u64 *response_type, unsigned int *data); +#else +static inline int qseecom_process_listener_from_smcinvoke(uint32_t *result, + u64 *response_type, unsigned int *data) +{ + return -EOPNOTSUPP; +} +#endif + +int get_qseecom_kernel_fun_ops(void); + +#endif diff --git a/qseecom/qseecom.c b/qseecom/qseecom.c index cfeb6dff7f..4ac91678e3 100644 --- a/qseecom/qseecom.c +++ b/qseecom/qseecom.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,12 @@ #include #include #include "ice.h" +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) +#include +#include "misc/qseecom_priv.h" +#else +#include "misc/qseecom_kernel.h" +#endif #define QSEECOM_DEV "qseecom" #define QSEOS_VERSION_14 0x14 @@ -4994,7 +4999,7 @@ static int qseecom_unload_commonlib_image(void) return ret; } -int qseecom_start_app(struct qseecom_handle **handle, +static int __qseecom_start_app(struct qseecom_handle **handle, char *app_name, uint32_t size) { int32_t ret = 0; @@ -5162,9 +5167,8 @@ err: __wakeup_unload_app_kthread(); return ret; } -EXPORT_SYMBOL(qseecom_start_app); -int qseecom_shutdown_app(struct qseecom_handle **handle) +static int __qseecom_shutdown_app(struct qseecom_handle **handle) { int ret = -EINVAL; struct qseecom_dev_handle *data; @@ -5218,9 +5222,8 @@ int qseecom_shutdown_app(struct qseecom_handle **handle) __wakeup_unload_app_kthread(); return ret; } -EXPORT_SYMBOL(qseecom_shutdown_app); -int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, +static int __qseecom_send_command(struct qseecom_handle *handle, void *send_buf, uint32_t sbuf_len, void *resp_buf, uint32_t rbuf_len) { int ret = 0; @@ -5302,7 +5305,42 @@ int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, req.resp_len, req.resp_buf); return ret; } + +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) +const static struct qseecom_drv_ops qseecom_driver_ops = { + .qseecom_send_command = __qseecom_send_command, + .qseecom_start_app = __qseecom_start_app, + .qseecom_shutdown_app = __qseecom_shutdown_app, +}; + +int get_qseecom_kernel_fun_ops(void) +{ + return provide_qseecom_kernel_fun_ops(&qseecom_driver_ops); +} + +#else + +int qseecom_start_app(struct qseecom_handle **handle, + char *app_name, uint32_t size) +{ + return __qseecom_start_app(handle, app_name, size); +} +EXPORT_SYMBOL(qseecom_start_app); + +int qseecom_shutdown_app(struct qseecom_handle **handle) +{ + return __qseecom_shutdown_app(handle); +} +EXPORT_SYMBOL(qseecom_shutdown_app); + +int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, + uint32_t sbuf_len, void *resp_buf, uint32_t rbuf_len) +{ + return __qseecom_send_command(handle, send_buf, sbuf_len, + resp_buf, rbuf_len); +} EXPORT_SYMBOL(qseecom_send_command); +#endif int qseecom_set_bandwidth(struct qseecom_handle *handle, bool high) { @@ -9577,6 +9615,14 @@ static int qseecom_probe(struct platform_device *pdev) rc = qseecom_create_kthreads(); if (rc) goto exit_deinit_bus; + +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) + /*If the api fails to get the func ops, print the error and continue + * Do not treat it as fatal*/ + rc = get_qseecom_kernel_fun_ops(); + if (rc) + pr_err("failed to provide qseecom ops %d", rc); +#endif atomic_set(&qseecom.qseecom_state, QSEECOM_STATE_READY); return 0; diff --git a/smcinvoke/smcinvoke.c b/smcinvoke/smcinvoke.c index d2d03e2547..d29258e75f 100644 --- a/smcinvoke/smcinvoke.c +++ b/smcinvoke/smcinvoke.c @@ -30,10 +30,15 @@ #include #include #include -#include "misc/qseecom_kernel.h" #include "smcinvoke.h" #include "smcinvoke_object.h" #include "IClientEnv.h" +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) +#include +#include "misc/qseecom_priv.h" +#else +#include "misc/qseecom_kernel.h" +#endif #define CREATE_TRACE_POINTS #include "trace_smcinvoke.h" @@ -2795,6 +2800,14 @@ static int smcinvoke_probe(struct platform_device *pdev) } smcinvoke_pdev = pdev; +#if !IS_ENABLED(CONFIG_QSEECOM) && IS_ENABLED(CONFIG_QSEECOM_PROXY) + /*If the api fails to get the func ops, print the error and continue + * Do not treat it as fatal*/ + rc = get_qseecom_kernel_fun_ops(); + if (rc) { + pr_err("failed to get qseecom kernel func ops %d", rc); + } +#endif return 0; exit_destroy_device: diff --git a/smcinvoke/smcinvoke_kernel.c b/smcinvoke/smcinvoke_kernel.c index 2e8aaec18e..020aee0dc8 100644 --- a/smcinvoke/smcinvoke_kernel.c +++ b/smcinvoke/smcinvoke_kernel.c @@ -15,12 +15,15 @@ #include "smcinvoke.h" #include "smcinvoke_object.h" #include "IClientEnv.h" - #if !IS_ENABLED(CONFIG_QSEECOM) -#include "linux/qseecom.h" -#include "misc/qseecom_kernel.h" #include "IQSEEComCompat.h" #include "IQSEEComCompatAppLoader.h" +#include "linux/qseecom.h" +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) +#include +#else +#include "misc/qseecom_kernel.h" +#endif #endif const uint32_t CQSEEComCompatAppLoader_UID = 122; @@ -361,7 +364,7 @@ exit_release_shm: return ret; } -int qseecom_start_app(struct qseecom_handle **handle, +static int __qseecom_start_app(struct qseecom_handle **handle, char *app_name, uint32_t size) { int ret = 0; @@ -430,9 +433,8 @@ exit_free_cxt: return ret; } -EXPORT_SYMBOL(qseecom_start_app); -int qseecom_shutdown_app(struct qseecom_handle **handle) +static int __qseecom_shutdown_app(struct qseecom_handle **handle) { struct qseecom_compat_context *cxt = (struct qseecom_compat_context *)(*handle); @@ -450,9 +452,8 @@ int qseecom_shutdown_app(struct qseecom_handle **handle) *handle = NULL; return 0; } -EXPORT_SYMBOL(qseecom_shutdown_app); -int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, +static int __qseecom_send_command(struct qseecom_handle *handle, void *send_buf, uint32_t sbuf_len, void *resp_buf, uint32_t rbuf_len) { struct qseecom_compat_context *cxt = @@ -477,5 +478,40 @@ int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, Object_NULL, Object_NULL, Object_NULL, Object_NULL); } + +#if IS_ENABLED(CONFIG_QSEECOM_PROXY) +const static struct qseecom_drv_ops qseecom_driver_ops = { + .qseecom_send_command = __qseecom_send_command, + .qseecom_start_app = __qseecom_start_app, + .qseecom_shutdown_app = __qseecom_shutdown_app, +}; + +int get_qseecom_kernel_fun_ops(void) +{ + return provide_qseecom_kernel_fun_ops(&qseecom_driver_ops); +} +#else + +int qseecom_start_app(struct qseecom_handle **handle, + char *app_name, uint32_t size) +{ + return __qseecom_start_app(handle, app_name, size); +} +EXPORT_SYMBOL(qseecom_start_app); + +int qseecom_shutdown_app(struct qseecom_handle **handle) +{ + return __qseecom_shutdown_app(handle); +} +EXPORT_SYMBOL(qseecom_shutdown_app); + +int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, + uint32_t sbuf_len, void *resp_buf, uint32_t rbuf_len) +{ + return __qseecom_send_command(handle, send_buf, sbuf_len, + resp_buf, rbuf_len); +} EXPORT_SYMBOL(qseecom_send_command); #endif + +#endif