Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

@@ -0,0 +1,33 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015-2019, MICROTRUST Incorporated
* All Rights Reserved.
*
*/
#ifndef __TEEI_FDRV_H__
#define __TEEI_FDRV_H__
#include <linux/list.h>
#include <notify_queue.h>
#include <teei_common.h>
struct teei_fdrv {
void *buf;
int buff_size;
int call_type;
struct list_head list;
};
/* used by fdrv drivers */
void register_fdrv(struct teei_fdrv *fdrv);
int create_fdrv(struct teei_fdrv *fdrv);
int fdrv_notify(struct teei_fdrv *fdrv);
void teei_handle_fdrv_call(struct NQ_entry *entry);
/* used internally by tz_driver */
int create_all_fdrv(void);
int __call_fdrv(struct fdrv_call_struct *fdrv_ent);
#endif
@@ -0,0 +1,115 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015-2019, MICROTRUST Incorporated
* All Rights Reserved.
*
*/
#ifndef _ISEE_IMSG_LOG_H_
#define _ISEE_IMSG_LOG_H_
#ifndef IMSG_TAG
#define IMSG_TAG "[ISEE DRV]"
#endif
enum {
IMSG_LV_DISABLE = 0,
IMSG_LV_ERROR,
IMSG_LV_WARN,
IMSG_LV_INFO,
IMSG_LV_DEBUG,
IMSG_LV_TRACE
};
#if defined(CONFIG_MICROTRUST_DEBUG)
#define IMSG_LOG_LEVEL IMSG_LV_DEBUG
#define IMSG_PROFILE_LEVEL IMSG_LV_TRACE
#else
/* DO NOT change the log level, this is for production */
#define IMSG_LOG_LEVEL IMSG_LV_WARN
#define IMSG_PROFILE_LEVEL IMSG_LV_TRACE
#endif
#include <linux/printk.h>
#include <linux/ktime.h>
#include <linux/timekeeping.h>
uint32_t get_imsg_log_level(void);
static inline unsigned long now_ms(void)
{
struct timeval now_time;
do_gettimeofday(&now_time);
return ((now_time.tv_sec * 1000000) + now_time.tv_usec)/1000;
}
#define IMSG_PRINTK(fmt, ...) pr_info(fmt, ##__VA_ARGS__)
#define IMSG_PRINTK_DEBUG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_ERROR(fmt, ...) pr_notice(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_WARN(fmt, ...) pr_notice(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_INFO(fmt, ...) pr_info(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_DEBUG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_TRACE(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_ENTER(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_LEAVE(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
#define IMSG_PRINT_PROFILE(fmt, ...) pr_debug(fmt, ##__VA_ARGS__)
#define IMSG_PRINT(level, func, fmt, ...) \
do { \
if (level <= get_imsg_log_level()) \
IMSG_PRINT_##func("%s[%s]: " fmt, IMSG_TAG, \
#func, ##__VA_ARGS__); \
} while (0)
#define IMSG_PRINT_TIME_S(level, fmt, ...) \
unsigned long start_ms; \
do { \
start_ms = now_ms(); \
IMSG_PRINT(level, PROFILE, fmt " (start:%lu)\n", \
##__VA_ARGS__, start_ms); \
} while (0)
#define IMSG_PRINT_TIME_E(level, fmt, ...) \
do { \
unsigned long end_ms, delta_ms; \
end_ms = now_ms(); \
delta_ms = end_ms - start_ms; \
IMSG_PRINT(level, PROFILE, fmt " (end:%lu, spend:%lu ms)\n", \
##__VA_ARGS__, end_ms, delta_ms); \
} while (0)
/*************************************************************************/
/* Declare macros ********************************************************/
/*************************************************************************/
#define IMSG_ERROR(fmt, ...) \
IMSG_PRINT(IMSG_LV_ERROR, ERROR, fmt, ##__VA_ARGS__)
#define IMSG_WARN(fmt, ...) \
IMSG_PRINT(IMSG_LV_WARN, WARN, fmt, ##__VA_ARGS__)
#define IMSG_INFO(fmt, ...) \
IMSG_PRINT(IMSG_LV_INFO, INFO, fmt, ##__VA_ARGS__)
#define IMSG_DEBUG(fmt, ...) \
IMSG_PRINT(IMSG_LV_DEBUG, DEBUG, fmt, ##__VA_ARGS__)
#define IMSG_TRACE(fmt, ...) \
IMSG_PRINT(IMSG_LV_TRACE, TRACE, fmt, ##__VA_ARGS__)
#define IMSG_ENTER() \
IMSG_PRINT(IMSG_LV_TRACE, ENTER, "%s\n", __func__)
#define IMSG_LEAVE() \
IMSG_PRINT(IMSG_LV_TRACE, LEAVE, "%s\n", __func__)
#define IMSG_PROFILE_S(fmt, ...) \
IMSG_PRINT_TIME_S(IMSG_PROFILE_LEVEL, fmt, ##__VA_ARGS__)
#define IMSG_PROFILE_E(fmt, ...) \
IMSG_PRINT_TIME_E(IMSG_PROFILE_LEVEL, fmt, ##__VA_ARGS__)
/*************************************************************************/
/* Declare Check Patch ***************************************************/
/*************************************************************************/
#define TZ_SEMA_INIT_0(x) sema_init(x, 0)
#define TZ_SEMA_INIT_1(x) sema_init(x, 1)
#define TZ_EMPTY_PARENTHESES(z) z
#define TZ_VOLATILE(x) TZ_EMPTY_PARENTHESES(vola##tile x)
#define TZ_NON_VOLATILE(x) x
#endif /* _ISEE_IMSG_LOG_H_ */
+465
View File
@@ -0,0 +1,465 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015-2016, Linaro Limited
* All rights reserved.
* Copyright (c) 2015-2019, MICROTRUST Incorporated
* All rights reserved.
*
*/
#ifndef __TEE_H
#define __TEE_H
#include <linux/ioctl.h>
#include <linux/types.h>
/*
* This file describes the API provided by a TEE driver to user space.
*
* Each TEE driver defines a TEE specific protocol which is used for the
* data passed back and forth using TEE_IOC_CMD.
*/
/* Helpers to make the ioctl defines */
#define TEE_IOC_MAGIC 0xa4
#define TEE_IOC_BASE 0
/* Flags relating to shared memory */
#define TEE_IOCTL_SHM_MAPPED 0x1 /* memory mapped in normal world */
#define TEE_IOCTL_SHM_DMA_BUF 0x2 /* dma-buf handle on shared memory */
#define TEE_MAX_ARG_SIZE 1024
#define TEE_MAX_HOSTNAME_SIZE 16
#define TEE_GEN_CAP_GP (1 << 0)/* GlobalPlatform compliant TEE */
#define TEE_GEN_CAP_PRIVILEGED (1 << 1)/* Privileged device (for supplicant) */
/*
* TEE Implementation ID
*/
#define TEE_IMPL_ID_OPTEE 1
/*
* OP-TEE specific capabilities
*/
#define TEE_OPTEE_CAP_TZ (1 << 0)
/**
* struct tee_ioctl_version_data - TEE version
* @impl_id: [out] TEE implementation id
* @impl_caps: [out] Implementation specific capabilities
* @gen_caps: [out] Generic capabilities, defined by TEE_GEN_CAPS_* above
*
* Identifies the TEE implementation, @impl_id is one of TEE_IMPL_ID_* above.
* @impl_caps is implementation specific, for example TEE_OPTEE_CAP_*
* is valid when @impl_id == TEE_IMPL_ID_OPTEE.
*/
struct tee_ioctl_version_data {
__u32 impl_id;
__u32 impl_caps;
__u32 gen_caps;
};
/**
* TEE_IOC_VERSION - query version of TEE
*
* Takes a tee_ioctl_version_data struct and returns with the TEE version
* data filled in.
*/
#define TEE_IOC_VERSION _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 0, \
struct tee_ioctl_version_data)
/**
* struct tee_ioctl_shm_alloc_data - Shared memory allocate argument
* @size: [in/out] Size of shared memory to allocate
* @flags: [in/out] Flags to/from allocation.
* @id: [out] Identifier of the shared memory
*
* The flags field should currently be zero as input. Updated by the call
* with actual flags as defined by TEE_IOCTL_SHM_* above.
* This structure is used as argument for TEE_IOC_SHM_ALLOC below.
*/
struct tee_ioctl_shm_alloc_data {
__u64 size;
__u32 flags;
__s32 id;
};
/**
* TEE_IOC_SHM_ALLOC - allocate shared memory
*
* Allocates shared memory between the user space process and secure OS.
*
* Returns a file descriptor on success or < 0 on failure
*
* The returned file descriptor is used to map the shared memory into user
* space. The shared memory is freed when the descriptor is closed and the
* memory is unmapped.
*/
#define TEE_IOC_SHM_ALLOC _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 1, \
struct tee_ioctl_shm_alloc_data)
/**
* struct tee_ioctl_shm_register_fd_data - Shared memory registering argument
* @fd: [in] file descriptor identifying the shared memory
* @size: [out] Size of shared memory to allocate
* @flags: [in] Flags to/from allocation.
* @id: [out] Identifier of the shared memory
*
* The flags field should currently be zero as input. Updated by the call
* with actual flags as defined by TEE_IOCTL_SHM_* above.
* This structure is used as argument for TEE_IOC_SHM_ALLOC below.
*/
struct tee_ioctl_shm_register_fd_data {
__s64 fd;
__u64 size;
__u32 flags;
__s32 id;
} __aligned(8);
/**
* TEE_IOC_SHM_REGISTER_FD - register a shared memory from a file descriptor
*
* Returns a file descriptor on success or < 0 on failure
*
* The returned file descriptor refers to the shared memory object in kernel
* land. The shared memory is freed when the descriptor is closed.
*/
#define TEE_IOC_SHM_REGISTER_FD _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 8, \
struct tee_ioctl_shm_register_fd_data)
/**
* struct tee_ioctl_buf_data - Variable sized buffer
* @buf_ptr: [in] A __user pointer to a buffer
* @buf_len: [in] Length of the buffer above
*
* Used as argument for TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE,
* TEE_IOC_SUPPL_RECV, and TEE_IOC_SUPPL_SEND below.
*/
struct tee_ioctl_buf_data {
__u64 buf_ptr;
__u64 buf_len;
};
/*
* Attributes for struct tee_ioctl_param, selects field in the union
*/
#define TEE_IOCTL_PARAM_ATTR_TYPE_NONE 0 /* parameter not used */
/*
* These defines value parameters (struct tee_ioctl_param_value)
*/
#define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT 1
#define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT 2
#define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT 3 /* input and output */
/*
* These defines shared memory reference parameters (struct
* tee_ioctl_param_memref)
*/
#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT 5
#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT 6
#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT 7 /* input and output */
/*
* Mask for the type part of the attribute, leaves room for more types
*/
#define TEE_IOCTL_PARAM_ATTR_TYPE_MASK 0xff
/* Meta parameter carrying extra information about the message. */
#define TEE_IOCTL_PARAM_ATTR_META 0x100
/* Mask of all known attr bits */
#define TEE_IOCTL_PARAM_ATTR_MASK \
(TEE_IOCTL_PARAM_ATTR_TYPE_MASK | TEE_IOCTL_PARAM_ATTR_META)
/*
* Matches TEEC_LOGIN_* in GP TEE Client API
* Are only defined for GP compliant TEEs
*/
#define TEE_IOCTL_LOGIN_PUBLIC 0
#define TEE_IOCTL_LOGIN_USER 1
#define TEE_IOCTL_LOGIN_GROUP 2
#define TEE_IOCTL_LOGIN_APPLICATION 4
#define TEE_IOCTL_LOGIN_USER_APPLICATION 5
#define TEE_IOCTL_LOGIN_GROUP_APPLICATION 6
/**
* struct tee_ioctl_param - parameter
* @attr: attributes
* @a: if a memref, offset into the shared memory object, else a value parameter
* @b: if a memref, size of the buffer, else a value parameter
* @c: if a memref, shared memory identifier, else a value parameter
*
* @attr & TEE_PARAM_ATTR_TYPE_MASK indicates if memref or value is used in
* the union. TEE_PARAM_ATTR_TYPE_VALUE_* indicates value and
* TEE_PARAM_ATTR_TYPE_MEMREF_* indicates memref. TEE_PARAM_ATTR_TYPE_NONE
* indicates that none of the members are used.
*
* Shared memory is allocated with TEE_IOC_SHM_ALLOC which returns an
* identifier representing the shared memory object. A memref can reference
* a part of a shared memory by specifying an offset (@a) and size (@b) of
* the object. To supply the entire shared memory object set the offset
* (@a) to 0 and size (@b) to the previously returned size of the object.
*/
struct tee_ioctl_param {
__u64 attr;
union {
__u64 a;
__u64 shm_offs;
};
union {
__u64 b;
__u64 size;
};
union {
__u64 c;
__s64 shm_id;
};
};
#define TEE_IOCTL_UUID_LEN 16
/**
* struct tee_ioctl_open_session_arg - Open session argument
* @uuid: [in] UUID of the Trusted Application
* @clnt_uuid: [in] UUID of client
* @clnt_login: [in] Login class of client, TEE_IOCTL_LOGIN_* above
* @cancel_id: [in] Cancellation id, a unique value to identify this request
* @session: [out] Session id
* @ret: [out] return value
* @ret_origin [out] origin of the return value
* @num_params [in] number of parameters following this struct
*/
struct tee_ioctl_open_session_arg {
__u8 uuid[TEE_IOCTL_UUID_LEN];
__u8 clnt_uuid[TEE_IOCTL_UUID_LEN];
__u32 clnt_login;
__u32 cancel_id;
__u32 session;
__u32 ret;
__u32 ret_origin;
__u32 num_params;
/* num_params tells the actual number of element in params */
struct tee_ioctl_param params[];
};
/**
* TEE_IOC_OPEN_SESSION - opens a session to a Trusted Application
*
* Takes a struct tee_ioctl_buf_data which contains a struct
* tee_ioctl_open_session_arg followed by any array of struct
* tee_ioctl_param
*/
#define TEE_IOC_OPEN_SESSION _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 2, \
struct tee_ioctl_buf_data)
/**
* struct tee_ioctl_invoke_func_arg - Invokes a function in a Trusted
* Application
* @func: [in] Trusted Application function, specific to the TA
* @session: [in] Session id
* @cancel_id: [in] Cancellation id, a unique value to identify this request
* @ret: [out] return value
* @ret_origin [out] origin of the return value
* @num_params [in] number of parameters following this struct
*/
struct tee_ioctl_invoke_arg {
__u32 func;
__u32 session;
__u32 cancel_id;
__u32 ret;
__u32 ret_origin;
__u32 num_params;
/* num_params tells the actual number of element in params */
struct tee_ioctl_param params[];
};
/**
* TEE_IOC_INVOKE - Invokes a function in a Trusted Application
*
* Takes a struct tee_ioctl_buf_data which contains a struct
* tee_invoke_func_arg followed by any array of struct tee_param
*/
#define TEE_IOC_INVOKE _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 3, \
struct tee_ioctl_buf_data)
/**
* struct tee_ioctl_cancel_arg - Cancels an open session or invoke ioctl
* @cancel_id: [in] Cancellation id, a unique value to identify this request
* @session: [in] Session id, if the session is opened, else set to 0
*/
struct tee_ioctl_cancel_arg {
__u32 cancel_id;
__u32 session;
};
/**
* TEE_IOC_CANCEL - Cancels an open session or invoke
*/
#define TEE_IOC_CANCEL _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 4, \
struct tee_ioctl_cancel_arg)
/**
* struct tee_ioctl_close_session_arg - Closes an open session
* @session: [in] Session id
*/
struct tee_ioctl_close_session_arg {
__u32 session;
};
/**
* TEE_IOC_CLOSE_SESSION - Closes a session
*/
#define TEE_IOC_CLOSE_SESSION _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 5, \
struct tee_ioctl_close_session_arg)
/**
* struct tee_iocl_supp_recv_arg - Receive a request for a supplicant function
* @func: [in] supplicant function
* @num_params [in/out] number of parameters following this struct
*
* @num_params is the number of params that tee-supplicant has room to
* receive when input, @num_params is the number of actual params
* tee-supplicant receives when output.
*/
struct tee_iocl_supp_recv_arg {
__u32 func;
__u32 num_params;
/* num_params tells the actual number of element in params */
struct tee_ioctl_param params[];
};
/**
* TEE_IOC_SUPPL_RECV - Receive a request for a supplicant function
*
* Takes a struct tee_ioctl_buf_data which contains a struct
* tee_iocl_supp_recv_arg followed by any array of struct tee_param
*/
#define TEE_IOC_SUPPL_RECV _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 6, \
struct tee_ioctl_buf_data)
/**
* struct tee_iocl_supp_send_arg - Send a response to a received request
* @ret: [out] return value
* @num_params [in] number of parameters following this struct
*/
struct tee_iocl_supp_send_arg {
__u32 ret;
__u32 num_params;
/* num_params tells the actual number of element in params */
struct tee_ioctl_param params[];
};
/**
* TEE_IOC_SUPPL_SEND - Receive a request for a supplicant function
*
* Takes a struct tee_ioctl_buf_data which contains a struct
* tee_iocl_supp_send_arg followed by any array of struct tee_param
*/
#define TEE_IOC_SUPPL_SEND _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 7, \
struct tee_ioctl_buf_data)
/**
* struct tee_ioctl_set_hostname - Set hostname in context data structure
* @hostname: [in] Hostname
*/
struct tee_ioctl_set_hostname_arg {
__u8 hostname[TEE_MAX_HOSTNAME_SIZE];
};
/**
* TEE_IOC_SET_HOSTNAME - Set hostname in context data structure
*/
#define TEE_IOC_SET_HOSTNAME _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 8, \
struct tee_ioctl_set_hostname_arg)
/**
* struct tee_ioctl_shm_kern_op_arg - Kernel operations for shared memory
* @id: [in] Identifier of the shared memory
* @opcode: [in] kernel operation for the specific shared memory
* @paddr: [out] The starting physical address of the shared memory
*/
struct tee_ioctl_shm_kern_op_arg {
__s32 id;
__u32 opcode;
__u64 paddr;
};
#define TEE_IOCTL_SHM_KERN_OP_GET_PA 0
#define TEE_IOCTL_SHM_KERN_OP_FLUSH_CACHE 1
#define TEE_IOCTL_SHM_KERN_OP_INVALID_CACHE 2
/**
* TEE_IOC_SHM_KERN_OP - kernel operations for specific shared memory
*/
#define TEE_IOC_SHM_KERN_OP _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 10, \
struct tee_ioctl_shm_kern_op_arg)
struct capi_proxy_param_value {
__u64 a;
__u64 b;
__u64 c; /* reserved */
__u64 d; /* reserved */
};
struct capi_proxy_param_memref {
__u64 buffer;
__u64 size;
__u64 shm_offset;
__u64 shm_id;
};
struct capi_proxy_param {
__u64 attr;
union {
struct capi_proxy_param_value value;
struct capi_proxy_param_memref memref;
};
};
/**
* struct tee_ioctl_capi_proxy_arg - CAPI proxy driver parameter
* @uuid: [in] TA UUID to communication with
* @capi_op: [in] CAPI operation: open_session, invoke_command, etc.
* @session: [in/out] Session for CAPI operations
* @func: [in] command id of invoke_command
* @ret: [out] Return values
* @reg_orig: [out] Function error origins
* @params: [in] TEEC parameters
*/
struct tee_ioctl_capi_proxy_arg {
__u8 uuid[TEE_IOCTL_UUID_LEN];
__u32 capi_op;
__u32 session;
__u32 func;
__u32 ret;
__u32 ret_orig;
struct capi_proxy_param params[4];
} __aligned(8);
/**
* TEE_IOC_CAPI_PROXY - for communication with CAPI proxy driver
*/
#define TEE_IOC_CAPI_PROXY _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 11, \
struct tee_ioctl_capi_proxy_arg)
/*
* Five syscalls are used when communicating with the TEE driver.
* open(): opens the device associated with the driver
* ioctl(): as described above operating on the file descriptor from open()
* close(): two cases
* - closes the device file descriptor
* - closes a file descriptor connected to allocated shared memory
* mmap(): maps shared memory into user space using information from struct
* tee_ioctl_shm_alloc_data
* munmap(): unmaps previously shared memory
*/
#define TEE_IOC_SHM_RELEASE _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 12, \
struct tee_ioctl_shm_alloc_data)
#define TEE_IOC_SHM_ID _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 13, \
struct tee_ioctl_shm_alloc_data)
#endif /*__TEE_H*/
@@ -0,0 +1,524 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
* Copyright (c) 2015, Linaro Limited
* All rights reserved.
* Copyright (c) 2015-2019, MICROTRUST Incorporated
* All rights reserved.
*
*/
#ifndef TEE_CLIENT_API_H
#define TEE_CLIENT_API_H
#ifndef __KERNEL__
#include <stdint.h>
#include <stddef.h>
#endif /* __KERNEL__ */
#include <linux/file.h>
/*
* Defines the number of available memory references in an open session or
* invoke command operation payload.
*/
#define TEEC_CONFIG_PAYLOAD_REF_COUNT 4
/**
* Defines the maximum size of a single shared memory block, in bytes, of both
* API allocated and API registered memory. The size is currently set to
* 512 * kB (512 * 1024).
*/
#define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0x8000
/**
* Flag constants indicating the type of parameters encoded inside the
* operation payload (TEEC_Operation), Type is uint32_t.
*
* TEEC_NONE The Parameter is not used
*
* TEEC_VALUE_INPUT The Parameter is a TEEC_Value tagged as input.
*
* TEEC_VALUE_OUTPUT The Parameter is a TEEC_Value tagged as output.
*
* TEEC_VALUE_INOUT The Parameter is a TEEC_Value tagged as both as
* input and output, i.e., for which both the
* behaviors of TEEC_VALUE_INPUT and
* TEEC_VALUE_OUTPUT apply.
*
* TEEC_MEMREF_TEMP_INPUT The Parameter is a TEEC_TempMemoryReference
* describing a region of memory which needs to be
* temporarily registered for the duration of the
* Operation and is tagged as input.
*
* TEEC_MEMREF_TEMP_OUTPUT Same as TEEC_MEMREF_TEMP_INPUT, but the Memory
* Reference is tagged as output. The
* Implementation may update the size field to
* reflect the required output size in some use
* cases.
*
* TEEC_MEMREF_TEMP_INOUT A Temporary Memory Reference tagged as both
* input and output, i.e., for which both the
* behaviors of TEEC_MEMREF_TEMP_INPUT and
* TEEC_MEMREF_TEMP_OUTPUT apply.
*
* TEEC_MEMREF_WHOLE The Parameter is a Registered Memory Reference
* that refers to the entirety of its parent Shared
* Memory block. The parameter structure is a
* TEEC_MemoryReference. In this structure, the
* Implementation MUST read only the parent field
* and MAY update the size field when the operation
* completes.
*
* TEEC_MEMREF_PARTIAL_INPUT A Registered Memory Reference structure that
* refers to a partial region of its parent Shared
* Memory block and is tagged as input.
*
* TEEC_MEMREF_PARTIAL_OUTPUT Registered Memory Reference structure that
* refers to a partial region of its parent Shared
* Memory block and is tagged as output.
*
* TEEC_MEMREF_PARTIAL_INOUT The Registered Memory Reference structure that
* refers to a partial region of its parent Shared
* Memory block and is tagged as both input and
* output, i.e., for which both the behaviors of
* TEEC_MEMREF_PARTIAL_INPUT and
* TEEC_MEMREF_PARTIAL_OUTPUT apply.
*/
#define TEEC_NONE 0x00000000
#define TEEC_VALUE_INPUT 0x00000001
#define TEEC_VALUE_OUTPUT 0x00000002
#define TEEC_VALUE_INOUT 0x00000003
#define TEEC_MEMREF_TEMP_INPUT 0x00000005
#define TEEC_MEMREF_TEMP_OUTPUT 0x00000006
#define TEEC_MEMREF_TEMP_INOUT 0x00000007
#define TEEC_MEMREF_WHOLE 0x0000000C
#define TEEC_MEMREF_PARTIAL_INPUT 0x0000000D
#define TEEC_MEMREF_PARTIAL_OUTPUT 0x0000000E
#define TEEC_MEMREF_PARTIAL_INOUT 0x0000000F
/**
* Flag constants indicating the data transfer direction of memory in
* TEEC_Parameter. TEEC_MEM_INPUT signifies data transfer direction from the
* client application to the TEE. TEEC_MEM_OUTPUT signifies data transfer
* direction from the TEE to the client application. Type is uint32_t.
*
* TEEC_MEM_INPUT The Shared Memory can carry data from the client
* application to the Trusted Application.
* TEEC_MEM_OUTPUT The Shared Memory can carry data from the Trusted
* Application to the client application.
*/
#define TEEC_MEM_INPUT 0x00000001
#define TEEC_MEM_OUTPUT 0x00000002
/**
* Return values. Type is TEEC_Result
*
* TEEC_SUCCESS The operation was successful.
* TEEC_ERROR_GENERIC Non-specific cause.
* TEEC_ERROR_ACCESS_DENIED Access privileges are not sufficient.
* TEEC_ERROR_CANCEL The operation was canceled.
* TEEC_ERROR_ACCESS_CONFLICT Concurrent accesses caused conflict.
* TEEC_ERROR_EXCESS_DATA Too much data for the requested operation was
* passed.
* TEEC_ERROR_BAD_FORMAT Input data was of invalid format.
* TEEC_ERROR_BAD_PARAMETERS Input parameters were invalid.
* TEEC_ERROR_BAD_STATE Operation is not valid in the current state.
* TEEC_ERROR_ITEM_NOT_FOUND The requested data item is not found.
* TEEC_ERROR_NOT_IMPLEMENTED The requested operation should exist but is not
* yet implemented.
* TEEC_ERROR_NOT_SUPPORTED The requested operation is valid but is not
* supported in this implementation.
* TEEC_ERROR_NO_DATA Expected data was missing.
* TEEC_ERROR_OUT_OF_MEMORY System ran out of resources.
* TEEC_ERROR_BUSY The system is busy working on something else.
* TEEC_ERROR_COMMUNICATION Communication with a remote party failed.
* TEEC_ERROR_SECURITY A security fault was detected.
* TEEC_ERROR_SHORT_BUFFER The supplied buffer is too short for the
* generated output.
* TEEC_ERROR_TARGET_DEAD Trusted Application has panicked
* during the operation.
*/
/**
* Standard defined error codes.
*/
#define TEEC_SUCCESS 0x00000000
#define TEEC_ERROR_GENERIC 0xFFFF0000
#define TEEC_ERROR_ACCESS_DENIED 0xFFFF0001
#define TEEC_ERROR_CANCEL 0xFFFF0002
#define TEEC_ERROR_ACCESS_CONFLICT 0xFFFF0003
#define TEEC_ERROR_EXCESS_DATA 0xFFFF0004
#define TEEC_ERROR_BAD_FORMAT 0xFFFF0005
#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
#define TEEC_ERROR_BAD_STATE 0xFFFF0007
#define TEEC_ERROR_ITEM_NOT_FOUND 0xFFFF0008
#define TEEC_ERROR_NOT_IMPLEMENTED 0xFFFF0009
#define TEEC_ERROR_NOT_SUPPORTED 0xFFFF000A
#define TEEC_ERROR_NO_DATA 0xFFFF000B
#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C
#define TEEC_ERROR_BUSY 0xFFFF000D
#define TEEC_ERROR_COMMUNICATION 0xFFFF000E
#define TEEC_ERROR_SECURITY 0xFFFF000F
#define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
#define TEEC_ERROR_EXTERNAL_CANCEL 0xFFFF0011
#define TEEC_ERROR_TARGET_DEAD 0xFFFF3024
/**
* Function error origins, of type TEEC_ErrorOrigin. These indicate where in
* the software stack a particular return value originates from.
*
* TEEC_ORIGIN_API The error originated within the TEE Client API
* implementation.
* TEEC_ORIGIN_COMMS The error originated within the underlying
* communications stack linking the rich OS with
* the TEE.
* TEEC_ORIGIN_TEE The error originated within the common TEE code.
* TEEC_ORIGIN_TRUSTED_APP The error originated within the Trusted Application
* code.
*/
#define TEEC_ORIGIN_API 0x00000001
#define TEEC_ORIGIN_COMMS 0x00000002
#define TEEC_ORIGIN_TEE 0x00000003
#define TEEC_ORIGIN_TRUSTED_APP 0x00000004
/**
* Session login methods, for use in TEEC_OpenSession() as parameter
* connectionMethod. Type is uint32_t.
*
* TEEC_LOGIN_PUBLIC No login data is provided.
* TEEC_LOGIN_USER Login data about the user running the Client
* Application process is provided.
* TEEC_LOGIN_GROUP Login data about the group running the Client
* Application process is provided.
* TEEC_LOGIN_APPLICATION Login data about the running Client Application
* itself is provided.
* TEEC_LOGIN_USER_APPLICATION Login data about the user and the running
* Client Application itself is provided.
* TEEC_LOGIN_GROUP_APPLICATION Login data about the group and the running
* Client Application itself is provided.
*/
#define TEEC_LOGIN_PUBLIC 0x00000000
#define TEEC_LOGIN_USER 0x00000001
#define TEEC_LOGIN_GROUP 0x00000002
#define TEEC_LOGIN_APPLICATION 0x00000004
#define TEEC_LOGIN_USER_APPLICATION 0x00000005
#define TEEC_LOGIN_GROUP_APPLICATION 0x00000006
/**
* Encode the paramTypes according to the supplied types.
*
* @param p0 The first param type.
* @param p1 The second param type.
* @param p2 The third param type.
* @param p3 The fourth param type.
*/
#define TEEC_PARAM_TYPES(p0, p1, p2, p3) \
((p0) | ((p1) << 4) | ((p2) << 8) | ((p3) << 12))
/**
* Get the i_th param type from the paramType.
*
* @param p The paramType.
* @param i The i-th parameter to get the type for.
*/
#define TEEC_PARAM_TYPE_GET(p, i) (((p) >> (i * 4)) & 0xF)
#define TEEC_Result uint32_t
/**
* struct TEEC_Context - Represents a connection between a client application
* and a TEE.
*/
struct TEEC_Context {
/* Implementation defined */
struct file *fd;
};
/**
* This type contains a Universally Unique Resource Identifier (UUID) type as
* defined in RFC4122. These UUID values are used to identify Trusted
* Applications.
*/
struct TEEC_UUID {
uint32_t timeLow;
uint16_t timeMid;
uint16_t timeHiAndVersion;
uint8_t clockSeqAndNode[8];
};
/**
* struct TEEC_SharedMemory - Memory to transfer data between a client
* application and trusted code.
*
* @param buffer The memory buffer which is to be, or has been, shared
* with the TEE.
* @param size The size, in bytes, of the memory buffer.
* @param flags Bit-vector which holds properties of buffer.
* The bit-vector can contain either or both of the
* TEEC_MEM_INPUT and TEEC_MEM_OUTPUT flags.
*
* A shared memory block is a region of memory allocated in the context of the
* client application memory space that can be used to transfer data between
* that client application and a trusted application. The user of this struct
* is responsible to populate the buffer pointer.
*/
struct TEEC_SharedMemory {
void *buffer;
size_t size;
uint32_t flags;
/*
* Implementation-Defined
*/
int id;
size_t alloced_size;
void *shadow_buffer;
int registered_fd;
void *priv;
};
/**
* struct TEEC_TempMemoryReference - Temporary memory to transfer data between
* a client application and trusted code, only used for the duration of the
* operation.
*
* @param buffer The memory buffer which is to be, or has been shared with
* the TEE.
* @param size The size, in bytes, of the memory buffer.
*
* A memory buffer that is registered temporarily for the duration of the
* operation to be called.
*/
struct TEEC_TempMemoryReference {
void *buffer;
size_t size;
};
/**
* struct TEEC_RegisteredMemoryReference - use a pre-registered or
* pre-allocated shared memory block of memory to transfer data between
* a client application and trusted code.
*
* @param parent Points to a shared memory structure. The memory reference
* may utilize the whole shared memory or only a part of it.
* Must not be NULL
*
* @param size The size, in bytes, of the memory buffer.
*
* @param offset The offset, in bytes, of the referenced memory region from
* the start of the shared memory block.
*
*/
struct TEEC_RegisteredMemoryReference {
struct TEEC_SharedMemory *parent;
size_t size;
size_t offset;
};
/**
* struct TEEC_Value - Small raw data container
*
* Instead of allocating a shared memory buffer this structure can be used
* to pass small raw data between a client application and trusted code.
*
* @param a The first integer value.
*
* @param b The second second value.
*/
struct TEEC_Value {
uint32_t a;
uint32_t b;
};
/**
* union TEEC_Parameter - Memory container to be used when passing data between
* client application and trusted code.
*
* Either the client uses a shared memory reference, parts of it or a small raw
* data container.
*
* @param tmpref A temporary memory reference only valid for the duration
* of the operation.
*
* @param memref The entire shared memory or parts of it.
*
* @param value The small raw data container to use
*/
union TEEC_Parameter {
struct TEEC_TempMemoryReference tmpref;
struct TEEC_RegisteredMemoryReference memref;
struct TEEC_Value value;
};
/**
* struct TEEC_Session - Represents a connection between a client application
* and a trusted application.
*/
struct TEEC_Session {
/* Implementation defined */
struct TEEC_Context *ctx;
uint32_t session_id;
};
/**
* struct TEEC_Operation - Holds information and memory references used in
* TEEC_InvokeCommand().
*
* @param started Client must initialize to zero if it needs to cancel
* an operation about to be performed.
* @param paramTypes Type of data passed. Use TEEC_PARAMS_TYPE macro to
* create the correct flags.
* 0 means TEEC_NONE is passed for all params.
* @param params Array of parameters of type union TEEC_Parameter.
* @param session Internal pointer to the last session used by
* TEEC_InvokeCommand with this operation.
*
*/
struct TEEC_Operation {
uint32_t started;
uint32_t paramTypes;
union TEEC_Parameter params[TEEC_CONFIG_PAYLOAD_REF_COUNT];
/* Implementation-Defined */
struct TEEC_Session *session;
};
/**
* TEEC_InitializeContext() - Initializes a context holding connection
* information on the specific TEE, designated by the name string.
* @param name A zero-terminated string identifying the TEE to connect to.
* If name is set to NULL, the default TEE is connected to. NULL
* is the only supported value in this version of the API
* implementation.
*
* @param context The context structure which is to be initialized.
*
* @return TEEC_SUCCESS The initialization was successful.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_InitializeContext(const char *name,
struct TEEC_Context *context);
/**
* TEEC_FinalizeContext() - Destroys a context holding connection information
* on the specific TEE.
*
* This function destroys an initialized TEE context, closing the connection
* between the client application and the TEE. This function must only be
* called when all sessions related to this TEE context have been closed and
* all shared memory blocks have been released.
*
* @param context The context to be destroyed.
*/
void TEEC_FinalizeContext(struct TEEC_Context *context);
/**
* TEEC_OpenSession() - Opens a new session with the specified trusted
* application.
*
* @param context The initialized TEE context structure in which
* scope to open the session.
* @param session The session to initialize.
* @param destination A structure identifying the trusted application
* with which to open a session.
*
* @param connectionMethod The connection method to use.
* @param connectionData Any data necessary to connect with the chosen
* connection method. Not supported, should be set to
* NULL.
* @param operation An operation structure to use in the session. May
* be set to NULL to signify no operation structure
* needed.
*
* @param returnOrigin A parameter which will hold the error origin if
* this function returns any value other than
* TEEC_SUCCESS.
*
* @return TEEC_SUCCESS OpenSession successfully opened a new session.
* @return TEEC_Result Something failed.
*
*/
TEEC_Result TEEC_OpenSession(struct TEEC_Context *context,
struct TEEC_Session *session,
const struct TEEC_UUID *destination,
uint32_t connectionMethod,
const void *connectionData,
struct TEEC_Operation *operation,
uint32_t *returnOrigin);
/**
* TEEC_CloseSession() - Closes the session which has been opened with the
* specific trusted application.
*
* @param session The opened session to close.
*/
void TEEC_CloseSession(struct TEEC_Session *session);
/**
* TEEC_InvokeCommand() - Executes a command in the specified trusted
* application.
*
* @param session A handle to an open connection to the trusted
* application.
* @param commandID Identifier of the command in the trusted application
* to invoke.
* @param operation An operation structure to use in the invoke command.
* May be set to NULL to signify no operation structure
* needed.
* @param returnOrigin A parameter which will hold the error origin if this
* function returns any value other than TEEC_SUCCESS.
*
* @return TEEC_SUCCESS OpenSession successfully opened a new session.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_InvokeCommand(struct TEEC_Session *session,
uint32_t commandID,
struct TEEC_Operation *operation,
uint32_t *returnOrigin);
/**
* TEEC_RegisterSharedMemory() - Register a block of existing memory as a
* shared block within the scope of the specified context.
*
* @param context The initialized TEE context structure in which scope to
* open the session.
* @param sharedMem pointer to the shared memory structure to register.
*
* @return TEEC_SUCCESS The registration was successful.
* @return TEEC_ERROR_OUT_OF_MEMORY Memory exhaustion.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_RegisterSharedMemory(struct TEEC_Context *context,
struct TEEC_SharedMemory *sharedMem);
/**
* TEEC_AllocateSharedMemory() - Allocate shared memory for TEE.
*
* @param context The initialized TEE context structure in which scope to
* open the session.
* @param sharedMem Pointer to the allocated shared memory.
*
* @return TEEC_SUCCESS The registration was successful.
* @return TEEC_ERROR_OUT_OF_MEMORY Memory exhaustion.
* @return TEEC_Result Something failed.
*/
TEEC_Result TEEC_AllocateSharedMemory(struct TEEC_Context *context,
struct TEEC_SharedMemory *sharedMem);
/**
* TEEC_ReleaseSharedMemory() - Free or deregister the shared memory.
*
* @param sharedMem Pointer to the shared memory to be freed.
*/
void TEEC_ReleaseSharedMemory(struct TEEC_SharedMemory *sharedMemory);
/**
* TEEC_RequestCancellation() - Request the cancellation of a pending open
* session or command invocation.
*
* @param operation Pointer to an operation previously passed to open session
* or invoke.
*/
void TEEC_RequestCancellation(struct TEEC_Operation *operation);
#endif
@@ -0,0 +1,312 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015-2016, Linaro Limited
* Copyright (c) 2015-2019, MICROTRUST Incorporated
*
*/
#ifndef __TEE_DRV_H
#define __TEE_DRV_H
#include <linux/types.h>
#include <linux/idr.h>
#include <linux/list.h>
#include <linux/device.h>
#include "tee.h"
/*
* The file describes the API provided by the generic TEE driver to the
* specific TEE driver.
*/
#define TEE_SHM_MAPPED BIT(0) /* Memory mapped by the kernel */
#define TEE_SHM_DMA_BUF BIT(1) /* Memory with dma-buf handle */
#define TEE_SHM_EXT_DMA_BUF BIT(2) /* Memory with dma-buf handle */
#define TEE_SHM_DMA_KERN_BUF BIT(3)
struct tee_device;
struct tee_shm;
struct tee_shm_pool;
/**
* struct tee_context - driver specific context on file pointer data
* @teedev: pointer to this drivers struct tee_device
* @list_shm: List of shared memory object owned by this context
* @hostname: to distinguish which TEE subsystem will serving client requests
* @data: driver specific context data, managed by the driver
*/
struct tee_context {
struct tee_device *teedev;
struct list_head list_shm;
u8 hostname[TEE_MAX_HOSTNAME_SIZE];
void *data;
struct mutex mutex;
};
struct tee_param_memref {
size_t shm_offs;
size_t size;
struct tee_shm *shm;
};
struct tee_param_value {
u64 a;
u64 b;
u64 c;
};
struct tee_param {
u64 attr;
union {
struct tee_param_memref memref;
struct tee_param_value value;
} u;
};
/**
* struct tee_driver_ops - driver operations vtable
* @get_version: returns version of driver
* @open: called when the device file is opened
* @release: release this open file
* @open_session: open a new session
* @close_session: close a session
* @invoke_func: invoke a trusted function
* @cancel_req: request cancel of an ongoing invoke or open
* @supp_revc: called for supplicant to get a command
* @supp_send: called for supplicant to send a response
*/
struct tee_driver_ops {
void (*get_version)(struct tee_device *teedev,
struct tee_ioctl_version_data *vers);
int (*open)(struct tee_context *ctx);
void (*release)(struct tee_context *ctx);
int (*open_session)(struct tee_context *ctx,
struct tee_ioctl_open_session_arg *arg,
struct tee_param *param);
int (*close_session)(struct tee_context *ctx, u32 session);
int (*invoke_func)(struct tee_context *ctx,
struct tee_ioctl_invoke_arg *arg,
struct tee_param *param);
int (*cancel_req)(struct tee_context *ctx, u32 cancel_id, u32 session);
int (*supp_recv)(struct tee_context *ctx, u32 *func, u32 *num_params,
struct tee_param *param);
int (*supp_send)(struct tee_context *ctx, u32 ret, u32 num_params,
struct tee_param *param);
};
/**
* struct tee_desc - Describes the TEE driver to the subsystem
* @name: name of driver
* @ops: driver operations vtable
* @owner: module providing the driver
* @flags: Extra properties of driver, defined by TEE_DESC_* below
*/
#define TEE_DESC_PRIVILEGED 0x1
struct tee_desc {
const char *name;
const struct tee_driver_ops *ops;
struct module *owner;
u32 flags;
};
/**
* isee_device_alloc() - Allocate a new struct tee_device instance
* @teedesc: Descriptor for this driver
* @dev: Parent device for this device
* @pool: Shared memory pool, NULL if not used
* @driver_data: Private driver data for this device
*
* Allocates a new struct tee_device instance. The device is
* removed by isee_device_unregister().
*
* @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure
*/
struct tee_device *isee_device_alloc(const struct tee_desc *teedesc,
struct device *dev,
struct tee_shm_pool *pool,
void *driver_data);
/**
* isee_device_register() - Registers a TEE device
* @teedev: Device to register
*
* isee_device_unregister() need to be called to remove the @teedev if
* this function fails.
*
* @returns < 0 on failure
*/
int isee_device_register(struct tee_device *teedev);
/**
* isee_device_unregister() - Removes a TEE device
* @teedev: Device to unregister
*
* This function should be called to remove the @teedev even if
* isee_device_register() hasn't been called yet. Does nothing if
* @teedev is NULL.
*/
void isee_device_unregister(struct tee_device *teedev);
/**
* struct tee_shm_pool_mem_info - holds information needed to create a shared
* memory pool
* @vaddr: Virtual address of start of pool
* @paddr: Physical address of start of pool
* @size: Size in bytes of the pool
*/
struct tee_shm_pool_mem_info {
unsigned long vaddr;
phys_addr_t paddr;
size_t size;
};
/**
* isee_shm_pool_alloc_res_mem() - Create a shared memory pool from reserved
* memory range
* @priv_info: Information for driver private shared memory pool
* @dmabuf_info: Information for dma-buf shared memory pool
*
* Start and end of pools will must be page aligned.
*
* Allocation with the flag TEE_SHM_DMA_BUF set will use the range supplied
* in @dmabuf, others will use the range provided by @priv.
*
* @returns pointer to a 'struct tee_shm_pool' or an ERR_PTR on failure.
*/
struct tee_shm_pool *
isee_shm_pool_alloc_res_mem(struct tee_shm_pool_mem_info *priv_info,
struct tee_shm_pool_mem_info *dmabuf_info);
/**
* isee_shm_pool_free() - Free a shared memory pool
* @pool: The shared memory pool to free
*
* The must be no remaining shared memory allocated from this pool when
* this function is called.
*/
void isee_shm_pool_free(struct tee_shm_pool *pool);
/**
* isee_get_drvdata() - Return driver_data pointer
* @returns the driver_data pointer supplied to isee_register().
*/
void *isee_get_drvdata(struct tee_device *teedev);
struct tee_shm *isee_shm_kalloc(struct tee_context *ctx, size_t size, u32 flags);
void isee_shm_kfree(struct tee_shm *shm);
/**
* isee_shm_alloc() - Allocate shared memory
* @ctx: Context that allocates the shared memory
* @size: Requested size of shared memory
* @flags: Flags setting properties for the requested shared memory.
*
* Memory allocated as global shared memory is automatically freed when the
* TEE file pointer is closed. The @flags field uses the bits defined by
* TEE_SHM_* above. TEE_SHM_MAPPED must currently always be set. If
* TEE_SHM_DMA_BUF global shared memory will be allocated and associated
* with a dma-buf handle, else driver private memory.
*
* @returns a pointer to 'struct tee_shm'
*/
struct tee_shm *isee_shm_alloc_noid(struct tee_context *ctx, size_t size, u32 flags);
struct tee_shm *isee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags);
/**
* isee_shm_free() - Free shared memory
* @shm: Handle to shared memory to free
*/
void isee_shm_free(struct tee_shm *shm);
/**
* isee_shm_put() - Decrease reference count on a shared memory handle
* @shm: Shared memory handle
*/
void isee_shm_put(struct tee_shm *shm);
/**
* isee_shm_va2pa() - Get physical address of a virtual address
* @shm: Shared memory handle
* @va: Virtual address to tranlsate
* @pa: Returned physical address
* @returns 0 on success and < 0 on failure
*/
int isee_shm_va2pa(struct tee_shm *shm, void *va, phys_addr_t *pa);
/**
* isee_shm_pa2va() - Get virtual address of a physical address
* @shm: Shared memory handle
* @pa: Physical address to tranlsate
* @va: Returned virtual address
* @returns 0 on success and < 0 on failure
*/
int isee_shm_pa2va(struct tee_shm *shm, phys_addr_t pa, void **va);
/**
* isee_shm_get_va() - Get virtual address of a shared memory plus an offset
* @shm: Shared memory handle
* @offs: Offset from start of this shared memory
* @returns virtual address of the shared memory + offs if offs is within
* the bounds of this shared memory, else an ERR_PTR
*/
void *isee_shm_get_va(struct tee_shm *shm, size_t offs);
/**
* isee_shm_get_pa() - Get physical address of a shared memory plus an offset
* @shm: Shared memory handle
* @offs: Offset from start of this shared memory
* @pa: Physical address to return
* @returns 0 if offs is within the bounds of this shared memory, else an
* error code.
*/
int isee_shm_get_pa(struct tee_shm *shm, size_t offs, phys_addr_t *pa);
/**
* isee_shm_get_id() - Get id of a shared memory object
* @shm: Shared memory handle
* @returns id
*/
int isee_shm_get_id(struct tee_shm *shm);
/**
* isee_shm_get_from_id() - Find shared memory object and increase reference
* count
* @ctx: Context owning the shared memory
* @id: Id of shared memory object
* @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure
*/
struct tee_shm *isee_shm_get_from_id(struct tee_context *ctx, int id);
static inline bool tee_param_is_memref(struct tee_param *param)
{
switch (param->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT:
case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
return true;
default:
return false;
}
}
struct tee_context *tee_client_open_context(struct tee_context *start,
int (*match)(struct tee_ioctl_version_data *,
const void *),
const void *data, struct tee_ioctl_version_data *vers);
void tee_client_close_context(struct tee_context *ctx);
void tee_client_get_version(struct tee_context *ctx,
struct tee_ioctl_version_data *vers);
int tee_client_open_session(struct tee_context *ctx,
struct tee_ioctl_open_session_arg *arg,
struct tee_param *param);
int tee_client_close_session(struct tee_context *ctx, u32 session);
int tee_client_invoke_func(struct tee_context *ctx,
struct tee_ioctl_invoke_arg *arg,
struct tee_param *param);
#endif /*__TEE_DRV_H*/
@@ -0,0 +1,53 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015-2019, MICROTRUST Incorporated
* All Rights Reserved.
*
*/
#ifndef __TEEI_IOC_H_
#define __TEEI_IOC_H_
#define TEEI_IOC_MAGIC 'T'
#define TEEI_CONFIG_IOC_MAGIC TEEI_IOC_MAGIC
#define TEEI_CLIENT_IOC_MAGIC TEEI_IOC_MAGIC
#define UT_TUI_CLIENT_IOC_MAGIC TEEI_IOC_MAGIC
/*
* /dev/teei_config
*/
#define MAX_DRV_UUIDS 30
#define UUID_LEN 32
struct init_param {
char uuids[MAX_DRV_UUIDS][UUID_LEN+1];
__u32 uuid_count;
__u32 flag;
};
#define TEEI_CONFIG_IOCTL_INIT_TEEI \
_IOWR(TEEI_CONFIG_IOC_MAGIC, 3, struct init_param)
#define TEEI_CONFIG_IOCTL_UNLOCK \
_IOWR(TEEI_CONFIG_IOC_MAGIC, 4, int)
/*
* /dev/ut_keymaster
*/
#define CMD_KM_MEM_CLEAR _IO(TEEI_IOC_MAGIC, 0x1)
#define CMD_KM_MEM_SEND _IO(TEEI_IOC_MAGIC, 0x2)
#define CMD_KM_NOTIFY_UTD _IO(TEEI_IOC_MAGIC, 0x3)
#define CMD_KM_FIRST_TIME_BOOT _IO(TEEI_IOC_MAGIC, 0x4)
/*
* /dev/teei_fp
*/
#define CMD_FP_MEM_CLEAR _IO(TEEI_IOC_MAGIC, 0x1)
#define CMD_FP_CMD _IO(TEEI_IOC_MAGIC, 0x2)
#define CMD_FP_LOAD_TEE _IO(TEEI_IOC_MAGIC, 0x4)
#define CMD_TEEI_SET_PRI _IO(TEEI_IOC_MAGIC, 0x5)
#define TEEI_VFS_NOTIFY_DRM _IOWR(TEEI_CONFIG_IOC_MAGIC, 0x75, int)
#define TEEI_VFS_GET_FP_UUID 0x50
#endif
@@ -0,0 +1,37 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2015-2019, MICROTRUST Incorporated
* All Rights Reserved.
*
*/
#ifndef _TEEI_KERN_API_
#define _TEEI_KERN_API_
#include <linux/arm-smccc.h>
#if defined(__GNUC__) && \
defined(__GNUC_MINOR__) && \
defined(__GNUC_PATCHLEVEL__) && \
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)) \
>= 40502
#define ARCH_EXTENSION_SEC
#endif
#define TEEI_FC_CPU_ON (0xb4000080)
#define TEEI_FC_CPU_OFF (0xb4000081)
#define TEEI_FC_CPU_DORMANT (0xb4000082)
#define TEEI_FC_CPU_DORMANT_CANCEL (0xb4000083)
#define TEEI_FC_CPU_ERRATA_802022 (0xb4000084)
static inline long teei_secure_call(u64 function_id,
u64 arg0, u64 arg1, u64 arg2)
{
struct arm_smccc_res res;
arm_smccc_smc(function_id, arg0, arg1, arg2,
0, 0, 0, 0, &res);
return res.a0;
}
#endif /* _TEEI_KERN_API_ */