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,710 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEESMC_H
#define TEESMC_H
#ifndef ASM
/*
* This section depends on uint64_t, uint32_t uint8_t already being
* defined. Since this file is used in several different environments
* (secure world OS and normal world Linux kernel to start with) where
* stdint.h may not be available it's the responsibility of the one
* including this file to provide those types.
*/
/*
* Trusted OS SMC interface.
*
* The SMC interface follows SMC Calling Convention
* (ARM_DEN0028A_SMC_Calling_Convention).
*
* The primary objective of this API is to provide a transport layer on
* which a Global Platform compliant TEE interfaces can be deployed. But the
* interface can also be used for other implementations.
*
* This file is divided in two parts.
* Part 1 deals with passing parameters to Trusted Applications running in
* a trusted OS in secure world.
* Part 2 deals with the lower level handling of the SMC.
*/
/*
*******************************************************************************
* Part 1 - passing parameters to Trusted Applications
*******************************************************************************
*/
/*
* Same values as TEE_PARAM_* from TEE Internal API
*/
#define TEESMC_ATTR_TYPE_NONE 0
#define TEESMC_ATTR_TYPE_VALUE_INPUT 1
#define TEESMC_ATTR_TYPE_VALUE_OUTPUT 2
#define TEESMC_ATTR_TYPE_VALUE_INOUT 3
#define TEESMC_ATTR_TYPE_MEMREF_INPUT 5
#define TEESMC_ATTR_TYPE_MEMREF_OUTPUT 6
#define TEESMC_ATTR_TYPE_MEMREF_INOUT 7
#define TEESMC_ATTR_TYPE_MASK 0x7
/*
* Meta parameter to be absorbed by the Secure OS and not passed
* to the Trusted Application.
*
* One example of this is a struct teesmc_meta_open_session which
* is added to TEESMC{32,64}_CMD_OPEN_SESSION.
*/
#define TEESMC_ATTR_META 0x8
/*
* Used as an indication from normal world of compatible cache usage.
* 'I' stands for inner cache and 'O' for outer cache.
*/
#define TEESMC_ATTR_CACHE_I_NONCACHE 0x0
#define TEESMC_ATTR_CACHE_I_WRITE_THR 0x1
#define TEESMC_ATTR_CACHE_I_WRITE_BACK 0x2
#define TEESMC_ATTR_CACHE_O_NONCACHE 0x0
#define TEESMC_ATTR_CACHE_O_WRITE_THR 0x4
#define TEESMC_ATTR_CACHE_O_WRITE_BACK 0x8
#define TEESMC_ATTR_CACHE_NONCACHE (TEESMC_ATTR_CACHE_I_NONCACHE | \
TEESMC_ATTR_CACHE_O_NONCACHE)
#define TEESMC_ATTR_CACHE_DEFAULT (TEESMC_ATTR_CACHE_I_WRITE_BACK | \
TEESMC_ATTR_CACHE_O_WRITE_BACK)
#define TEESMC_ATTR_CACHE_SHIFT 4
#define TEESMC_ATTR_CACHE_MASK 0xf
#define TEESMC_CMD_OPEN_SESSION 0
#define TEESMC_CMD_INVOKE_COMMAND 1
#define TEESMC_CMD_CLOSE_SESSION 2
#define TEESMC_CMD_CANCEL 3
/**
* struct teesmc32_param_memref - memory reference
* @buf_ptr: Address of the buffer
* @size: Size of the buffer
*
* Secure and normal world communicates pointer via physical address instead of
* the virtual address with is usually used for pointers. This is because
* Secure and normal world has completely independent memory mapping. Normal
* world can even have a hypervisor which need to translate the guest
* physical address (AKA IPA in ARM lingo) to a real physical address
* before passing the structure to secure world.
*/
struct teesmc32_param_memref {
uint32_t buf_ptr;
uint32_t size;
};
/**
* struct teesmc32_param_memref - memory reference
* @buf_ptr: Address of the buffer
* @size: Size of the buffer
*
* See description of struct teesmc32_param_memref.
*/
struct teesmc64_param_memref {
uint64_t buf_ptr;
uint64_t size;
};
/**
* struct teesmc32_param_value - values
* @a: first value
* @b: second value
*/
struct teesmc32_param_value {
uint32_t a;
uint32_t b;
};
/**
* struct teesmc64_param_value - values
* @a: first value
* @b: second value
*/
struct teesmc64_param_value {
uint64_t a;
uint64_t b;
};
/**
* struct teesmc32_param - parameter
* @attr: attributes
* @memref: a memory reference
* @value: a value
*
* attr & TEESMC_ATTR_TYPE_MASK indicates if memref or value is used in the
* union. TEESMC_ATTR_TYPE_VALUE_* indicates value and
* TEESMC_ATTR_TYPE_MEMREF_* indicates memref. TEESMC_ATTR_TYPE_NONE
* indicates that none of the members are used.
*/
struct teesmc32_param {
uint32_t attr;
union {
struct teesmc32_param_memref memref;
struct teesmc32_param_value value;
} u;
};
/**
* struct teesmc64_param - parameter
* @attr: attributes
* @memref: a memory reference
* @value: a value
*
* See description of union teesmc32_param.
*/
struct teesmc64_param {
uint64_t attr;
union {
struct teesmc64_param_memref memref;
struct teesmc64_param_value value;
} u;
};
/**
* struct teesmc32_arg - SMC argument for Trusted OS
* @cmd: Command, one of TEESMC_CMD_*
* @ta_func: Trusted Application function, specific to the Trusted Application,
* used if cmd == TEESMC_CMD_INVOKE_COMMAND
* @session: In parameter for all TEESMC_CMD_* except
* TEESMC_CMD_OPEN_SESSION where it's an output parameter instead
* @ret: return value
* @ret_origin: origin of the return value
* @num_params: number of parameters supplied to the OS Command
* @params: the parameters supplied to the OS Command
*
* All normal SMC calls to Trusted OS uses this struct. If cmd requires
* further information than what these field holds it can be passed as a
* parameter tagged as meta (setting the TEESMC_ATTR_META bit in
* corresponding param_attrs). This is used for TEESMC_CMD_OPEN_SESSION
* to pass a struct teesmc32_meta_open_session which is needed find the
* Trusted Application and to indicate the credentials of the client.
*/
struct teesmc32_arg {
uint32_t cmd;
uint32_t ta_func;
uint32_t session;
uint32_t ret;
uint32_t ret_origin;
uint32_t num_params;
/*
* Commented out elements used to visualize the layout dynamic part
* of the struct. Note that these fields are not available at all
* if num_params == 0.
*
* params is accessed through the macro TEESMC32_GET_PARAMS
*/
/* struct teesmc32_param params[num_params]; */
};
/**
* TEESMC32_GET_PARAMS - return pointer to union teesmc32_param *
*
* @x: Pointer to a struct teesmc32_arg
*
* Returns a pointer to the params[] inside a struct teesmc32_arg.
*/
#define TEESMC32_GET_PARAMS(x) \
(struct teesmc32_param *)(((struct teesmc32_arg *)(x)) + 1)
/**
* TEESMC32_GET_ARG_SIZE - return size of struct teesmc32_arg
*
* @num_params: Number of parameters embedded in the struct teesmc32_arg
*
* Returns the size of the struct teesmc32_arg together with the number
* of embedded parameters.
*/
#define TEESMC32_GET_ARG_SIZE(num_params) \
(sizeof(struct teesmc32_arg) + \
sizeof(struct teesmc32_param) * (num_params))
/**
* struct teesmc64_arg - SMC argument for Trusted OS
* @cmd: OS Command, one of TEESMC_CMD_*
* @ta_func: Trusted Application function, specific to the Trusted Application
* @session: In parameter for all TEESMC_CMD_* but
* TEESMC_CMD_OPEN_SESSION
* @ret: return value
* @ret_origin: origin of the return value
* @num_params: number of parameters supplied to the OS Command
* @params: the parameters supplied to the OS Command
*
* See description of struct teesmc32_arg.
*/
struct teesmc64_arg {
uint64_t cmd;
uint64_t ta_func;
uint64_t session;
uint64_t ret;
uint64_t ret_origin;
uint64_t num_params;
/*
* Commented out elements used to visualize the layout dynamic part
* of the struct. Note that these fields are not available at all
* if num_params == 0.
*
* params is accessed through the macro TEESMC64_GET_PARAMS
*/
/* struct teesmc64_param params[num_params]; */
};
/**
* TEESMC64_GET_PARAMS - return pointer to union teesmc64_param *
*
* @x: Pointer to a struct teesmc64_arg
*
* Returns a pointer to the params[] inside a struct teesmc64_arg.
*/
#define TEESMC64_GET_PARAMS(x) \
(struct teesmc64_param *)(((struct teesmc64_arg *)(x)) + 1)
/**
* TEESMC64_GET_ARG_SIZE - return size of struct teesmc64_arg
*
* @num_params: Number of parameters embedded in the struct teesmc64_arg
*
* Returns the size of the struct teesmc64_arg together with the number
* of embedded parameters.
*/
#define TEESMC64_GET_ARG_SIZE(num_params) \
(sizeof(struct teesmc64_arg) + \
sizeof(union teesmc64_param) * (num_params))
#define TEESMC_UUID_LEN 16
/**
* struct teesmc_meta_open_session - additional parameters for
* TEESMC32_CMD_OPEN_SESSION and
* TEESMC64_CMD_OPEN_SESSION
* @uuid: UUID of the Trusted Application
* @clnt_uuid: UUID of client
* @clnt_login: Login class of client, TEE_LOGIN_* if being Global Platform
* compliant
*
* This struct is passed in the first parameter as an input memref tagged
* as meta on an TEESMC{32,64}_CMD_OPEN_SESSION cmd. It's important
* that it really is the first parameter to make it easy for an eventual
* hypervisor to inspect and possibly update clnt_* values.
*/
struct teesmc_meta_open_session {
uint8_t uuid[TEESMC_UUID_LEN];
uint8_t clnt_uuid[TEESMC_UUID_LEN];
uint32_t clnt_login;
};
#endif /*!ASM*/
/*
*******************************************************************************
* Part 2 - low level SMC interaction
*******************************************************************************
*/
#define TEESMC_32 0
#define TEESMC_64 0x40000000
#define TEESMC_FAST_CALL 0x80000000
#define TEESMC_STD_CALL 0
#define TEESMC_OWNER_MASK 0x3F
#define TEESMC_OWNER_SHIFT 24
#define TEESMC_FUNC_MASK 0xFFFF
#define TEESMC_IS_FAST_CALL(smc_val) ((smc_val) & TEESMC_FAST_CALL)
#define TEESMC_IS_64(smc_val) ((smc_val) & TEESMC_64)
#define TEESMC_FUNC_NUM(smc_val) ((smc_val) & TEESMC_FUNC_MASK)
#define TEESMC_OWNER_NUM(smc_val) (((smc_val) >> TEESMC_OWNER_SHIFT) & \
TEESMC_OWNER_MASK)
#define TEESMC_CALL_VAL(type, calling_convention, owner, func_num) \
((type) | (calling_convention) | \
(((owner) & TEESMC_OWNER_MASK) << TEESMC_OWNER_SHIFT) |\
((func_num) & TEESMC_FUNC_MASK))
#define TEESMC_OWNER_ARCH 0
#define TEESMC_OWNER_CPU 1
#define TEESMC_OWNER_SIP 2
#define TEESMC_OWNER_OEM 3
#define TEESMC_OWNER_STANDARD 4
#define TEESMC_OWNER_TRUSTED_APP 48
#define TEESMC_OWNER_TRUSTED_OS 50
#define TEESMC_OWNER_TRUSTED_OS_API 63
/*
* Function specified by SMC Calling convention.
*/
#define TEESMC32_FUNCID_CALLS_COUNT 0xFF00
#define TEESMC32_CALLS_COUNT \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
TEESMC_OWNER_TRUSTED_OS_API, \
TEESMC32_FUNCID_CALLS_COUNT)
/*
* Function specified by SMC Calling convention
*
* Return one of the following UIDs if using API specified in this file
* without further extentions:
* 65cb6b93-af0c-4617-8ed6-644a8d1140f8 : Only 32 bit calls are supported
* 65cb6b93-af0c-4617-8ed6-644a8d1140f9 : Both 32 and 64 bit calls are supported
*/
#define TEESMC_UID_R0 0x65cb6b93
#define TEESMC_UID_R1 0xaf0c4617
#define TEESMC_UID_R2 0x8ed6644a
#define TEESMC_UID32_R3 0x8d1140f8
#define TEESMC_UID64_R3 0x8d1140f9
#define TEESMC32_FUNCID_CALLS_UID 0xFF01
#define TEESMC32_CALLS_UID \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
TEESMC_OWNER_TRUSTED_OS_API, \
TEESMC32_FUNCID_CALLS_UID)
/*
* Function specified by SMC Calling convention
*
* Returns 1.0 if using API specified in this file without further extentions.
*/
#define TEESMC_REVISION_MAJOR 1
#define TEESMC_REVISION_MINOR 0
#define TEESMC32_FUNCID_CALLS_REVISION 0xFF03
#define TEESMC32_CALLS_REVISION \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, \
TEESMC_OWNER_TRUSTED_OS_API, \
TEESMC32_FUNCID_CALLS_REVISION)
/*
* Get UUID of Trusted OS.
*
* Used by non-secure world to figure out which Trusted OS is installed.
* Note that returned UUID is the UUID of the Trusted OS, not of the API.
*
* Returns UUID in r0-4/w0-4 in the same way as TEESMC32_CALLS_UID
* described above.
*/
#define TEESMC_FUNCID_GET_OS_UUID 0
#define TEESMC32_CALL_GET_OS_UUID \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_GET_OS_UUID)
/*
* Get revision of Trusted OS.
*
* Used by non-secure world to figure out which version of the Trusted OS
* is installed. Note that the returned revision is the revision of the
* Trusted OS, not of the API.
*
* Returns revision in r0-1/w0-1 in the same way as TEESMC32_CALLS_REVISION
* described above.
*/
#define TEESMC_FUNCID_GET_OS_REVISION 1
#define TEESMC32_CALL_GET_OS_REVISION \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_GET_OS_REVISION)
/*
* Call with struct teesmc32_arg as argument
*
* Call register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_WITH_ARG
* r1/x1 Physical pointer to a struct teesmc32_arg
* r2-6/x2-6 Not used
* r7/x7 Hypervisor Client ID register
*
* Normal return register usage:
* r0/x0 Return value, TEESMC_RETURN_*
* r1-3/x1-3 Not used
* r4-7/x4-7 Preserved
*
* Ebusy return register usage:
* r0/x0 Return value, TEESMC_RETURN_ETHREAD_LIMIT
* r1-3/x1-3 Preserved
* r4-7/x4-7 Preserved
*
* RPC return register usage:
* r0/x0 Return value, TEESMC_RETURN_IS_RPC(val)
* r1-2/x1-2 RPC parameters
* r3-7/x3-7 Resume information, must be preserved
*
* Possible return values:
* TEESMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
* function.
* TEESMC_RETURN_OK Call completed, result updated in
* the previously supplied struct
* teesmc32_arg.
* TEESMC_RETURN_ETHREAD_LIMIT Trusted OS out of threads,
* try again later.
* TEESMC_RETURN_EBADADDR Bad physcial pointer to struct
* teesmc32_arg.
* TEESMC_RETURN_EBADCMD Bad/unknown cmd in struct teesmc32_arg
* TEESMC_RETURN_IS_RPC() Call suspended by RPC call to normal
* world.
*/
#define TEESMC_FUNCID_CALL_WITH_ARG 2
#define TEESMC32_CALL_WITH_ARG \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_CALL_WITH_ARG)
/* Same as TEESMC32_CALL_WITH_ARG but a "fast call". */
#define TEESMC32_FASTCALL_WITH_ARG \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_CALL_WITH_ARG)
/*
* Call with struct teesmc64_arg as argument
*
* See description of TEESMC32_CALL_WITH_ARG above, uses struct
* teesmc64_arg in x1 instead.
*/
#define TEESMC64_CALL_WITH_ARG \
TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_CALL_WITH_ARG)
/* Same as TEESMC64_CALL_WITH_ARG but a "fast call". */
#define TEESMC64_FASTCALL_WITH_ARG \
TEESMC_CALL_VAL(TEESMC_64, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_CALL_WITH_ARG)
/*
* Resume from RPC (for example after processing an IRQ)
*
* Call register usage:
* r0/x0 SMC Function ID,
* TEESMC32_CALL_RETURN_FROM_RPC or
* TEESMC32_FASTCALL_RETURN_FROM_RPC
* r1-3/x1-3 Value of r1-3/x1-3 when TEESMC32_CALL_WITH_ARG returned
* TEESMC_RETURN_RPC in r0/x0
*
* Return register usage is the same as for TEESMC32_CALL_WITH_ARG above.
*
* Possible return values
* TEESMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
* function.
* TEESMC_RETURN_OK Original call completed, result
* updated in the previously supplied.
* struct teesmc32_arg
* TEESMC_RETURN_RPC Call suspended by RPC call to normal
* world.
* TEESMC_RETURN_ETHREAD_LIMIT Trusted OS out of threads,
* try again later.
* TEESMC_RETURN_ERESUME Resume failed, the opaque resume
* information was corrupt.
*/
#define TEESMC_FUNCID_RETURN_FROM_RPC 3
#define TEESMC32_CALL_RETURN_FROM_RPC \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_RETURN_FROM_RPC)
/* Same as TEESMC32_CALL_RETURN_FROM_RPC but a "fast call". */
#define TEESMC32_FASTCALL_RETURN_FROM_RPC \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_RETURN_FROM_RPC)
/*
* Resume from RPC (for example after processing an IRQ)
*
* See description of TEESMC32_CALL_RETURN_FROM_RPC above, used when
* it's a 64bit call that has returned.
*/
#define TEESMC64_CALL_RETURN_FROM_RPC \
TEESMC_CALL_VAL(TEESMC_64, TEESMC_STD_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_RETURN_FROM_RPC)
/* Same as TEESMC64_CALL_RETURN_FROM_RPC but a "fast call". */
#define TEESMC64_FASTCALL_RETURN_FROM_RPC \
TEESMC_CALL_VAL(TEESMC_64, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_RETURN_FROM_RPC)
/*
* From secure monitor to Trusted OS, handle FIQ
*
* A virtual call which is injected by the Secure Monitor when an FIQ is
* raised while in normal world (SCR_NS is set). The monitor restores
* secure architecture registers and secure EL_SP1 and jumps to previous
* secure EL3_ELR. Trusted OS should preserve all general purpose
* registers.
*
* Call register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_HANDLE_FIQ
* r1-7/x1-7 Not used, but must be preserved
*
* Return register usage:
* Note used
*/
#define TEESMC_FUNCID_CALL_HANDLE_FIQ 0xf000
#define TEESMC32_CALL_HANDLE_FIQ \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_FUNCID_CALL_HANDLE_FIQ)
#define TEESMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000
#define TEESMC_RETURN_RPC_PREFIX 0xFFFF0000
#define TEESMC_RETURN_RPC_FUNC_MASK 0x0000FFFF
#define TEESMC_RETURN_GET_RPC_FUNC(ret) ((ret) & TEESMC_RETURN_RPC_FUNC_MASK)
#define TEESMC_RPC_VAL(func) ((func) | TEESMC_RETURN_RPC_PREFIX)
/*
* Allocate argument memory for RPC parameter passing.
* Argument memory is used to hold a struct teesmc32_arg.
*
* "Call" register usage:
* r0/x0 This value, TEESMC_RETURN_RPC_ALLOC
* r1/x1 Size in bytes of required argument memory
* r2-7/x2-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1/x1 Physical pointer to allocated argument memory, 0 if size
* was 0 or if memory can't be allocated
* r2-7/x2-7 Preserved
*/
#define TEESMC_RPC_FUNC_ALLOC_ARG 0
#define TEESMC_RETURN_RPC_ALLOC_ARG \
TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_ARG)
/*
* Allocate payload memory for RPC parameter passing.
* Payload memory is used to hold the memory referred to by struct
* teesmc32_param_memref.
*
* "Call" register usage:
* r0/x0 This value, TEESMC_RETURN_RPC_ALLOC
* r1/x1 Size in bytes of required payload memory
* r2-7/x2-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1/x1 Physical pointer to allocated payload memory, 0 if size
* was 0 or if memory can't be allocated
* r2-7/x2-7 Preserved
*/
#define TEESMC_RPC_FUNC_ALLOC_PAYLOAD 1
#define TEESMC_RETURN_RPC_ALLOC_PAYLOAD \
TEESMC_RPC_VAL(TEESMC_RPC_FUNC_ALLOC_PAYLOAD)
/*
* Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_ARG.
*
* "Call" register usage:
* r0/x0 This value, TEESMC_RETURN_RPC_FREE
* r1/x1 Physical pointer to previously allocated argument memory
* r2-7/x2-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1/x1 Not used
* r2-7/x2-7 Preserved
*/
#define TEESMC_RPC_FUNC_FREE_ARG 2
#define TEESMC_RETURN_RPC_FREE_ARG TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_ARG)
/*
* Free memory previously allocated by TEESMC_RETURN_RPC_ALLOC_PAYLOAD.
*
* "Call" register usage:
* r0/x0 This value, TEESMC_RETURN_RPC_FREE
* r1/x1 Physical pointer to previously allocated payload memory
* r3-7/x3-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1-2/x1-2 Not used
* r3-7/x3-7 Preserved
*/
#define TEESMC_RPC_FUNC_FREE_PAYLOAD 3
#define TEESMC_RETURN_RPC_FREE_PAYLOAD \
TEESMC_RPC_VAL(TEESMC_RPC_FUNC_FREE_PAYLOAD)
/*
* Deliver an IRQ in normal world.
*
* "Call" register usage:
* r0/x0 TEESMC_RETURN_RPC_IRQ
* r1-7/x1-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1-7/x1-7 Preserved
*/
#define TEESMC_RPC_FUNC_IRQ 4
#define TEESMC_RETURN_RPC_IRQ TEESMC_RPC_VAL(TEESMC_RPC_FUNC_IRQ)
/*
* Do an RPC request. The supplied struct teesmc{32,64}_arg tells which
* request to do and the parameters for the request. The following fields
* are used (the rest are unused):
* - cmd the Request ID
* - ret return value of the request, filled in by normal world
* - num_params number of parameters for the request
* - params the parameters
* - param_attrs attributes of the parameters
*
* "Call" register usage:
* r0/x0 TEESMC_RETURN_RPC_CMD
* r1/x1 Physical pointer to a struct teesmc32_arg if returning from
* a AArch32 SMC or a struct teesmc64_arg if returning from a
* AArch64 SMC, must be preserved, only the data should
* be updated
* r2-7/x2-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1-7/x1-7 Preserved
*/
#define TEESMC_RPC_FUNC_CMD 5
#define TEESMC_RETURN_RPC_CMD TEESMC_RPC_VAL(TEESMC_RPC_FUNC_CMD)
#define T6SMC_RPC_NONPREEMPT_CMD 6
#define T6SMC_RPC_NONPREEMPT_GET_FUNC(ret) \
((TEESMC_RETURN_GET_RPC_FUNC(ret) >> 8) & 0xff)
#define T6SMC_RETURN_RPC_NONPREEMPT_CMD(cmd) \
TEESMC_RPC_VAL(T6SMC_RPC_NONPREEMPT_CMD | (((cmd) & 0xff) << 8))
#define T6SMC_RPC_CLKMGR_CMD 0
#define T6SMC_RETURN_RPC_CLKMGR_CMD \
T6SMC_RETURN_RPC_NONPREEMPT_CMD(T6SMC_RPC_CLKMGR_CMD)
/* not used. for compatible with old tos version */
#define T6SMC_RPC_CLKMGR_LEGACY_CMD 7
#define T6SMC_RETURN_RPC_CLKMGR_LEGACY_CMD \
TEESMC_RPC_VAL(T6SMC_RPC_CLKMGR_LEGACY_CMD)
/* Returned in r0 */
#define TEESMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
/* Returned in r0 only from Trusted OS functions */
#define TEESMC_RETURN_OK 0x0
#define TEESMC_RETURN_ETHREAD_LIMIT 0x1
#define TEESMC_RETURN_ERESUME 0x2
#define TEESMC_RETURN_EBADADDR 0x3
#define TEESMC_RETURN_EBADCMD 0x4
#define TEESMC_RETURN_IS_RPC(ret) \
(((ret) & TEESMC_RETURN_RPC_PREFIX_MASK) == TEESMC_RETURN_RPC_PREFIX)
/*
* Returned in r1 by Trusted OS functions if r0 = TEESMC_RETURN_RPC
*/
#define TEESMC_RPC_REQUEST_IRQ 0x0
#endif /* TEESMC_H */
@@ -0,0 +1,149 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEESMC_ST_H
#define TEESMC_ST_H
#define TEESMC_ST_RETURN_NOTAVAIL 0x5700
/*
* Get Shared Memory Config
*
* Returns the Secure/Non-secure shared memory config.
*
* Call register usage:
* r0 SMC Function ID, TEESMC32_ST_FASTCALL_GET_SHM_CONFIG
* r1-6 Not used
* r7 Hypervisor Client ID register
*
* Have config return register usage:
* r0 TEESMC_RETURN_OK
* r1 Physical address of start of SHM
* r2 Size of of SHM
* r3 1 if SHM is cached, 0 if uncached.
* r4-7 Preserved
*
* Not available register usage:
* r0 TEESMC_ST_RETURN_NOTAVAIL
* r1-3 Not used
* r4-7 Preserved
*/
#define TEESMC_ST_FUNCID_GET_SHM_CONFIG 0x5700
#define TEESMC32_ST_FASTCALL_GET_SHM_CONFIG \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_ST_FUNCID_GET_SHM_CONFIG)
/*
* Get Log Memory Config
*
* Returns the Secure/Non-secure shared memory config.
*
* Call register usage:
* r0 SMC Function ID, TEESMC32_ST_FASTCALL_GET_LOGM_CONFIG
* r1-6 Not used
* r7 Hypervisor Client ID register
*
* Have config return register usage:
* r0 TEESMC_RETURN_OK
* r1 Physical address of start of LOGM
* r2 Size of of SHM
* r3 1 if SHM is cached, 0 if uncached.
* r4-7 Preserved
*
* Not available register usage:
* r0 TEESMC_ST_RETURN_NOTAVAIL
* r1-3 Not used
* r4-7 Preserved
*/
#define TEESMC_ST_FUNCID_GET_LOGM_CONFIG 0x5702
#define TEESMC32_ST_FASTCALL_GET_LOGM_CONFIG \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_ST_FUNCID_GET_LOGM_CONFIG)
#define TKCORE_FUNCID_TRACE_CONFIG 0x5703
#define TKCORE_FASTCALL_TRACE_CONFIG \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TKCORE_FUNCID_TRACE_CONFIG)
/*
* Configures TZ/NS shared mutex for outer cache maintenance
*
* Disables, enables usage of outercache mutex.
* Returns or sets physical address of outercache mutex.
*
* Call register usage:
* r0 SMC Function ID, TEESMC32_ST_FASTCALL_L2CC_MUTEX
* r1 TEESMC_ST_L2CC_MUTEX_GET_ADDR Get physical address of mutex
* TEESMC_ST_L2CC_MUTEX_SET_ADDR Set physical address of mutex
* TEESMC_ST_L2CC_MUTEX_ENABLE Enable usage of mutex
* TEESMC_ST_L2CC_MUTEX_DISABLE Disable usage of mutex
* r2 if r1 == TEESMC_ST_L2CC_MUTEX_SET_ADDR, physical address of mutex
* r3-6 Not used
* r7 Hypervisor Client ID register
*
* Have config return register usage:
* r0 TEESMC_RETURN_OK
* r1 Preserved
* r2 if r1 == 0, physical address of L2CC mutex
* r3-7 Preserved
*
* Error return register usage:
* r0 TEESMC_ST_RETURN_NOTAVAIL Physical address not available
* TEESMC_RETURN_EBADADDR Bad supplied physical address
* TEESMC_RETURN_EBADCMD Unsupported value in r1
* r1-7 Preserved
*/
#define TEESMC_ST_L2CC_MUTEX_GET_ADDR 0
#define TEESMC_ST_L2CC_MUTEX_SET_ADDR 1
#define TEESMC_ST_L2CC_MUTEX_ENABLE 2
#define TEESMC_ST_L2CC_MUTEX_DISABLE 3
#define TEESMC_ST_FUNCID_L2CC_MUTEX 0x5701
#define TEESMC32_ST_FASTCALL_L2CC_MUTEX \
TEESMC_CALL_VAL(TEESMC_32, TEESMC_FAST_CALL, TEESMC_OWNER_TRUSTED_OS, \
TEESMC_ST_FUNCID_L2CC_MUTEX)
/*
* Allocate payload memory for RPC parameter passing.
*
* "Call" register usage:
* r0/x0 This value, TEESMC_RETURN_ST_RPC_ALLOC_PAYLOAD
* r1/x1 Size in bytes of required payload memory
* r2/x2 Not used
* r3-7/x3-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r1/x1 Physical pointer to allocated payload memory, 0 if size
* was 0 or if memory can't be allocated
* r2/x2 Shared memory cookie used when freeing the memory
* r3-7/x3-7 Preserved
*/
#define TEESMC_ST_RPC_FUNC_ALLOC_PAYLOAD 0x5700
#define TEESMC_RETURN_ST_RPC_ALLOC_PAYLOAD \
TEESMC_RPC_VAL(TEESMC_ST_RPC_FUNC_ALLOC_PAYLOAD)
/*
* Free memory previously allocated by TEESMC_RETURN_ST_RPC_ALLOC_PAYLOAD
*
* "Call" register usage:
* r0/x0 This value, TEESMC_RETURN_ST_RPC_FREE_PAYLOAD
* r1/x1 Shared memory cookie belonging to this payload memory
* r2-7/x2-7 Resume information, must be preserved
*
* "Return" register usage:
* r0/x0 SMC Function ID, TEESMC32_CALL_RETURN_FROM_RPC if it was an
* AArch32 SMC return or TEESMC64_CALL_RETURN_FROM_RPC for
* AArch64 SMC return
* r2-7/x2-7 Preserved
*/
#define TEESMC_ST_RPC_FUNC_FREE_PAYLOAD 0x5701
#define TEESMC_RETURN_ST_RPC_FREE_PAYLOAD \
TEESMC_RPC_VAL(TEESMC_ST_RPC_FUNC_FREE_PAYLOAD)
#endif /*TEESMC_ST_H*/
@@ -0,0 +1,161 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEE_CLIENT_API_H
#define TEE_CLIENT_API_H
#define TEEC_CONFIG_PAYLOAD_REF_COUNT 4
#define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0x8000
#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
#define TEEC_MEMREF_PERMANENT 0x00000008
#define TEEC_MEM_INPUT 0x00000001
#define TEEC_MEM_OUTPUT 0x00000002
#define TEEC_MEM_DMABUF 0x00010000
#define TEEC_MEM_KAPI 0x00020000
#define TEEC_MEM_NONSECURE 0x00040000
#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_TARGET_DEAD 0xFFFF3024
#define TEEC_ORIGIN_API 0x00000001
#define TEEC_ORIGIN_COMMS 0x00000002
#define TEEC_ORIGIN_TEE 0x00000003
#define TEEC_ORIGIN_TRUSTED_APP 0x00000004
#define TEEC_LOGIN_PUBLIC 0x00000000
#define TEEC_LOGIN_USER 0x00000001
#define TEEC_LOGIN_GROUP 0x00000002
#define TEEC_LOGIN_APPLICATION 0x00000004
#define TEEC_PARAM_TYPES(p0, p1, p2, p3) \
((p0) | ((p1) << 4) | ((p2) << 8) | ((p3) << 12))
#define TEEC_PARAM_TYPE_GET(p, i)\
(((p) >> (i * 4)) & 0xF)
typedef uint32_t TEEC_Result;
struct TEEC_Context {
char devname[256];
union {
struct tee_context *ctx;
int fd;
};
};
struct TEEC_UUID {
uint32_t timeLow;
uint16_t timeMid;
uint16_t timeHiAndVersion;
uint8_t clockSeqAndNode[8];
};
struct TEEC_SharedMemory {
union {
void *buffer;
uint64_t padding_ptr;
};
union {
size_t size;
uint64_t padding_sz;
};
uint32_t flags;
uint32_t reserved;
union {
int fd;
void *ptr;
uint64_t padding_d;
} d;
uint64_t registered;
};
struct TEEC_TempMemoryReference {
union {
void *buffer;
uint64_t padding_ptr;
};
union {
size_t size;
uint64_t padding_sz;
};
};
struct TEEC_RegisteredMemoryReference {
union {
struct TEEC_SharedMemory *parent;
uint64_t padding_ptr;
};
union {
size_t size;
uint64_t padding_sz;
};
union {
size_t offset;
uint64_t padding_off;
};
};
struct TEEC_Value {
uint32_t a;
uint32_t b;
};
union TEEC_Parameter {
struct TEEC_TempMemoryReference tmpref;
struct TEEC_RegisteredMemoryReference memref;
struct TEEC_Value value;
};
struct TEEC_Session {
int fd;
};
struct TEEC_Operation {
uint32_t started;
uint32_t paramTypes;
union TEEC_Parameter params[TEEC_CONFIG_PAYLOAD_REF_COUNT];
/* Implementation-Defined */
union {
struct TEEC_Session *session;
uint64_t padding_ptr;
};
struct TEEC_SharedMemory memRefs[TEEC_CONFIG_PAYLOAD_REF_COUNT];
uint64_t flags;
};
#endif
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEE_CLKMGR_H
#define TEE_CLKMGR_H
/* TKCORE clk manager framework assumes that
* the clock enable/disable operations are
* symmetric, that is, a clock enabling operation
* requires the same amount of arguments as
* the clock disabling operation.
*
* TKCORE Clk mgr supports at the most 3 arguments
* for a clk operation
*/
int tee_clkmgr_register(const char *clkname, int master_id,
void *enable_fn, void *disable_fn,
void *p1, void *p2, void *p3, size_t argnum);
#define tee_clkmgr_register0(clkname, id, e, d) \
tee_clkmgr_register((clkname), (id), \
(void *) (e), (void *) (d), \
NULL, NULL, NULL, 0)
#define tee_clkmgr_register1(clkname, id, e, d, p0) \
tee_clkmgr_register((clkname), (id), \
(void *) (e), (void *) (d), \
(void *) (p0), NULL, NULL, 1)
#define tee_clkmgr_register2(clkname, id, e, d, p0, p1)\
tee_clkmgr_register((clkname), (id), \
(void *) (e), (void *) (d), \
(void *) (p0), (void *) (p1), NULL, 2)
#define tee_clkmgr_register3(clkname, id, e, d, p0, p1, p2)\
tee_clkmgr_register((clkname), (id), \
(void *) (e), (void *) (d), \
(void *) (p0), (void *) (p1), (void *) (p2), 3)
#define TEE_CLKMGR_TOKEN_NOT_LEGACY (0x1)
#define TEE_CLKMGR_TOKEN_ID_SHIFT (1)
#define TEE_CLKMGR_TOKEN_TYPE_MASK (0xffffu)
#define TEE_CLKMGR_TOKEN_TYPE_SHIFT (16)
#define TEE_CLKMGR_TOKEN(type, id) \
(((type) << TEE_CLKMGR_TOKEN_TYPE_SHIFT) | \
((id) << TEE_CLKMGR_TOKEN_ID_SHIFT) | \
TEE_CLKMGR_TOKEN_NOT_LEGACY)
#define TEE_CLKMGR_OP_ENABLE (0x1)
int tee_clkmgr_handle(uint32_t token, uint32_t op);
#endif
+231
View File
@@ -0,0 +1,231 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef __TEE_CORE_DRV_H__
#define __TEE_CORE_DRV_H__
#include <linux/klist.h>
#include <linux/device.h>
#include <linux/file.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>
#include <linux/types.h>
#include <linux/atomic.h>
#include <linux/scatterlist.h>
#include <linux/types.h>
#include <linux/tee_client_api.h>
#include <linux/err.h>
#include <linux/sched.h>
struct tee_cmd_io;
struct tee_shm_io;
struct tee_rpc;
enum tee_state {
TEE_OFFLINE = 0,
TEE_ONLINE = 1,
TEE_SUSPENDED = 2,
TEE_RUNNING = 3,
TEE_CRASHED = 4,
TEE_LAST = 5,
};
#define TEE_CONF_TEST_MODE 0x01000000
#define TEE_CONF_FW_NOT_CAPABLE 0x00000001
struct tee_stats_entry {
int count;
int max;
};
#define TEE_STATS_CONTEXT_IDX 0
#define TEE_STATS_SESSION_IDX 1
#define TEE_STATS_SHM_IDX 2
#define TEE_MAX_TEE_DEV_NAME (64)
struct tee {
struct klist_node node;
char name[TEE_MAX_TEE_DEV_NAME];
int id;
void *priv;
const struct tee_ops *ops;
struct device *dev;
struct miscdevice miscdev;
struct tee_rpc *rpc;
atomic_t refcount;
int max_refcount;
struct tee_stats_entry stats[3];
struct list_head list_ctx;
struct list_head list_rpc_shm;
struct mutex lock;
unsigned int state;
uint32_t shm_flags; /* supported flags for shm allocation */
uint32_t conf;
uint32_t test;
};
#define _DEV(tee) (tee->miscdev.this_device)
#define TEE_MAX_CLIENT_NAME (128)
/**
* struct tee_context - internal structure to store a TEE context.
*
* @tee: tee attached to the tee_context
* @usr_client: flag to known if the client is user side client
* @entry: list of tee_context
* @list_sess: list of tee_session that denotes all tee_session attached
* @list_shm: list of tee_shm that denotes all tee_shm attached
* @refcount: number of objects which reference it (including itself)
*/
struct tee_context {
struct tee *tee;
char name[TEE_MAX_CLIENT_NAME];
int tgid;
int usr_client;
struct list_head entry;
struct list_head list_sess;
struct list_head list_shm;
struct kref refcount;
};
/**
* struct tee_session - internal structure to store a TEE session.
*
* @entry: list of tee_context
* @ctx: tee_context attached to the tee_session
* @sessid: session ID returned by the secure world
* @priv: exporter specific private data for this buffer object
*/
struct tee_session {
struct list_head entry;
struct tee_context *ctx;
uint32_t sessid;
void *priv;
};
struct tee_shm_dma_buf {
struct dma_buf_attachment *attach;
struct sg_table *sgt;
bool tee_allocated;
};
struct tee_shm_resv {
void *kaddr;
dma_addr_t paddr;
struct sg_table sgt;
struct tee_shm_dma_buf *sdb;
};
struct tee_shm_ns {
uint32_t token;
struct page **pages;
size_t nr_pages;
atomic_t ref;
};
/**
* struct tee_shm - internal structure to store a shm object.
*
* @ctx: tee_context attached to the buffer.
* @tee: tee attached to the buffer.
* @dev: device attached to the buffer.
* @size_req: requested size for the buffer
* @size_alloc: effective size of the buffer
* @kaddr: kernel address if mapped kernel side
* @paddr: physical address
* @flags: flags which denote the type of the buffer
* @entry: list of tee_shm
*/
struct tee_shm {
struct list_head entry;
struct tee_context *ctx;
struct tee *tee;
struct device *dev;
size_t size_req;
size_t size_alloc;
uint32_t flags;
union {
struct tee_shm_resv resv;
struct tee_shm_ns ns;
};
};
#define TEE_SHM_MAPPED 0x01000000
#define TEE_SHM_TEMP 0x02000000
#define TEE_SHM_FROM_RPC 0x04000000
#define TEE_SHM_REGISTERED 0x08000000
#define TEE_SHM_MEMREF 0x10000000
#define TEE_SHM_CACHED 0x20000000
#define TEE_SHM_DRV_PRIV_MASK 0xFF000000
struct tee_data {
uint32_t type;
uint32_t type_original;
struct TEEC_SharedMemory c_shm[TEEC_CONFIG_PAYLOAD_REF_COUNT];
union {
struct tee_shm *shm;
struct TEEC_Value value;
} params[TEEC_CONFIG_PAYLOAD_REF_COUNT];
};
struct tee_cmd {
TEEC_Result err;
uint32_t origin;
uint32_t cmd;
struct tee_shm *uuid;
struct tee_shm *ta;
struct tee_data param;
};
void *tee_map_cached_shm(unsigned long pa, size_t len);
void tee_unmap_cached_shm(void *va);
struct tee_shm *tee_shm_alloc_from_rpc(struct tee *tee,
size_t size, uint32_t extra_flags);
void tee_shm_realloc_from_rpc(struct tee *tee,
struct tee_shm *shm);
void tee_shm_free_from_rpc(struct tee_shm *shm);
int tee_core_add(struct tee *tee);
int tee_core_del(struct tee *tee);
int __tee_get(struct tee *tee);
struct tee *tee_core_alloc(struct device *dev, char *name, int id,
const struct tee_ops *ops, size_t len);
int tee_core_free(struct tee *tee);
#include <linux/tee_kernel_lowlevel_api.h>
struct tee_ops {
struct module *owner;
const char *type;
int (*start)(struct tee *tee);
int (*stop)(struct tee *tee);
int (*open)(struct tee_session *sess, struct tee_cmd *cmd);
int (*close)(struct tee_session *sess);
int (*invoke)(struct tee_session *sess, struct tee_cmd *cmd);
int (*cancel)(struct tee_session *sess, struct tee_cmd *cmd);
struct tee_shm *(*alloc)(struct tee *tee, size_t size,
uint32_t flags);
void (*free)(struct tee_shm *shm);
int (*shm_inc_ref)(struct tee_shm *shm);
void (*call_tee)(struct smc_param *p);
void (*raw_call_tee)(struct smc_param *p);
};
#endif /* __TEE_CORE_DRV_H__ */
+16
View File
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEE_FP_H
#define TEE_FP_H
int tee_spi_cfg_padsel(uint32_t padsel);
int tee_spi_transfer(void *conf, uint32_t conf_size, void *inbuf, void *outbuf,
uint32_t size);
int tee_spi_transfer_disable(void);
#endif
+141
View File
@@ -0,0 +1,141 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef _TEE_IOC_H
#define _TEE_IOC_H
#include <linux/tee_client_api.h>
#ifndef __KERNEL__
#define __user
#endif
/**
* struct tee_cmd_io - The command sent to an open tee device.
* @err: Error code (as in Global Platform TEE Client API spec)
* @origin: Origin for the error code (also from spec).
* @cmd: The command to be executed in the trusted application.
* @uuid: The uuid for the trusted application.
* @data: The trusted application or memory block.
* @data_size: The size of the trusted application or memory block.
* @op: The cmd payload operation for the trusted application.
*
* This structure is mainly used in the Linux kernel for communication
* with the user space.
*/
struct tee_cmd_io {
TEEC_Result err;
uint32_t origin;
uint32_t cmd;
int fd_sess;
/*
* Here fd_sess is 32-bit variable. Since TEEC_Result also is defined as
* "uint32_t", this structure is aligned.
*/
union {
struct TEEC_UUID __user *uuid;
uint64_t padding_uuid;
};
union {
void __user *data;
uint64_t padding_data;
};
union {
struct TEEC_Operation __user *op;
uint64_t padding_op;
};
uint32_t data_size;
/* use this field to represent
* whether there is a difference
* in abi
*/
int32_t reserved;
};
struct tee_shm_io {
union {
void __user *buffer;
void *paddr;
uint64_t padding_buf;
};
uint32_t size;
uint32_t flags;
/*
* Here fd_shm is 32-bit. To be compliant with the convention of file
* descriptor definition, fd_shm is defined as "int" type other
* than "int32_t". Even though using "int32_t" is more obvious to
* indicate that we intend to keep this structure aligned.
*/
int fd_shm;
uint32_t registered;
};
struct tee_ta_inst_desc {
union {
struct TEEC_UUID __user *uuid;
uint64_t pad1;
};
union {
void __user *ta_buf;
uint64_t pad2;
};
uint32_t ta_buf_size;
union {
uint32_t *resp_size;
uint64_t pad3;
};
};
struct tee_spta_inst_desc {
union {
void *ta_binary;
uint64_t padding_buf;
};
uint32_t ta_size;
union {
uint32_t *response_len;
uint64_t paddind_response_len;
};
};
#define TEE_OPEN_SESSION_IOC \
_IOWR('t', 161, struct tee_cmd_io)
#define TEE_INVOKE_COMMAND_IOC \
_IOWR('t', 163, struct tee_cmd_io)
#define TEE_REQUEST_CANCELLATION_IOC \
_IOWR('t', 164, struct tee_cmd_io)
#define TEE_ALLOC_SHM_IOC \
_IOWR('t', 165, struct tee_shm_io)
#define TEE_ALLOC_SHM_PERM_IOC \
_IOWR('t', 166, struct tee_shm_io)
#define TEE_GET_FD_FOR_RPC_SHM_IOC \
_IOWR('t', 167, struct tee_shm_io)
#define TEE_TUI_OPEN_SESSION_IOC \
_IOWR('t', 168, struct tee_cmd_io)
#define TEE_TUI_CLOSE_SESSION_IOC \
_IOWR('t', 169, struct tee_cmd_io)
#define TEE_TUI_NOTIFY_IOC \
_IOWR('t', 170, uint32_t)
#define TEE_TUI_WAITCMD_IOC \
_IOWR('t', 171, uint32_t)
#define TEE_INSTALL_TA_IOC \
_IOWR('t', 174, struct tee_spta_inst_desc)
#define TEE_INSTALL_TA_RESP_IOC \
_IO('t', 175)
#define TEE_DELETE_TA_IOC \
_IOWR('t', 176, struct TEEC_UUID)
#define TEE_QUERY_DRV_FEATURE_IOC \
_IOR('t', 183, uint32_t)
/* Command IDs */
#define TEEC_TUI_CMD_NONE 0
#define TEEC_TUI_CMD_START_ACTIVITY 1
#define TEEC_TUI_CMD_STOP_ACTIVITY 2
#endif /* _TEE_IOC_H */
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef _TEE_KERNEL_API_H
#define _TEE_KERNEL_API_H
#include <linux/tee_client_api.h>
TEEC_Result TEEC_InitializeContext(const char *name,
struct TEEC_Context *context);
void TEEC_FinalizeContext(struct TEEC_Context *context);
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);
void TEEC_CloseSession(struct TEEC_Session *session);
TEEC_Result TEEC_InvokeCommand(struct TEEC_Session *session,
uint32_t commandID,
struct TEEC_Operation *operation,
uint32_t *returnOrigin);
TEEC_Result TEEC_RegisterSharedMemory(struct TEEC_Context *context,
struct TEEC_SharedMemory *sharedMem);
TEEC_Result TEEC_AllocateSharedMemory(struct TEEC_Context *context,
struct TEEC_SharedMemory *sharedMem);
void TEEC_ReleaseSharedMemory(struct TEEC_SharedMemory *sharedMemory);
#endif
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef _TEE_KERNEL_LOWLEVEL_API_H
#define _TEE_KERNEL_LOWLEVEL_API_H
#include <linux/arm-smccc.h>
#ifdef CONFIG_ARM
struct smc_param {
uint32_t a0;
uint32_t a1;
uint32_t a2;
uint32_t a3;
uint32_t a4;
uint32_t a5;
uint32_t a6;
uint32_t a7;
};
#endif
#ifdef CONFIG_ARM64
struct smc_param {
uint64_t a0;
uint64_t a1;
uint64_t a2;
uint64_t a3;
uint64_t a4;
uint64_t a5;
uint64_t a6;
uint64_t a7;
};
#endif
#define tee_smc_call(p) do {\
struct arm_smccc_res res; \
arm_smccc_smc(p->a0, p->a1, p->a2, p->a3, \
p->a4, p->a5, p->a6, p->a7, &res); \
p->a0 = res.a0; \
p->a1 = res.a1; \
p->a2 = res.a2; \
p->a3 = res.a3; \
} while (0)
#endif
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEE_PM_SEC_CALL_H_
#define TEE_PM_SEC_CALL_H_
#ifdef CONFIG_ARM
#define TKCORE_SET_NS_BOOT_ADDR (0xBF000103U)
#define TKCORE_PREPARE_CPU_OFF (0xBF000104U)
#define TKCORE_ERRATA_802022 (0xBF000105U)
#define TKCORE_SET_WDT_KADDR (0xBF000300U)
static void tee_pm_sec_call(u32 cmd, u32 p0, u32 p1, u32 p2)
{
__asm__ __volatile__(
".arch_extension sec\n"
"mov r0, %0\n"
"mov r1, %1\n"
"mov r2, %2\n"
"mov r3, %3\n"
"smc #0\n" :
: "r"(cmd), "r"(p0), "r"(p1), "r"(p2)
: "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7");
}
#endif
#endif
@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2015-2019 TrustKernel Incorporated
*/
#ifndef TEE_RPMB_H
#define TEE_RPMB_H
#define TEE_RPMB_EMMC_CID_SIZE 16
#if defined(IN_KERNEL_RPMB_SUPPORT)
struct tee_rpmb_dev_info {
uint8_t cid[TEE_RPMB_EMMC_CID_SIZE];
uint8_t rpmb_size_mult;
uint8_t rel_wr_sec_c;
uint8_t ret_code;
};
struct tkcore_rpmb_request {
uint16_t type;
uint16_t blk_cnt;
uint16_t addr;
uint8_t *data_frame;
};
#define TEE_RPMB_GET_DEV_INFO 0x10
#define TEE_RPMB_PROGRAM_KEY 0x11
#define TEE_RPMB_GET_WRITE_COUNTER 0x12
#define TEE_RPMB_WRITE_DATA 0x13
#define TEE_RPMB_READ_DATA 0x14
#define TEE_RPMB_SWITCH_NORMAL 0x15
/*
* the following function must be
* implemented in kernel driver
*/
extern int tkcore_emmc_rpmb_execute(
struct tkcore_rpmb_request *req);
#endif
#endif