1419b0af8Sopenharmony_ci/*
2 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#ifndef TUI_H
15#define TUI_H
16
17#include "teek_ns_client.h"
18#include "teek_client_type.h"
19
20#define TEE_TUI_AGENT_ID 0x54554944 /* TUID */
21
22/* tui states */
23#define TUI_STATE_UNUSED	0
24#define TUI_STATE_CONFIG	1
25#define TUI_STATE_RUNNING   2
26#define TUI_STATE_ERROR	    3
27
28#define TUI_PID_CLEAR       0
29#define TUI_PID_CONFIG		1
30/* command from secure os */
31#define TUI_CMD_ENABLE	    1
32#define TUI_CMD_DISABLE	    2
33#define TUI_CMD_POLL		3
34#define TUI_CMD_SET_STATE   4
35#define TUI_CMD_PAUSE	    5
36#define TUI_CMD_DO_SYNC	    6
37#define TUI_CMD_START_DELAY_WORK	7
38#define TUI_CMD_CANCEL_DELAY_WORK   8
39#define TUI_CMD_LOAD_TTF	        9
40#define TUI_CMD_FREE_TTF_MEM		11
41#define TUI_CMD_EXIT		        12
42
43#define TUI_DRV_NAME_MAX	        32
44
45/* poll event type from normal to secure */
46enum tui_poll_type {
47	TUI_POLL_CFG_OK,
48	TUI_POLL_CFG_FAIL,
49	TUI_POLL_TP,
50	TUI_POLL_TICK,
51	TUI_POLL_DELAYED_WORK,
52	TUI_POLL_TIMEOUT,
53	TUI_POLL_RESUME_TUI,
54/* For some reasons, we need a method to terminate TUI from no secure
55 * OS, for example the TUI CA maybe killed.
56 */
57	TUI_POLL_CANCEL,
58	TUI_POLL_HANDLE_TUI,  /* for tui to handle event */
59	TUI_POLL_NAVI_H_TO_S, /* for navigator hide and show */
60	TUI_POLL_NAVI_S_TO_H,
61	TUI_POLL_SHS_0_TO_1,  /* for single hand mode switch */
62	TUI_POLL_SHS_0_TO_2,
63	TUI_POLL_SHS_1_TO_0,
64	TUI_POLL_SHS_2_TO_0,
65	TUI_POLL_ROTATION_0,  /* for retation switch */
66	TUI_POLL_ROTATION_90,
67	TUI_POLL_ROTATION_180,
68	TUI_POLL_ROTATION_270,
69	TUI_POLL_KEYBOARDTYPE_0,
70	TUI_POLL_KEYBOARDTYPE_3,
71	TUI_POLL_SEMITRANS,
72	TUI_POLL_CURSOR,
73	TUI_POLL_GETFP,
74	TUI_POLL_NOTCH,	      /* for tui to get notch height */
75	TUI_POLL_DIALOGTIMEOUT,
76	TUI_POLL_FOLD,	      /* for tui to get fold_screen */
77	TUI_POLL_MAX		  /* Do Not add type behind this one */
78};
79
80/* tui max should be bigger than TUI_POLL_MAX in tui.h */
81static const char *const poll_event_type_name[] = {
82	"config-ok",
83	"config-fail",
84	"tp",
85	"tui-tick",
86	"tui-delaywork",
87	"tui-pause",
88	"tui-resume",
89	"tui-terminate",
90	"tui-handle",
91	"tui-hs",
92	"tui-sh",
93	"tui-01",
94	"tui-02",
95	"tui-10",
96	"tui-20",
97	"tui-0",
98	"tui-90",
99	"tui-180",
100	"tui-270",
101	"tui_key_board_type0",
102	"tui_key_board_type3",
103	"tui-SEMI",
104	"tui-cursor",
105	"tui-gettp",
106	"tui-notch",
107	"tui-dialogtimeout",
108	"tui-fold",
109	"tui-max"
110};
111
112static const char *const state_name[] = {
113	"unused",
114	"config",
115	"running",
116	"error"
117};
118
119struct tui_ctl_shm {
120	struct {
121		int command;
122		int value;
123		int ret;
124	} s2n;
125	struct {
126		int event_type;
127		int value;
128		unsigned int addr;
129		unsigned int addr_h;
130		int tp_info;
131		int tp_info_h_addr;
132		int status;
133		int x;
134		int y;
135		uint32_t npages;
136		uint64_t info_length;
137		uint32_t phy_size;
138	} n2s;
139};
140
141struct tui_msg_node {
142	int type;
143	int val;
144	void *data;
145	struct list_head list;
146};
147
148typedef int (*tui_drv_init) (void *pdata, int secure);
149
150struct tui_drv_node {
151	tui_drv_init init_func;
152	void *pdata;
153	char name[TUI_DRV_NAME_MAX];
154	int state;
155	int priority;
156	struct list_head list;
157};
158
159/* tui need memory is calculated dynamically according to the screen resolution */
160struct tui_mem {
161	unsigned int tui_addr_size;
162	unsigned int tui_addr;
163	unsigned int tui_addr_h;
164	struct device *tui_dev;
165	char *tui_virt;
166};
167
168struct ttf_mem {
169	unsigned int ttf_addr_h;
170	unsigned int ttf_addr_l;
171	char *ttf_buff_virt;
172	unsigned int ttf_file_size;
173};
174
175typedef struct tui_memory {
176	phys_addr_t tui_ion_phys_addr;
177	void *tui_ion_virt_addr;
178	size_t len;
179	uint32_t size;
180	uint32_t configid;
181	struct sg_table *tui_sg_table;
182	phys_addr_t fb_phys_addr;
183	uint32_t npages;
184	uint64_t info_length;
185} tui_ion_mem;
186
187#ifdef CONFIG_TEE_TUI
188extern int ts_tui_report_input(void *finger_data);
189extern int tui_fp_notify(void);
190int __init init_tui(const struct device *dev);
191void free_tui(void);
192int tui_send_event(int event, struct teec_tui_parameter *tui_param);
193int register_tui_driver(tui_drv_init fun, const char *name,
194						void *pdata);
195void unregister_tui_driver(const char *name);
196/*
197 * TUI has different state that can recieve given types of message,
198 * there are 3 APIs to send message.
199 * send_tui_msg_config:send message to TUI in config state only.
200 */
201int send_tui_msg_config(int type, int val, void *data);
202void tui_poweroff_work_start(void);
203
204void set_tui_caller_info(unsigned int devid, int pid);
205void free_tui_caller_info(void);
206
207unsigned int tui_attach_device(void);
208void do_ns_tui_release(void);
209int is_tui_in_use(int pid_value);
210int tc_ns_tui_event(struct tc_ns_dev_file *dev_file, const void *argp);
211bool is_tui_agent(unsigned int agent_id);
212#else
213static inline bool is_tui_agent(unsigned int agent_id)
214{
215	(void)agent_id;
216	return false;
217}
218
219static inline int init_tui(const struct device *dev)
220{
221	(void)dev;
222	return 0;
223}
224
225static inline void free_tui(void)
226{
227}
228
229static inline void unregister_tui_driver(const char *name)
230{
231	(void)name;
232}
233
234static inline int send_tui_msg_config(int type, int val, const void *data)
235{
236	(void)type;
237	(void)val;
238	(void)data;
239	return 0;
240}
241
242static inline void set_tui_caller_info(unsigned int devid, int pid)
243{
244	(void)devid;
245	(void)pid;
246}
247
248static inline void free_tui_caller_info(void)
249{
250}
251
252static inline unsigned int tui_attach_device(void)
253{
254	return 0;
255}
256
257static inline int is_tui_in_use(int pid_value)
258{
259	(void)pid_value;
260	return 0;
261}
262
263static inline void do_ns_tui_release(void)
264{
265}
266
267static inline int tc_ns_tui_event(struct tc_ns_dev_file *dev_file, const void *argp)
268{
269	(void)dev_file;
270	(void)argp;
271	return 0;
272}
273#endif
274
275#endif