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