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,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