• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * FaceAuth coordinator driver
3  *
4  * Copyright (C) 2018 Google, Inc.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15 
16 #ifndef _LINUX_FACEAUTH_H
17 #define _LINUX_FACEAUTH_H
18 
19 #include <linux/types.h>
20 #include <linux/ioctl.h>
21 #include <linux/time.h>
22 
23 /* Keep it in sync with faceauth firmware */
24 #define FACEAUTH_RESULT_SUCCESS 0
25 #define FACEAUTH_RESULT_FAILURE 1
26 
27 #define FACEAUTH_ERROR_NO_ERROR 0
28 
29 #define FACEAUTH_MAX_TASKS 32
30 #define FACEAUTH_DEBUG_REGISTER_COUNT 24
31 #define FACEAUTH_BUFFER_TAG_LENGTH 16
32 #define FACEAUTH_BUFFER_LIST_LENGTH 32
33 
34 struct faceauth_init_data {
35 	__u64 features;
36 } __attribute__((packed));
37 
38 #define FACEAUTH_MAX_CACHE_FLUSH_SIZE 20
39 #define FACEAUTH_AUX_DATA_SIZE 32
40 
41 /* This struct is written by userspace and read by kernel */
42 struct faceauth_start_data {
43 	/*
44 	 * Operation requested by user, see FACEAUTH_OP_*
45 	 */
46 	__u8 profile_id;
47 	__u8 operation;
48 
49 	__u32 input_time_ms;
50 
51 	/* ION buffer fd */
52 	__u64 image_dot_left_fd;
53 	__u64 image_dot_right_fd;
54 	/* TODO: change uapi for image_flood_fd b/131321019 */
55 	__u64 image_flood_fd;
56 	__u64 image_flood_right_fd;
57 	__u64 calibration_fd;
58 	__u64 deferred_autocal_fd; /* b/134792835 */
59 
60 	__u32 image_dot_left_size;
61 	__u32 image_dot_right_size;
62 	__u32 image_flood_size;
63 	__u32 image_flood_right_size;
64 	__u32 calibration_size;
65 	__u32 deferred_autocal_size;
66 
67 	__s16 cache_flush_indexes[FACEAUTH_MAX_CACHE_FLUSH_SIZE];
68 	__u32 cache_flush_size;
69 
70 	/* Output parameters */
71 	__u8 result; /* result code from AB */
72 	union {
73 		__u32 citadel_output3;
74 		__u32 lockout_event;
75 	};
76 	__u32 angles;
77 	__s32 error_code; /* ab-faceauth error code */
78 	__u32 ab_exception_number;
79 	__u32 fw_version; /* ab-faceauth firmware version */
80 
81 	__u8 *citadel_token;
82 	__u32 citadel_token_size;
83 
84 	__u32 citadel_input;
85 	__u32 citadel_input2;
86 	__u32 citadel_output1;
87 	__u32 citadel_output2;
88 
89 	__u32 aux_data[FACEAUTH_AUX_DATA_SIZE];
90 
91 } __attribute__((packed));
92 
93 /* This struct contains a user supplied buffer that is written by kernel */
94 struct faceauth_debug_data {
95 	/* ION buffer fd */
96 	__u64 buffer_fd;
97 
98 	/* TODO(b/123892068): remove these user-buffer fields */
99 	union {
100 		__u8 *debug_buffer;
101 		__u8 *print_buffer;
102 	};
103 	union {
104 		__u32 debug_buffer_size;
105 		__u32 print_buffer_size;
106 	};
107 
108 	__u32 flags;
109 } __attribute__((packed));
110 
111 struct faceauth_workload_control {
112 	__u32 workload_state;
113 	__u32 run_count;
114 	__u32 run_time_ms;
115 	__u32 run_time_us;
116 	__u32 status;
117 } __attribute__((packed));
118 
119 struct faceauth_debug_register {
120 	__u64 address;
121 	__u64 value;
122 } __attribute__((packed));
123 
124 enum faceauth_buffer_type {
125 	OUTPUT_NONE,
126 	OUTPUT_DEPTH_EMBEDDING,
127 	OUTPUT_FACENET_EMBEDDING,
128 	OUTPUT_QUANTIZED_EMBEDDINGS,
129 	OUTPUT_BINARY_BLOB,
130 	OUTPUT_8BIT_GRAYSCALE_320x320,
131 	OUTPUT_16BIT_GRAYSCALE_128x128,
132 	OUTPUT_16BIT_GRAYSCALE_480x640,
133 	OUTPUT_8BITRGB_128x128,
134 	OUTPUT_FACE_BUF,
135 	OUTPUT_NUM_FACES,
136 
137 	/* used to extend enum size to 4 bytes */
138 	OUTPUT_INTMAX = 0xffffffff,
139 };
140 
141 struct faceauth_buffer_descriptor {
142 	/* offset of the buffer from the buffer_base_address */
143 	__u32 offset_to_buffer;
144 	__u32 size;
145 	__u32 type; /* cast to enum faceauth_buffer_type */
146 	char buffer_tag[FACEAUTH_BUFFER_TAG_LENGTH];
147 } __attribute__((packed));
148 
149 struct faceauth_buffer_list {
150 	/* ab stores the buffer base address, the kernel replaces this with
151 	 * the offset into the debug_entry
152 	 */
153 	__u32 buffer_base;
154 	__u32 buffer_count;
155 	struct faceauth_buffer_descriptor buffers[FACEAUTH_BUFFER_LIST_LENGTH];
156 } __attribute__((packed));
157 
158 #define SHA1SUM_LEN 20
159 
160 struct faceauth_model_version_list {
161 	__u8 fssd_version[SHA1SUM_LEN];
162 	__u8 facenet_version[SHA1SUM_LEN];
163 	__u8 gazenet_version[SHA1SUM_LEN];
164 	__u8 skin_version[SHA1SUM_LEN];
165 	__u8 ultradepth_version[SHA1SUM_LEN];
166 	__u8 depthid_version[SHA1SUM_LEN];
167 } __attribute__((packed));
168 
169 struct faceauth_airbrush_state {
170 	__u32 faceauth_version;
171 	__s32 error_code;
172 	__u32 internal_state_size;
173 	__u32 command;
174 	__s32 rightbox_x1;
175 	__s32 rightbox_y1;
176 	__s32 rightbox_x2;
177 	__s32 rightbox_y2;
178 	__s32 leftbox_x1;
179 	__s32 leftbox_y1;
180 	__s32 leftbox_x2;
181 	__s32 leftbox_y2;
182 	__u32 num_tasks;
183 	__u32 register_list_length;
184 	__u32 saved_register_count;
185 	struct faceauth_workload_control control_list[FACEAUTH_MAX_TASKS];
186 	struct faceauth_debug_register
187 		debug_registers[FACEAUTH_DEBUG_REGISTER_COUNT];
188 	struct faceauth_buffer_list output_buffers;
189 	__u32 flags;
190 	__u32 command_id;
191 	__u64 citadel_input_data;
192 	__u64 feature_bypass_flags;
193 	__u32 embedding_version;
194 	__u32 input_time_ms;
195 	struct faceauth_model_version_list model_versions;
196 } __attribute__((packed));
197 
198 struct faceauth_debug_image {
199 	__u32 offset_to_image;
200 	__u32 image_size;
201 };
202 
203 struct faceauth_debug_entry {
204 	struct timeval timestamp;
205 	uint32_t status;
206 	uint32_t ab_exception_number;
207 	uint32_t fault_address;
208 	uint32_t ab_link_reg;
209 	struct faceauth_debug_image left_dot;
210 	struct faceauth_debug_image right_dot;
211 	struct faceauth_debug_image left_flood;
212 	struct faceauth_debug_image right_flood;
213 	struct faceauth_debug_image calibration;
214 	struct faceauth_airbrush_state ab_state;
215 } __attribute__((packed));
216 
217 /*
218  * Prepare AP and AB for faceauth workflow. This step might include slow
219  * operations like reading firmware from filesystem and copying to AB memory.
220  */
221 #define FACEAUTH_DEV_IOC_INIT _IOR('f', 1, struct faceauth_init_data)
222 #define FACEAUTH_DEV_IOC_START _IOWR('f', 2, struct faceauth_start_data)
223 #define FACEAUTH_DEV_IOC_CLEANUP _IO('f', 4)
224 #define FACEAUTH_DEV_IOC_DEBUG _IOR('f', 5, struct faceauth_debug_data)
225 #define FACEAUTH_DEV_IOC_DEBUG_DATA _IOR('f', 6, struct faceauth_debug_data)
226 
227 /* Get debug data flags:
228  *  - Data from fifo is the default option, this returns debug data in first-in
229  *    first-out order. When all data has been returned the ENODATA status is
230  *    returned.
231  *  - Data from most recent, returns the most recent set of debug data and
232  *    then clears the fifo. If the fifo is empty then ENODATA will be returned.
233  *  - From AB dram clears the fifo, and then copies the data from ab dram. Data
234  *    is always returned. This is intended to be primarily a debug tool.
235  */
236 #define FACEAUTH_GET_DEBUG_DATA_FROM_FIFO (0)
237 #define FACEAUTH_GET_DEBUG_DATA_MOST_RECENT (1)
238 #define FACEAUTH_GET_DEBUG_DATA_FROM_AB_DRAM (2)
239 
240 #define FACEAUTH_DEBUG_DATA_PAYLOAD_SIZE (2 * 1024 * 1024)
241 
242 #endif /* _LINUX_FACEAUTH_H */
243