aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gud/MobiCoreDriver/public/mcDrvModuleApi.h
blob: 6ac92cbfad881ff936090932b901c26031a3325a (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/** @addtogroup MCD_MCDIMPL_KMOD
 * @{
 * Interface to Mobicore Driver Kernel Module.
 *
 * <h2>Introduction</h2>
 * The MobiCore Driver Kernel Module is a Linux device driver, which represents
 * the command proxy on the lowest layer to the secure world (Swd). Additional
 * services like memory allocation via mmap and generation of a L2 tables for
 * given virtual memory are also supported. IRQ functionallity receives
 * information from the SWd in the non secure world (NWd).
 * As customary the driver is handled as linux device driver with "open",
 * "close" and "ioctl" commands. Access to the driver is possible after the
 * device "/dev/mobicore" has been opened.
 * The MobiCore Driver Kernel Module must be installed via
 * "insmod mcDrvModule.ko".
 *
 *
 * <h2>Version history</h2>
 * <table class="customtab">
 * <tr><td width="100px"><b>Date</b></td><td width="80px"><b>Version</b></td>
 * <td><b>Changes</b></td></tr>
 * <tr><td>2010-05-25</td><td>0.1</td><td>Initial Release</td></tr>
 * </table>
 *
 * <!-- Copyright Giesecke & Devrient GmbH 2010-2012 -->
 */

#ifndef _MC_DRV_MODULEAPI_H_
#define _MC_DRV_MODULEAPI_H_

#include "version.h"

#define MC_DRV_MOD_DEVNODE           "mobicore"
#define MC_DRV_MOD_DEVNODE_FULLPATH  "/dev/" MC_DRV_MOD_DEVNODE

/**
 * Data exchange structure of the MC_DRV_MODULE_INIT ioctl command.
 * INIT request data to SWD
 */
union mcIoCtlInitParams {
	struct {
		/** base address of mci buffer 4KB align */
		uint32_t  base;
		/** notification buffer start/length [16:16] [start, length] */
		uint32_t  nqOffset;
		/** length of notification queue */
		uint32_t  nqLength;
		/** mcp buffer start/length [16:16] [start, length] */
		uint32_t  mcpOffset;
		/** length of mcp buffer */
		uint32_t  mcpLength;
	} in;
	struct {
		/* nothing */
	} out;
};


/**
 * Data exchange structure of the MC_DRV_MODULE_INFO ioctl command.
 * INFO request data to the SWD
 */
union mcIoCtlInfoParams {
	struct {
		uint32_t  extInfoId; /**< extended info ID */
	} in;
	struct {
		uint32_t  state; /**< state */
		uint32_t  extInfo; /**< extended info */
	} out;
};

/**
 * Mmap allocates and maps contiguous memory into a process.
 * We use the third parameter, void *offset, to distinguish between some cases
 * offset = MC_DRV_KMOD_MMAP_WSM	usual operation, pages are registered in
					device structure and freed later.
 * offset = MC_DRV_KMOD_MMAP_MCI	get Instance of MCI, allocates or mmaps
					the MCI to daemon
 * offset = MC_DRV_KMOD_MMAP_PERSISTENTWSM	special operation, without
						registration of pages
 *
 * In mmap(), the offset specifies which of several device I/O pages is
 *  requested. Linux only transfers the page number, i.e. the upper 20 bits to
 *  kernel module. Therefore we define our special offsets as multiples of page
 *  size.
 */
enum mcMmapMemtype {
	MC_DRV_KMOD_MMAP_WSM		= 0,
	MC_DRV_KMOD_MMAP_MCI		= 4096,
	MC_DRV_KMOD_MMAP_PERSISTENTWSM	= 8192
};

struct mcMmapResp {
	uint32_t  handle; /**< WSN handle */
	uint32_t  physAddr; /**< physical address of WSM (or NULL) */
	bool	  isReused; /**< if WSM memory was reused, or new allocated */
};

/**
 * Data exchange structure of the MC_DRV_KMOD_IOCTL_FREE ioctl command.
 */
union mcIoCtltoFreeParams {
	struct {
		uint32_t  handle; /**< driver handle */
		uint32_t  pid; /**< process id */
	} in;
	struct {
		/* nothing */
	} out;
};


/**
 * Data exchange structure of the MC_DRV_KMOD_IOCTL_APP_REGISTER_WSM_L2 command.
 *
 * Allocates a physical L2 table and maps the buffer into this page.
 * Returns the physical address of the L2 table.
 * The page alignment will be created and the appropriated pSize and pOffsetL2
 * will be modified to the used values.
 */
union mcIoCtlAppRegWsmL2Params {
	struct {
		uint32_t  buffer; /**< base address of the virtual address  */
		uint32_t  len; /**< size of the virtual address space */
		uint32_t  pid; /**< process id */
	} in;
	struct {
		uint32_t  handle; /**< driver handle for locked memory */
		uint32_t  physWsmL2Table; /* physical address of the L2 table */
	} out;
};


/**
 * Data exchange structure of the MC_DRV_KMOD_IOCTL_APP_UNREGISTER_WSM_L2
 * command.
 */
struct mcIoCtlAppUnregWsmL2Params {
	struct {
		uint32_t  handle; /**< driver handle for locked memory */
		uint32_t  pid; /**< process id */
	} in;
	struct {
		/* nothing */
	} out;
};


/**
 * Data exchange structure of the MC_DRV_KMOD_IOCTL_DAEMON_LOCK_WSM_L2 command.
 */
struct mcIoCtlDaemonLockWsmL2Params {
	struct {
		uint32_t  handle; /**< driver handle for locked memory */
	} in;
	struct {
		uint32_t physWsmL2Table;
	} out;
};


/**
 * Data exchange structure of the MC_DRV_KMOD_IOCTL_DAEMON_UNLOCK_WSM_L2
 * command.
 */
struct mcIoCtlDaemonUnlockWsmL2Params {
	struct {
		uint32_t  handle; /**< driver handle for locked memory */
	} in;
	struct {
		/* nothing */
	} out;
};

/**
 * Data exchange structure of the MC_DRV_MODULE_FC_EXECUTE ioctl command.
 */
union mcIoCtlFcExecuteParams {
	struct {
		uint32_t  physStartAddr;/**< base address of mobicore binary */
		uint32_t  length;	/**< length of DDR area */
	} in;
	struct {
		/* nothing */
	} out;
};

/**
 * Data exchange structure of the MC_DRV_MODULE_GET_VERSION ioctl command.
 */
struct mcIoCtlGetVersionParams {
	struct {
		uint32_t    kernelModuleVersion;
	} out;
};

/* @defgroup Mobicore_Driver_Kernel_Module_Interface IOCTL */




/* TODO: use IOCTL macros like _IOWR. See Documentation/ioctl/ioctl-number.txt,
	Documentation/ioctl/ioctl-decoding.txt */
/**
 * defines for the ioctl mobicore driver module function call from user space.
 */
enum mcKModIoClt {

	/*
	 * get detailed MobiCore Status
	 */
	MC_DRV_KMOD_IOCTL_DUMP_STATUS  = 200,

	/*
	 * initialize MobiCore
	 */
	MC_DRV_KMOD_IOCTL_FC_INIT  = 201,

	/*
	 * get MobiCore status
	 */
	MC_DRV_KMOD_IOCTL_FC_INFO  = 202,

	/**
	 * ioctl parameter to send the YIELD command to the SWD.
	 * Only possible in Privileged Mode.
	 * ioctl(fd, MC_DRV_MODULE_YIELD)
	 */
	MC_DRV_KMOD_IOCTL_FC_YIELD =  203,
	/**
	 * ioctl parameter to send the NSIQ signal to the SWD.
	 * Only possible in Privileged Mode
	 * ioctl(fd, MC_DRV_MODULE_NSIQ)
	 */
	MC_DRV_KMOD_IOCTL_FC_NSIQ   =  204,
	/**
	 * ioctl parameter to tzbsp to start Mobicore binary from DDR.
	 * Only possible in Privileged Mode
	 * ioctl(fd, MC_DRV_KMOD_IOCTL_FC_EXECUTE)
	 */
	MC_DRV_KMOD_IOCTL_FC_EXECUTE =  205,

	/**
	 * Free's memory which is formerly allocated by the driver's mmap
	 * command. The parameter must be this mmaped address.
	 * The internal instance data regarding to this address are deleted as
	 * well as each according memory page and its appropriated reserved bit
	 * is cleared (ClearPageReserved).
	 * Usage: ioctl(fd, MC_DRV_MODULE_FREE, &address) with address beeing of
	 * type long address
	 */
	MC_DRV_KMOD_IOCTL_FREE = 218,

	/**
	 * Creates a L2 Table of the given base address and the size of the
	 * data.
	 * Parameter: mcIoCtlAppRegWsmL2Params
	 */
	MC_DRV_KMOD_IOCTL_APP_REGISTER_WSM_L2 = 220,

	/**
	 * Frees the L2 table created by a MC_DRV_KMOD_IOCTL_APP_REGISTER_WSM_L2
	 * ioctl.
	 * Parameter: mcIoCtlAppUnRegWsmL2Params
	 */
	MC_DRV_KMOD_IOCTL_APP_UNREGISTER_WSM_L2 = 221,


	/* TODO: comment this. */
	MC_DRV_KMOD_IOCTL_DAEMON_LOCK_WSM_L2 = 222,
	MC_DRV_KMOD_IOCTL_DAEMON_UNLOCK_WSM_L2 = 223,

    /**
     * Return kernel driver version.
     * Parameter: mcIoCtlGetVersionParams
     */
    MC_DRV_KMOD_IOCTL_GET_VERSION = 224,
};


#endif /* _MC_DRV_MODULEAPI_H_ */
/** @} */