1 | /** @file
|
---|
2 | * tstDevice: Shared definitions between the framework and the shim library.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2017-2019 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h
|
---|
18 | #define VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h
|
---|
19 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
20 | # pragma once
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #include <VBox/param.h>
|
---|
24 | #include <VBox/types.h>
|
---|
25 | #include <iprt/assert.h>
|
---|
26 | #include <iprt/list.h>
|
---|
27 | #include <iprt/semaphore.h>
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 |
|
---|
30 | #include "tstDevicePlugin.h"
|
---|
31 |
|
---|
32 | RT_C_DECLS_BEGIN
|
---|
33 |
|
---|
34 |
|
---|
35 | /** Converts PDM device instance to the device under test structure. */
|
---|
36 | #define TSTDEV_PDMDEVINS_2_DUT(a_pDevIns) ((a_pDevIns)->Internal.s.pDut)
|
---|
37 |
|
---|
38 | /** Forward declaration of internal test device instance data. */
|
---|
39 | typedef struct TSTDEVDUTINT *PTSTDEVDUTINT;
|
---|
40 |
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * CFGM node structure.
|
---|
44 | */
|
---|
45 | typedef struct CFGMNODE
|
---|
46 | {
|
---|
47 | /** Device under test this CFGM node is for. */
|
---|
48 | PTSTDEVDUTINT pDut;
|
---|
49 | /** @todo: */
|
---|
50 | } CFGMNODE;
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Private device instance data.
|
---|
55 | */
|
---|
56 | typedef struct PDMDEVINSINTR3
|
---|
57 | {
|
---|
58 | /** Pointer to the device under test the PDM device instance is for. */
|
---|
59 | PTSTDEVDUTINT pDut;
|
---|
60 | } PDMDEVINSINTR3;
|
---|
61 | AssertCompile(sizeof(PDMDEVINSINTR3) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Private device instance data.
|
---|
65 | */
|
---|
66 | typedef struct PDMDEVINSINTR0
|
---|
67 | {
|
---|
68 | /** Pointer to the device under test the PDM device instance is for. */
|
---|
69 | PTSTDEVDUTINT pDut;
|
---|
70 | } PDMDEVINSINTR0;
|
---|
71 | AssertCompile(sizeof(PDMDEVINSINTR0) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Private device instance data.
|
---|
75 | */
|
---|
76 | typedef struct PDMDEVINSINTRC
|
---|
77 | {
|
---|
78 | /** Pointer to the device under test the PDM device instance is for. */
|
---|
79 | PTSTDEVDUTINT pDut;
|
---|
80 | } PDMDEVINSINTRC;
|
---|
81 | AssertCompile(sizeof(PDMDEVINSINTRC) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
|
---|
82 |
|
---|
83 | typedef struct PDMPCIDEVINT
|
---|
84 | {
|
---|
85 | bool fRegistered;
|
---|
86 | } PDMPCIDEVINT;
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Internal PDM critical section structure.
|
---|
91 | */
|
---|
92 | typedef struct PDMCRITSECTINT
|
---|
93 | {
|
---|
94 | /** The actual critical section used for emulation. */
|
---|
95 | RTCRITSECT CritSect;
|
---|
96 | } PDMCRITSECTINT;
|
---|
97 | AssertCompile(sizeof(PDMCRITSECTINT) <= (HC_ARCH_BITS == 32 ? 0x80 : 0xc0));
|
---|
98 |
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * MM Heap allocation.
|
---|
102 | */
|
---|
103 | typedef struct TSTDEVMMHEAPALLOC
|
---|
104 | {
|
---|
105 | /** Node for the list of allocations. */
|
---|
106 | RTLISTNODE NdMmHeap;
|
---|
107 | /** Pointer to the device under test the allocation was made for. */
|
---|
108 | PTSTDEVDUTINT pDut;
|
---|
109 | /** Size of the allocation. */
|
---|
110 | size_t cbAlloc;
|
---|
111 | /** Start of the real allocation. */
|
---|
112 | uint8_t abAlloc[RT_FLEXIBLE_ARRAY];
|
---|
113 | } TSTDEVMMHEAPALLOC;
|
---|
114 | /** Pointer to a MM Heap allocation. */
|
---|
115 | typedef TSTDEVMMHEAPALLOC *PTSTDEVMMHEAPALLOC;
|
---|
116 | /** Pointer to a const MM Heap allocation. */
|
---|
117 | typedef const TSTDEVMMHEAPALLOC *PCTSTDEVMMHEAPALLOC;
|
---|
118 |
|
---|
119 | AssertCompileMemberAlignment(TSTDEVMMHEAPALLOC, abAlloc, HC_ARCH_BITS == 64 ? 16 : 8);
|
---|
120 |
|
---|
121 |
|
---|
122 | #define PDMCRITSECTINT_DECLARED
|
---|
123 | #define PDMDEVINSINT_DECLARED
|
---|
124 | #define PDMPCIDEVINT_DECLARED
|
---|
125 | #define VMM_INCLUDED_SRC_include_VMInternal_h
|
---|
126 | #define VMM_INCLUDED_SRC_include_VMMInternal_h
|
---|
127 | RT_C_DECLS_END
|
---|
128 | #include <VBox/vmm/pdmcritsect.h>
|
---|
129 | #include <VBox/vmm/pdmdev.h>
|
---|
130 | #include <VBox/vmm/pdmpci.h>
|
---|
131 | #include <VBox/vmm/pdmdrv.h>
|
---|
132 | #include <VBox/vmm/tm.h>
|
---|
133 | RT_C_DECLS_BEGIN
|
---|
134 |
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * TM timer structure.
|
---|
138 | */
|
---|
139 | typedef struct TMTIMER
|
---|
140 | {
|
---|
141 | /** List of timers created by the device. */
|
---|
142 | RTLISTNODE NdDevTimers;
|
---|
143 | /** Clock this timer belongs to. */
|
---|
144 | TMCLOCK enmClock;
|
---|
145 | /** Callback to call when the timer expires. */
|
---|
146 | PFNTMTIMERDEV pfnCallbackDev;
|
---|
147 | /** Opaque user data to pass to the callback. */
|
---|
148 | void *pvUser;
|
---|
149 | /** Flags. */
|
---|
150 | uint32_t fFlags;
|
---|
151 | /** Assigned critical section. */
|
---|
152 | PPDMCRITSECT pCritSect;
|
---|
153 | /** @todo: */
|
---|
154 | } TMTIMER;
|
---|
155 |
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * PDM module descriptor type.
|
---|
159 | */
|
---|
160 | typedef enum TSTDEVPDMMODTYPE
|
---|
161 | {
|
---|
162 | /** Invalid module type. */
|
---|
163 | TSTDEVPDMMODTYPE_INVALID = 0,
|
---|
164 | /** Ring 3 module. */
|
---|
165 | TSTDEVPDMMODTYPE_R3,
|
---|
166 | /** Ring 0 module. */
|
---|
167 | TSTDEVPDMMODTYPE_R0,
|
---|
168 | /** Raw context module. */
|
---|
169 | TSTDEVPDMMODTYPE_RC,
|
---|
170 | /** 32bit hack. */
|
---|
171 | TSTDEVPDMMODTYPE_32BIT_HACK = 0x7fffffff
|
---|
172 | } TSTDEVPDMMODTYPE;
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Registered I/O port access handler.
|
---|
176 | */
|
---|
177 | typedef struct RTDEVDUTIOPORT
|
---|
178 | {
|
---|
179 | /** Node for the list of registered handlers. */
|
---|
180 | RTLISTNODE NdIoPorts;
|
---|
181 | /** Start I/O port the handler is for. */
|
---|
182 | RTIOPORT PortStart;
|
---|
183 | /** Number of ports handled. */
|
---|
184 | RTIOPORT cPorts;
|
---|
185 | /** Opaque user data - R3. */
|
---|
186 | void *pvUserR3;
|
---|
187 | /** Out handler - R3. */
|
---|
188 | PFNIOMIOPORTNEWOUT pfnOutR3;
|
---|
189 | /** In handler - R3. */
|
---|
190 | PFNIOMIOPORTNEWIN pfnInR3;
|
---|
191 | /** Out string handler - R3. */
|
---|
192 | PFNIOMIOPORTNEWOUTSTRING pfnOutStrR3;
|
---|
193 | /** In string handler - R3. */
|
---|
194 | PFNIOMIOPORTNEWINSTRING pfnInStrR3;
|
---|
195 |
|
---|
196 | /** Opaque user data - R0. */
|
---|
197 | void *pvUserR0;
|
---|
198 | /** Out handler - R0. */
|
---|
199 | PFNIOMIOPORTNEWOUT pfnOutR0;
|
---|
200 | /** In handler - R0. */
|
---|
201 | PFNIOMIOPORTNEWIN pfnInR0;
|
---|
202 | /** Out string handler - R0. */
|
---|
203 | PFNIOMIOPORTNEWOUTSTRING pfnOutStrR0;
|
---|
204 | /** In string handler - R0. */
|
---|
205 | PFNIOMIOPORTNEWINSTRING pfnInStrR0;
|
---|
206 |
|
---|
207 | #ifdef TSTDEV_SUPPORTS_RC
|
---|
208 | /** Opaque user data - RC. */
|
---|
209 | void *pvUserRC;
|
---|
210 | /** Out handler - RC. */
|
---|
211 | PFNIOMIOPORTNEWOUT pfnOutRC;
|
---|
212 | /** In handler - RC. */
|
---|
213 | PFNIOMIOPORTNEWIN pfnInRC;
|
---|
214 | /** Out string handler - RC. */
|
---|
215 | PFNIOMIOPORTNEWOUTSTRING pfnOutStrRC;
|
---|
216 | /** In string handler - RC. */
|
---|
217 | PFNIOMIOPORTNEWINSTRING pfnInStrRC;
|
---|
218 | #endif
|
---|
219 | } RTDEVDUTIOPORT;
|
---|
220 | /** Pointer to a registered I/O port handler. */
|
---|
221 | typedef RTDEVDUTIOPORT *PRTDEVDUTIOPORT;
|
---|
222 | /** Pointer to a const I/O port handler. */
|
---|
223 | typedef const RTDEVDUTIOPORT *PCRTDEVDUTIOPORT;
|
---|
224 |
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Registered SSM handlers.
|
---|
228 | */
|
---|
229 | typedef struct TSTDEVDUTSSM
|
---|
230 | {
|
---|
231 | /** Node for the list of registered SSM handlers. */
|
---|
232 | RTLISTNODE NdSsm;
|
---|
233 | /** Version */
|
---|
234 | uint32_t uVersion;
|
---|
235 | PFNSSMDEVLIVEPREP pfnLivePrep;
|
---|
236 | PFNSSMDEVLIVEEXEC pfnLiveExec;
|
---|
237 | PFNSSMDEVLIVEVOTE pfnLiveVote;
|
---|
238 | PFNSSMDEVSAVEPREP pfnSavePrep;
|
---|
239 | PFNSSMDEVSAVEEXEC pfnSaveExec;
|
---|
240 | PFNSSMDEVSAVEDONE pfnSaveDone;
|
---|
241 | PFNSSMDEVLOADPREP pfnLoadPrep;
|
---|
242 | PFNSSMDEVLOADEXEC pfnLoadExec;
|
---|
243 | PFNSSMDEVLOADDONE pfnLoadDone;
|
---|
244 | } TSTDEVDUTSSM;
|
---|
245 | /** Pointer to the registered SSM handlers. */
|
---|
246 | typedef TSTDEVDUTSSM *PTSTDEVDUTSSM;
|
---|
247 | /** Pointer to a const SSM handler. */
|
---|
248 | typedef const TSTDEVDUTSSM *PCTSTDEVDUTSSM;
|
---|
249 |
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * The Support Driver session state.
|
---|
253 | */
|
---|
254 | typedef struct TSTDEVSUPDRVSESSION
|
---|
255 | {
|
---|
256 | /** Pointer to the owning device under test instance. */
|
---|
257 | PTSTDEVDUTINT pDut;
|
---|
258 | /** List of event semaphores. */
|
---|
259 | RTLISTANCHOR LstSupSem;
|
---|
260 | } TSTDEVSUPDRVSESSION;
|
---|
261 | /** Pointer to the Support Driver session state. */
|
---|
262 | typedef TSTDEVSUPDRVSESSION *PTSTDEVSUPDRVSESSION;
|
---|
263 |
|
---|
264 | /** Converts a Support Driver session handle to the internal state. */
|
---|
265 | #define TSTDEV_PSUPDRVSESSION_2_PTSTDEVSUPDRVSESSION(a_pSession) ((PTSTDEVSUPDRVSESSION)(a_pSession))
|
---|
266 | /** Converts the internal session state to a Support Driver session handle. */
|
---|
267 | #define TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(a_pSession) ((PSUPDRVSESSION)(a_pSession))
|
---|
268 |
|
---|
269 | /**
|
---|
270 | * Support driver event semaphore.
|
---|
271 | */
|
---|
272 | typedef struct TSTDEVSUPSEMEVENT
|
---|
273 | {
|
---|
274 | /** Node for the event semaphore list. */
|
---|
275 | RTLISTNODE NdSupSem;
|
---|
276 | /** Flag whether this is multi event semaphore. */
|
---|
277 | bool fMulti;
|
---|
278 | /** Event smeaphore handles depending on the flag above. */
|
---|
279 | union
|
---|
280 | {
|
---|
281 | RTSEMEVENT hSemEvt;
|
---|
282 | RTSEMEVENTMULTI hSemEvtMulti;
|
---|
283 | } u;
|
---|
284 | } TSTDEVSUPSEMEVENT;
|
---|
285 | /** Pointer to a support event semaphore state. */
|
---|
286 | typedef TSTDEVSUPSEMEVENT *PTSTDEVSUPSEMEVENT;
|
---|
287 |
|
---|
288 | /** Converts a Support event semaphore handle to the internal state. */
|
---|
289 | #define TSTDEV_SUPSEMEVENT_2_PTSTDEVSUPSEMEVENT(a_pSupSemEvt) ((PTSTDEVSUPSEMEVENT)(a_pSupSemEvt))
|
---|
290 | /** Converts the internal session state to a Support event semaphore handle. */
|
---|
291 | #define TSTDEV_PTSTDEVSUPSEMEVENT_2_SUPSEMEVENT(a_pSupSemEvt) ((SUPSEMEVENT)(a_pSupSemEvt))
|
---|
292 |
|
---|
293 | /**
|
---|
294 | * The contex the device under test is currently in.
|
---|
295 | */
|
---|
296 | typedef enum TSTDEVDUTCTX
|
---|
297 | {
|
---|
298 | /** Invalid context. */
|
---|
299 | TSTDEVDUTCTX_INVALID = 0,
|
---|
300 | /** R3 context. */
|
---|
301 | TSTDEVDUTCTX_R3,
|
---|
302 | /** R0 context. */
|
---|
303 | TSTDEVDUTCTX_R0,
|
---|
304 | /** RC context. */
|
---|
305 | TSTDEVDUTCTX_RC,
|
---|
306 | /** 32bit hack. */
|
---|
307 | TSTDEVDUTCTX_32BIT_HACK = 0x7fffffff
|
---|
308 | } TSTDEVDUTCTX;
|
---|
309 |
|
---|
310 | /**
|
---|
311 | * PCI region descriptor.
|
---|
312 | */
|
---|
313 | typedef struct TSTDEVDUTPCIREGION
|
---|
314 | {
|
---|
315 | /** Size of the region. */
|
---|
316 | RTGCPHYS cbRegion;
|
---|
317 | /** Address space type. */
|
---|
318 | PCIADDRESSSPACE enmType;
|
---|
319 | /** Region mapping callback. */
|
---|
320 | PFNPCIIOREGIONMAP pfnRegionMap;
|
---|
321 | } TSTDEVDUTPCIREGION;
|
---|
322 | /** Pointer to a PCI region descriptor. */
|
---|
323 | typedef TSTDEVDUTPCIREGION *PTSTDEVDUTPCIREGION;
|
---|
324 | /** Pointer to a const PCI region descriptor. */
|
---|
325 | typedef const TSTDEVDUTPCIREGION *PCTSTDEVDUTPCIREGION;
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * Device under test instance data.
|
---|
329 | */
|
---|
330 | typedef struct TSTDEVDUTINT
|
---|
331 | {
|
---|
332 | /** Pointer to the testcase this device is part of. */
|
---|
333 | PCTSTDEVTESTCASEREG pTestcaseReg;
|
---|
334 | /** Pointer to the PDM device instance. */
|
---|
335 | PPDMDEVINS pDevIns;
|
---|
336 | /** Current device context. */
|
---|
337 | TSTDEVDUTCTX enmCtx;
|
---|
338 | /** Critical section protecting the lists below. */
|
---|
339 | RTCRITSECTRW CritSectLists;
|
---|
340 | /** List of registered I/O port handlers. */
|
---|
341 | RTLISTANCHOR LstIoPorts;
|
---|
342 | /** List of timers registered. */
|
---|
343 | RTLISTANCHOR LstTimers;
|
---|
344 | /** List of registered MMIO regions. */
|
---|
345 | RTLISTANCHOR LstMmio;
|
---|
346 | /** List of MM Heap allocations. */
|
---|
347 | RTLISTANCHOR LstMmHeap;
|
---|
348 | /** List of PDM threads. */
|
---|
349 | RTLISTANCHOR LstPdmThreads;
|
---|
350 | /** List of SSM handlers (just one normally). */
|
---|
351 | RTLISTANCHOR LstSsmHandlers;
|
---|
352 | /** The SUP session we emulate. */
|
---|
353 | TSTDEVSUPDRVSESSION SupSession;
|
---|
354 | /** The NOP critical section. */
|
---|
355 | PDMCRITSECT CritSectNop;
|
---|
356 | /** The VM state associated with this device. */
|
---|
357 | PVM pVm;
|
---|
358 | /** The registered PCI device instance if this is a PCI device. */
|
---|
359 | PPDMPCIDEV pPciDev;
|
---|
360 | /** PCI Region descriptors. */
|
---|
361 | TSTDEVDUTPCIREGION aPciRegions[VBOX_PCI_NUM_REGIONS];
|
---|
362 | } TSTDEVDUTINT;
|
---|
363 |
|
---|
364 |
|
---|
365 | extern const PDMDEVHLPR3 g_tstDevPdmDevHlpR3;
|
---|
366 |
|
---|
367 |
|
---|
368 | DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType,
|
---|
369 | const char *pszSymbol, PFNRT *ppfn);
|
---|
370 |
|
---|
371 |
|
---|
372 | DECLINLINE(int) tstDevDutLockShared(PTSTDEVDUTINT pThis)
|
---|
373 | {
|
---|
374 | return RTCritSectRwEnterShared(&pThis->CritSectLists);
|
---|
375 | }
|
---|
376 |
|
---|
377 | DECLINLINE(int) tstDevDutUnlockShared(PTSTDEVDUTINT pThis)
|
---|
378 | {
|
---|
379 | return RTCritSectRwLeaveShared(&pThis->CritSectLists);
|
---|
380 | }
|
---|
381 |
|
---|
382 | DECLINLINE(int) tstDevDutLockExcl(PTSTDEVDUTINT pThis)
|
---|
383 | {
|
---|
384 | return RTCritSectRwEnterExcl(&pThis->CritSectLists);
|
---|
385 | }
|
---|
386 |
|
---|
387 | DECLINLINE(int) tstDevDutUnlockExcl(PTSTDEVDUTINT pThis)
|
---|
388 | {
|
---|
389 | return RTCritSectRwLeaveExcl(&pThis->CritSectLists);
|
---|
390 | }
|
---|
391 |
|
---|
392 | RT_C_DECLS_END
|
---|
393 |
|
---|
394 | #endif /* !VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h */
|
---|