blob: 98e7af1dae8fe2ed3c5f2dbfd28bded5ced20e0a [file] [log] [blame]
Oana Medvesan8f5df3a2013-03-04 19:04:03 +01001/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +02002 * The MobiCore Driver Kernel Module is a Linux device driver, which represents
3 * the command proxy on the lowest layer to the secure world (Swd). Additional
Oana Medvesan8dfbf012013-12-20 15:40:49 +01004 * services like memory allocation via mmap and generation of a MMU tables for
Oana Medvesan8f5df3a2013-03-04 19:04:03 +01005 * given virtual memory are also supported. IRQ functionality receives
Lukas Häneldb4b53e2012-10-22 13:49:41 +02006 * information from the SWd in the non secure world (NWd).
7 * As customary the driver is handled as linux device driver with "open",
8 * "close" and "ioctl" commands. Access to the driver is possible after the
9 * device "/dev/mobicore" has been opened.
10 * The MobiCore Driver Kernel Module must be installed via
11 * "insmod mcDrvModule.ko".
12 *
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010013 * <-- Copyright Giesecke & Devrient GmbH 2010-2012 -->
14 * <-- Copyright Trustonic Limited 2013 -->
Lukas Häneldb4b53e2012-10-22 13:49:41 +020015 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. The name of the author may not be used to endorse or promote
25 * products derived from this software without specific prior
26 * written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
29 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
34 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef _MC_LINUX_H_
42#define _MC_LINUX_H_
43
44#include "version.h"
45
Oana Medvesan74024a12013-07-04 14:49:22 +020046#ifndef __KERNEL__
47#include <stdint.h>
48#endif
49
Lukas Häneldb4b53e2012-10-22 13:49:41 +020050#define MC_ADMIN_DEVNODE "mobicore"
51#define MC_USER_DEVNODE "mobicore-user"
52
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010053/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +020054 * Data exchange structure of the MC_DRV_MODULE_INIT ioctl command.
55 * INIT request data to SWD
56 */
57struct mc_ioctl_init {
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010058 /* length of notification queue */
Lukas Häneldb4b53e2012-10-22 13:49:41 +020059 uint32_t nq_length;
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010060 /* mcp buffer start/length [16:16] [start, length] */
Lukas Häneldb4b53e2012-10-22 13:49:41 +020061 uint32_t mcp_offset;
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010062 /* length of mcp buffer */
Lukas Häneldb4b53e2012-10-22 13:49:41 +020063 uint32_t mcp_length;
64};
65
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010066/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +020067 * Data exchange structure of the MC_DRV_MODULE_INFO ioctl command.
68 * INFO request data to the SWD
69 */
70struct mc_ioctl_info {
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010071 uint32_t ext_info_id; /* extended info ID */
72 uint32_t state; /* state */
73 uint32_t ext_info; /* extended info */
Lukas Häneldb4b53e2012-10-22 13:49:41 +020074};
75
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010076/*
Oana Medvesan8dfbf012013-12-20 15:40:49 +010077 * Data exchange structure of the MC_IO_MAP_WSM and MC_IO_MAP_MCI commands.
Lukas Häneldb4b53e2012-10-22 13:49:41 +020078 *
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010079 * Allocate a contiguous memory buffer for a process.
80 * The physical address can be used as for later calls to mmap.
81 * The handle can be used to communicate about this buffer to the Daemon.
82 * For MC_IO_MAP_MCI command, the reused field indicates that MCI was set up
83 * already. I.e. Daemon was restarted.
Lukas Häneldb4b53e2012-10-22 13:49:41 +020084 */
85struct mc_ioctl_map {
Oana Medvesan8dfbf012013-12-20 15:40:49 +010086 size_t len; /* Buffer length */
87 uint32_t handle; /* WSM handle */
88 uint64_t phys_addr; /* physical address of WSM (or 0) */
89 unsigned long addr; /* Virtual address */
90 bool reused; /* if WSM memory was reused, or new allocated */
Lukas Häneldb4b53e2012-10-22 13:49:41 +020091};
92
Oana Medvesan8f5df3a2013-03-04 19:04:03 +010093/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +020094 * Data exchange structure of the MC_IO_REG_WSM command.
95 *
Oana Medvesan8dfbf012013-12-20 15:40:49 +010096 * Allocates a physical MMU table and maps the buffer into this page.
97 * Returns the physical address of the MMU table.
98 * The page alignment will be created and the appropriated pSize and pOffsetMMU
Lukas Häneldb4b53e2012-10-22 13:49:41 +020099 * will be modified to the used values.
100 */
101struct mc_ioctl_reg_wsm {
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100102 uint32_t buffer; /* base address of the virtual address */
103 uint32_t len; /* size of the virtual address space */
104 uint32_t pid; /* process id */
105 uint32_t handle; /* driver handle for locked memory */
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100106 uint64_t table_phys; /* physical address of the MMU table */
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200107};
108
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100109/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200110 * Data exchange structure of the MC_IO_RESOLVE_CONT_WSM ioctl command.
111 */
112struct mc_ioctl_resolv_cont_wsm {
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100113 /* driver handle for buffer */
114 uint32_t handle;
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100115 /* length memory */
116 uint32_t length;
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100117 /* base address of memory */
118 uint64_t phys;
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100119 /* fd to owner of the buffer */
120 int32_t fd;
121};
122
123/*
124 * Data exchange structure of the MC_IO_RESOLVE_WSM ioctl command.
125 */
126struct mc_ioctl_resolv_wsm {
127 /* driver handle for buffer */
128 uint32_t handle;
129 /* fd to owner of the buffer */
130 int32_t fd;
131 /* base address of memory */
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100132 uint64_t phys;
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200133};
134
135
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100136/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200137 * defines for the ioctl mobicore driver module function call from user space.
138 */
139/* MobiCore IOCTL magic number */
140#define MC_IOC_MAGIC 'M'
141
142#define MC_IO_INIT _IOWR(MC_IOC_MAGIC, 0, struct mc_ioctl_init)
143#define MC_IO_INFO _IOWR(MC_IOC_MAGIC, 1, struct mc_ioctl_info)
144#define MC_IO_VERSION _IOR(MC_IOC_MAGIC, 2, uint32_t)
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100145/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200146 * ioctl parameter to send the YIELD command to the SWD.
147 * Only possible in Privileged Mode.
148 * ioctl(fd, MC_DRV_MODULE_YIELD)
149 */
150#define MC_IO_YIELD _IO(MC_IOC_MAGIC, 3)
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100151/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200152 * ioctl parameter to send the NSIQ signal to the SWD.
153 * Only possible in Privileged Mode
154 * ioctl(fd, MC_DRV_MODULE_NSIQ)
155 */
156#define MC_IO_NSIQ _IO(MC_IOC_MAGIC, 4)
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100157/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200158 * Free's memory which is formerly allocated by the driver's mmap
159 * command. The parameter must be this mmaped address.
160 * The internal instance data regarding to this address are deleted as
161 * well as each according memory page and its appropriated reserved bit
162 * is cleared (ClearPageReserved).
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100163 * Usage: ioctl(fd, MC_DRV_MODULE_FREE, &address) with address being of
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200164 * type long address
165 */
166#define MC_IO_FREE _IO(MC_IOC_MAGIC, 5)
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100167/*
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100168 * Creates a MMU Table of the given base address and the size of the
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200169 * data.
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100170 * Parameter: mc_ioctl_reg_wsm
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200171 */
172#define MC_IO_REG_WSM _IOWR(MC_IOC_MAGIC, 6, struct mc_ioctl_reg_wsm)
173#define MC_IO_UNREG_WSM _IO(MC_IOC_MAGIC, 7)
174#define MC_IO_LOCK_WSM _IO(MC_IOC_MAGIC, 8)
175#define MC_IO_UNLOCK_WSM _IO(MC_IOC_MAGIC, 9)
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200176
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100177/*
178 * Allocate contiguous memory for a process for later mapping with mmap.
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100179 * MC_IO_MAP_WSM usual operation, pages are registered in
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200180 * device structure and freed later.
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100181 * MC_IO_MAP_MCI get Instance of MCI, allocates or mmaps
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200182 * the MCI to daemon
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200183 */
184#define MC_IO_MAP_WSM _IOWR(MC_IOC_MAGIC, 11, struct mc_ioctl_map)
185#define MC_IO_MAP_MCI _IOWR(MC_IOC_MAGIC, 12, struct mc_ioctl_map)
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200186
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100187/*
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200188 * Clean orphaned WSM buffers. Only available to the daemon and should
189 * only be carried out if the TLC crashes or otherwise calls exit() in
190 * an unexpected manner.
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100191 * The clean is needed together with the lock/unlock mechanism so the daemon
192 * has clear control of the mapped buffers so it can close a Trustlet before
193 * release all the WSM buffers, otherwise the Trustlet would be able to write
194 * to possibly kernel memory areas
195 */
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200196#define MC_IO_CLEAN_WSM _IO(MC_IOC_MAGIC, 14)
197
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100198/*
Oana Medvesan8dfbf012013-12-20 15:40:49 +0100199 * Get MMU phys address of a buffer handle allocated to the user.
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100200 * Only available to the daemon.
201 */
202#define MC_IO_RESOLVE_WSM _IOWR(MC_IOC_MAGIC, 15, \
203 struct mc_ioctl_resolv_wsm)
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200204
Oana Medvesan8f5df3a2013-03-04 19:04:03 +0100205/*
206 * Get the phys address & length of a allocated contiguous buffer.
207 * Only available to the daemon */
208#define MC_IO_RESOLVE_CONT_WSM _IOWR(MC_IOC_MAGIC, 16, \
209 struct mc_ioctl_resolv_cont_wsm)
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200210
Oana Medvesanedfb7202013-02-06 21:58:30 +0100211/*
212 * Setup the mem traces when called.
213 * Only available to the daemon */
214#define MC_IO_LOG_SETUP _IO(MC_IOC_MAGIC, 17)
215
Lukas Häneldb4b53e2012-10-22 13:49:41 +0200216#endif /* _MC_LINUX_H_ */