Add 'qcom/opensource/securemsm-kernel/' from commit 'a6005ceed271246683596608e4c56b4d921fb363'
git-subtree-dir: qcom/opensource/securemsm-kernel git-subtree-mainline:46e9caf0d0
git-subtree-split:a6005ceed2
Change-Id: repo: https://git.codelinaro.org/clo/la/platform/vendor/qcom/opensource/securemsm-kernel tag: LA.VENDOR.14.3.0.r1-17300-lanai.QSSI15.0
This commit is contained in:
71
qcom/opensource/securemsm-kernel/smcinvoke/IQSEEComCompat.h
Normal file
71
qcom/opensource/securemsm-kernel/smcinvoke/IQSEEComCompat.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Copyright (c) 2021 The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "smcinvoke_object.h"
|
||||
|
||||
#define IQSEEComCompat_ERROR_APP_UNAVAILABLE INT32_C(10)
|
||||
#define IQSEEComCompat_OP_sendRequest 0
|
||||
#define IQSEEComCompat_OP_disconnect 1
|
||||
#define IQSEEComCompat_OP_unload 2
|
||||
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompat_release(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, Object_OP_release, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompat_retain(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, Object_OP_retain, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompat_sendRequest(struct Object self,
|
||||
const void *reqIn_ptr, size_t reqIn_len,
|
||||
const void *rspIn_ptr, size_t rspIn_len,
|
||||
void *reqOut_ptr, size_t reqOut_len, size_t *reqOut_lenout,
|
||||
void *rspOut_ptr, size_t rspOut_len, size_t *rspOut_lenout,
|
||||
const uint32_t *embeddedBufOffsets_ptr,
|
||||
size_t embeddedBufOffsets_len, uint32_t is64_val,
|
||||
struct Object smo1_val, struct Object smo2_val,
|
||||
struct Object smo3_val, struct Object smo4_val)
|
||||
{
|
||||
union ObjectArg a[10];
|
||||
int32_t result;
|
||||
|
||||
a[0].bi = (struct ObjectBufIn) { reqIn_ptr, reqIn_len * 1 };
|
||||
a[1].bi = (struct ObjectBufIn) { rspIn_ptr, rspIn_len * 1 };
|
||||
a[4].b = (struct ObjectBuf) { reqOut_ptr, reqOut_len * 1 };
|
||||
a[5].b = (struct ObjectBuf) { rspOut_ptr, rspOut_len * 1 };
|
||||
a[2].bi = (struct ObjectBufIn) { embeddedBufOffsets_ptr,
|
||||
embeddedBufOffsets_len * sizeof(uint32_t) };
|
||||
a[3].b = (struct ObjectBuf) { &is64_val, sizeof(uint32_t) };
|
||||
a[6].o = smo1_val;
|
||||
a[7].o = smo2_val;
|
||||
a[8].o = smo3_val;
|
||||
a[9].o = smo4_val;
|
||||
|
||||
result = Object_invoke(self, IQSEEComCompat_OP_sendRequest, a,
|
||||
ObjectCounts_pack(4, 2, 4, 0));
|
||||
|
||||
*reqOut_lenout = a[4].b.size / 1;
|
||||
*rspOut_lenout = a[5].b.size / 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompat_disconnect(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, IQSEEComCompat_OP_disconnect, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompat_unload(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, IQSEEComCompat_OP_unload, 0, 0);
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
/* 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"
|
||||
|
||||
#define IQSEEComCompatAppLoader_MAX_FILENAME_LEN UINT32_C(64)
|
||||
#define IQSEEComCompatAppLoader_ELFCLASS32 UINT32_C(1)
|
||||
#define IQSEEComCompatAppLoader_ELFCLASS64 UINT32_C(2)
|
||||
|
||||
#define IQSEEComCompatAppLoader_ERROR_INVALID_BUFFER INT32_C(10)
|
||||
#define IQSEEComCompatAppLoader_ERROR_PIL_ROLLBACK_FAILURE INT32_C(11)
|
||||
#define IQSEEComCompatAppLoader_ERROR_ELF_SIGNATURE_ERROR INT32_C(12)
|
||||
#define IQSEEComCompatAppLoader_ERROR_METADATA_INVALID INT32_C(13)
|
||||
#define IQSEEComCompatAppLoader_ERROR_MAX_NUM_APPS INT32_C(14)
|
||||
#define IQSEEComCompatAppLoader_ERROR_NO_NAME_IN_METADATA INT32_C(15)
|
||||
#define IQSEEComCompatAppLoader_ERROR_ALREADY_LOADED INT32_C(16)
|
||||
#define IQSEEComCompatAppLoader_ERROR_EMBEDDED_IMAGE_NOT_FOUND INT32_C(17)
|
||||
#define IQSEEComCompatAppLoader_ERROR_TZ_HEAP_MALLOC_FAILURE INT32_C(18)
|
||||
#define IQSEEComCompatAppLoader_ERROR_TA_APP_REGION_MALLOC_FAILURE INT32_C(19)
|
||||
#define IQSEEComCompatAppLoader_ERROR_CLIENT_CRED_PARSING_FAILURE INT32_C(20)
|
||||
#define IQSEEComCompatAppLoader_ERROR_APP_UNTRUSTED_CLIENT INT32_C(21)
|
||||
#define IQSEEComCompatAppLoader_ERROR_APP_BLACKLISTED INT32_C(22)
|
||||
#define IQSEEComCompatAppLoader_ERROR_APP_NOT_LOADED INT32_C(23)
|
||||
#define IQSEEComCompatAppLoader_ERROR_NOT_QSEECOM_COMPAT_APP INT32_C(24)
|
||||
#define IQSEEComCompatAppLoader_ERROR_FILENAME_TOO_LONG INT32_C(25)
|
||||
#define IQSEEComCompatAppLoader_ERROR_APP_ARCH_NOT_SUPPORTED INT32_C(26)
|
||||
|
||||
#define IQSEEComCompatAppLoader_OP_loadFromRegion 0
|
||||
#define IQSEEComCompatAppLoader_OP_loadFromBuffer 1
|
||||
#define IQSEEComCompatAppLoader_OP_lookupTA 2
|
||||
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompatAppLoader_release(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, Object_OP_release, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompatAppLoader_retain(struct Object self)
|
||||
{
|
||||
return Object_invoke(self, Object_OP_retain, 0, 0);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompatAppLoader_loadFromRegion(struct Object self,
|
||||
struct Object appElf_val, const void *filename_ptr,
|
||||
size_t filename_len, struct Object *appCompat_ptr)
|
||||
{
|
||||
union ObjectArg a[3];
|
||||
int32_t result;
|
||||
|
||||
a[1].o = appElf_val;
|
||||
a[0].bi = (struct ObjectBufIn) { filename_ptr, filename_len * 1 };
|
||||
|
||||
result = Object_invoke(self, IQSEEComCompatAppLoader_OP_loadFromRegion, a,
|
||||
ObjectCounts_pack(1, 0, 1, 1));
|
||||
|
||||
*appCompat_ptr = a[2].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompatAppLoader_loadFromBuffer(struct Object self,
|
||||
const void *appElf_ptr, size_t appElf_len,
|
||||
const void *filename_ptr, size_t filename_len,
|
||||
void *distName_ptr, size_t distName_len,
|
||||
size_t *distName_lenout, struct Object *appCompat_ptr)
|
||||
{
|
||||
union ObjectArg a[4];
|
||||
int32_t result;
|
||||
|
||||
a[0].bi = (struct ObjectBufIn) { appElf_ptr, appElf_len * 1 };
|
||||
a[1].bi = (struct ObjectBufIn) { filename_ptr, filename_len * 1 };
|
||||
a[2].b = (struct ObjectBuf) { distName_ptr, distName_len * 1 };
|
||||
|
||||
result = Object_invoke(self, IQSEEComCompatAppLoader_OP_loadFromBuffer,
|
||||
a, ObjectCounts_pack(2, 1, 0, 1));
|
||||
|
||||
*distName_lenout = a[2].b.size / 1;
|
||||
*appCompat_ptr = a[3].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
IQSEEComCompatAppLoader_lookupTA(struct Object self, const void *appName_ptr,
|
||||
size_t appName_len, struct Object *appCompat_ptr)
|
||||
{
|
||||
union ObjectArg a[2];
|
||||
int32_t result;
|
||||
|
||||
a[0].bi = (struct ObjectBufIn) { appName_ptr, appName_len * 1 };
|
||||
|
||||
result = Object_invoke(self, IQSEEComCompatAppLoader_OP_lookupTA,
|
||||
a, ObjectCounts_pack(1, 0, 0, 1));
|
||||
|
||||
*appCompat_ptr = a[1].o;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -0,0 +1,64 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __SMCI_QSEECOMCOMPAT_H
|
||||
#define __SMCI_QSEECOMCOMPAT_H
|
||||
|
||||
#include "smci_object.h"
|
||||
#include "IQSEEComCompat.h"
|
||||
|
||||
#define SMCI_QSEECOMCOMPAT_ERROR_APP_UNAVAILABLE INT32_C(10)
|
||||
#define SMCI_QSEECOMCOMPAT_OP_SENDREQUEST 0
|
||||
#define SMCI_QSEECOMCOMPAT_OP_DISCONNECT 1
|
||||
#define SMCI_QSEECOMCOMPAT_OP_UNLOAD 2
|
||||
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompat_release(struct smci_object self)
|
||||
{
|
||||
return IQSEEComCompat_release(self);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompat_retain(struct smci_object self)
|
||||
{
|
||||
return IQSEEComCompat_retain(self);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompat_sendrequest(struct smci_object self,
|
||||
const void *req_in_ptr, size_t req_in_len,
|
||||
const void *rsp_in_ptr, size_t rsp_in_len,
|
||||
void *req_out_ptr, size_t req_out_len, size_t *req_out_lenout,
|
||||
void *rsp_out_ptr, size_t rsp_out_len, size_t *rsp_out_lenout,
|
||||
const uint32_t *embedded_buf_offsets_ptr,
|
||||
size_t embedded_buf_offsets_len, uint32_t is64_val,
|
||||
struct smci_object smo1_val, struct smci_object smo2_val,
|
||||
struct smci_object smo3_val, struct smci_object smo4_val)
|
||||
{
|
||||
return IQSEEComCompat_sendRequest(self,
|
||||
req_in_ptr, req_in_len,
|
||||
rsp_in_ptr, rsp_in_len,
|
||||
req_out_ptr, req_out_len, req_out_lenout,
|
||||
rsp_out_ptr, rsp_out_len, rsp_out_lenout,
|
||||
embedded_buf_offsets_ptr,
|
||||
embedded_buf_offsets_len, is64_val,
|
||||
smo1_val, smo2_val,
|
||||
smo3_val, smo4_val);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompat_disconnect(struct smci_object self)
|
||||
{
|
||||
return IQSEEComCompat_disconnect(self);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompat_unload(struct smci_object self)
|
||||
{
|
||||
return IQSEEComCompat_unload(self);
|
||||
}
|
||||
|
||||
#endif /* __SMCI_QSEECOMCOMPAT_H */
|
@@ -0,0 +1,83 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __SMCI_QSEECOMCOMPATAPPLOADER_H
|
||||
#define __SMCI_QSEECOMCOMPATAPPLOADER_H
|
||||
|
||||
#include "smci_object.h"
|
||||
#include "IQSEEComCompatAppLoader.h"
|
||||
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_MAX_FILENAME_LEN UINT32_C(64)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ELFCLASS32 UINT32_C(1)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ELFCLASS64 UINT32_C(2)
|
||||
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_INVALID_BUFFER INT32_C(10)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_PIL_ROLLBACK_FAILURE INT32_C(11)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_ELF_SIGNATURE_ERROR INT32_C(12)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_METADATA_INVALID INT32_C(13)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_MAX_NUM_APPS INT32_C(14)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_NO_NAME_IN_METADATA INT32_C(15)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_ALREADY_LOADED INT32_C(16)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_EMBEDDED_IMAGE_NOT_FOUND INT32_C(17)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_TZ_HEAP_MALLOC_FAILURE INT32_C(18)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_TA_APP_REGION_MALLOC_FAILURE INT32_C(19)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_CLIENT_CRED_PARSING_FAILURE INT32_C(20)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_APP_UNTRUSTED_CLIENT INT32_C(21)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_APP_BLACKLISTED INT32_C(22)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_APP_NOT_LOADED INT32_C(23)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_NOT_QSEECOM_COMPAT_APP INT32_C(24)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_FILENAME_TOO_LONG INT32_C(25)
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_ERROR_APP_ARCH_NOT_SUPPORTED INT32_C(26)
|
||||
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_OP_LOADFROMREGION 0
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_OP_LOADFROMBUFFER 1
|
||||
#define SMCI_QSEECOMCOMPATAPPLOADER_OP_LOOKUPTA 2
|
||||
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompatapploader_release(struct smci_object self)
|
||||
{
|
||||
return IQSEEComCompatAppLoader_release(self);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompatapploader_retain(struct smci_object self)
|
||||
{
|
||||
return IQSEEComCompatAppLoader_retain(self);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompatapploader_loadfromregion(struct smci_object self,
|
||||
struct smci_object app_elf_val, const void *filename_ptr,
|
||||
size_t filename_len, struct smci_object *app_compat_ptr)
|
||||
{
|
||||
return IQSEEComCompatAppLoader_loadFromRegion(self,
|
||||
app_elf_val, filename_ptr,
|
||||
filename_len, app_compat_ptr);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompatapploader_loadfrombuffer(struct smci_object self,
|
||||
const void *app_elf_ptr, size_t app_elf_len,
|
||||
const void *filename_ptr, size_t filename_len,
|
||||
void *dist_name_ptr, size_t dist_name_len,
|
||||
size_t *dist_name_lenout, struct smci_object *app_compat_ptr)
|
||||
{
|
||||
return IQSEEComCompatAppLoader_loadFromBuffer(self,
|
||||
app_elf_ptr, app_elf_len,
|
||||
filename_ptr, filename_len,
|
||||
dist_name_ptr, dist_name_len,
|
||||
dist_name_lenout, app_compat_ptr);
|
||||
}
|
||||
|
||||
static inline int32_t
|
||||
smci_qseecomcompatapploader_lookupta(struct smci_object self, const void *app_name_ptr,
|
||||
size_t app_name_len, struct smci_object *app_compat_ptr)
|
||||
{
|
||||
return IQSEEComCompatAppLoader_lookupTA(self, app_name_ptr,
|
||||
app_name_len, app_compat_ptr);
|
||||
}
|
||||
|
||||
#endif /* __SMCI_QSEECOMCOMPATAPPLOADER_H */
|
3296
qcom/opensource/securemsm-kernel/smcinvoke/smcinvoke.c
Normal file
3296
qcom/opensource/securemsm-kernel/smcinvoke/smcinvoke.c
Normal file
File diff suppressed because it is too large
Load Diff
639
qcom/opensource/securemsm-kernel/smcinvoke/smcinvoke_kernel.c
Normal file
639
qcom/opensource/securemsm-kernel/smcinvoke/smcinvoke_kernel.c
Normal file
@@ -0,0 +1,639 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
#include <linux/file.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/fdtable.h>
|
||||
#include <linux/anon_inodes.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/kref.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/elf.h>
|
||||
#include "smcinvoke.h"
|
||||
#include "smcinvoke_object.h"
|
||||
#include "IClientEnv.h"
|
||||
#if IS_ENABLED(CONFIG_QSEECOM_COMPAT)
|
||||
#include "IQSEEComCompat.h"
|
||||
#include "IQSEEComCompatAppLoader.h"
|
||||
#include "linux/qseecom_api.h"
|
||||
#if IS_ENABLED(CONFIG_QSEECOM_PROXY)
|
||||
#include <linux/qseecom_kernel.h>
|
||||
#else
|
||||
#include "misc/qseecom_kernel.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAX_FW_APP_SIZE 256 //Application name size.
|
||||
#define FILE_EXT_SIZE 5 //File extension like .mbn etc
|
||||
|
||||
const uint32_t CQSEEComCompatAppLoader_UID = 122;
|
||||
extern struct device *class_dev;
|
||||
|
||||
struct qseecom_compat_context {
|
||||
void *dev; /* in/out */
|
||||
unsigned char *sbuf; /* in/out */
|
||||
uint32_t sbuf_len; /* in/out */
|
||||
struct qtee_shm shm;
|
||||
uint8_t app_arch;
|
||||
struct Object client_env;
|
||||
struct Object app_loader;
|
||||
struct Object app_controller;
|
||||
};
|
||||
|
||||
struct tzobject_context {
|
||||
int fd;
|
||||
struct kref refs;
|
||||
};
|
||||
|
||||
static int invoke_over_smcinvoke(void *cxt,
|
||||
uint32_t op,
|
||||
union ObjectArg *args,
|
||||
uint32_t counts);
|
||||
|
||||
static struct Object tzobject_new(int fd)
|
||||
{
|
||||
struct tzobject_context *me =
|
||||
kzalloc(sizeof(struct tzobject_context), GFP_KERNEL);
|
||||
if (!me)
|
||||
return Object_NULL;
|
||||
|
||||
kref_init(&me->refs);
|
||||
me->fd = fd;
|
||||
pr_debug("%s: me->fd = %d, me->refs = %u\n", __func__,
|
||||
me->fd, kref_read(&me->refs));
|
||||
return (struct Object) { invoke_over_smcinvoke, me };
|
||||
}
|
||||
|
||||
static void tzobject_delete(struct kref *refs)
|
||||
{
|
||||
struct tzobject_context *me = container_of(refs,
|
||||
struct tzobject_context, refs);
|
||||
|
||||
pr_info("%s: me->fd = %d, me->refs = %d, files = %p\n",
|
||||
__func__, me->fd, kref_read(&me->refs), current->files);
|
||||
/*
|
||||
* after _close_fd(), ref_cnt will be 0,
|
||||
* but smcinvoke_release() was still not called,
|
||||
* so we first call smcinvoke_release_from_kernel_client() to
|
||||
* free filp and ask TZ to release object, then call _close_fd()
|
||||
*/
|
||||
smcinvoke_release_from_kernel_client(me->fd);
|
||||
close_fd(me->fd);
|
||||
kfree(me);
|
||||
}
|
||||
|
||||
int getObjectFromHandle(int handle, struct Object *obj)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (handle == SMCINVOKE_USERSPACE_OBJ_NULL) {
|
||||
/* NULL object*/
|
||||
Object_ASSIGN_NULL(*obj);
|
||||
} else if (handle > SMCINVOKE_USERSPACE_OBJ_NULL) {
|
||||
*obj = tzobject_new(handle);
|
||||
if (Object_isNull(*obj))
|
||||
ret = OBJECT_ERROR_BADOBJ;
|
||||
} else {
|
||||
pr_err("CBobj not supported for handle %d\n", handle);
|
||||
ret = OBJECT_ERROR_BADOBJ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getHandleFromObject(struct Object obj, int *handle)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (Object_isNull(obj)) {
|
||||
/* set NULL Object's fd to be -1 */
|
||||
*handle = SMCINVOKE_USERSPACE_OBJ_NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (obj.invoke == invoke_over_smcinvoke) {
|
||||
struct tzobject_context *ctx = (struct tzobject_context *)(obj.context);
|
||||
|
||||
if (ctx != NULL) {
|
||||
*handle = ctx->fd;
|
||||
} else {
|
||||
pr_err("Failed to get tzobject_context obj handle, ret = %d\n", ret);
|
||||
ret = OBJECT_ERROR_BADOBJ;
|
||||
}
|
||||
} else {
|
||||
pr_err("CBobj not supported\n");
|
||||
ret = OBJECT_ERROR_BADOBJ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int marshalIn(struct smcinvoke_cmd_req *req,
|
||||
union smcinvoke_arg *argptr,
|
||||
uint32_t op, union ObjectArg *args,
|
||||
uint32_t counts)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
req->op = op;
|
||||
req->counts = counts;
|
||||
req->argsize = sizeof(union smcinvoke_arg);
|
||||
req->args = (uintptr_t)argptr;
|
||||
|
||||
FOR_ARGS(i, counts, buffers) {
|
||||
argptr[i].b.addr = (uintptr_t) args[i].b.ptr;
|
||||
argptr[i].b.size = args[i].b.size;
|
||||
}
|
||||
|
||||
FOR_ARGS(i, counts, OI) {
|
||||
int handle = -1, ret;
|
||||
|
||||
ret = getHandleFromObject(args[i].o, &handle);
|
||||
if (ret) {
|
||||
pr_err("invalid OI[%zu]\n", i);
|
||||
return OBJECT_ERROR_BADOBJ;
|
||||
}
|
||||
argptr[i].o.fd = handle;
|
||||
}
|
||||
|
||||
FOR_ARGS(i, counts, OO) {
|
||||
argptr[i].o.fd = SMCINVOKE_USERSPACE_OBJ_NULL;
|
||||
}
|
||||
return OBJECT_OK;
|
||||
}
|
||||
|
||||
static int marshalOut(struct smcinvoke_cmd_req *req,
|
||||
union smcinvoke_arg *argptr,
|
||||
union ObjectArg *args, uint32_t counts,
|
||||
struct tzobject_context *me)
|
||||
{
|
||||
int ret = req->result;
|
||||
bool failed = false;
|
||||
size_t i = 0;
|
||||
|
||||
argptr = (union smcinvoke_arg *)(uintptr_t)(req->args);
|
||||
|
||||
FOR_ARGS(i, counts, BO) {
|
||||
args[i].b.size = argptr[i].b.size;
|
||||
}
|
||||
|
||||
FOR_ARGS(i, counts, OO) {
|
||||
ret = getObjectFromHandle(argptr[i].o.fd, &(args[i].o));
|
||||
if (ret) {
|
||||
pr_err("Failed to get OO[%zu] from handle = %d\n",
|
||||
i, (int)argptr[i].o.fd);
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
pr_debug("Succeed to create OO for args[%zu].o, fd = %d\n",
|
||||
i, (int)argptr[i].o.fd);
|
||||
}
|
||||
if (failed) {
|
||||
FOR_ARGS(i, counts, OO) {
|
||||
Object_ASSIGN_NULL(args[i].o);
|
||||
}
|
||||
/* Only overwrite ret value if invoke result is 0 */
|
||||
if (ret == 0)
|
||||
ret = OBJECT_ERROR_BADOBJ;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int invoke_over_smcinvoke(void *cxt,
|
||||
uint32_t op,
|
||||
union ObjectArg *args,
|
||||
uint32_t counts)
|
||||
{
|
||||
int ret = OBJECT_OK;
|
||||
struct smcinvoke_cmd_req req = {0, 0, 0, 0, 0};
|
||||
size_t i = 0;
|
||||
struct tzobject_context *me = NULL;
|
||||
uint32_t method;
|
||||
union smcinvoke_arg *argptr = NULL;
|
||||
|
||||
FOR_ARGS(i, counts, OO) {
|
||||
args[i].o = Object_NULL;
|
||||
}
|
||||
|
||||
me = (struct tzobject_context *)cxt;
|
||||
method = ObjectOp_methodID(op);
|
||||
pr_debug("%s: cxt = %p, fd = %d, op = %u, cnt = %x, refs = %u\n",
|
||||
__func__, me, me->fd, op, counts, kref_read(&me->refs));
|
||||
|
||||
if (ObjectOp_isLocal(op)) {
|
||||
switch (method) {
|
||||
case Object_OP_retain:
|
||||
kref_get(&me->refs);
|
||||
return OBJECT_OK;
|
||||
case Object_OP_release:
|
||||
kref_put(&me->refs, tzobject_delete);
|
||||
return OBJECT_OK;
|
||||
}
|
||||
return OBJECT_ERROR_REMOTE;
|
||||
}
|
||||
|
||||
argptr = kcalloc(OBJECT_COUNTS_TOTAL(counts),
|
||||
sizeof(union smcinvoke_arg), GFP_KERNEL);
|
||||
if (argptr == NULL)
|
||||
return OBJECT_ERROR_KMEM;
|
||||
|
||||
ret = marshalIn(&req, argptr, op, args, counts);
|
||||
if (ret)
|
||||
goto exit;
|
||||
|
||||
ret = process_invoke_request_from_kernel_client(me->fd, &req);
|
||||
if (ret) {
|
||||
pr_err("INVOKE failed with ret = %d, result = %d\n"
|
||||
"obj.context = %p, fd = %d, op = %d, counts = 0x%x\n",
|
||||
ret, req.result, me, me->fd, op, counts);
|
||||
FOR_ARGS(i, counts, OO) {
|
||||
struct smcinvoke_obj obj = argptr[i].o;
|
||||
|
||||
if (obj.fd >= 0) {
|
||||
pr_err("Close OO[%zu].fd = %lld\n", i, obj.fd);
|
||||
close_fd(obj.fd);
|
||||
}
|
||||
}
|
||||
if (ret == -EBUSY) {
|
||||
ret = OBJECT_ERROR_BUSY;
|
||||
}
|
||||
else if (ret == -ENOMEM){
|
||||
ret = OBJECT_ERROR_KMEM;
|
||||
} else {
|
||||
ret = OBJECT_ERROR_UNAVAIL;
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!req.result)
|
||||
ret = marshalOut(&req, argptr, args, counts, me);
|
||||
exit:
|
||||
kfree(argptr);
|
||||
return ret | req.result;
|
||||
}
|
||||
|
||||
int get_root_obj(struct Object *rootObj)
|
||||
{
|
||||
int ret = 0;
|
||||
int root_fd = -1;
|
||||
|
||||
ret = get_root_fd(&root_fd);
|
||||
if (ret) {
|
||||
pr_err("Failed to get root fd, ret = %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
*rootObj = tzobject_new(root_fd);
|
||||
if (Object_isNull(*rootObj)) {
|
||||
close_fd(root_fd);
|
||||
ret = -ENOMEM;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a client environment using a NULL credentials Object
|
||||
*/
|
||||
int32_t get_client_env_object(struct Object *clientEnvObj)
|
||||
{
|
||||
int32_t ret = OBJECT_ERROR;
|
||||
int retry_count = 0;
|
||||
struct Object rootObj = Object_NULL;
|
||||
|
||||
/* get rootObj */
|
||||
ret = get_root_obj(&rootObj);
|
||||
if (ret) {
|
||||
pr_err("Failed to create rootobj\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* get client env */
|
||||
do {
|
||||
ret = IClientEnv_registerWithCredentials(rootObj,
|
||||
Object_NULL, clientEnvObj);
|
||||
if (ret == OBJECT_ERROR_BUSY) {
|
||||
pr_err("Secure side is busy,will retry after 5 ms, retry_count = %d",retry_count);
|
||||
msleep(SMCINVOKE_INTERFACE_BUSY_WAIT_MS);
|
||||
}
|
||||
} while ((ret == OBJECT_ERROR_BUSY) && (retry_count++ < SMCINVOKE_INTERFACE_MAX_RETRY));
|
||||
|
||||
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_COMPAT)
|
||||
|
||||
static int load_app(struct qseecom_compat_context *cxt, const char *app_name)
|
||||
{
|
||||
size_t fw_size = 0;
|
||||
u8 *imgbuf_va = NULL;
|
||||
int ret = 0;
|
||||
char dist_name[MAX_FW_APP_SIZE] = {0};
|
||||
size_t dist_name_len = 0;
|
||||
struct qtee_shm shm = {0};
|
||||
|
||||
if (strnlen(app_name, MAX_FW_APP_SIZE) == MAX_FW_APP_SIZE) {
|
||||
pr_err("The app_name (%s) with length %zu is not valid\n",
|
||||
app_name, strnlen(app_name, MAX_FW_APP_SIZE));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = IQSEEComCompatAppLoader_lookupTA(cxt->app_loader,
|
||||
app_name, strlen(app_name), &cxt->app_controller);
|
||||
if (!ret) {
|
||||
pr_info("app %s exists\n", app_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
imgbuf_va = firmware_request_from_smcinvoke(app_name, &fw_size, &shm);
|
||||
if (imgbuf_va == NULL) {
|
||||
pr_err("Failed on firmware_request_from_smcinvoke\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = IQSEEComCompatAppLoader_loadFromBuffer(
|
||||
cxt->app_loader, imgbuf_va, fw_size,
|
||||
app_name, strlen(app_name),
|
||||
dist_name, MAX_FW_APP_SIZE, &dist_name_len,
|
||||
&cxt->app_controller);
|
||||
if (ret) {
|
||||
pr_err("loadFromBuffer failed for app %s, ret = %d\n",
|
||||
app_name, ret);
|
||||
goto exit_release_shm;
|
||||
}
|
||||
cxt->app_arch = *(uint8_t *)(imgbuf_va + EI_CLASS);
|
||||
|
||||
pr_info("%s %d, loaded app %s, dist_name %s, dist_name_len %zu\n",
|
||||
__func__, __LINE__, app_name, dist_name, dist_name_len);
|
||||
|
||||
exit_release_shm:
|
||||
qtee_shmbridge_free_shm(&shm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __qseecom_start_app(struct qseecom_handle **handle,
|
||||
char *app_name, uint32_t size)
|
||||
{
|
||||
int ret = 0;
|
||||
struct qseecom_compat_context *cxt = NULL;
|
||||
|
||||
pr_warn("%s, start app %s, size %u\n",
|
||||
__func__, app_name, size);
|
||||
if (app_name == NULL || handle == NULL) {
|
||||
pr_err("app_name is null or invalid handle\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
/* allocate qseecom_compat_context */
|
||||
cxt = kzalloc(sizeof(struct qseecom_compat_context), GFP_KERNEL);
|
||||
if (!cxt)
|
||||
return -ENOMEM;
|
||||
|
||||
/* get client env */
|
||||
ret = get_client_env_object(&cxt->client_env);
|
||||
if (ret) {
|
||||
pr_err("failed to get clientEnv when loading app %s, ret %d\n",
|
||||
app_name, ret);
|
||||
ret = -EINVAL;
|
||||
goto exit_free_cxt;
|
||||
}
|
||||
/* get apploader with CQSEEComCompatAppLoader_UID */
|
||||
ret = IClientEnv_open(cxt->client_env, CQSEEComCompatAppLoader_UID,
|
||||
&cxt->app_loader);
|
||||
if (ret) {
|
||||
pr_err("failed to get apploader when loading app %s, ret %d\n",
|
||||
app_name, ret);
|
||||
ret = -EINVAL;
|
||||
goto exit_release_clientenv;
|
||||
}
|
||||
|
||||
/* load app*/
|
||||
ret = load_app(cxt, app_name);
|
||||
if (ret) {
|
||||
pr_err("failed to load app %s, ret = %d\n",
|
||||
app_name, ret);
|
||||
ret = -EINVAL;
|
||||
goto exit_release_apploader;
|
||||
}
|
||||
|
||||
/* Get the physical address of the req/resp buffer */
|
||||
ret = qtee_shmbridge_allocate_shm(size, &cxt->shm);
|
||||
|
||||
if (ret) {
|
||||
pr_err("qtee_shmbridge_allocate_shm failed, ret :%d\n", ret);
|
||||
ret = -EINVAL;
|
||||
goto exit_release_appcontroller;
|
||||
}
|
||||
cxt->sbuf = cxt->shm.vaddr;
|
||||
cxt->sbuf_len = size;
|
||||
*handle = (struct qseecom_handle *)cxt;
|
||||
|
||||
return ret;
|
||||
|
||||
exit_release_appcontroller:
|
||||
Object_release(cxt->app_controller);
|
||||
exit_release_apploader:
|
||||
Object_release(cxt->app_loader);
|
||||
exit_release_clientenv:
|
||||
Object_release(cxt->client_env);
|
||||
exit_free_cxt:
|
||||
kfree(cxt);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __qseecom_shutdown_app(struct qseecom_handle **handle)
|
||||
{
|
||||
|
||||
struct qseecom_compat_context *cxt = NULL;
|
||||
if ((handle == NULL) || (*handle == NULL)) {
|
||||
pr_err("Handle is NULL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cxt = (struct qseecom_compat_context *)(*handle);
|
||||
|
||||
qtee_shmbridge_free_shm(&cxt->shm);
|
||||
Object_release(cxt->app_controller);
|
||||
Object_release(cxt->app_loader);
|
||||
Object_release(cxt->client_env);
|
||||
kfree(cxt);
|
||||
*handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 =
|
||||
(struct qseecom_compat_context *)handle;
|
||||
size_t out_len = 0;
|
||||
|
||||
pr_debug("%s, sbuf_len %u, rbuf_len %u\n",
|
||||
__func__, sbuf_len, rbuf_len);
|
||||
|
||||
if (!handle || !send_buf || !resp_buf || !sbuf_len || !rbuf_len) {
|
||||
pr_err("One of params is invalid. %s, handle %p, send_buf %p,resp_buf %p,sbuf_len %u, rbuf_len %u\n",
|
||||
__func__, handle, send_buf, resp_buf, sbuf_len, rbuf_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
return IQSEEComCompat_sendRequest(cxt->app_controller,
|
||||
send_buf, sbuf_len,
|
||||
resp_buf, rbuf_len,
|
||||
send_buf, sbuf_len, &out_len,
|
||||
resp_buf, rbuf_len, &out_len,
|
||||
NULL, 0, /* embedded offset array */
|
||||
(cxt->app_arch == ELFCLASS64),
|
||||
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
|
||||
|
||||
char *firmware_request_from_smcinvoke(const char *appname, size_t *fw_size, struct qtee_shm *shm)
|
||||
{
|
||||
|
||||
int rc = 0;
|
||||
const struct firmware *fw_entry = NULL, *fw_entry00 = NULL, *fw_entrylast = NULL;
|
||||
char fw_name[MAX_FW_APP_SIZE + FILE_EXT_SIZE] = "\0";
|
||||
int num_images = 0, phi = 0;
|
||||
unsigned char app_arch = 0;
|
||||
u8 *img_data_ptr = NULL;
|
||||
size_t bufferOffset = 0, phdr_table_offset = 0;
|
||||
size_t *offset = NULL;
|
||||
Elf32_Phdr phdr32;
|
||||
Elf64_Phdr phdr64;
|
||||
struct elf32_hdr *ehdr = NULL;
|
||||
struct elf64_hdr *ehdr64 = NULL;
|
||||
|
||||
|
||||
/* load b00*/
|
||||
snprintf(fw_name, sizeof(fw_name), "%s.b00", appname);
|
||||
rc = firmware_request_nowarn(&fw_entry00, fw_name, class_dev);
|
||||
if (rc) {
|
||||
pr_err("Load %s failed, ret:%d\n", fw_name, rc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
app_arch = *(unsigned char *)(fw_entry00->data + EI_CLASS);
|
||||
|
||||
/*Get the offsets for split images header*/
|
||||
if (app_arch == ELFCLASS32) {
|
||||
|
||||
ehdr = (struct elf32_hdr *)fw_entry00->data;
|
||||
num_images = ehdr->e_phnum;
|
||||
offset = kcalloc(num_images, sizeof(size_t), GFP_KERNEL);
|
||||
if (offset == NULL)
|
||||
goto release_fw_entry00;
|
||||
phdr_table_offset = (size_t) ehdr->e_phoff;
|
||||
for (phi = 1; phi < num_images; ++phi) {
|
||||
bufferOffset = phdr_table_offset + phi * sizeof(Elf32_Phdr);
|
||||
phdr32 = *(Elf32_Phdr *)(fw_entry00->data + bufferOffset);
|
||||
offset[phi] = (size_t)phdr32.p_offset;
|
||||
}
|
||||
|
||||
} else if (app_arch == ELFCLASS64) {
|
||||
|
||||
ehdr64 = (struct elf64_hdr *)fw_entry00->data;
|
||||
num_images = ehdr64->e_phnum;
|
||||
offset = kcalloc(num_images, sizeof(size_t), GFP_KERNEL);
|
||||
if (offset == NULL)
|
||||
goto release_fw_entry00;
|
||||
phdr_table_offset = (size_t) ehdr64->e_phoff;
|
||||
for (phi = 1; phi < num_images; ++phi) {
|
||||
bufferOffset = phdr_table_offset + phi * sizeof(Elf64_Phdr);
|
||||
phdr64 = *(Elf64_Phdr *)(fw_entry00->data + bufferOffset);
|
||||
offset[phi] = (size_t)phdr64.p_offset;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
pr_err("QSEE %s app, arch %u is not supported\n", appname, app_arch);
|
||||
goto release_fw_entry00;
|
||||
}
|
||||
|
||||
/*Find the size of last split bin image*/
|
||||
snprintf(fw_name, ARRAY_SIZE(fw_name), "%s.b%02d", appname, num_images-1);
|
||||
rc = firmware_request_nowarn(&fw_entrylast, fw_name, class_dev);
|
||||
if (rc) {
|
||||
pr_err("Failed to locate blob %s\n", fw_name);
|
||||
goto release_fw_entry00;
|
||||
}
|
||||
|
||||
/*Total size of image will be the offset of last image + the size of last split image*/
|
||||
*fw_size = fw_entrylast->size + offset[num_images-1];
|
||||
|
||||
/*Allocate memory for the buffer that will hold the split image*/
|
||||
rc = qtee_shmbridge_allocate_shm((*fw_size), shm);
|
||||
if (rc) {
|
||||
pr_err("smbridge alloc failed for size: %zu\n", *fw_size);
|
||||
goto release_fw_entrylast;
|
||||
}
|
||||
img_data_ptr = shm->vaddr;
|
||||
/*
|
||||
* Copy contents of split bins to the buffer
|
||||
*/
|
||||
memcpy(img_data_ptr, fw_entry00->data, fw_entry00->size);
|
||||
for (phi = 1; phi < num_images-1; phi++) {
|
||||
snprintf(fw_name, ARRAY_SIZE(fw_name), "%s.b%02d", appname, phi);
|
||||
rc = firmware_request_nowarn(&fw_entry, fw_name, class_dev);
|
||||
if (rc) {
|
||||
pr_err("Failed to locate blob %s\n", fw_name);
|
||||
qtee_shmbridge_free_shm(shm);
|
||||
img_data_ptr = NULL;
|
||||
goto release_fw_entrylast;
|
||||
}
|
||||
memcpy(img_data_ptr + offset[phi], fw_entry->data, fw_entry->size);
|
||||
release_firmware(fw_entry);
|
||||
fw_entry = NULL;
|
||||
}
|
||||
memcpy(img_data_ptr + offset[phi], fw_entrylast->data, fw_entrylast->size);
|
||||
|
||||
release_fw_entrylast:
|
||||
release_firmware(fw_entrylast);
|
||||
release_fw_entry00:
|
||||
release_firmware(fw_entry00);
|
||||
kfree(offset);
|
||||
return img_data_ptr;
|
||||
}
|
||||
EXPORT_SYMBOL(firmware_request_from_smcinvoke);
|
502
qcom/opensource/securemsm-kernel/smcinvoke/trace_smcinvoke.h
Normal file
502
qcom/opensource/securemsm-kernel/smcinvoke/trace_smcinvoke.h
Normal file
@@ -0,0 +1,502 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
|
||||
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#undef TRACE_SYSTEM
|
||||
#define TRACE_SYSTEM smcinvoke
|
||||
|
||||
#if !defined(_TRACE_SMCINVOKE_H) || defined(TRACE_HEADER_MULTI_READ)
|
||||
#define _TRACE_SMCINVOKE_H
|
||||
#include <linux/types.h>
|
||||
#include <linux/tracepoint.h>
|
||||
#include "smcinvoke.h"
|
||||
|
||||
TRACE_EVENT(put_pending_cbobj_locked,
|
||||
TP_PROTO(uint16_t srvr_id, uint16_t obj_id),
|
||||
TP_ARGS(srvr_id, obj_id),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint16_t, srvr_id)
|
||||
__field(uint16_t, obj_id)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->srvr_id = srvr_id;
|
||||
__entry->obj_id = obj_id;
|
||||
),
|
||||
TP_printk("srvr_id=0x%x obj_id=0x%x",
|
||||
__entry->srvr_id, __entry->obj_id)
|
||||
);
|
||||
|
||||
TRACE_EVENT(release_mem_obj_locked,
|
||||
TP_PROTO(uint32_t tzhandle, size_t buf_len),
|
||||
TP_ARGS(tzhandle, buf_len),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(size_t, buf_len)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->buf_len = buf_len;
|
||||
),
|
||||
TP_printk("tzhandle=0x%08x, buf_len=%zu",
|
||||
__entry->tzhandle, __entry->buf_len)
|
||||
);
|
||||
|
||||
TRACE_EVENT(invoke_cmd_handler,
|
||||
TP_PROTO(int cmd, uint64_t response_type, int32_t result, int ret),
|
||||
TP_ARGS(cmd, response_type, result, ret),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, cmd)
|
||||
__field(uint64_t, response_type)
|
||||
__field(int32_t, result)
|
||||
__field(int, ret)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->response_type = response_type;
|
||||
__entry->result = result;
|
||||
__entry->ret = ret;
|
||||
__entry->cmd = cmd;
|
||||
),
|
||||
TP_printk("cmd=0x%x (%d), response_type=%llu, result=0x%x (%d), ret=%d",
|
||||
__entry->cmd, __entry->cmd, __entry->response_type,
|
||||
__entry->result, __entry->result, __entry->ret)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_tzcb_req_handle,
|
||||
TP_PROTO(uint32_t tzhandle, uint32_t op, uint32_t counts),
|
||||
TP_ARGS(tzhandle, op, counts),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(uint32_t, op)
|
||||
__field(uint32_t, counts)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->op = op;
|
||||
__entry->counts = counts;
|
||||
),
|
||||
TP_printk("tzhandle=0x%08x op=0x%02x counts=0x%04x",
|
||||
__entry->tzhandle, __entry->op, __entry->counts)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_tzcb_req_wait,
|
||||
TP_PROTO(uint32_t tzhandle, int cbobj_retries, uint32_t txn_id, pid_t pid, pid_t tgid,
|
||||
uint16_t server_state, uint16_t server_id, unsigned int cb_reqs_inflight),
|
||||
TP_ARGS(tzhandle, cbobj_retries, txn_id, pid, tgid, server_state, server_id,
|
||||
cb_reqs_inflight),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(int, cbobj_retries)
|
||||
__field(uint32_t, txn_id)
|
||||
__field(pid_t, pid)
|
||||
__field(pid_t, tgid)
|
||||
__field(uint16_t, server_state)
|
||||
__field(uint16_t, server_id)
|
||||
__field(unsigned int, cb_reqs_inflight)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->cbobj_retries = cbobj_retries;
|
||||
__entry->txn_id = txn_id;
|
||||
__entry->pid = pid;
|
||||
__entry->tgid = tgid;
|
||||
__entry->server_state = server_state;
|
||||
__entry->server_id = server_id;
|
||||
__entry->cb_reqs_inflight = cb_reqs_inflight;
|
||||
),
|
||||
TP_printk("tzhandle=0x%08x, retries=%d, txn_id=%d, pid %x,tid %x, srvr state=%d, server_id=0x%x, cb_reqs_inflight=%d",
|
||||
__entry->tzhandle, __entry->cbobj_retries, __entry->txn_id,
|
||||
__entry->pid, __entry->tgid, __entry->server_state,
|
||||
__entry->server_id, __entry->cb_reqs_inflight)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_tzcb_req_result,
|
||||
TP_PROTO(int32_t result, uint32_t tzhandle, uint32_t op, uint32_t counts,
|
||||
unsigned int cb_reqs_inflight),
|
||||
TP_ARGS(result, tzhandle, op, counts, cb_reqs_inflight),
|
||||
TP_STRUCT__entry(
|
||||
__field(int32_t, result)
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(uint32_t, op)
|
||||
__field(uint32_t, counts)
|
||||
__field(unsigned int, cb_reqs_inflight)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->result = result;
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->op = op;
|
||||
__entry->counts = counts;
|
||||
__entry->cb_reqs_inflight = cb_reqs_inflight;
|
||||
),
|
||||
TP_printk("result=%d tzhandle=0x%08x op=0x%02x counts=0x%04x, cb_reqs_inflight=%d",
|
||||
__entry->result, __entry->tzhandle, __entry->op, __entry->counts,
|
||||
__entry->cb_reqs_inflight)
|
||||
);
|
||||
|
||||
TRACE_EVENT(marshal_out_invoke_req,
|
||||
TP_PROTO(int i, uint32_t tzhandle, uint16_t server, uint32_t fd),
|
||||
TP_ARGS(i, tzhandle, server, fd),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, i)
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(uint16_t, server)
|
||||
__field(uint32_t, fd)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->i = i;
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->server = server;
|
||||
__entry->fd = fd;
|
||||
),
|
||||
TP_printk("OO[%d]: tzhandle=0x%x server=0x%x fd=0x%x",
|
||||
__entry->i, __entry->tzhandle, __entry->server, __entry->fd)
|
||||
);
|
||||
|
||||
TRACE_EVENT(prepare_send_scm_msg,
|
||||
TP_PROTO(uint64_t response_type, int32_t result),
|
||||
TP_ARGS(response_type, result),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint64_t, response_type)
|
||||
__field(int32_t, result)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->response_type = response_type;
|
||||
__entry->result = result;
|
||||
),
|
||||
TP_printk("response_type=%llu (%llu), result=0x%x (%d)",
|
||||
__entry->response_type, __entry->response_type,
|
||||
__entry->result, __entry->result)
|
||||
);
|
||||
|
||||
TRACE_EVENT(marshal_in_invoke_req,
|
||||
TP_PROTO(int i, int64_t fd, int32_t cb_server_fd, uint32_t tzhandle),
|
||||
TP_ARGS(i, fd, cb_server_fd, tzhandle),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, i)
|
||||
__field(int64_t, fd)
|
||||
__field(int32_t, cb_server_fd)
|
||||
__field(uint32_t, tzhandle)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->i = i;
|
||||
__entry->fd = fd;
|
||||
__entry->cb_server_fd = cb_server_fd;
|
||||
__entry->tzhandle = tzhandle;
|
||||
),
|
||||
TP_printk("OI[%d]: fd=%lld cb_server_fd=0x%x tzhandle=0x%x",
|
||||
__entry->i, __entry->fd, __entry->cb_server_fd, __entry->tzhandle)
|
||||
);
|
||||
|
||||
TRACE_EVENT(marshal_in_tzcb_req_handle,
|
||||
TP_PROTO(uint32_t tzhandle, int srvr_id, int32_t cbobj_id, uint32_t op, uint32_t counts),
|
||||
TP_ARGS(tzhandle, srvr_id, cbobj_id, op, counts),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(int, srvr_id)
|
||||
__field(int32_t, cbobj_id)
|
||||
__field(uint32_t, op)
|
||||
__field(uint32_t, counts)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->srvr_id = srvr_id;
|
||||
__entry->cbobj_id = cbobj_id;
|
||||
__entry->op = op;
|
||||
__entry->counts = counts;
|
||||
),
|
||||
TP_printk("tzhandle=0x%x srvr_id=0x%x cbobj_id=0x%08x op=0x%02x counts=0x%04x",
|
||||
__entry->tzhandle, __entry->srvr_id, __entry->cbobj_id,
|
||||
__entry->op, __entry->counts)
|
||||
);
|
||||
|
||||
TRACE_EVENT(marshal_in_tzcb_req_fd,
|
||||
TP_PROTO(int i, uint32_t tzhandle, int srvr_id, int32_t fd),
|
||||
TP_ARGS(i, tzhandle, srvr_id, fd),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, i)
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(int, srvr_id)
|
||||
__field(int32_t, fd)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->i = i;
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->srvr_id = srvr_id;
|
||||
__entry->fd = fd;
|
||||
),
|
||||
TP_printk("OI[%d]: tzhandle=0x%x srvr_id=0x%x fd=0x%x",
|
||||
__entry->i, __entry->tzhandle, __entry->srvr_id, __entry->fd)
|
||||
);
|
||||
|
||||
TRACE_EVENT(marshal_out_tzcb_req,
|
||||
TP_PROTO(uint32_t i, int32_t fd, int32_t cb_server_fd, uint32_t tzhandle),
|
||||
TP_ARGS(i, fd, cb_server_fd, tzhandle),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, i)
|
||||
__field(int32_t, fd)
|
||||
__field(int32_t, cb_server_fd)
|
||||
__field(uint32_t, tzhandle)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->i = i;
|
||||
__entry->fd = fd;
|
||||
__entry->cb_server_fd = cb_server_fd;
|
||||
__entry->tzhandle = tzhandle;
|
||||
),
|
||||
TP_printk("OO[%d]: fd=0x%x cb_server_fd=0x%x tzhandle=0x%x",
|
||||
__entry->i, __entry->fd, __entry->cb_server_fd, __entry->tzhandle)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_invoke_req_tzhandle,
|
||||
TP_PROTO(uint32_t tzhandle, uint32_t op, uint32_t counts),
|
||||
TP_ARGS(tzhandle, op, counts),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(uint32_t, op)
|
||||
__field(uint32_t, counts)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->op = op;
|
||||
__entry->counts = counts;
|
||||
),
|
||||
TP_printk("tzhandle=0x%08x op=0x%02x counts=0x%04x",
|
||||
__entry->tzhandle, __entry->op, __entry->counts)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_invoke_req_result,
|
||||
TP_PROTO(int ret, int32_t result, uint32_t tzhandle, uint32_t op, uint32_t counts),
|
||||
TP_ARGS(ret, result, tzhandle, op, counts),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, ret)
|
||||
__field(int32_t, result)
|
||||
__field(uint32_t, tzhandle)
|
||||
__field(uint32_t, op)
|
||||
__field(uint32_t, counts)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->ret = ret;
|
||||
__entry->result = result;
|
||||
__entry->tzhandle = tzhandle;
|
||||
__entry->op = op;
|
||||
__entry->counts = counts;
|
||||
),
|
||||
TP_printk("ret=%d result=%d tzhandle=0x%08x op=0x%02x counts=0x%04x",
|
||||
__entry->ret, __entry->result, __entry->tzhandle,
|
||||
__entry->op, __entry->counts)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_log_info,
|
||||
TP_PROTO(char *buf, uint32_t context_type, uint32_t tzhandle),
|
||||
TP_ARGS(buf, context_type, tzhandle),
|
||||
TP_STRUCT__entry(
|
||||
__string(str, buf)
|
||||
__field(uint32_t, context_type)
|
||||
__field(uint32_t, tzhandle)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__assign_str(str, buf);
|
||||
__entry->context_type = context_type;
|
||||
__entry->tzhandle = tzhandle;
|
||||
),
|
||||
TP_printk("%s context_type=%d tzhandle=0x%08x",
|
||||
__get_str(str),
|
||||
__entry->context_type, __entry->tzhandle)
|
||||
);
|
||||
|
||||
TRACE_EVENT_CONDITION(smcinvoke_ioctl,
|
||||
TP_PROTO(unsigned int cmd, long ret),
|
||||
TP_ARGS(cmd, ret),
|
||||
TP_CONDITION(ret),
|
||||
TP_STRUCT__entry(
|
||||
__field(unsigned int, cmd)
|
||||
__field(long, ret)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->cmd = cmd;
|
||||
__entry->ret = ret;
|
||||
),
|
||||
TP_printk("cmd=%s ret=%ld",
|
||||
__print_symbolic(__entry->cmd,
|
||||
{SMCINVOKE_IOCTL_INVOKE_REQ, "SMCINVOKE_IOCTL_INVOKE_REQ"},
|
||||
{SMCINVOKE_IOCTL_ACCEPT_REQ, "SMCINVOKE_IOCTL_ACCEPT_REQ"},
|
||||
{SMCINVOKE_IOCTL_SERVER_REQ, "SMCINVOKE_IOCTL_SERVER_REQ"},
|
||||
{SMCINVOKE_IOCTL_ACK_LOCAL_OBJ, "SMCINVOKE_IOCTL_ACK_LOCAL_OBJ"},
|
||||
{SMCINVOKE_IOCTL_LOG, "SMCINVOKE_IOCTL_LOG"}
|
||||
), __entry->ret)
|
||||
);
|
||||
|
||||
TRACE_EVENT(smcinvoke_create_bridge,
|
||||
TP_PROTO(uint64_t shmbridge_handle, uint16_t mem_region_id),
|
||||
TP_ARGS(shmbridge_handle, mem_region_id),
|
||||
TP_STRUCT__entry(
|
||||
__field(uint64_t, shmbridge_handle)
|
||||
__field(uint16_t, mem_region_id)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->shmbridge_handle = shmbridge_handle;
|
||||
__entry->mem_region_id = mem_region_id;
|
||||
),
|
||||
TP_printk("created shm bridge handle %llu for mem_region_id %u",
|
||||
__entry->shmbridge_handle, __entry->mem_region_id)
|
||||
);
|
||||
|
||||
TRACE_EVENT(status,
|
||||
TP_PROTO(const char *func, const char *status),
|
||||
TP_ARGS(func, status),
|
||||
TP_STRUCT__entry(
|
||||
__string(str, func)
|
||||
__string(str2, status)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__assign_str(str, func);
|
||||
__assign_str(str2, status);
|
||||
),
|
||||
TP_printk("%s status=%s", __get_str(str), __get_str(str2))
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_accept_req_has_response,
|
||||
TP_PROTO(pid_t pid, pid_t tgid),
|
||||
TP_ARGS(pid, tgid),
|
||||
TP_STRUCT__entry(
|
||||
__field(pid_t, pid)
|
||||
__field(pid_t, tgid)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->pid = pid;
|
||||
__entry->tgid = tgid;
|
||||
),
|
||||
TP_printk("pid=0x%x, tgid=0x%x", __entry->pid, __entry->tgid)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_accept_req_ret,
|
||||
TP_PROTO(pid_t pid, pid_t tgid, int ret),
|
||||
TP_ARGS(pid, tgid, ret),
|
||||
TP_STRUCT__entry(
|
||||
__field(pid_t, pid)
|
||||
__field(pid_t, tgid)
|
||||
__field(int, ret)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->pid = pid;
|
||||
__entry->tgid = tgid;
|
||||
__entry->ret = ret;
|
||||
),
|
||||
TP_printk("pid=0x%x tgid=0x%x ret=%d", __entry->pid, __entry->tgid, __entry->ret)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_accept_req_placed,
|
||||
TP_PROTO(pid_t pid, pid_t tgid),
|
||||
TP_ARGS(pid, tgid),
|
||||
TP_STRUCT__entry(
|
||||
__field(pid_t, pid)
|
||||
__field(pid_t, tgid)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->pid = pid;
|
||||
__entry->tgid = tgid;
|
||||
),
|
||||
TP_printk("pid=0x%x, tgid=0x%x", __entry->pid, __entry->tgid)
|
||||
);
|
||||
|
||||
TRACE_EVENT(process_invoke_request_from_kernel_client,
|
||||
TP_PROTO(int fd, struct file *filp, int f_count),
|
||||
TP_ARGS(fd, filp, f_count),
|
||||
TP_STRUCT__entry(
|
||||
__field(int, fd)
|
||||
__field(struct file*, filp)
|
||||
__field(int, f_count)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->fd = fd;
|
||||
__entry->filp = filp;
|
||||
__entry->f_count = f_count;
|
||||
),
|
||||
TP_printk("fd=%d, filp=%p, f_count=%d",
|
||||
__entry->fd,
|
||||
__entry->filp,
|
||||
__entry->f_count)
|
||||
);
|
||||
|
||||
TRACE_EVENT(smcinvoke_release_filp,
|
||||
TP_PROTO(struct files_struct *files, struct file *filp,
|
||||
int f_count, uint32_t context_type),
|
||||
TP_ARGS(files, filp, f_count, context_type),
|
||||
TP_STRUCT__entry(
|
||||
__field(struct files_struct*, files)
|
||||
__field(struct file*, filp)
|
||||
__field(int, f_count)
|
||||
__field(uint32_t, context_type)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->files = files;
|
||||
__entry->filp = filp;
|
||||
__entry->f_count = f_count;
|
||||
__entry->context_type = context_type;
|
||||
),
|
||||
TP_printk("files=%p, filp=%p, f_count=%u, cxt_type=%d",
|
||||
__entry->files,
|
||||
__entry->filp,
|
||||
__entry->f_count,
|
||||
__entry->context_type)
|
||||
);
|
||||
|
||||
TRACE_EVENT(smcinvoke_release_from_kernel_client,
|
||||
TP_PROTO(struct files_struct *files, struct file *filp, int f_count),
|
||||
TP_ARGS(files, filp, f_count),
|
||||
TP_STRUCT__entry(
|
||||
__field(struct files_struct*, files)
|
||||
__field(struct file*, filp)
|
||||
__field(int, f_count)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->files = files;
|
||||
__entry->filp = filp;
|
||||
__entry->f_count = f_count;
|
||||
),
|
||||
TP_printk("files=%p, filp=%p, f_count=%u",
|
||||
__entry->files,
|
||||
__entry->filp,
|
||||
__entry->f_count)
|
||||
);
|
||||
|
||||
TRACE_EVENT(smcinvoke_release,
|
||||
TP_PROTO(struct files_struct *files, struct file *filp,
|
||||
int f_count, void *private_data),
|
||||
TP_ARGS(files, filp, f_count, private_data),
|
||||
TP_STRUCT__entry(
|
||||
__field(struct files_struct*, files)
|
||||
__field(struct file*, filp)
|
||||
__field(int, f_count)
|
||||
__field(void*, private_data)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->files = files;
|
||||
__entry->filp = filp;
|
||||
__entry->f_count = f_count;
|
||||
__entry->private_data = private_data;
|
||||
),
|
||||
TP_printk("files=%p, filp=%p, f_count=%d, private_data=%p",
|
||||
__entry->files,
|
||||
__entry->filp,
|
||||
__entry->f_count,
|
||||
__entry->private_data)
|
||||
);
|
||||
|
||||
#endif /* _TRACE_SMCINVOKE_H */
|
||||
/*
|
||||
* Path must be relative to location of 'define_trace.h' header in kernel
|
||||
* Define path if not defined in bazel file
|
||||
*/
|
||||
#ifndef SMCINVOKE_TRACE_INCLUDE_PATH
|
||||
#define SMCINVOKE_TRACE_INCLUDE_PATH ../../../../vendor/qcom/opensource/securemsm-kernel/smcinvoke
|
||||
#endif
|
||||
|
||||
#undef TRACE_INCLUDE_PATH
|
||||
#define TRACE_INCLUDE_PATH SMCINVOKE_TRACE_INCLUDE_PATH
|
||||
#undef TRACE_INCLUDE_FILE
|
||||
#define TRACE_INCLUDE_FILE trace_smcinvoke
|
||||
|
||||
/* This part must be outside protection */
|
||||
#include <trace/define_trace.h>
|
Reference in New Issue
Block a user