VirtualBox

source: vbox/trunk/src/VBox/Devices/testcase/tstDeviceInternal.h@ 82902

Last change on this file since 82902 was 82902, checked in by vboxsync, 5 years ago

Devices/tstDevice: Working on restoring the old state of the device testbench

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
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
32RT_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. */
39typedef struct TSTDEVDUTINT *PTSTDEVDUTINT;
40
41
42/**
43 * CFGM node structure.
44 */
45typedef 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 */
56typedef struct PDMDEVINSINTR3
57{
58 /** Pointer to the device under test the PDM device instance is for. */
59 PTSTDEVDUTINT pDut;
60} PDMDEVINSINTR3;
61AssertCompile(sizeof(PDMDEVINSINTR3) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
62
63/**
64 * Private device instance data.
65 */
66typedef struct PDMDEVINSINTR0
67{
68 /** Pointer to the device under test the PDM device instance is for. */
69 PTSTDEVDUTINT pDut;
70} PDMDEVINSINTR0;
71AssertCompile(sizeof(PDMDEVINSINTR0) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
72
73/**
74 * Private device instance data.
75 */
76typedef struct PDMDEVINSINTRC
77{
78 /** Pointer to the device under test the PDM device instance is for. */
79 PTSTDEVDUTINT pDut;
80} PDMDEVINSINTRC;
81AssertCompile(sizeof(PDMDEVINSINTRC) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
82
83typedef struct PDMPCIDEVINT
84{
85 bool fRegistered;
86} PDMPCIDEVINT;
87
88
89/**
90 * Internal PDM critical section structure.
91 */
92typedef struct PDMCRITSECTINT
93{
94 /** The actual critical section used for emulation. */
95 RTCRITSECT CritSect;
96} PDMCRITSECTINT;
97AssertCompile(sizeof(PDMCRITSECTINT) <= (HC_ARCH_BITS == 32 ? 0x80 : 0xc0));
98
99
100/**
101 * MM Heap allocation.
102 */
103typedef 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. */
115typedef TSTDEVMMHEAPALLOC *PTSTDEVMMHEAPALLOC;
116/** Pointer to a const MM Heap allocation. */
117typedef const TSTDEVMMHEAPALLOC *PCTSTDEVMMHEAPALLOC;
118
119AssertCompileMemberAlignment(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
127RT_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>
133RT_C_DECLS_BEGIN
134
135
136/**
137 * TM timer structure.
138 */
139typedef 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 /** @todo: */
152} TMTIMER;
153
154
155/**
156 * PDM module descriptor type.
157 */
158typedef enum TSTDEVPDMMODTYPE
159{
160 /** Invalid module type. */
161 TSTDEVPDMMODTYPE_INVALID = 0,
162 /** Ring 3 module. */
163 TSTDEVPDMMODTYPE_R3,
164 /** Ring 0 module. */
165 TSTDEVPDMMODTYPE_R0,
166 /** Raw context module. */
167 TSTDEVPDMMODTYPE_RC,
168 /** 32bit hack. */
169 TSTDEVPDMMODTYPE_32BIT_HACK = 0x7fffffff
170} TSTDEVPDMMODTYPE;
171
172/**
173 * Registered I/O port access handler.
174 */
175typedef struct RTDEVDUTIOPORT
176{
177 /** Node for the list of registered handlers. */
178 RTLISTNODE NdIoPorts;
179 /** Start I/O port the handler is for. */
180 RTIOPORT PortStart;
181 /** Number of ports handled. */
182 RTIOPORT cPorts;
183 /** Opaque user data - R3. */
184 void *pvUserR3;
185 /** Out handler - R3. */
186 PFNIOMIOPORTNEWOUT pfnOutR3;
187 /** In handler - R3. */
188 PFNIOMIOPORTNEWIN pfnInR3;
189 /** Out string handler - R3. */
190 PFNIOMIOPORTNEWOUTSTRING pfnOutStrR3;
191 /** In string handler - R3. */
192 PFNIOMIOPORTNEWINSTRING pfnInStrR3;
193
194 /** Opaque user data - R0. */
195 void *pvUserR0;
196 /** Out handler - R0. */
197 PFNIOMIOPORTNEWOUT pfnOutR0;
198 /** In handler - R0. */
199 PFNIOMIOPORTNEWIN pfnInR0;
200 /** Out string handler - R0. */
201 PFNIOMIOPORTNEWOUTSTRING pfnOutStrR0;
202 /** In string handler - R0. */
203 PFNIOMIOPORTNEWINSTRING pfnInStrR0;
204
205#ifdef TSTDEV_SUPPORTS_RC
206 /** Opaque user data - RC. */
207 void *pvUserRC;
208 /** Out handler - RC. */
209 PFNIOMIOPORTNEWOUT pfnOutRC;
210 /** In handler - RC. */
211 PFNIOMIOPORTNEWIN pfnInRC;
212 /** Out string handler - RC. */
213 PFNIOMIOPORTNEWOUTSTRING pfnOutStrRC;
214 /** In string handler - RC. */
215 PFNIOMIOPORTNEWINSTRING pfnInStrRC;
216#endif
217} RTDEVDUTIOPORT;
218/** Pointer to a registered I/O port handler. */
219typedef RTDEVDUTIOPORT *PRTDEVDUTIOPORT;
220/** Pointer to a const I/O port handler. */
221typedef const RTDEVDUTIOPORT *PCRTDEVDUTIOPORT;
222
223/**
224 * The Support Driver session state.
225 */
226typedef struct TSTDEVSUPDRVSESSION
227{
228 /** Pointer to the owning device under test instance. */
229 PTSTDEVDUTINT pDut;
230 /** List of event semaphores. */
231 RTLISTANCHOR LstSupSem;
232} TSTDEVSUPDRVSESSION;
233/** Pointer to the Support Driver session state. */
234typedef TSTDEVSUPDRVSESSION *PTSTDEVSUPDRVSESSION;
235
236/** Converts a Support Driver session handle to the internal state. */
237#define TSTDEV_PSUPDRVSESSION_2_PTSTDEVSUPDRVSESSION(a_pSession) ((PTSTDEVSUPDRVSESSION)(a_pSession))
238/** Converts the internal session state to a Support Driver session handle. */
239#define TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(a_pSession) ((PSUPDRVSESSION)(a_pSession))
240
241/**
242 * Support driver event semaphore.
243 */
244typedef struct TSTDEVSUPSEMEVENT
245{
246 /** Node for the event semaphore list. */
247 RTLISTNODE NdSupSem;
248 /** Flag whether this is multi event semaphore. */
249 bool fMulti;
250 /** Event smeaphore handles depending on the flag above. */
251 union
252 {
253 RTSEMEVENT hSemEvt;
254 RTSEMEVENTMULTI hSemEvtMulti;
255 } u;
256} TSTDEVSUPSEMEVENT;
257/** Pointer to a support event semaphore state. */
258typedef TSTDEVSUPSEMEVENT *PTSTDEVSUPSEMEVENT;
259
260/** Converts a Support event semaphore handle to the internal state. */
261#define TSTDEV_SUPSEMEVENT_2_PTSTDEVSUPSEMEVENT(a_pSupSemEvt) ((PTSTDEVSUPSEMEVENT)(a_pSupSemEvt))
262/** Converts the internal session state to a Support event semaphore handle. */
263#define TSTDEV_PTSTDEVSUPSEMEVENT_2_SUPSEMEVENT(a_pSupSemEvt) ((SUPSEMEVENT)(a_pSupSemEvt))
264
265/**
266 * The contex the device under test is currently in.
267 */
268typedef enum TSTDEVDUTCTX
269{
270 /** Invalid context. */
271 TSTDEVDUTCTX_INVALID = 0,
272 /** R3 context. */
273 TSTDEVDUTCTX_R3,
274 /** R0 context. */
275 TSTDEVDUTCTX_R0,
276 /** RC context. */
277 TSTDEVDUTCTX_RC,
278 /** 32bit hack. */
279 TSTDEVDUTCTX_32BIT_HACK = 0x7fffffff
280} TSTDEVDUTCTX;
281
282/**
283 * PCI region descriptor.
284 */
285typedef struct TSTDEVDUTPCIREGION
286{
287 /** Size of the region. */
288 RTGCPHYS cbRegion;
289 /** Address space type. */
290 PCIADDRESSSPACE enmType;
291 /** Region mapping callback. */
292 PFNPCIIOREGIONMAP pfnRegionMap;
293} TSTDEVDUTPCIREGION;
294/** Pointer to a PCI region descriptor. */
295typedef TSTDEVDUTPCIREGION *PTSTDEVDUTPCIREGION;
296/** Pointer to a const PCI region descriptor. */
297typedef const TSTDEVDUTPCIREGION *PCTSTDEVDUTPCIREGION;
298
299/**
300 * Device under test instance data.
301 */
302typedef struct TSTDEVDUTINT
303{
304 /** Pointer to the testcase this device is part of. */
305 PCTSTDEVTESTCASEREG pTestcaseReg;
306 /** Pointer to the PDM device instance. */
307 PPDMDEVINS pDevIns;
308 /** Current device context. */
309 TSTDEVDUTCTX enmCtx;
310 /** Critical section protecting the lists below. */
311 RTCRITSECTRW CritSectLists;
312 /** List of registered I/O port handlers. */
313 RTLISTANCHOR LstIoPorts;
314 /** List of timers registered. */
315 RTLISTANCHOR LstTimers;
316 /** List of registered MMIO regions. */
317 RTLISTANCHOR LstMmio;
318 /** List of MM Heap allocations. */
319 RTLISTANCHOR LstMmHeap;
320 /** List of PDM threads. */
321 RTLISTANCHOR LstPdmThreads;
322 /** The SUP session we emulate. */
323 TSTDEVSUPDRVSESSION SupSession;
324 /** The VM state associated with this device. */
325 PVM pVm;
326 /** The registered PCI device instance if this is a PCI device. */
327 PPDMPCIDEV pPciDev;
328 /** PCI Region descriptors. */
329 TSTDEVDUTPCIREGION aPciRegions[VBOX_PCI_NUM_REGIONS];
330} TSTDEVDUTINT;
331
332
333extern const PDMDEVHLPR3 g_tstDevPdmDevHlpR3;
334
335
336DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType,
337 const char *pszSymbol, PFNRT *ppfn);
338
339
340DECLINLINE(int) tstDevDutLockShared(PTSTDEVDUTINT pThis)
341{
342 return RTCritSectRwEnterShared(&pThis->CritSectLists);
343}
344
345DECLINLINE(int) tstDevDutUnlockShared(PTSTDEVDUTINT pThis)
346{
347 return RTCritSectRwLeaveShared(&pThis->CritSectLists);
348}
349
350DECLINLINE(int) tstDevDutLockExcl(PTSTDEVDUTINT pThis)
351{
352 return RTCritSectRwEnterExcl(&pThis->CritSectLists);
353}
354
355DECLINLINE(int) tstDevDutUnlockExcl(PTSTDEVDUTINT pThis)
356{
357 return RTCritSectRwLeaveExcl(&pThis->CritSectLists);
358}
359
360RT_C_DECLS_END
361
362#endif /* !VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette