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
|
/**
* Header file of MobiCore Driver Kernel Module.
*
* @addtogroup MobiCore_Driver_Kernel_Module
* @{
* Internal structures of the McDrvModule
* @file
*
* Header file the MobiCore Driver Kernel Module,
* its internal structures and defines.
*
* <!-- Copyright Giesecke & Devrient GmbH 2009-2012 -->
*
* 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.
*/
#ifndef _MC_DRV_KMOD_H_
#define _MC_DRV_KMOD_H_
#include "mcDrvModuleLinuxApi.h"
#include "public/mcDrvModuleApi.h"
/** Platform specific settings */
#include "platform.h"
/** ARM Specific masks and modes */
#define ARM_CPSR_MASK 0x1F
#define ARM_MONITOR_MODE 0b10110
#define ARM_SECURITY_EXTENSION_MASK 0x30
/** Number of page table entries in one L2 table. This is ARM specific, an
* L2 table covers 1 MiB by using 256 entry referring to 4KiB pages each.
*/
#define MC_ARM_L2_TABLE_ENTRIES 256
/** Number of address allocations for one driver instance. */
#define MC_DRV_KMOD_TUPLE_NR 16
/** Number of pages for L2 tables. There are 4 table in each page. */
#define MC_DRV_KMOD_L2_TABLE_PER_PAGES 4
#define MC_DRV_KMOD_L2_TABLE_PAGES 8
struct l2Table {
pte_t tableEntries[MC_ARM_L2_TABLE_ENTRIES];
};
#define INVALID_ADDRESS ((void *)(-1))
/** ARM L2 PTE bits */
#define L2_FLAG_SMALL_XN (1U << 0)
#define L2_FLAG_SMALL (1U << 1)
#define L2_FLAG_B (1U << 2)
#define L2_FLAG_C (1U << 3)
#define L2_FLAG_AP0 (1U << 4)
#define L2_FLAG_AP1 (1U << 5)
#define L2_FLAG_SMALL_TEX0 (1U << 6)
#define L2_FLAG_SMALL_TEX1 (1U << 7)
#define L2_FLAG_SMALL_TEX2 (1U << 8)
#define L2_FLAG_APX (1U << 9)
#define L2_FLAG_S (1U << 10)
#define L2_FLAG_NG (1U << 11)
/**
* tuple list entry.
* It describes the tuple, physical Kernel start address to the virtual Client
* address. The virtual kernel address is added for a simpler search algorithm.
*/
struct mc_tuple {
unsigned int handle; /* unique handle */
void *virtUserAddr; /**< virtual User start address */
void *virtKernelAddr; /**< virtual Kernel start address */
void *physAddr; /**< physical start address */
unsigned int numPages; /**< number of pages */
};
/**
* Driver instance data.
*/
struct mcInstance {
/** unique handle */
unsigned int handle;
/** process that opened this instance */
pid_t pidVnr;
struct {
/** number of pages */
unsigned int numPages;
/** virtual start address kernel address space generated
by mmap command */
void *virtAddr;
/** physical start address kernel address space generated
by mmap command */
void *physAddr;
} map;
/** tuple list for mmap generated address space and
its virtual client address */
struct mc_tuple tuple[MC_DRV_KMOD_TUPLE_NR];
};
/** data structure of 4 L2 tables within one 4kb page*/
struct mcL2Page {
struct l2Table table[MC_DRV_KMOD_L2_TABLE_PER_PAGES];
};
/** bookkeeping data structure that manages 4 L2 tables in one page */
struct mcL2TablesChunk {
struct list_head list;
unsigned int usageBitmap; /**< usage bitmap */
struct mcL2Page *kernelVirt; /**< kernel virtual address */
struct mcL2Page *phys; /**< physical address */
struct page *pPage; /**< pointer to page struct */
};
/** bookkeeping data structure that binds one L2 table
to its chunk(page) and its user */
struct mcL2TablesDescr {
struct list_head list;
unsigned int handle;
unsigned int flags;
struct mcInstance *pInstance;
struct mcL2TablesChunk *pChunk;
unsigned int idx;
unsigned int nrOfPages;
};
#define MC_WSM_L2_CONTAINER_WSM_LOCKED_BY_APP (1U << 0)
#define MC_WSM_L2_CONTAINER_WSM_LOCKED_BY_MC (1U << 1)
/** MobiCore S-SIQ interrupt context data. */
struct mcSSiqCtx {
atomic_t counter; /**< S-SIQ interrupt counter */
};
/** MobiCore Daemon context data. */
struct mcDaemonCtx {
struct semaphore sem; /**< event semaphore */
struct fasync_struct *pAsyncQueue;
unsigned int ssiqCounter; /**< event counter */
};
/** MobiCore Driver Kernel Module context data. */
struct mcDrvKModCtx {
atomic_t uniqueCounter; /**< ever incrementing counter */
struct mcSSiqCtx ssiqCtx; /**< S-SIQ interrupt context */
struct mcDaemonCtx daemonCtx; /**< MobiCore Daemon context */
struct mcInstance *daemonInst; /**< pointer to instance of daemon */
struct list_head wsmL2Chunks; /**< Backing store for L2 tables */
struct list_head wsmL2Descriptors; /**< Bookkeeping for L2 tables */
struct semaphore wsmL2Sem; /**< semaphore to synchronize access to
above lists */
};
/** MobiCore internal trace buffer structure. */
struct mcTraceBuf {
uint32_t version; /**< version of trace buffer */
uint32_t length; /**< length of allocated buffer(includes header) */
uint32_t write_pos; /**< last write position */
char buff[1]; /**< start of the log buffer */
};
#define MCDRV_DBG_ERROR(txt, ...) \
printk(KERN_ERR "mcDrvKMod [%d] %s() ### ERROR: " txt, \
task_pid_vnr(current), \
__func__, \
##__VA_ARGS__)
/* dummy function helper macro. */
#define DUMMY_FUNCTION() do {} while (0)
#if defined(DEBUG)
/* #define DEBUG_VERBOSE */
#if defined(DEBUG_VERBOSE)
#define MCDRV_DBG_VERBOSE MCDRV_DBG
#else
#define MCDRV_DBG_VERBOSE(...) DUMMY_FUNCTION()
#endif
#define MCDRV_DBG(txt, ...) \
printk(KERN_INFO "mcDrvKMod [%d on CPU%d] %s(): " txt, \
task_pid_vnr(current), \
raw_smp_processor_id(), \
__func__, \
##__VA_ARGS__)
#define MCDRV_DBG_WARN(txt, ...) \
printk(KERN_WARNING "mcDrvKMod [%d] %s() WARNING: " txt, \
task_pid_vnr(current), \
__func__, \
##__VA_ARGS__)
#define MCDRV_ASSERT(cond) \
do { \
if (unlikely(!(cond))) { \
panic("mcDrvKMod Assertion failed: %s:%d\n", \
__FILE__, __LINE__); \
} \
} while (0)
#else
#define MCDRV_DBG_VERBOSE(...) DUMMY_FUNCTION()
#define MCDRV_DBG(...) DUMMY_FUNCTION()
#define MCDRV_DBG_WARN(...) DUMMY_FUNCTION()
#define MCDRV_ASSERT(...) DUMMY_FUNCTION()
#endif /* [not] defined(DEBUG) */
#endif /* _MC_DRV_KMOD_H_ */
/** @} */
|