1419b0af8Sopenharmony_ci/*
2419b0af8Sopenharmony_ci * tc_ns_client.h
3419b0af8Sopenharmony_ci *
4419b0af8Sopenharmony_ci * data structure declaration for nonsecure world
5419b0af8Sopenharmony_ci *
6419b0af8Sopenharmony_ci * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7419b0af8Sopenharmony_ci *
8419b0af8Sopenharmony_ci * This software is licensed under the terms of the GNU General Public
9419b0af8Sopenharmony_ci * License version 2, as published by the Free Software Foundation, and
10419b0af8Sopenharmony_ci * may be copied, distributed, and modified under those terms.
11419b0af8Sopenharmony_ci *
12419b0af8Sopenharmony_ci * This program is distributed in the hope that it will be useful,
13419b0af8Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14419b0af8Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15419b0af8Sopenharmony_ci * GNU General Public License for more details.
16419b0af8Sopenharmony_ci */
17419b0af8Sopenharmony_ci#ifndef TC_NS_CLIENT_H
18419b0af8Sopenharmony_ci#define TC_NS_CLIENT_H
19419b0af8Sopenharmony_ci
20419b0af8Sopenharmony_ci#include <linux/types.h>
21419b0af8Sopenharmony_ci#include <linux/version.h>
22419b0af8Sopenharmony_ci
23419b0af8Sopenharmony_ci#define UUID_LEN			16
24419b0af8Sopenharmony_ci#define PARAM_NUM			4
25419b0af8Sopenharmony_ci#define ADDR_TRANS_NUM		32
26419b0af8Sopenharmony_ci
27419b0af8Sopenharmony_ci#define teec_param_types(param0_type, param1_type, param2_type, param3_type) \
28419b0af8Sopenharmony_ci	((param3_type) << 12 | (param2_type) << 8 | \
29419b0af8Sopenharmony_ci	(param1_type) << 4 | (param0_type))
30419b0af8Sopenharmony_ci
31419b0af8Sopenharmony_ci#define teec_param_type_get(param_types, index) \
32419b0af8Sopenharmony_ci	(((param_types) >> ((index) << 2)) & 0x0F)
33419b0af8Sopenharmony_ci
34419b0af8Sopenharmony_ci#ifndef ZERO_SIZE_PTR
35419b0af8Sopenharmony_ci#define ZERO_SIZE_PTR ((void *)16)
36419b0af8Sopenharmony_ci#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= (unsigned long)ZERO_SIZE_PTR)
37419b0af8Sopenharmony_ci#endif
38419b0af8Sopenharmony_ci
39419b0af8Sopenharmony_ci#if (KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE)
40419b0af8Sopenharmony_ci#define mm_sem_lock(mm) (mm)->mmap_lock
41419b0af8Sopenharmony_ci#else
42419b0af8Sopenharmony_ci#define mm_sem_lock(mm) (mm)->mmap_sem
43419b0af8Sopenharmony_ci#endif
44419b0af8Sopenharmony_ci
45419b0af8Sopenharmony_cistruct tc_ns_client_login {
46419b0af8Sopenharmony_ci	__u32 method;
47419b0af8Sopenharmony_ci	__u32 mdata;
48419b0af8Sopenharmony_ci};
49419b0af8Sopenharmony_ci
50419b0af8Sopenharmony_ciunion tc_ns_client_param {
51419b0af8Sopenharmony_ci	struct {
52419b0af8Sopenharmony_ci		__u32 buffer;
53419b0af8Sopenharmony_ci		__u32 buffer_h_addr;
54419b0af8Sopenharmony_ci		__u32 offset;
55419b0af8Sopenharmony_ci		__u32 h_offset;
56419b0af8Sopenharmony_ci		__u32 size_addr;
57419b0af8Sopenharmony_ci		__u32 size_h_addr;
58419b0af8Sopenharmony_ci	} memref;
59419b0af8Sopenharmony_ci	struct {
60419b0af8Sopenharmony_ci		__u32 a_addr;
61419b0af8Sopenharmony_ci		__u32 a_h_addr;
62419b0af8Sopenharmony_ci		__u32 b_addr;
63419b0af8Sopenharmony_ci		__u32 b_h_addr;
64419b0af8Sopenharmony_ci	} value;
65419b0af8Sopenharmony_ci};
66419b0af8Sopenharmony_ci
67419b0af8Sopenharmony_cistruct tc_ns_client_return {
68419b0af8Sopenharmony_ci	int code;
69419b0af8Sopenharmony_ci	__u32 origin;
70419b0af8Sopenharmony_ci};
71419b0af8Sopenharmony_ci
72419b0af8Sopenharmony_cistruct tc_ns_client_context {
73419b0af8Sopenharmony_ci	unsigned char uuid[UUID_LEN];
74419b0af8Sopenharmony_ci	__u32 session_id;
75419b0af8Sopenharmony_ci	__u32 cmd_id;
76419b0af8Sopenharmony_ci	struct tc_ns_client_return returns;
77419b0af8Sopenharmony_ci	struct tc_ns_client_login login;
78419b0af8Sopenharmony_ci	union tc_ns_client_param params[PARAM_NUM];
79419b0af8Sopenharmony_ci	__u32 param_types;
80419b0af8Sopenharmony_ci	__u8 started;
81419b0af8Sopenharmony_ci	__u32 calling_pid;
82419b0af8Sopenharmony_ci	unsigned int file_size;
83419b0af8Sopenharmony_ci	union {
84419b0af8Sopenharmony_ci		char *file_buffer;
85419b0af8Sopenharmony_ci		struct {
86419b0af8Sopenharmony_ci			uint32_t file_addr;
87419b0af8Sopenharmony_ci			uint32_t file_h_addr;
88419b0af8Sopenharmony_ci		} memref;
89419b0af8Sopenharmony_ci	};
90419b0af8Sopenharmony_ci};
91419b0af8Sopenharmony_ci
92419b0af8Sopenharmony_cistruct tc_ns_client_time {
93419b0af8Sopenharmony_ci	uint32_t seconds;
94419b0af8Sopenharmony_ci	uint32_t millis;
95419b0af8Sopenharmony_ci};
96419b0af8Sopenharmony_ci
97419b0af8Sopenharmony_cienum secfile_type_t {
98419b0af8Sopenharmony_ci	LOAD_TA = 0,
99419b0af8Sopenharmony_ci	LOAD_SERVICE,
100419b0af8Sopenharmony_ci	LOAD_LIB,
101419b0af8Sopenharmony_ci	LOAD_DYNAMIC_DRV,
102419b0af8Sopenharmony_ci	LOAD_PATCH,
103419b0af8Sopenharmony_ci	LOAD_TYPE_MAX,
104419b0af8Sopenharmony_ci};
105419b0af8Sopenharmony_ci
106419b0af8Sopenharmony_cistruct sec_file_info {
107419b0af8Sopenharmony_ci	enum secfile_type_t secfile_type;
108419b0af8Sopenharmony_ci	uint32_t file_size;
109419b0af8Sopenharmony_ci	int32_t sec_load_err;
110419b0af8Sopenharmony_ci};
111419b0af8Sopenharmony_ci
112419b0af8Sopenharmony_cistruct load_secfile_ioctl_struct {
113419b0af8Sopenharmony_ci	struct sec_file_info sec_file_info;
114419b0af8Sopenharmony_ci	unsigned char uuid[UUID_LEN];
115419b0af8Sopenharmony_ci	union {
116419b0af8Sopenharmony_ci		char *file_buffer;
117419b0af8Sopenharmony_ci		struct {
118419b0af8Sopenharmony_ci			uint32_t file_addr;
119419b0af8Sopenharmony_ci			uint32_t file_h_addr;
120419b0af8Sopenharmony_ci		} memref;
121419b0af8Sopenharmony_ci	};
122419b0af8Sopenharmony_ci}__attribute__((packed));
123419b0af8Sopenharmony_ci
124419b0af8Sopenharmony_cistruct agent_ioctl_args {
125419b0af8Sopenharmony_ci	uint32_t id;
126419b0af8Sopenharmony_ci	uint32_t buffer_size;
127419b0af8Sopenharmony_ci	union {
128419b0af8Sopenharmony_ci		void *buffer;
129419b0af8Sopenharmony_ci		unsigned long long addr;
130419b0af8Sopenharmony_ci	};
131419b0af8Sopenharmony_ci};
132419b0af8Sopenharmony_ci
133419b0af8Sopenharmony_cistruct tc_ns_client_crl {
134419b0af8Sopenharmony_ci	union {
135419b0af8Sopenharmony_ci		uint8_t *buffer;
136419b0af8Sopenharmony_ci		struct {
137419b0af8Sopenharmony_ci			uint32_t buffer_addr;
138419b0af8Sopenharmony_ci			uint32_t buffer_h_addr;
139419b0af8Sopenharmony_ci		} memref;
140419b0af8Sopenharmony_ci	};
141419b0af8Sopenharmony_ci	uint32_t size;
142419b0af8Sopenharmony_ci};
143419b0af8Sopenharmony_ci
144419b0af8Sopenharmony_ci#ifdef CONFIG_LOG_POOL_ENABLE
145419b0af8Sopenharmony_cistruct tc_ns_log_pool {
146419b0af8Sopenharmony_ci	uint64_t addr;
147419b0af8Sopenharmony_ci	uint64_t size;
148419b0af8Sopenharmony_ci};
149419b0af8Sopenharmony_ci#endif
150419b0af8Sopenharmony_ci
151419b0af8Sopenharmony_ci#define MAX_SHA_256_SZ 32
152419b0af8Sopenharmony_ci
153419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SES_OPEN_REQ \
154419b0af8Sopenharmony_ci	 _IOW(TC_NS_CLIENT_IOC_MAGIC, 1, struct tc_ns_client_context)
155419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SES_CLOSE_REQ \
156419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 2, struct tc_ns_client_context)
157419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SEND_CMD_REQ \
158419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 3, struct tc_ns_client_context)
159419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SHRD_MEM_RELEASE \
160419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 4, unsigned int)
161419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_WAIT_EVENT \
162419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 5, unsigned int)
163419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SEND_EVENT_RESPONSE \
164419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 6, unsigned int)
165419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_REGISTER_AGENT \
166419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 7, struct agent_ioctl_args)
167419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_UNREGISTER_AGENT \
168419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 8, unsigned int)
169419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_LOAD_APP_REQ \
170419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 9, struct load_secfile_ioctl_struct)
171419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_NEED_LOAD_APP \
172419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 10, struct tc_ns_client_context)
173419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_ALLOC_EXCEPTING_MEM \
174419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 12, unsigned int)
175419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_CANCEL_CMD_REQ \
176419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 13, struct tc_ns_client_context)
177419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_LOGIN \
178419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 14, int)
179419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_TUI_EVENT \
180419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 16, int)
181419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SYC_SYS_TIME \
182419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 17, struct tc_ns_client_time)
183419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_SET_NATIVECA_IDENTITY \
184419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 18, int)
185419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_LOAD_TTF_FILE_AND_NOTCH_HEIGHT \
186419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 19, unsigned int)
187419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_LATEINIT \
188419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 20, unsigned int)
189419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_GET_TEE_VERSION \
190419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 21, unsigned int)
191419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_UPDATE_TA_CRL \
192419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 22, struct tc_ns_client_crl)
193419b0af8Sopenharmony_ci#ifdef CONFIG_LOG_POOL_ENABLE
194419b0af8Sopenharmony_ci#define TC_NS_CLIENT_IOCTL_GET_LOG_POOL \
195419b0af8Sopenharmony_ci	_IOWR(TC_NS_CLIENT_IOC_MAGIC, 23, struct tc_ns_log_pool)
196419b0af8Sopenharmony_ci#endif
197419b0af8Sopenharmony_ci#endif
198