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