2 * Copyright (c) 2013-2014 TRUSTONIC LIMITED
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.
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.
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.
34 #define MC_ADMIN_DEVNODE "mobicore"
35 #define MC_USER_DEVNODE "mobicore-user"
38 * Data exchange structure of the MC_DRV_MODULE_INIT ioctl command.
39 * INIT request data to SWD
41 struct mc_ioctl_init
{
42 /* length of notification queue */
44 /* mcp buffer start/length [16:16] [start, length] */
46 /* length of mcp buffer */
51 * Data exchange structure of the MC_DRV_MODULE_INFO ioctl command.
52 * INFO request data to the SWD
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 */
61 * Data exchange structure of the MC_IO_MAP_WSM and MC_IO_MAP_MCI commands.
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.
70 uint32_t len
; /* Buffer length */
71 uint32_t handle
; /* WSM handle */
72 uint64_t phys_addr
; /* physical address of WSM (or 0) */
74 bool reused
; /* if WSM memory was reused, or new allocated */
78 * Data exchange structure of the MC_IO_REG_WSM command.
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.
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.
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 */
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 */
105 * Data exchange structure of the MC_IO_RESOLVE_CONT_WSM ioctl command.
107 struct mc_ioctl_resolv_cont_wsm
{
108 /* driver handle for buffer */
112 /* base address of memory */
114 /* fd to owner of the buffer */
119 * Data exchange structure of the MC_IO_RESOLVE_WSM ioctl command.
121 struct mc_ioctl_resolv_wsm
{
122 /* driver handle for buffer */
124 /* fd to owner of the buffer */
126 /* base address of memory */
132 * defines for the ioctl mobicore driver module function call from user space.
134 /* MobiCore IOCTL magic number */
135 #define MC_IOC_MAGIC 'M'
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)
141 * ioctl parameter to send the YIELD command to the SWD.
142 * Only possible in Privileged Mode.
143 * ioctl(fd, MC_DRV_MODULE_YIELD)
145 #define MC_IO_YIELD _IO(MC_IOC_MAGIC, 3)
147 * ioctl parameter to send the NSIQ signal to the SWD.
148 * Only possible in Privileged Mode
149 * ioctl(fd, MC_DRV_MODULE_NSIQ)
151 #define MC_IO_NSIQ _IO(MC_IOC_MAGIC, 4)
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
161 #define MC_IO_FREE _IO(MC_IOC_MAGIC, 5)
163 * Creates a MMU Table of the given base address and the size of the
165 * Parameter: mc_ioctl_reg_wsm
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
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)
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)
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
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)
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
197 #define MC_IO_CLEAN_WSM _IO(MC_IOC_MAGIC, 14)
200 * Get MMU phys address of a buffer handle allocated to the user.
201 * Only available to the daemon.
203 #define MC_IO_RESOLVE_WSM _IOWR(MC_IOC_MAGIC, 15, \
204 struct mc_ioctl_resolv_wsm)
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)
213 * Setup the mem traces when called.
214 * Only available to the daemon */
215 #define MC_IO_LOG_SETUP _IO(MC_IOC_MAGIC, 17)
217 #endif /* _MC_LINUX_H_ */