Merge "smcinvoke_kernel_client: Move header to /soc/qcom"

This commit is contained in:
qctecmdr 2022-07-30 00:38:29 -07:00 committed by Gerrit - the friendly Code Review server
commit 6f95c77b27
13 changed files with 471 additions and 27 deletions

View File

@ -1,9 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#include "smcinvoke_object.h"
#include <soc/qcom/smcinvoke_object.h>
#define IQSEEComCompat_ERROR_APP_UNAVAILABLE INT32_C(10)
#define IQSEEComCompat_OP_sendRequest 0

View File

@ -1,9 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#include "smcinvoke_object.h"
#include <soc/qcom/smcinvoke_object.h>
#define IQSEEComCompatAppLoader_ERROR_INVALID_BUFFER INT32_C(10)
#define IQSEEComCompatAppLoader_ERROR_PIL_ROLLBACK_FAILURE INT32_C(11)

View File

@ -30,12 +30,14 @@
#include <asm/cacheflush.h>
#include <soc/qcom/qseecomi.h>
#include <linux/qtee_shmbridge.h>
#include "smcinvoke_object.h"
#include <soc/qcom/smcinvoke_object.h>
#include <misc/qseecom_kernel.h>
#include <soc/qcom/IClientEnv.h>
#define CREATE_TRACE_POINTS
#include "trace_smcinvoke.h"
#define SMCINVOKE_DEV "smcinvoke"
#define SMCINVOKE_TZ_ROOT_OBJ 1
#define SMCINVOKE_TZ_OBJ_NULL 0
@ -1945,6 +1947,14 @@ static long process_invoke_req(struct file *filp, unsigned int cmd,
return -EINVAL;
}
if (context_type == SMCINVOKE_OBJ_TYPE_TZ_OBJ &&
tzobj->tzhandle == SMCINVOKE_TZ_ROOT_OBJ &&
(req.op == IClientEnv_OP_notifyDomainChange ||
req.op == IClientEnv_OP_registerWithCredentials)) {
pr_err("invalid rootenv op\n");
return -EINVAL;
}
nr_args = OBJECT_COUNTS_NUM_buffers(req.counts) +
OBJECT_COUNTS_NUM_objects(req.counts);

View File

@ -0,0 +1,20 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __SMCINVOKE_HELPER_H
#define __SMCINVOKE_HELPER_H
#include <linux/types.h>
#include <linux/firmware.h>
#include <linux/qtee_shmbridge.h>
#include <soc/qcom/smcinvoke_object.h>
int smcinvoke_release_from_kernel_client(int fd);
int get_root_fd(int *root_fd);
int process_invoke_request_from_kernel_client(
int fd, struct smcinvoke_cmd_req *req);
#endif /* __SMCINVOKE_HELPER_H */

View File

