mmc: core: Fix HS switch failure in mmc_select_hs400
[firefly-linux-kernel-4.4.55.git] / security / optee_linuxdriver / core / tee_supp_com.h
1 /*
2  * Copyright (c) 2014, STMicroelectronics International N.V.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License Version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  */
13 #ifndef TEE_SUPP_COMM_H
14 #define TEE_SUPP_COMM_H
15
16 #define TEE_RPC_ICMD_ALLOCATE 0x1001
17 #define TEE_RPC_ICMD_FREE     0x1002
18 #define TEE_RPC_ICMD_INVOKE   0x1003
19
20 #define TEE_RPC_NBR_BUFF 1
21 #define TEE_RPC_DATA_SIZE 64
22 #define TEE_RPC_BUFFER_NUMBER 5
23
24 #define TEE_RPC_STATE_IDLE    0x00
25 #define TEE_RPC_STATE_ACTIVE  0x01
26
27 /* Keep aligned with optee_client (user space) */
28 #define TEE_RPC_BUFFER          0x00000001
29 #define TEE_RPC_VALUE           0x00000002
30 #define TEE_RPC_LOAD_TA         0x10000001
31 /*
32  * Handled within the driver only
33  * Keep aligned with optee_os (secure space)
34  */
35 #define TEE_RPC_MUTEX_WAIT              0x20000000
36 #define TEE_RPC_WAIT_QUEUE_SLEEP        0x20000001
37 #define TEE_RPC_WAIT_QUEUE_WAKEUP       0x20000002
38 #define TEE_RPC_WAIT                    0x30000000
39
40 /* Parameters for TEE_RPC_WAIT_MUTEX above */
41 #define TEE_MUTEX_WAIT_SLEEP    0
42 #define TEE_MUTEX_WAIT_WAKEUP   1
43 #define TEE_MUTEX_WAIT_DELETE   2
44
45 #include <linux/semaphore.h>
46
47 /**
48  * struct tee_rpc_bf - Contains definition of the tee com buffer
49  * @state: Buffer state
50  * @data: Command data
51  */
52 struct tee_rpc_bf {
53         uint32_t state;
54         uint8_t data[TEE_RPC_DATA_SIZE];
55 };
56
57 struct tee_rpc_alloc {
58         uint32_t size;  /* size of block */
59         void *data;     /* pointer to data */
60         void *shm;      /* pointer to an opaque data, being shm structure */
61 };
62
63 struct tee_rpc_free {
64         void *shm;      /* pointer to an opaque data, being shm structure */
65 };
66
67 struct tee_rpc_cmd {
68         void *buffer;
69         uint32_t size;
70         uint32_t type;
71         int fd;
72 };
73
74 struct tee_rpc_invoke {
75         uint32_t cmd;
76         uint32_t res;
77         uint32_t nbr_bf;
78         struct tee_rpc_cmd cmds[TEE_RPC_BUFFER_NUMBER];
79 };
80
81 struct tee_rpc {
82         struct tee_rpc_invoke commToUser;
83         struct tee_rpc_invoke commFromUser;
84         struct semaphore datatouser;
85         struct semaphore datafromuser;
86         struct mutex outsync; /* Out sync mutex */
87         struct mutex insync; /* In sync mutex */
88         struct mutex reqsync; /* Request sync mutex */
89         atomic_t  used;
90 };
91
92 enum teec_rpc_result {
93         TEEC_RPC_OK,
94         TEEC_RPC_FAIL
95 };
96
97 struct tee;
98
99 int tee_supp_init(struct tee *tee);
100 void tee_supp_deinit(struct tee *tee);
101
102 enum teec_rpc_result tee_supp_cmd(struct tee *tee,
103                                   uint32_t id, void *data, size_t datalen);
104
105 ssize_t tee_supp_read(struct file *filp, char __user *buffer,
106                   size_t length, loff_t *offset);
107
108 ssize_t tee_supp_write(struct file *filp, const char __user *buffer,
109                    size_t length, loff_t *offset);
110
111 #endif