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
|
/** @file
* tstDevice: Shared definitions between the framework and the shim library.
*/
/*
* Copyright (C) 2017-2019 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h
#define VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif
#include <VBox/types.h>
#include <iprt/assert.h>
#include <iprt/list.h>
#include <iprt/semaphore.h>
#include "tstDevicePlugin.h"
#include "tstDeviceVMMInternal.h"
RT_C_DECLS_BEGIN
/** Converts PDM device instance to the device under test structure. */
#define TSTDEV_PDMDEVINS_2_DUT(a_pDevIns) ((a_pDevIns)->Internal.s.pDut)
/**
* PDM module descriptor type.
*/
typedef enum TSTDEVPDMMODTYPE
{
/** Invalid module type. */
TSTDEVPDMMODTYPE_INVALID = 0,
/** Ring 3 module. */
TSTDEVPDMMODTYPE_R3,
/** Ring 0 module. */
TSTDEVPDMMODTYPE_R0,
/** Raw context module. */
TSTDEVPDMMODTYPE_RC,
/** 32bit hack. */
TSTDEVPDMMODTYPE_32BIT_HACK = 0x7fffffff
} TSTDEVPDMMODTYPE;
/**
* Registered I/O port access handler.
*/
typedef struct RTDEVDUTIOPORT
{
/** Node for the list of registered handlers. */
RTLISTNODE NdIoPorts;
/** Start I/O port the handler is for. */
RTIOPORT PortStart;
/** Number of ports handled. */
RTIOPORT cPorts;
/** Opaque user data - R3. */
void *pvUserR3;
/** Out handler - R3. */
PFNIOMIOPORTOUT pfnOutR3;
/** In handler - R3. */
PFNIOMIOPORTIN pfnInR3;
/** Out string handler - R3. */
PFNIOMIOPORTOUTSTRING pfnOutStrR3;
/** In string handler - R3. */
PFNIOMIOPORTINSTRING pfnInStrR3;
/** Opaque user data - R0. */
void *pvUserR0;
/** Out handler - R0. */
PFNIOMIOPORTOUT pfnOutR0;
/** In handler - R0. */
PFNIOMIOPORTIN pfnInR0;
/** Out string handler - R0. */
PFNIOMIOPORTOUTSTRING pfnOutStrR0;
/** In string handler - R0. */
PFNIOMIOPORTINSTRING pfnInStrR0;
#ifdef TSTDEV_SUPPORTS_RC
/** Opaque user data - RC. */
void *pvUserRC;
/** Out handler - RC. */
PFNIOMIOPORTOUT pfnOutRC;
/** In handler - RC. */
PFNIOMIOPORTIN pfnInRC;
/** Out string handler - RC. */
PFNIOMIOPORTOUTSTRING pfnOutStrRC;
/** In string handler - RC. */
PFNIOMIOPORTINSTRING pfnInStrRC;
#endif
} RTDEVDUTIOPORT;
/** Pointer to a registered I/O port handler. */
typedef RTDEVDUTIOPORT *PRTDEVDUTIOPORT;
/** Pointer to a const I/O port handler. */
typedef const RTDEVDUTIOPORT *PCRTDEVDUTIOPORT;
/**
* The Support Driver session state.
*/
typedef struct TSTDEVSUPDRVSESSION
{
/** Pointer to the owning device under test instance. */
PTSTDEVDUTINT pDut;
/** List of event semaphores. */
RTLISTANCHOR LstSupSem;
} TSTDEVSUPDRVSESSION;
/** Pointer to the Support Driver session state. */
typedef TSTDEVSUPDRVSESSION *PTSTDEVSUPDRVSESSION;
/** Converts a Support Driver session handle to the internal state. */
#define TSTDEV_PSUPDRVSESSION_2_PTSTDEVSUPDRVSESSION(a_pSession) ((PTSTDEVSUPDRVSESSION)(a_pSession))
/** Converts the internal session state to a Support Driver session handle. */
#define TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(a_pSession) ((PSUPDRVSESSION)(a_pSession))
/**
* Support driver event semaphore.
*/
typedef struct TSTDEVSUPSEMEVENT
{
/** Node for the event semaphore list. */
RTLISTNODE NdSupSem;
/** Flag whether this is multi event semaphore. */
bool fMulti;
/** Event smeaphore handles depending on the flag above. */
union
{
RTSEMEVENT hSemEvt;
RTSEMEVENTMULTI hSemEvtMulti;
} u;
} TSTDEVSUPSEMEVENT;
/** Pointer to a support event semaphore state. */
typedef TSTDEVSUPSEMEVENT *PTSTDEVSUPSEMEVENT;
/** Converts a Support event semaphore handle to the internal state. */
#define TSTDEV_SUPSEMEVENT_2_PTSTDEVSUPSEMEVENT(a_pSupSemEvt) ((PTSTDEVSUPSEMEVENT)(a_pSupSemEvt))
/** Converts the internal session state to a Support event semaphore handle. */
#define TSTDEV_PTSTDEVSUPSEMEVENT_2_SUPSEMEVENT(a_pSupSemEvt) ((SUPSEMEVENT)(a_pSupSemEvt))
/**
* The contex the device under test is currently in.
*/
typedef enum TSTDEVDUTCTX
{
/** Invalid context. */
TSTDEVDUTCTX_INVALID = 0,
/** R3 context. */
TSTDEVDUTCTX_R3,
/** R0 context. */
TSTDEVDUTCTX_R0,
/** RC context. */
TSTDEVDUTCTX_RC,
/** 32bit hack. */
TSTDEVDUTCTX_32BIT_HACK = 0x7fffffff
} TSTDEVDUTCTX;
/**
* PCI region descriptor.
*/
typedef struct TSTDEVDUTPCIREGION
{
/** Size of the region. */
RTGCPHYS cbRegion;
/** Address space type. */
PCIADDRESSSPACE enmType;
/** Region mapping callback. */
PFNPCIIOREGIONMAP pfnRegionMap;
} TSTDEVDUTPCIREGION;
/** Pointer to a PCI region descriptor. */
typedef TSTDEVDUTPCIREGION *PTSTDEVDUTPCIREGION;
/** Pointer to a const PCI region descriptor. */
typedef const TSTDEVDUTPCIREGION *PCTSTDEVDUTPCIREGION;
/**
* Device under test instance data.
*/
typedef struct TSTDEVDUTINT
{
/** Pointer to the testcase this device is part of. */
PCTSTDEVTESTCASEREG pTestcaseReg;
/** Pointer to the PDM device instance. */
PPDMDEVINS pDevIns;
/** Current device context. */
TSTDEVDUTCTX enmCtx;
/** Critical section protecting the lists below. */
RTCRITSECTRW CritSectLists;
/** List of registered I/O port handlers. */
RTLISTANCHOR LstIoPorts;
/** List of timers registered. */
RTLISTANCHOR LstTimers;
/** List of registered MMIO regions. */
RTLISTANCHOR LstMmio;
/** List of MM Heap allocations. */
RTLISTANCHOR LstMmHeap;
/** List of PDM threads. */
RTLISTANCHOR LstPdmThreads;
/** The SUP session we emulate. */
TSTDEVSUPDRVSESSION SupSession;
/** The VM state assoicated with this device. */
PVM pVm;
/** The registered PCI device instance if this is a PCI device. */
PPDMPCIDEV pPciDev;
/** PCI Region descriptors. */
TSTDEVDUTPCIREGION aPciRegions[VBOX_PCI_NUM_REGIONS];
} TSTDEVDUTINT;
DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType,
const char *pszSymbol, PFNRT *ppfn);
DECLINLINE(int) tstDevDutLockShared(PTSTDEVDUTINT pThis)
{
return RTCritSectRwEnterShared(&pThis->CritSectLists);
}
DECLINLINE(int) tstDevDutUnlockShared(PTSTDEVDUTINT pThis)
{
return RTCritSectRwLeaveShared(&pThis->CritSectLists);
}
DECLINLINE(int) tstDevDutLockExcl(PTSTDEVDUTINT pThis)
{
return RTCritSectRwEnterExcl(&pThis->CritSectLists);
}
DECLINLINE(int) tstDevDutUnlockExcl(PTSTDEVDUTINT pThis)
{
return RTCritSectRwLeaveExcl(&pThis->CritSectLists);
}
RT_C_DECLS_END
#endif /* !VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h */
|