@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#if !IS_ENABLED(CONFIG_QSEECOM)
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/fdtable.h>
@ -13,12 +14,20 @@
#include <linux/firmware.h>
#include <linux/elf.h>
#include <linux/smcinvoke.h>
#include "smcinvoke_helper.h"
#include <soc/qcom/IAppLoader.h>
#include <soc/qcom/CAppLoader.h>
#include <soc/qcom/IAppController.h>
#include <soc/qcom/IClientEnv.h>
#include <soc/qcom/IOpener.h>
#if !IS_ENABLED(CONFIG_QSEECOM)
#include <linux/qseecom.h>
#include "smcinvoke_object.h"
#include <misc/qseecom_kernel.h>
#include "IQSEEComCompat.h"
#include "IQSEEComCompatAppLoader.h"
#include "IClientEnv.h"
#endif
const uint32_t CQSEEComCompatAppLoader_UID = 122;
@ -280,20 +289,10 @@ static int get_root_obj(struct Object *rootObj)
* Get a client environment using CBOR encoded credentials
* with UID of SYSTEM_UID (1000)
*/
static int32_t get_client_env_object(struct Object *clientEnvObj)
int32_t get_client_env_object(struct Object *clientEnvObj)
{
int32_t ret = OBJECT_ERROR;
struct Object rootObj = Object_NULL;
/* Hardcode self cred buffer in CBOR encoded format.
* CBOR encoded credentials is created using following parameters,
* #define ATTR_UID 1
* #define ATTR_PKG_NAME 3
* #define SYSTEM_UID 1000
* static const uint8_t bufString[] = {"UefiSmcInvoke"};
*/
uint8_t encodedBuf[] = {0xA2, 0x01, 0x19, 0x03, 0xE8, 0x03, 0x6E, 0x55,
0x65, 0x66, 0x69, 0x53, 0x6D, 0x63, 0x49, 0x6E,
0x76, 0x6F, 0x6B, 0x65, 0x0};
/* get rootObj */
ret = get_root_obj(&rootObj);
@ -302,14 +301,17 @@ static int32_t get_client_env_object(struct Object *clientEnvObj)
return ret;
}
/* get client env */
ret = IClientEnv_registerLegacy(rootObj, encodedBuf,
sizeof(encodedBuf), clientEnvObj);
ret = IClientEnv_registerWithCredentials(rootObj, Object_NULL, clientEnvObj);
if (ret)
pr_err("Failed to get ClientEnvObject, ret = %d\n", ret);
Object_release(rootObj);
return ret;
}
EXPORT_SYMBOL(get_client_env_object);
#if !IS_ENABLED(CONFIG_QSEECOM)
static int load_app(struct qseecom_compat_context *cxt, const char *app_name)
{

View File

@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __CAPP_CLIENT_H
#define __CAPP_CLIENT_H
#define CAppClient_UID (0x97)
#endif /* __CAPP_CLIENT_H */

View File

@ -0,0 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __CAPP_LOADER_H
#define __CAPP_LOADER_H
#define CAppLoader_UID (0x3)
#endif /* __CAPP_LOADER_H */

View File

@ -0,0 +1,45 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __IAPP_CLIENT_H
#define __IAPP_CLIENT_H
#define IAppClient_ERROR_APP_NOT_FOUND INT32_C(10)
#define IAppClient_ERROR_APP_RESTART_FAILED INT32_C(11)
#define IAppClient_ERROR_APP_UNTRUSTED_CLIENT INT32_C(12)
#define IAppClient_ERROR_CLIENT_CRED_PARSING_FAILURE INT32_C(13)
#define IAppClient_ERROR_APP_LOAD_FAILED INT32_C(14)
#define IAppClient_OP_getAppObject 0
static inline int32_t
IAppClient_release(struct Object self)
{
return Object_invoke(self, Object_OP_release, 0, 0);
}
static inline int32_t
IAppClient_retain(struct Object self)
{
return Object_invoke(self, Object_OP_retain, 0, 0);
}
static inline int32_t
IAppClient_getAppObject(struct Object self, const void *appDistName_ptr, size_t appDistName_len,
struct Object *obj_ptr)
{
int32_t result;
union ObjectArg a[2];
a[0].bi = (struct ObjectBufIn) { appDistName_ptr, appDistName_len * 1 };
result = Object_invoke(self, IAppClient_OP_getAppObject, a, ObjectCounts_pack(1, 0, 0, 1));
*obj_ptr = a[1].o;
return result;
}
#endif /* __IAPP_CLIENT_H */

View File

@ -0,0 +1,153 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __IAPP_CONTROLLER_H
#define __IAPP_CONTROLLER_H
#define IAppController_CBO_INTERFACE_WAIT UINT32_C(1)
#define IAppController_ERROR_APP_SUSPENDED INT32_C(10)
#define IAppController_ERROR_APP_BLOCKED_ON_LISTENER INT32_C(11)
#define IAppController_ERROR_APP_UNLOADED INT32_C(12)
#define IAppController_ERROR_APP_IN_USE INT32_C(13)
#define IAppController_ERROR_NOT_SUPPORTED INT32_C(14)
#define IAppController_ERROR_CBO_UNKNOWN INT32_C(15)
#define IAppController_ERROR_APP_UNLOAD_NOT_ALLOWED INT32_C(16)
#define IAppController_ERROR_APP_DISCONNECTED INT32_C(17)
#define IAppController_ERROR_USER_DISCONNECT_REJECTED INT32_C(18)
#define IAppController_ERROR_STILL_RUNNING INT32_C(19)
#define IAppController_OP_openSession 0
#define IAppController_OP_unload 1
#define IAppController_OP_getAppObject 2
#define IAppController_OP_installCBO 3
#define IAppController_OP_disconnect 4
#define IAppController_OP_restart 5
static inline int32_t
IAppController_release(struct Object self)
{
return Object_invoke(self, Object_OP_release, 0, 0);
}
static inline int32_t
IAppController_retain(struct Object self)
{
return Object_invoke(self, Object_OP_retain, 0, 0);
}
static inline int32_t
IAppController_openSession(struct Object self, uint32_t cancelCode_val,
uint32_t connectionMethod_val, uint32_t connectionData_val, uint32_t paramTypes_val,
uint32_t exParamTypes_val, const void *i1_ptr, size_t i1_len, const void *i2_ptr,
size_t i2_len, const void *i3_ptr, size_t i3_len, const void *i4_ptr, size_t i4_len,
void *o1_ptr, size_t o1_len, size_t *o1_lenout, void *o2_ptr, size_t o2_len,
size_t *o2_lenout, void *o3_ptr, size_t o3_len, size_t *o3_lenout, void *o4_ptr,
size_t o4_len, size_t *o4_lenout, struct Object imem1_val, struct Object imem2_val,
struct Object imem3_val, struct Object imem4_val, uint32_t *memrefOutSz1_ptr,
uint32_t *memrefOutSz2_ptr, uint32_t *memrefOutSz3_ptr, uint32_t *memrefOutSz4_ptr,
struct Object *session_ptr, uint32_t *retValue_ptr, uint32_t *retOrigin_ptr)
{
union ObjectArg a[15];
struct {
uint32_t m_cancelCode;
uint32_t m_connectionMethod;
uint32_t m_connectionData;
uint32_t m_paramTypes;
uint32_t m_exParamTypes;
} i;
struct {
uint32_t m_memrefOutSz1;
uint32_t m_memrefOutSz2;
uint32_t m_memrefOutSz3;
uint32_t m_memrefOutSz4;
uint32_t m_retValue;
uint32_t m_retOrigin;
} o;
int32_t result;
a[0].b = (struct ObjectBuf) { &i, 20 };
a[5].b = (struct ObjectBuf) { &o, 24 };
i.m_cancelCode = cancelCode_val;
i.m_connectionMethod = connectionMethod_val;
i.m_connectionData = connectionData_val;
i.m_paramTypes = paramTypes_val;
i.m_exParamTypes = exParamTypes_val;
a[1].bi = (struct ObjectBufIn) { i1_ptr, i1_len * 1 };
a[2].bi = (struct ObjectBufIn) { i2_ptr, i2_len * 1 };
a[3].bi = (struct ObjectBufIn) { i3_ptr, i3_len * 1 };
a[4].bi = (struct ObjectBufIn) { i4_ptr, i4_len * 1 };
a[6].b = (struct ObjectBuf) { o1_ptr, o1_len * 1 };
a[7].b = (struct ObjectBuf) { o2_ptr, o2_len * 1 };
a[8].b = (struct ObjectBuf) { o3_ptr, o3_len * 1 };
a[9].b = (struct ObjectBuf) { o4_ptr, o4_len * 1 };
a[10].o = imem1_val;
a[11].o = imem2_val;
a[12].o = imem3_val;
a[13].o = imem4_val;
result = Object_invoke(self, IAppController_OP_openSession, a,
ObjectCounts_pack(5, 5, 4, 1));
*o1_lenout = a[6].b.size / 1;
*o2_lenout = a[7].b.size / 1;
*o3_lenout = a[8].b.size / 1;
*o4_lenout = a[9].b.size / 1;
*memrefOutSz1_ptr = o.m_memrefOutSz1;
*memrefOutSz2_ptr = o.m_memrefOutSz2;
*memrefOutSz3_ptr = o.m_memrefOutSz3;
*memrefOutSz4_ptr = o.m_memrefOutSz4;
*session_ptr = a[14].o;
*retValue_ptr = o.m_retValue;
*retOrigin_ptr = o.m_retOrigin;
return result;
}
static inline int32_t
IAppController_unload(struct Object self)
{
return Object_invoke(self, IAppController_OP_unload, 0, 0);
}
static inline int32_t
IAppController_getAppObject(struct Object self, struct Object *obj_ptr)
{
union ObjectArg a[1];
int32_t result = Object_invoke(self, IAppController_OP_getAppObject, a,
ObjectCounts_pack(0, 0, 0, 1));
*obj_ptr = a[0].o;
return result;
}
static inline int32_t
IAppController_installCBO(struct Object self, uint32_t uid_val, struct Object obj_val)
{
union ObjectArg a[2];
a[0].b = (struct ObjectBuf) { &uid_val, sizeof(uint32_t) };
a[1].o = obj_val;
return Object_invoke(self, IAppController_OP_installCBO, a,
ObjectCounts_pack(1, 0, 1, 0));
}
static inline int32_t
IAppController_disconnect(struct Object self)
{
return Object_invoke(self, IAppController_OP_disconnect, 0, 0);
}
static inline int32_t
IAppController_restart(struct Object self)
{
return Object_invoke(self, IAppController_OP_restart, 0, 0);
}
#endif /* __IAPP_CONTROLLER_H */

View File

@ -0,0 +1,109 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __IAPP_LOADER_H
#define __IAPP_LOADER_H
#define IAppLoader_ERROR_INVALID_BUFFER INT32_C(10)
#define IAppLoader_ERROR_PIL_ROLLBACK_FAILURE INT32_C(11)
#define IAppLoader_ERROR_ELF_SIGNATURE_ERROR INT32_C(12)
#define IAppLoader_ERROR_METADATA_INVALID INT32_C(13)
#define IAppLoader_ERROR_MAX_NUM_APPS INT32_C(14)
#define IAppLoader_ERROR_NO_NAME_IN_METADATA INT32_C(15)
#define IAppLoader_ERROR_ALREADY_LOADED INT32_C(16)
#define IAppLoader_ERROR_EMBEDDED_IMAGE_NOT_FOUND INT32_C(17)
#define IAppLoader_ERROR_TZ_HEAP_MALLOC_FAILURE INT32_C(18)
#define IAppLoader_ERROR_TA_APP_REGION_MALLOC_FAILURE INT32_C(19)
#define IAppLoader_ERROR_CLIENT_CRED_PARSING_FAILURE INT32_C(20)
#define IAppLoader_ERROR_APP_UNTRUSTED_CLIENT INT32_C(21)
#define IAppLoader_ERROR_APP_NOT_LOADED INT32_C(22)
#define IAppLoader_ERROR_APP_MAX_CLIENT_CONNECTIONS INT32_C(23)
#define IAppLoader_ERROR_APP_BLACKLISTED INT32_C(24)
#define IAppLoader_OP_loadFromBuffer 0
#define IAppLoader_OP_loadFromRegion 1
#define IAppLoader_OP_loadEmbedded 2
#define IAppLoader_OP_connect 3
static inline int32_t
IAppLoader_release(struct Object self)
{
return Object_invoke(self, Object_OP_release, 0, 0);
}
static inline int32_t
IAppLoader_retain(struct Object self)
{
return Object_invoke(self, Object_OP_retain, 0, 0);
}
static inline int32_t
IAppLoader_loadFromBuffer(struct Object self, const void *appElf_ptr, size_t appElf_len,
struct Object *appController_ptr)
{
union ObjectArg a[2];
int32_t result;
a[0].bi = (struct ObjectBufIn) { appElf_ptr, appElf_len * 1 };
result = Object_invoke(self, IAppLoader_OP_loadFromBuffer, a,
ObjectCounts_pack(1, 0, 0, 1));
*appController_ptr = a[1].o;
return result;
}
static inline int32_t
IAppLoader_loadFromRegion(struct Object self, struct Object appElf_val,
struct Object *appController_ptr)
{
union ObjectArg a[2];
int32_t result;
a[0].o = appElf_val;
result = Object_invoke(self, IAppLoader_OP_loadFromRegion, a,
ObjectCounts_pack(0, 0, 1, 1));
*appController_ptr = a[1].o;
return result;
}
static inline int32_t
IAppLoader_loadEmbedded(struct Object self, const void *appName_ptr, size_t appName_len,
struct Object *appController_ptr)
{
union ObjectArg a[2];
int32_t result;
a[0].bi = (struct ObjectBufIn) { appName_ptr, appName_len * 1 };
result = Object_invoke(self, IAppLoader_OP_loadEmbedded, a, ObjectCounts_pack(1, 0, 0, 1));
*appController_ptr = a[1].o;
return result;
}
static inline int32_t
IAppLoader_connect(struct Object self, const void *appName_ptr, size_t appName_len,
struct Object *appController_ptr)
{
union ObjectArg a[2];
int32_t result;
a[0].bi = (struct ObjectBufIn) { appName_ptr, appName_len * 1 };
result = Object_invoke(self, IAppLoader_OP_connect, a, ObjectCounts_pack(1, 0, 0, 1));
*appController_ptr = a[1].o;
return result;
}
#endif /* __IAPP_LOADER_H */

View File

@ -1,12 +1,20 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __ICLIENT_ENV_H
#define __ICLIENT_ENV_H
#include "smcinvoke_object.h"
#define IClientEnv_OP_open 0
#define IClientEnv_OP_registerLegacy 1
#define IClientEnv_OP_register 2
#define IClientEnv_OP_registerWithWhitelist 3
#define IClientEnv_OP_notifyDomainChange 4
#define IClientEnv_OP_registerWithCredentials 5
static inline int32_t
IClientEnv_release(struct Object self)
@ -89,3 +97,27 @@ IClientEnv_registerWithWhitelist(struct Object self,
return result;
}
static inline int32_t
IClientEnv_notifyDomainChange(struct Object self)
{
return Object_invoke(self, IClientEnv_OP_notifyDomainChange, 0, 0);
}
static inline int32_t
IClientEnv_registerWithCredentials(struct Object self, struct Object
credentials_val, struct Object *clientEnv_ptr)
{
union ObjectArg a[2] = {{{0, 0}}};
int32_t result;
a[0].o = credentials_val;
result = Object_invoke(self, IClientEnv_OP_registerWithCredentials, a,
ObjectCounts_pack(0, 0, 1, 1));
*clientEnv_ptr = a[1].o;
return result;
}
#endif /* __ICLIENT_ENV_H */

View File

@ -0,0 +1,45 @@
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __IOPENER_H
#define __IOPENER_H
/** 0 is not a valid service ID. */
#define IOpener_INVALID_ID UINT32_C(0)
#define IOpener_ERROR_NOT_FOUND INT32_C(10)
#define IOpener_ERROR_PRIVILEGE INT32_C(11)
#define IOpener_ERROR_NOT_SUPPORTED INT32_C(12)
#define IOpener_OP_open 0
static inline int32_t
IOpener_release(struct Object self)
{
return Object_invoke(self, Object_OP_release, 0, 0);
}
static inline int32_t
IOpener_retain(struct Object self)
{
return Object_invoke(self, Object_OP_retain, 0, 0);
}
static inline int32_t
IOpener_open(struct Object self, uint32_t id_val, struct Object *obj_ptr)
{
int32_t result;
union ObjectArg a[2];
a[0].b = (struct ObjectBuf) { &id_val, sizeof(uint32_t) };
result = Object_invoke(self, IOpener_OP_open, a, ObjectCounts_pack(1, 0, 0, 1));
*obj_ptr = a[1].o;
return result;
}
#endif /* __IOPENER_H */

View File

@ -1,11 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __SMCINVOKE_OBJECT_H
#define __SMCINVOKE_OBJECT_H
#include <linux/types.h>
#include <linux/firmware.h>
#include <linux/qtee_shmbridge.h>
@ -183,13 +184,13 @@ static inline void Object_replace(struct Object *loc, struct Object objNew)
#define Object_ASSIGN_NULL(loc) Object_replace(&(loc), Object_NULL)
int smcinvoke_release_from_kernel_client(int fd);
int get_root_fd(int *root_fd);
int process_invoke_request_from_kernel_client(
int fd, struct smcinvoke_cmd_req *req);
/* API Exposed Functionality for Kernel Client to get root env object */
int32_t get_client_env_object(struct Object *clientEnvObj);
/* API to provide functionality to Client to load a firmware using shared memory Bridge
* app name is the TA name which will load the firmware and we will search for firmware on
* predefined path.
*/
char *firmware_request_from_smcinvoke(const char *appname, size_t *fw_size, struct qtee_shm *shm);
#endif /* __SMCINVOKE_OBJECT_H */