3 * sep_driver_api.h - Security Processor Driver api definitions
5 * Copyright(c) 2009 Intel Corporation. All rights reserved.
6 * Copyright(c) 2009 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; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Mark Allyn mark.a.allyn@intel.com
28 * 2009.06.26 Initial publish
32 #ifndef __SEP_DRIVER_API_H__
33 #define __SEP_DRIVER_API_H__
37 /*----------------------------------------------------------------
39 -----------------------------------------------------------------*/
41 /* magic number 1 of the sep IOCTL command */
42 #define SEP_IOC_MAGIC_NUMBER 's'
44 /* sends interrupt to sep that message is ready */
45 #define SEP_IOCSENDSEPCOMMAND _IO(SEP_IOC_MAGIC_NUMBER , 0)
47 /* sends interrupt to sep that message is ready */
48 #define SEP_IOCSENDSEPRPLYCOMMAND _IO(SEP_IOC_MAGIC_NUMBER , 1)
50 /* allocate memory in data pool */
51 #define SEP_IOCALLOCDATAPOLL _IO(SEP_IOC_MAGIC_NUMBER , 2)
53 /* write to pre-allocated memory in data pool */
54 #define SEP_IOCWRITEDATAPOLL _IO(SEP_IOC_MAGIC_NUMBER , 3)
56 /* read from pre-allocated memory in data pool */
57 #define SEP_IOCREADDATAPOLL _IO(SEP_IOC_MAGIC_NUMBER , 4)
59 /* create sym dma lli tables */
60 #define SEP_IOCCREATESYMDMATABLE _IO(SEP_IOC_MAGIC_NUMBER , 5)
62 /* create flow dma lli tables */
63 #define SEP_IOCCREATEFLOWDMATABLE _IO(SEP_IOC_MAGIC_NUMBER , 6)
65 /* free dynamic data aalocated during table creation */
66 #define SEP_IOCFREEDMATABLEDATA _IO(SEP_IOC_MAGIC_NUMBER , 7)
68 /* get the static pool area addersses (physical and virtual) */
69 #define SEP_IOCGETSTATICPOOLADDR _IO(SEP_IOC_MAGIC_NUMBER , 8)
71 /* set flow id command */
72 #define SEP_IOCSETFLOWID _IO(SEP_IOC_MAGIC_NUMBER , 9)
74 /* add tables to the dynamic flow */
75 #define SEP_IOCADDFLOWTABLE _IO(SEP_IOC_MAGIC_NUMBER , 10)
77 /* add flow add tables message */
78 #define SEP_IOCADDFLOWMESSAGE _IO(SEP_IOC_MAGIC_NUMBER , 11)
80 /* start sep command */
81 #define SEP_IOCSEPSTART _IO(SEP_IOC_MAGIC_NUMBER , 12)
83 /* init sep command */
84 #define SEP_IOCSEPINIT _IO(SEP_IOC_MAGIC_NUMBER , 13)
86 /* set non blocking mode */
87 #define SEP_IOCSETAPIMODE _IO(SEP_IOC_MAGIC_NUMBER , 14)
89 /* end transaction command */
90 #define SEP_IOCENDTRANSACTION _IO(SEP_IOC_MAGIC_NUMBER , 15)
92 /* reallocate cache and resident */
93 #define SEP_IOCREALLOCCACHERES _IO(SEP_IOC_MAGIC_NUMBER , 16)
95 /* get the offset of the address starting from the beginnnig of the map area */
96 #define SEP_IOCGETMAPPEDADDROFFSET _IO(SEP_IOC_MAGIC_NUMBER , 17)
98 /* get time address and value */
99 #define SEP_IOCGETIME _IO(SEP_IOC_MAGIC_NUMBER , 19)
101 /*-------------------------------------------
103 ----------------------------------------------*/
108 struct sep_driver_init_t {
109 /* start of the 1G of the host memory address that SEP can access */
110 unsigned long message_addr;
112 /* start address of resident */
113 unsigned long message_size_in_words;
119 realloc cache resident command
121 struct sep_driver_realloc_cache_resident_t {
123 unsigned long base_addr;
125 /* current cache address */
126 unsigned long cache_addr;
128 /* cache size in bytes*/
129 unsigned long cache_size_in_bytes;
131 /* current resident address */
132 unsigned long resident_addr;
134 /* resident size in bytes*/
135 unsigned long resident_size_in_bytes;
137 /* new cache address */
138 unsigned long new_cache_addr;
140 /* new resident address */
141 unsigned long new_resident_addr;
143 /* new resident address */
144 unsigned long new_shared_area_addr;
146 /* new base address */
147 unsigned long new_base_addr;
151 set api mode command struct
153 struct sep_driver_set_api_mode_t {
154 /* mode to set - 1 - blocking, 0 - non-blocking */
158 struct sep_driver_alloc_t {
159 /* virtual address of allocated space */
160 unsigned long offset;
162 /* physical address of allocated space */
163 unsigned long phys_address;
165 /* number of bytes to allocate */
166 unsigned long num_bytes;
171 struct sep_driver_write_t {
172 /* application space address */
173 unsigned long app_address;
175 /* address of the data pool */
176 unsigned long datapool_address;
178 /* number of bytes to write */
179 unsigned long num_bytes;
184 struct sep_driver_read_t {
185 /* application space address */
186 unsigned long app_address;
188 /* address of the data pool */
189 unsigned long datapool_address;
191 /* number of bytes to read */
192 unsigned long num_bytes;
197 struct sep_driver_build_sync_table_t {
198 /* address value of the data in */
199 unsigned long app_in_address;
201 /* size of data in */
202 unsigned long data_in_size;
204 /* address of the data out */
205 unsigned long app_out_address;
207 /* the size of the block of the operation - if needed,
208 every table will be modulo this parameter */
209 unsigned long block_size;
211 /* the physical address of the first input DMA table */
212 unsigned long in_table_address;
214 /* number of entries in the first input DMA table */
215 unsigned long in_table_num_entries;
217 /* the physical address of the first output DMA table */
218 unsigned long out_table_address;
220 /* number of entries in the first output DMA table */
221 unsigned long out_table_num_entries;
223 /* data in the first input table */
224 unsigned long table_data_size;
226 /* distinct user/kernel layout */
227 bool isKernelVirtualAddress;
233 struct sep_driver_build_flow_table_t {
235 unsigned long flow_type;
237 /* flag for input output */
238 unsigned long input_output_flag;
240 /* address value of the data in */
241 unsigned long virt_buff_data_addr;
243 /* size of data in */
244 unsigned long num_virtual_buffers;
246 /* the physical address of the first input DMA table */
247 unsigned long first_table_addr;
249 /* number of entries in the first input DMA table */
250 unsigned long first_table_num_entries;
252 /* data in the first input table */
253 unsigned long first_table_data_size;
255 /* distinct user/kernel layout */
256 bool isKernelVirtualAddress;
260 struct sep_driver_add_flow_table_t {
262 unsigned long flow_id;
264 /* flag for input output */
265 unsigned long inputOutputFlag;
267 /* address value of the data in */
268 unsigned long virt_buff_data_addr;
270 /* size of data in */
271 unsigned long num_virtual_buffers;
273 /* address of the first table */
274 unsigned long first_table_addr;
276 /* number of entries in the first table */
277 unsigned long first_table_num_entries;
279 /* data size of the first table */
280 unsigned long first_table_data_size;
282 /* distinct user/kernel layout */
283 bool isKernelVirtualAddress;
288 command struct for set flow id
290 struct sep_driver_set_flow_id_t {
292 unsigned long flow_id;
296 /* command struct for add tables message */
297 struct sep_driver_add_message_t {
299 unsigned long flow_id;
301 /* message size in bytes */
302 unsigned long message_size_in_bytes;
304 /* address of the message */
305 unsigned long message_address;
308 /* command struct for static pool addresses */
309 struct sep_driver_static_pool_addr_t {
310 /* physical address of the static pool */
311 unsigned long physical_static_address;
313 /* virtual address of the static pool */
314 unsigned long virtual_static_address;
317 /* command struct for getiing offset of the physical address from
318 the start of the mapped area */
319 struct sep_driver_get_mapped_offset_t {
320 /* physical address of the static pool */
321 unsigned long physical_address;
323 /* virtual address of the static pool */
324 unsigned long offset;
327 /* command struct for getting time value and address */
328 struct sep_driver_get_time_t {
329 /* physical address of stored time */
330 unsigned long time_physical_address;
332 /* value of the stored time */
333 unsigned long time_value;
338 structure that represent one entry in the DMA LLI table
340 struct sep_lli_entry_t {
341 /* physical address */
342 unsigned long physical_address;
345 unsigned long block_size;
349 structure that reperesents data needed for lli table construction
351 struct sep_lli_prepare_table_data_t {
352 /* pointer to the memory where the first lli entry to be built */
353 struct sep_lli_entry_t *lli_entry_ptr;
355 /* pointer to the array of lli entries from which the table is to be built */
356 struct sep_lli_entry_t *lli_array_ptr;
358 /* number of elements in lli array */
361 /* number of entries in the created table */
362 int num_table_entries;
364 /* number of array entries processed during table creation */
365 int num_array_entries_processed;
367 /* the totatl data size in the created table */
368 int lli_table_total_data_size;
372 structure that represent tone table - it is not used in code, jkust
373 to show what table looks like
375 struct sep_lli_table_t {
376 /* number of pages mapped in this tables. If 0 - means that the table
377 is not defined (used as a valid flag)*/
378 unsigned long num_pages;
380 pointer to array of page pointers that represent the mapping of the
381 virtual buffer defined by the table to the physical memory. If this
382 pointer is NULL, it means that the table is not defined
383 (used as a valid flag)
385 struct page **table_page_array_ptr;
387 /* maximum flow entries in table */
388 struct sep_lli_entry_t lli_entries[SEP_DRIVER_MAX_FLOW_NUM_ENTRIES_IN_TABLE];
393 structure for keeping the mapping of the virtual buffer into physical pages
395 struct sep_flow_buffer_data {
396 /* pointer to the array of page structs pointers to the pages of the
398 struct page **page_array_ptr;
400 /* number of pages taken by the virtual buffer */
401 unsigned long num_pages;
403 /* this flag signals if this page_array is the last one among many that were
404 sent in one setting to SEP */
405 unsigned long last_page_array_flag;
409 struct that keeps all the data for one flow
411 struct sep_flow_context_t {
413 work struct for handling the flow done interrupt in the workqueue
414 this structure must be in the first place, since it will be used
415 forcasting to the containing flow context
417 struct work_struct flow_wq;
420 unsigned long flow_id;
422 /* additional input tables exists */
423 unsigned long input_tables_flag;
425 /* additional output tables exists */
426 unsigned long output_tables_flag;
428 /* data of the first input file */
429 struct sep_lli_entry_t first_input_table;
431 /* data of the first output table */
432 struct sep_lli_entry_t first_output_table;
434 /* last input table data */
435 struct sep_lli_entry_t last_input_table;
437 /* last output table data */
438 struct sep_lli_entry_t last_output_table;
440 /* first list of table */
441 struct sep_lli_entry_t input_tables_in_process;
443 /* output table in process (in sep) */
444 struct sep_lli_entry_t output_tables_in_process;
446 /* size of messages in bytes */
447 unsigned long message_size_in_bytes;
450 unsigned char message[SEP_MAX_ADD_MESSAGE_LENGTH_IN_BYTES];
456 this function locks SEP by locking the semaphore
461 this function unlocks SEP
463 void sep_unlock(void);
466 this function returns the address of the message shared area
468 void sep_map_shared_area(unsigned long *mappedAddr_ptr);
472 this function returns the address of the message shared area
474 void sep_send_msg_rdy_cmd(void);
478 This function releases all the application virtual
479 buffer physical pages, that were previously locked
481 int sep_free_dma_pages(struct page **page_array_ptr,
482 unsigned long num_pages,
483 unsigned long dirtyFlag);
486 This function creates the input and output dma tables for
487 symmetric operations (AES/DES) according to the block size
490 int sep_construct_dma_tables_from_lli(
491 struct sep_lli_entry_t *lli_in_array,
492 unsigned long sep_in_lli_entries,
493 struct sep_lli_entry_t *lli_out_array,
494 unsigned long sep_out_lli_entries,
495 unsigned long block_size,
496 unsigned long *lli_table_in_ptr,
497 unsigned long *lli_table_out_ptr,
498 unsigned long *in_num_entries_ptr,
499 unsigned long *out_num_entries_ptr,
500 unsigned long *table_data_size_ptr);
503 This function builds input and output DMA tables for synhronic symmetric
504 operations (AES, DES) It also checks that each table is of the modular
507 int sep_prepare_input_output_dma_table(unsigned long app_virt_in_addr,
508 unsigned long app_virt_out_addr,
509 unsigned long data_size,
510 unsigned long block_size,
511 unsigned long *lli_table_in_ptr,
512 unsigned long *lli_table_out_ptr,
513 unsigned long *in_num_entries_ptr,
514 unsigned long *out_num_entries_ptr,
515 unsigned long *table_data_size_ptr,
516 bool isKernelVirtualAddress);
519 This function prepares only input DMA table for synhronic symmetric
522 int sep_prepare_input_dma_table(unsigned long app_virt_addr,
523 unsigned long data_size,
524 unsigned long block_size,
525 unsigned long *lli_table_ptr,
526 unsigned long *num_entries_ptr,
527 unsigned long *table_data_size_ptr,
528 bool isKernelVirtualAddress);
530 /* this functions frees all the resources that were allocated for the building
531 of the LLI DMA tables */
532 void sep_free_dma_resources(void);
535 /* poll(suspend) , until reply from sep */
536 void sep_driver_poll(void);
539 this function handles the request for freeing dma table for
542 int sep_free_dma_table_data_handler(void);