import old mobicore
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos7580.git] / mobicore / include / Public / mc_linux.h
1 /*
2 * Copyright (c) 2013-2014 TRUSTONIC LIMITED
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 /*
15 * The <t-base Driver Kernel Module is a Linux device driver, which represents
16 * the command proxy on the lowest layer to the secure world (Swd). Additional
17 * services like memory allocation via mmap and generation of a MMU tables for
18 * given virtual memory are also supported. IRQ functionality receives
19 * information from the SWd in the non secure world (NWd).
20 * As customary the driver is handled as Linux device driver with "open",
21 * "close" and "ioctl" commands. Access to the driver is possible after the
22 * devices "/dev/mobicore" and "/dev/mobicore-user" have been created.
23 */
24
25 #ifndef _MC_LINUX_H_
26 #define _MC_LINUX_H_
27
28 #include "version.h"
29
30 #ifndef __KERNEL__
31 #include <stdint.h>
32 #endif
33
34 #define MC_ADMIN_DEVNODE "mobicore"
35 #define MC_USER_DEVNODE "mobicore-user"
36
37 /*
38 * Data exchange structure of the MC_DRV_MODULE_INIT ioctl command.
39 * INIT request data to SWD
40 */
41 struct mc_ioctl_init {
42 /* length of notification queue */
43 uint32_t nq_length;
44 /* mcp buffer start/length [16:16] [start, length] */
45 uint32_t mcp_offset;
46 /* length of mcp buffer */
47 uint32_t mcp_length;
48 };
49
50 /*
51 * Data exchange structure of the MC_DRV_MODULE_INFO ioctl command.
52 * INFO request data to the SWD
53 */
54 struct mc_ioctl_info {
55 uint32_t ext_info_id; /* extended info ID */
56 uint32_t state; /* state */
57 uint32_t ext_info; /* extended info */
58 };
59
60 /*
61 * Data exchange structure of the MC_IO_MAP_WSM and MC_IO_MAP_MCI commands.
62 *
63 * Allocate a contiguous memory buffer for a process.
64 * The physical address can be used as for later calls to mmap.
65 * The handle can be used to communicate about this buffer to the Daemon.
66 * For MC_IO_MAP_MCI command, the reused field indicates that MCI was set up
67 * already. I.e. Daemon was restarted.
68 */
69 struct mc_ioctl_map {
70 uint32_t len; /* Buffer length */
71 uint32_t handle; /* WSM handle */
72 uint64_t phys_addr; /* physical address of WSM (or 0) */
73 uint32_t rfu;
74 bool reused; /* if WSM memory was reused, or new allocated */
75 };
76
77 /*
78 * Data exchange structure of the MC_IO_REG_WSM command.
79 *
80 * Allocates a physical MMU table and maps the buffer into this page.
81 * Returns the physical address of the MMU table.
82 * The page alignment will be created and the appropriated pSize and pOffsetMMU
83 * will be modified to the used values.
84 *
85 * We assume the 64 bit compatible one to be the default and the
86 * 32 bit one to be the compat one but we must serve both of them.
87 */
88 struct mc_compat_ioctl_reg_wsm {
89 uint32_t buffer; /* base address of the virtual address */
90 uint32_t len; /* size of the virtual address space */
91 uint32_t pid; /* process id */
92 uint32_t handle; /* driver handle for locked memory */
93 uint64_t table_phys; /* physical address of the MMU table */
94 };
95
96 struct mc_ioctl_reg_wsm {
97 uint64_t buffer; /* base address of the virtual address */
98 uint32_t len; /* size of the virtual address space */
99 uint32_t pid; /* process id */
100 uint32_t handle; /* driver handle for locked memory */
101 uint64_t table_phys;/* physical address of the MMU table */
102 };
103
104 /*
105 * Data exchange structure of the MC_IO_RESOLVE_CONT_WSM ioctl command.
106 */
107 struct mc_ioctl_resolv_cont_wsm {
108 /* driver handle for buffer */
109 uint32_t handle;
110 /* length memory */
111 uint32_t length;
112 /* base address of memory */
113 uint64_t phys;
114 /* fd to owner of the buffer */
115 int32_t fd;
116 };
117
118 /*
119 * Data exchange structure of the MC_IO_RESOLVE_WSM ioctl command.
120 */
121 struct mc_ioctl_resolv_wsm {
122 /* driver handle for buffer */
123 uint32_t handle;
124 /* fd to owner of the buffer */
125 int32_t fd;
126 /* base address of memory */
127 uint64_t phys;
128 };
129
130
131 /*
132 * defines for the ioctl mobicore driver module function call from user space.
133 */
134 /* MobiCore IOCTL magic number */
135 #define MC_IOC_MAGIC 'M'
136
137 #define MC_IO_INIT _IOWR(MC_IOC_MAGIC, 0, struct mc_ioctl_init)
138 #define MC_IO_INFO _IOWR(MC_IOC_MAGIC, 1, struct mc_ioctl_info)
139 #define MC_IO_VERSION _IOR(MC_IOC_MAGIC, 2, uint32_t)
140 /*
141 * ioctl parameter to send the YIELD command to the SWD.
142 * Only possible in Privileged Mode.
143 * ioctl(fd, MC_DRV_MODULE_YIELD)
144 */
145 #define MC_IO_YIELD _IO(MC_IOC_MAGIC, 3)
146 /*
147 * ioctl parameter to send the NSIQ signal to the SWD.
148 * Only possible in Privileged Mode
149 * ioctl(fd, MC_DRV_MODULE_NSIQ)
150 */
151 #define MC_IO_NSIQ _IO(MC_IOC_MAGIC, 4)
152 /*
153 * Free's memory which is formerly allocated by the driver's mmap
154 * command. The parameter must be this mmaped address.
155 * The internal instance data regarding to this address are deleted as
156 * well as each according memory page and its appropriated reserved bit
157 * is cleared (ClearPageReserved).
158 * Usage: ioctl(fd, MC_DRV_MODULE_FREE, &address) with address being of
159 * type long address
160 */
161 #define MC_IO_FREE _IO(MC_IOC_MAGIC, 5)
162 /*
163 * Creates a MMU Table of the given base address and the size of the
164 * data.
165 * Parameter: mc_ioctl_reg_wsm
166 *
167 * Since the end ID is also based on the size of the structure it is
168 * safe to use the same ID(6) for both
169 */
170 #define MC_IO_REG_WSM _IOWR(MC_IOC_MAGIC, 6, struct mc_ioctl_reg_wsm)
171 #define MC_COMPAT_REG_WSM _IOWR(MC_IOC_MAGIC, 6, \
172 struct mc_compat_ioctl_reg_wsm)
173
174 #define MC_IO_UNREG_WSM _IO(MC_IOC_MAGIC, 7)
175 #define MC_IO_LOCK_WSM _IO(MC_IOC_MAGIC, 8)
176 #define MC_IO_UNLOCK_WSM _IO(MC_IOC_MAGIC, 9)
177
178 /*
179 * Allocate contiguous memory for a process for later mapping with mmap.
180 * MC_IO_MAP_WSM usual operation, pages are registered in
181 * device structure and freed later.
182 * MC_IO_MAP_MCI get Instance of MCI, allocates or mmaps
183 * the MCI to daemon
184 */
185 #define MC_IO_MAP_WSM _IOWR(MC_IOC_MAGIC, 11, struct mc_ioctl_map)
186 #define MC_IO_MAP_MCI _IOWR(MC_IOC_MAGIC, 12, struct mc_ioctl_map)
187
188 /*
189 * Clean orphaned WSM buffers. Only available to the daemon and should
190 * only be carried out if the TLC crashes or otherwise calls exit() in
191 * an unexpected manner.
192 * The clean is needed together with the lock/unlock mechanism so the daemon
193 * has clear control of the mapped buffers so it can close a Trustlet before
194 * release all the WSM buffers, otherwise the Trustlet would be able to write
195 * to possibly kernel memory areas
196 */
197 #define MC_IO_CLEAN_WSM _IO(MC_IOC_MAGIC, 14)
198
199 /*
200 * Get MMU phys address of a buffer handle allocated to the user.
201 * Only available to the daemon.
202 */
203 #define MC_IO_RESOLVE_WSM _IOWR(MC_IOC_MAGIC, 15, \
204 struct mc_ioctl_resolv_wsm)
205
206 /*
207 * Get the phys address & length of a allocated contiguous buffer.
208 * Only available to the daemon */
209 #define MC_IO_RESOLVE_CONT_WSM _IOWR(MC_IOC_MAGIC, 16, \
210 struct mc_ioctl_resolv_cont_wsm)
211
212 /*
213 * Setup the mem traces when called.
214 * Only available to the daemon */
215 #define MC_IO_LOG_SETUP _IO(MC_IOC_MAGIC, 17)
216
217 #endif /* _MC_LINUX_H_ */