KVM: x86: update KVM_SAVE_MSRS_BEGIN to correct value
[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-2011 Intel Corporation. All rights reserved.
6  *  Contributions(c) 2009-2011 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; version 2 of the License.
11  *
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
15  *  more details.
16  *
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.
20  *
21  *  CONTACTS:
22  *
23  *  Mark Allyn          mark.a.allyn@intel.com
24  *  Jayant Mangalampalli jayant.mangalampalli@intel.com
25  *
26  *  CHANGES:
27  *
28  *  2010.09.14  Upgrade to Medfield
29  *  2011.02.22  Enable kernel crypto
30  *
31  */
32
33 #ifndef __SEP_DRIVER_API_H__
34 #define __SEP_DRIVER_API_H__
35
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
40
41 /* Power state */
42 #define SEP_DRIVER_POWERON              1
43 #define SEP_DRIVER_POWEROFF             2
44
45 /* Following enums are used only for kernel crypto api */
46 enum type_of_request {
47         NO_REQUEST,
48         AES_CBC,
49         AES_ECB,
50         DES_CBC,
51         DES_ECB,
52         DES3_ECB,
53         DES3_CBC,
54         SHA1,
55         MD5,
56         SHA224,
57         SHA256
58         };
59
60 enum hash_stage {
61         HASH_INIT,
62         HASH_UPDATE,
63         HASH_FINISH,
64         HASH_DIGEST,
65         HASH_FINUP_DATA,
66         HASH_FINUP_FINISH
67 };
68
69 /*
70   structure that represents DCB
71 */
72 struct sep_dcblock {
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 */
88         u32     tail_data_size;
89         /* input tail data array */
90         u8      tail_data[68];
91 };
92
93 /*
94         command structure for building dcb block (currently for ext app only
95 */
96 struct build_dcb_struct {
97         /* address value of the data in */
98         aligned_u64 app_in_address;
99         /* size of data in */
100         u32  data_in_size;
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 */
105         u32  block_size;
106         /* the size of the block of the operation - if needed,
107         every table will be modulo this parameter */
108         u32  tail_block_size;
109
110         /* which application calls the driver DX or applet */
111         u32  is_applet;
112 };
113
114 /*
115         command structure for building dcb block for kernel crypto
116 */
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 */
126         u32  block_size;
127         /* the size of the block of the operation - if needed,
128         every table will be modulo this parameter */
129         u32  tail_block_size;
130
131         /* which application calls the driver DX or applet */
132         u32  is_applet;
133
134         struct scatterlist *src_sg;
135         struct scatterlist *dst_sg;
136 };
137
138 /**
139  * @struct sep_dma_map
140  *
141  * Structure that contains all information needed for mapping the user pages
142  *           or kernel buffers for dma operations
143  *
144  *
145  */
146 struct sep_dma_map {
147         /* mapped dma address */
148         dma_addr_t    dma_addr;
149         /* size of the mapped data */
150         size_t        size;
151 };
152
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;
157
158         /* array of pointers to the pages that represent out
159         data for the synchronic DMA action */
160         struct page **out_page_array;
161
162         /* number of pages in the sep_in_page_array */
163         u32 in_num_pages;
164
165         /* number of pages in the sep_out_page_array */
166         u32 out_num_pages;
167
168         /* map array of the input data */
169         struct sep_dma_map *in_map_array;
170
171         /* map array of the output data */
172         struct sep_dma_map *out_map_array;
173
174         /* number of entries of the input mapp array */
175         u32 in_map_num_entries;
176
177         /* number of entries of the output mapp array */
178         u32 out_map_num_entries;
179
180         /* Scatter list for kernel operations */
181         struct scatterlist *src_sg;
182         struct scatterlist *dst_sg;
183 };
184
185
186 /* command struct for translating rar handle to bus address
187    and setting it at predefined location */
188 struct rar_hndl_to_bus_struct {
189
190         /* rar handle */
191         aligned_u64 rar_handle;
192 };
193
194 /*
195   structure that represent one entry in the DMA LLI table
196 */
197 struct sep_lli_entry {
198         /* physical address */
199         u32 bus_address;
200
201         /* block size */
202         u32 block_size;
203 };
204
205 /*
206  * header format for each fastcall write operation
207  */
208 struct sep_fastcall_hdr {
209         u32 magic;
210         u32 secure_dma;
211         u32 msg_len;
212         u32 num_dcbs;
213 };
214
215 /*
216  * structure used in file pointer's private data field
217  * to track the status of the calls to the various
218  * driver interface
219  */
220 struct sep_call_status {
221         unsigned long status;
222 };
223
224 /*
225  * format of dma context buffer used to store all DMA-related
226  * context information of a particular transaction
227  */
228 struct sep_dma_context {
229         /* number of data control blocks */
230         u32 nr_dcb_creat;
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 */
234         u32 dmatables_len;
235         /* size of input data */
236         u32 input_data_len;
237         /* secure dma use (for imr memory restriced area in output */
238         bool secure_dma;
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;
243 };
244
245 /*
246  * format for file pointer's private_data field
247  */
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;
253 };
254
255
256 /* Functions used by sep_crypto */
257
258 /**
259  * sep_queue_status_remove - Removes transaction from status queue
260  * @sep: SEP device
261  * @sep_queue_info: pointer to status queue
262  *
263  * This function will removes information about transaction from the queue.
264  */
265 void sep_queue_status_remove(struct sep_device *sep,
266                                       struct sep_queue_info **queue_elem);
267 /**
268  * sep_queue_status_add - Adds transaction to status queue
269  * @sep: SEP device
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)
275  *
276  * This function adds information about about transaction started to the status
277  * queue.
278  */
279 struct sep_queue_info *sep_queue_status_add(
280                                                 struct sep_device *sep,
281                                                 u32 opcode,
282                                                 u32 size,
283                                                 u32 pid,
284                                                 u8 *name, size_t name_len);
285
286 /**
287  *      sep_create_dcb_dmatables_context_kernel - Creates DCB & MLLI/DMA table context
288  *      for kernel crypto
289  *      @sep: SEP device
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
295  */
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,
301                         const u32 num_dcbs);
302
303 /**
304  *      sep_activate_dcb_dmatables_context - Takes DCB & DMA tables
305  *                                              contexts into use
306  *      @sep: SEP device
307  *      @dcb_region: DCB region copy
308  *      @dmatables_region: MLLI/DMA tables copy
309  *      @dma_ctx: DMA context for current transaction
310  */
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);
315
316 /**
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
326  *
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
332  */
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,
336         u32  data_in_size,
337         u32  block_size,
338         u32  tail_block_size,
339         bool isapplet,
340         bool    is_kva,
341         bool    secure_dma,
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);
347
348 /**
349  * sep_free_dma_table_data_handler - free DMA table
350  * @sep: pointere to struct sep_device
351  * @dma_ctx: dma context
352  *
353  * Handles the request to  free DMA table for synchronic actions
354  */
355 int sep_free_dma_table_data_handler(struct sep_device *sep,
356                                            struct sep_dma_context **dma_ctx);
357 /**
358  * sep_send_command_handler - kick off a command
359  * @sep: SEP being signalled
360  *
361  * This function raises interrupt to SEP that signals that is has a new
362  * command from the host
363  *
364  * Note that this function does fall under the ioctl lock
365  */
366 int sep_send_command_handler(struct sep_device *sep);
367
368 /**
369  *      sep_wait_transaction - Used for synchronizing transactions
370  *      @sep: SEP device
371  */
372 int sep_wait_transaction(struct sep_device *sep);
373
374 /**
375  * IOCTL command defines
376  */
377 /* magic number 1 of the sep IOCTL command */
378 #define SEP_IOC_MAGIC_NUMBER    's'
379
380 /* sends interrupt to sep that message is ready */
381 #define SEP_IOCSENDSEPCOMMAND    \
382         _IO(SEP_IOC_MAGIC_NUMBER, 0)
383
384 /* end transaction command */
385 #define SEP_IOCENDTRANSACTION    \
386         _IO(SEP_IOC_MAGIC_NUMBER, 15)
387
388 #define SEP_IOCPREPAREDCB                                       \
389         _IOW(SEP_IOC_MAGIC_NUMBER, 35, struct build_dcb_struct)
390
391 #define SEP_IOCFREEDCB                                  \
392         _IO(SEP_IOC_MAGIC_NUMBER, 36)
393
394 struct sep_device;
395
396 #define SEP_IOCPREPAREDCB_SECURE_DMA    \
397         _IOW(SEP_IOC_MAGIC_NUMBER, 38, struct build_dcb_struct)
398
399 #define SEP_IOCFREEDCB_SECURE_DMA       \
400         _IO(SEP_IOC_MAGIC_NUMBER, 39)
401
402 #endif