• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2 /*
3  * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef _SPCOM_H_
7 #define _SPCOM_H_
8 
9 #include <linux/types.h>	/* uint32_t, bool */
10 #ifndef BIT
11 	#define BIT(x) (1 << x)
12 #endif
13 
14 #ifndef PAGE_SIZE
15 	#define PAGE_SIZE 4096
16 #endif
17 
18 /**
19  * @brief - Secure Processor Communication interface to user space spcomlib.
20  *
21  * Sending data and control commands by write() file operation.
22  * Receiving data by read() file operation.
23  * Getting the next request size by read() file operation,
24  * with special size SPCOM_GET_NEXT_REQUEST_SIZE.
25  */
26 
27 /*
28  * Maximum number of channel between Secure Processor and HLOS.
29  * including predefined channels, like "sp_kernel".
30  */
31 #define SPCOM_MAX_CHANNELS	0x20
32 
33 /* Maximum size (including null) for channel names */
34 #define SPCOM_CHANNEL_NAME_SIZE		32
35 /*
36  * file read(fd, buf, size) with this size,
37  * hints the kernel that user space wants to read the next-req-size.
38  * This size is bigger than both SPCOM_MAX_REQUEST_SIZE and
39  * SPCOM_MAX_RESPONSE_SIZE , so it is not a valid data size.
40  */
41 #define SPCOM_GET_NEXT_REQUEST_SIZE	(PAGE_SIZE-1)
42 
43 /* Command Id between spcomlib and spcom driver, on write() */
44 enum spcom_cmd_id {
45 	SPCOM_CMD_LOAD_APP	= 0x4C4F4144, /* "LOAD" = 0x4C4F4144 */
46 	SPCOM_CMD_RESET_SP	= 0x52455354, /* "REST" = 0x52455354 */
47 	SPCOM_CMD_SEND		= 0x53454E44, /* "SEND" = 0x53454E44 */
48 	SPCOM_CMD_SEND_MODIFIED	= 0x534E444D, /* "SNDM" = 0x534E444D */
49 	SPCOM_CMD_LOCK_ION_BUF  = 0x4C4F434B, /* "LOCK" = 0x4C4F434B */
50 	SPCOM_CMD_UNLOCK_ION_BUF = 0x554C434B, /* "ULCK" = 0x4C4F434B */
51 	SPCOM_CMD_FSSR		= 0x46535352, /* "FSSR" = 0x46535352 */
52 	SPCOM_CMD_CREATE_CHANNEL = 0x43524554, /* "CRET" = 0x43524554 */
53 
54 #define SPCOM_CMD_ENABLE_SSR \
55 	SPCOM_CMD_ENABLE_SSR
56 	SPCOM_CMD_ENABLE_SSR     = 0x45535352,   /* "ESSR" =0x45535352*/
57 
58 #define SPCOM_CMD_RESTART_SP \
59 	SPCOM_CMD_RESTART_SP
60 	SPCOM_CMD_RESTART_SP         = 0x52535452,   /* "RSTR" = 0x52535452 */
61 };
62 
63 /*
64  * @note: Event types that are always implicitly polled:
65  * POLLERR=0x08 | POLLHUP=0x10 | POLLNVAL=0x20
66  * so bits 3,4,5 can't be used
67  */
68 enum spcom_poll_events {
69 	SPCOM_POLL_LINK_STATE	= BIT(1),
70 	SPCOM_POLL_CH_CONNECT	= BIT(2),
71 	SPCOM_POLL_READY_FLAG	= BIT(14), /* output */
72 	SPCOM_POLL_WAIT_FLAG	= BIT(15), /* if set , wait for the event */
73 };
74 
75 /* Common Command structure between User Space and spcom driver, on write() */
76 struct spcom_user_command {
77 	enum spcom_cmd_id cmd_id;
78 	uint32_t arg;
79 } __attribute__((packed));
80 
81 /* Command structure between User Space and spcom driver, on write() */
82 struct spcom_send_command {
83 	enum spcom_cmd_id cmd_id;
84 	uint32_t timeout_msec;
85 	uint32_t buf_size;
86 	char buf[0]; /* Variable buffer size - must be last field */
87 } __attribute__((packed));
88 
89 /* Command structure between userspace spcomlib and spcom driver, on write() */
90 struct spcom_user_create_channel_command {
91 	enum spcom_cmd_id cmd_id;
92 	char ch_name[SPCOM_CHANNEL_NAME_SIZE];
93 #define SPCOM_IS_SHARABLE_SUPPORTED
94 	bool is_sharable;
95 } __attribute__((packed));
96 
97 /* Command structure between userspace spcomlib and spcom driver, on write() */
98 #define SPCOM_USER_RESTART_SP_CMD
99 struct spcom_user_restart_sp_command {
100 	enum spcom_cmd_id cmd_id;
101 	uint32_t arg;
102 #define SPCOM_IS_UPDATED_SUPPORETED
103 	uint32_t is_updated;
104 } __attribute__((packed));
105 
106 /* maximum ION buf for send-modfied-command */
107 #define SPCOM_MAX_ION_BUF 4
108 
109 struct spcom_ion_info {
110 	int32_t fd; /* ION buffer File Descriptor, set -1 for invalid fd */
111 	uint32_t buf_offset; /* virtual address offset in request/response */
112 };
113 
114 /* Pass this FD to unlock all ION buffer for the specific channel */
115 #define SPCOM_ION_FD_UNLOCK_ALL	0xFFFF
116 
117 struct spcom_ion_handle {
118 	int32_t fd;		/* File Descriptor associated with the buffer */
119 };
120 
121 /* Command structure between User Space and spcom driver, on write() */
122 struct spcom_user_send_modified_command {
123 	enum spcom_cmd_id cmd_id;
124 	struct spcom_ion_info ion_info[SPCOM_MAX_ION_BUF];
125 	uint32_t timeout_msec;
126 	uint32_t buf_size;
127 	char buf[0]; /* Variable buffer size - must be last field */
128 } __attribute__((packed));
129 
130 enum {
131 	SPCOM_IONFD_CMD,
132 	SPCOM_POLL_CMD,
133 };
134 
135 enum spcom_poll_cmd_id {
136 	SPCOM_LINK_STATE_REQ,
137 	SPCOM_CH_CONN_STATE_REQ,
138 };
139 
140 struct spcom_poll_param {
141 	/* input parameters */
142 	bool wait;
143 	enum spcom_poll_cmd_id cmd_id;
144 	/* output parameter */
145 	int retval;
146 } __attribute__((packed));
147 
148 #define SPCOM_IOCTL_MAGIC	'S'
149 #define SPCOM_GET_IONFD _IOR(SPCOM_IOCTL_MAGIC, SPCOM_IONFD_CMD, \
150 			     struct spcom_ion_handle)
151 #define SPCOM_SET_IONFD _IOW(SPCOM_IOCTL_MAGIC, SPCOM_IONFD_CMD, \
152 			     struct spcom_ion_handle)
153 #define SPCOM_POLL_STATE _IOWR(SPCOM_IOCTL_MAGIC, SPCOM_POLL_CMD, \
154 			       struct spcom_poll_param)
155 
156 #endif /* _SPCOM_H_ */
157