c9f4e56057fbd8bc5d6d755f7c979626619bacc2
[cascardo/linux.git] / drivers / staging / sep / sep_driver_api.h
1 /*
2  *
3  *  sep_driver_api.h - Security Processor Driver api definitions
4  *
5  *  Copyright(c) 2009 Intel Corporation. All rights reserved.
6  *  Copyright(c) 2009 Discretix. All rights reserved.
7  *
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)
11  *  any later version.
12  *
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
16  *  more details.
17  *
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.
21  *
22  *  CONTACTS:
23  *
24  *  Mark Allyn          mark.a.allyn@intel.com
25  *
26  *  CHANGES:
27  *
28  *  2009.06.26  Initial publish
29  *
30  */
31
32 #ifndef __SEP_DRIVER_API_H__
33 #define __SEP_DRIVER_API_H__
34
35
36
37 /*----------------------------------------------------------------
38   IOCTL command defines
39   -----------------------------------------------------------------*/
40
41 /* magic number 1 of the sep IOCTL command */
42 #define SEP_IOC_MAGIC_NUMBER                           's'
43
44 /* sends interrupt to sep that message is ready */
45 #define SEP_IOCSENDSEPCOMMAND                 _IO(SEP_IOC_MAGIC_NUMBER , 0)
46
47 /* sends interrupt to sep that message is ready */
48 #define SEP_IOCSENDSEPRPLYCOMMAND             _IO(SEP_IOC_MAGIC_NUMBER , 1)
49
50 /* allocate memory in data pool */
51 #define SEP_IOCALLOCDATAPOLL                  _IO(SEP_IOC_MAGIC_NUMBER , 2)
52
53 /* write to pre-allocated  memory in data pool */
54 #define SEP_IOCWRITEDATAPOLL                  _IO(SEP_IOC_MAGIC_NUMBER , 3)
55
56 /* read from  pre-allocated  memory in data pool */
57 #define SEP_IOCREADDATAPOLL                   _IO(SEP_IOC_MAGIC_NUMBER , 4)
58
59 /* create sym dma lli tables */
60 #define SEP_IOCCREATESYMDMATABLE              _IO(SEP_IOC_MAGIC_NUMBER , 5)
61
62 /* create flow dma lli tables */
63 #define SEP_IOCCREATEFLOWDMATABLE             _IO(SEP_IOC_MAGIC_NUMBER , 6)
64
65 /* free dynamic data aalocated during table creation */
66 #define SEP_IOCFREEDMATABLEDATA                _IO(SEP_IOC_MAGIC_NUMBER , 7)
67
68 /* get the static pool area addersses (physical and virtual) */
69 #define SEP_IOCGETSTATICPOOLADDR               _IO(SEP_IOC_MAGIC_NUMBER , 8)
70
71 /* set flow id command */
72 #define SEP_IOCSETFLOWID                       _IO(SEP_IOC_MAGIC_NUMBER , 9)
73
74 /* add tables to the dynamic flow */
75 #define SEP_IOCADDFLOWTABLE                    _IO(SEP_IOC_MAGIC_NUMBER , 10)
76
77 /* add flow add tables message */
78 #define SEP_IOCADDFLOWMESSAGE                  _IO(SEP_IOC_MAGIC_NUMBER , 11)
79
80 /* start sep command */
81 #define SEP_IOCSEPSTART                        _IO(SEP_IOC_MAGIC_NUMBER , 12)
82
83 /* init sep command */
84 #define SEP_IOCSEPINIT                         _IO(SEP_IOC_MAGIC_NUMBER , 13)
85
86 /* set non blocking mode */
87 #define SEP_IOCSETAPIMODE                      _IO(SEP_IOC_MAGIC_NUMBER , 14)
88
89 /* end transaction command */
90 #define SEP_IOCENDTRANSACTION                  _IO(SEP_IOC_MAGIC_NUMBER , 15)
91
92 /* reallocate cache and resident */
93 #define SEP_IOCREALLOCCACHERES                 _IO(SEP_IOC_MAGIC_NUMBER , 16)
94
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)
97
98 /* get time address and value */
99 #define SEP_IOCGETIME                          _IO(SEP_IOC_MAGIC_NUMBER , 19)
100
101 /*-------------------------------------------
102     TYPEDEFS
103 ----------------------------------------------*/
104
105 /*
106   init command struct
107 */
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;
111
112         /* start address of resident */
113         unsigned long message_size_in_words;
114
115 };
116
117
118 /*
119   realloc cache resident command
120 */
121 struct sep_driver_realloc_cache_resident_t {
122         /* base address */
123         unsigned long base_addr;
124
125         /* current cache address */
126         unsigned long cache_addr;
127
128         /* cache size in bytes */
129         unsigned long cache_size_in_bytes;
130
131         /* current resident address */
132         unsigned long resident_addr;
133
134         /* resident size in bytes */
135         unsigned long resident_size_in_bytes;
136
137         /* new cache address */
138         unsigned long new_cache_addr;
139
140         /* new resident address */
141         unsigned long new_resident_addr;
142
143         /* new resident address */
144         unsigned long new_shared_area_addr;
145
146         /* new base address */
147         unsigned long new_base_addr;
148 };
149
150 /*
151   set api mode command struct
152 */
153 struct sep_driver_set_api_mode_t {
154         /* mode to set - 1 - blocking, 0 - non-blocking */
155         unsigned long mode;
156 };
157
158 struct sep_driver_alloc_t {
159         /* virtual address of allocated space */
160         unsigned long offset;
161
162         /* physical address of allocated space */
163         unsigned long phys_address;
164
165         /* number of bytes to allocate */
166         unsigned long num_bytes;
167 };
168
169 /*
170  */
171 struct sep_driver_write_t {
172         /* application space address */
173         unsigned long app_address;
174
175         /* address of the data pool */
176         unsigned long datapool_address;
177
178         /* number of bytes to write */
179         unsigned long num_bytes;
180 };
181
182 /*
183  */
184 struct sep_driver_read_t {
185         /* application space address */
186         unsigned long app_address;
187
188         /* address of the data pool */
189         unsigned long datapool_address;
190
191         /* number of bytes to read */
192         unsigned long num_bytes;
193 };
194
195 /*
196 */
197 struct sep_driver_build_sync_table_t {
198         /* address value of the data in */
199         unsigned long app_in_address;
200
201         /* size of data in */
202         unsigned long data_in_size;
203
204         /* address of the data out */
205         unsigned long app_out_address;
206
207         /* the size of the block of the operation - if needed,
208            every table will be modulo this parameter */
209         unsigned long block_size;
210
211         /* the physical address of the first input DMA table */
212         unsigned long in_table_address;
213
214         /* number of entries in the first input DMA table */
215         unsigned long in_table_num_entries;
216
217         /* the physical address of the first output DMA table */
218         unsigned long out_table_address;
219
220         /* number of entries in the first output DMA table */
221         unsigned long out_table_num_entries;
222
223         /* data in the first input table */
224         unsigned long table_data_size;
225
226         /* distinct user/kernel layout */
227         bool isKernelVirtualAddress;
228
229 };
230
231 /*
232 */
233 struct sep_driver_build_flow_table_t {
234         /* flow type */
235         unsigned long flow_type;
236
237         /* flag for input output */
238         unsigned long input_output_flag;
239
240         /* address value of the data in */
241         unsigned long virt_buff_data_addr;
242
243         /* size of data in */
244         unsigned long num_virtual_buffers;
245
246         /* the physical address of the first input DMA table */
247         unsigned long first_table_addr;
248
249         /* number of entries in the first input DMA table */
250         unsigned long first_table_num_entries;
251
252         /* data in the first input table */
253         unsigned long first_table_data_size;
254
255         /* distinct user/kernel layout */
256         bool isKernelVirtualAddress;
257 };
258
259
260 struct sep_driver_add_flow_table_t {
261         /* flow id  */
262         unsigned long flow_id;
263
264         /* flag for input output */
265         unsigned long inputOutputFlag;
266
267         /* address value of the data in */
268         unsigned long virt_buff_data_addr;
269
270         /* size of data in */
271         unsigned long num_virtual_buffers;
272
273         /* address of the first table */
274         unsigned long first_table_addr;
275
276         /* number of entries in the first table */
277         unsigned long first_table_num_entries;
278
279         /* data size of the first table */
280         unsigned long first_table_data_size;
281
282         /* distinct user/kernel layout */
283         bool isKernelVirtualAddress;
284
285 };
286
287 /*
288   command struct for set flow id
289 */
290 struct sep_driver_set_flow_id_t {
291         /* flow id to set */
292         unsigned long flow_id;
293 };
294
295
296 /* command struct for add tables message */
297 struct sep_driver_add_message_t {
298         /* flow id to set */
299         unsigned long flow_id;
300
301         /* message size in bytes */
302         unsigned long message_size_in_bytes;
303
304         /* address of the message */
305         unsigned long message_address;
306 };
307
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;
312
313         /* virtual address of the static pool */
314         unsigned long virtual_static_address;
315 };
316
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;
322
323         /* virtual address of the static pool */
324         unsigned long offset;
325 };
326
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;
331
332         /* value of the stored time */
333         unsigned long time_value;
334 };
335
336
337 /*
338   structure that represent one entry in the DMA LLI table
339 */
340 struct sep_lli_entry_t {
341         /* physical address */
342         unsigned long physical_address;
343
344         /* block size */
345         unsigned long block_size;
346 };
347
348 /*
349   structure that reperesents data needed for lli table construction
350 */
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;
354
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;
357
358         /* number of elements in lli array */
359         int lli_array_size;
360
361         /* number of entries in the created table */
362         int num_table_entries;
363
364         /* number of array entries processed during table creation */
365         int num_array_entries_processed;
366
367         /* the totatl data size in the created table */
368         int lli_table_total_data_size;
369 };
370
371 /*
372   structure that represent tone table - it is not used in code, jkust
373   to show what table looks like
374 */
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;
379         /*
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)
384          */
385         struct page **table_page_array_ptr;
386
387         /* maximum flow entries in table */
388         struct sep_lli_entry_t lli_entries[SEP_DRIVER_MAX_FLOW_NUM_ENTRIES_IN_TABLE];
389 };
390
391
392 /*
393   structure for keeping the mapping of the virtual buffer into physical pages
394 */
395 struct sep_flow_buffer_data {
396         /* pointer to the array of page structs pointers to the pages of the
397            virtual buffer */
398         struct page **page_array_ptr;
399
400         /* number of pages taken by the virtual buffer */
401         unsigned long num_pages;
402
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;
406 };
407
408 /*
409   struct that keeps all the data for one flow
410 */
411 struct sep_flow_context_t {
412         /*
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
416          */
417         struct work_struct flow_wq;
418
419         /* flow id */
420         unsigned long flow_id;
421
422         /* additional input tables exists */
423         unsigned long input_tables_flag;
424
425         /* additional output tables exists */
426         unsigned long output_tables_flag;
427
428         /*  data of the first input file */
429         struct sep_lli_entry_t first_input_table;
430
431         /* data of the first output table */
432         struct sep_lli_entry_t first_output_table;
433
434         /* last input table data */
435         struct sep_lli_entry_t last_input_table;
436
437         /* last output table data */
438         struct sep_lli_entry_t last_output_table;
439
440         /* first list of table */
441         struct sep_lli_entry_t input_tables_in_process;
442
443         /* output table in process (in sep) */
444         struct sep_lli_entry_t output_tables_in_process;
445
446         /* size of messages in bytes */
447         unsigned long message_size_in_bytes;
448
449         /* message */
450         unsigned char message[SEP_MAX_ADD_MESSAGE_LENGTH_IN_BYTES];
451 };
452
453
454 #endif