3 * sep_driver_api.h - Security Processor Driver api definitions
5 * Copyright(c) 2009-2011 Intel Corporation. All rights reserved.
6 * Contributions(c) 2009-2011 Discretix. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Mark Allyn mark.a.allyn@intel.com
24 * Jayant Mangalampalli jayant.mangalampalli@intel.com
28 * 2010.09.14 Upgrade to Medfield
29 * 2011.02.22 Enable kernel crypto
33 #ifndef __SEP_DRIVER_API_H__
34 #define __SEP_DRIVER_API_H__
36 /* Type of request from device */
37 #define SEP_DRIVER_SRC_REPLY 1
38 #define SEP_DRIVER_SRC_REQ 2
39 #define SEP_DRIVER_SRC_PRINTF 3
42 #define SEP_DRIVER_POWERON 1
43 #define SEP_DRIVER_POWEROFF 2
45 /* Following enums are used only for kernel crypto api */
46 enum type_of_request
{
70 structure that represents DCB
73 /* physical address of the first input mlli */
74 u32 input_mlli_address
;
75 /* num of entries in the first input mlli */
76 u32 input_mlli_num_entries
;
77 /* size of data in the first input mlli */
78 u32 input_mlli_data_size
;
79 /* physical address of the first output mlli */
80 u32 output_mlli_address
;
81 /* num of entries in the first output mlli */
82 u32 output_mlli_num_entries
;
83 /* size of data in the first output mlli */
84 u32 output_mlli_data_size
;
85 /* pointer to the output virtual tail */
86 aligned_u64 out_vr_tail_pt
;
87 /* size of tail data */
89 /* input tail data array */
94 command structure for building dcb block (currently for ext app only)
96 struct build_dcb_struct
{
97 /* address value of the data in */
98 aligned_u64 app_in_address
;
101 /* address of the data out */
102 aligned_u64 app_out_address
;
103 /* the size of the block of the operation - if needed,
104 every table will be modulo this parameter */
106 /* the size of the block of the operation - if needed,
107 every table will be modulo this parameter */
110 /* which application calls the driver DX or applet */
115 command structure for building dcb block for kernel crypto
117 struct build_dcb_struct_kernel
{
118 /* address value of the data in */
119 void *app_in_address
;
120 /* size of data in */
121 ssize_t data_in_size
;
122 /* address of the data out */
123 void *app_out_address
;
124 /* the size of the block of the operation - if needed,
125 every table will be modulo this parameter */
127 /* the size of the block of the operation - if needed,
128 every table will be modulo this parameter */
131 /* which application calls the driver DX or applet */
134 struct scatterlist
*src_sg
;
135 struct scatterlist
*dst_sg
;
139 * @struct sep_dma_map
141 * Structure that contains all information needed for mapping the user pages
142 * or kernel buffers for dma operations
147 /* mapped dma address */
149 /* size of the mapped data */
153 struct sep_dma_resource
{
154 /* array of pointers to the pages that represent
155 input data for the synchronic DMA action */
156 struct page
**in_page_array
;
158 /* array of pointers to the pages that represent out
159 data for the synchronic DMA action */
160 struct page
**out_page_array
;
162 /* number of pages in the sep_in_page_array */
165 /* number of pages in the sep_out_page_array */
168 /* map array of the input data */
169 struct sep_dma_map
*in_map_array
;
171 /* map array of the output data */
172 struct sep_dma_map
*out_map_array
;
174 /* number of entries of the input mapp array */
175 u32 in_map_num_entries
;
177 /* number of entries of the output mapp array */
178 u32 out_map_num_entries
;
180 /* Scatter list for kernel operations */
181 struct scatterlist
*src_sg
;
182 struct scatterlist
*dst_sg
;
186 /* command struct for translating rar handle to bus address
187 and setting it at predefined location */
188 struct rar_hndl_to_bus_struct
{
191 aligned_u64 rar_handle
;
195 structure that represent one entry in the DMA LLI table
197 struct sep_lli_entry
{
198 /* physical address */
206 * header format for each fastcall write operation
208 struct sep_fastcall_hdr
{
216 * structure used in file pointer's private data field
217 * to track the status of the calls to the various
220 struct sep_call_status
{
221 unsigned long status
;
225 * format of dma context buffer used to store all DMA-related
226 * context information of a particular transaction
228 struct sep_dma_context
{
229 /* number of data control blocks */
231 /* number of the lli tables created in the current transaction */
232 u32 num_lli_tables_created
;
233 /* size of currently allocated dma tables region */
235 /* size of input data */
237 /* secure dma use (for imr memory restricted area in output) */
239 struct sep_dma_resource dma_res_arr
[SEP_MAX_NUM_SYNC_DMA_OPS
];
240 /* Scatter gather for kernel crypto */
241 struct scatterlist
*src_sg
;
242 struct scatterlist
*dst_sg
;
246 * format for file pointer's private_data field
248 struct sep_private_data
{
249 struct sep_queue_info
*my_queue_elem
;
250 struct sep_device
*device
;
251 struct sep_call_status call_status
;
252 struct sep_dma_context
*dma_ctx
;
256 /* Functions used by sep_crypto */
259 * sep_queue_status_remove - Removes transaction from status queue
261 * @sep_queue_info: pointer to status queue
263 * This function will removes information about transaction from the queue.
265 void sep_queue_status_remove(struct sep_device
*sep
,
266 struct sep_queue_info
**queue_elem
);
268 * sep_queue_status_add - Adds transaction to status queue
270 * @opcode: transaction opcode
271 * @size: input data size
272 * @pid: pid of current process
273 * @name: current process name
274 * @name_len: length of name (current process)
276 * This function adds information about about transaction started to the status
279 struct sep_queue_info
*sep_queue_status_add(
280 struct sep_device
*sep
,
284 u8
*name
, size_t name_len
);
287 * sep_create_dcb_dmatables_context_kernel - Creates DCB & MLLI/DMA table context
290 * @dcb_region: DCB region buf to create for current transaction
291 * @dmatables_region: MLLI/DMA tables buf to create for current transaction
292 * @dma_ctx: DMA context buf to create for current transaction
293 * @user_dcb_args: User arguments for DCB/MLLI creation
294 * @num_dcbs: Number of DCBs to create
296 int sep_create_dcb_dmatables_context_kernel(struct sep_device
*sep
,
297 struct sep_dcblock
**dcb_region
,
298 void **dmatables_region
,
299 struct sep_dma_context
**dma_ctx
,
300 const struct build_dcb_struct_kernel
*dcb_data
,
304 * sep_activate_dcb_dmatables_context - Takes DCB & DMA tables
307 * @dcb_region: DCB region copy
308 * @dmatables_region: MLLI/DMA tables copy
309 * @dma_ctx: DMA context for current transaction
311 ssize_t
sep_activate_dcb_dmatables_context(struct sep_device
*sep
,
312 struct sep_dcblock
**dcb_region
,
313 void **dmatables_region
,
314 struct sep_dma_context
*dma_ctx
);
317 * sep_prepare_input_output_dma_table_in_dcb - prepare control blocks
318 * @app_in_address: unsigned long; for data buffer in (user space)
319 * @app_out_address: unsigned long; for data buffer out (user space)
320 * @data_in_size: u32; for size of data
321 * @block_size: u32; for block size
322 * @tail_block_size: u32; for size of tail block
323 * @isapplet: bool; to indicate external app
324 * @is_kva: bool; kernel buffer; only used for kernel crypto module
325 * @secure_dma; indicates whether this is secure_dma using IMR
327 * This function prepares the linked DMA tables and puts the
328 * address for the linked list of tables inta a DCB (data control
329 * block) the address of which is known by the SEP hardware
330 * Note that all bus addresses that are passed to the SEP
331 * are in 32 bit format; the SEP is a 32 bit device
333 int sep_prepare_input_output_dma_table_in_dcb(struct sep_device
*sep
,
334 unsigned long app_in_address
,
335 unsigned long app_out_address
,
342 struct sep_dcblock
*dcb_region
,
343 void **dmatables_region
,
344 struct sep_dma_context
**dma_ctx
,
345 struct scatterlist
*src_sg
,
346 struct scatterlist
*dst_sg
);
349 * sep_free_dma_table_data_handler - free DMA table
350 * @sep: pointer to struct sep_device
351 * @dma_ctx: dma context
353 * Handles the request to free DMA table for synchronic actions
355 int sep_free_dma_table_data_handler(struct sep_device
*sep
,
356 struct sep_dma_context
**dma_ctx
);
358 * sep_send_command_handler - kick off a command
359 * @sep: SEP being signalled
361 * This function raises interrupt to SEP that signals that is has a new
362 * command from the host
364 * Note that this function does fall under the ioctl lock
366 int sep_send_command_handler(struct sep_device
*sep
);
369 * sep_wait_transaction - Used for synchronizing transactions
372 int sep_wait_transaction(struct sep_device
*sep
);
375 * IOCTL command defines
377 /* magic number 1 of the sep IOCTL command */
378 #define SEP_IOC_MAGIC_NUMBER 's'
380 /* sends interrupt to sep that message is ready */
381 #define SEP_IOCSENDSEPCOMMAND \
382 _IO(SEP_IOC_MAGIC_NUMBER, 0)
384 /* end transaction command */
385 #define SEP_IOCENDTRANSACTION \
386 _IO(SEP_IOC_MAGIC_NUMBER, 15)
388 #define SEP_IOCPREPAREDCB \
389 _IOW(SEP_IOC_MAGIC_NUMBER, 35, struct build_dcb_struct)
391 #define SEP_IOCFREEDCB \
392 _IO(SEP_IOC_MAGIC_NUMBER, 36)
396 #define SEP_IOCPREPAREDCB_SECURE_DMA \
397 _IOW(SEP_IOC_MAGIC_NUMBER, 38, struct build_dcb_struct)
399 #define SEP_IOCFREEDCB_SECURE_DMA \
400 _IO(SEP_IOC_MAGIC_NUMBER, 39)