VirtualBox

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

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

Devices/testcase: Restarted work on the device testbench/fuzzing work (#9006), adjusting to the interface changes in 6.1 dropping the VMM stub library which is not required anymore (yay), work in progress

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 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
29#include "tstDevicePlugin.h"
30
31RT_C_DECLS_BEGIN
32
33
34/** Converts PDM device instance to the device under test structure. */
35#define TSTDEV_PDMDEVINS_2_DUT(a_pDevIns) ((a_pDevIns)->Internal.s.pDut)
36
37/** Forward declaration of internal test device instance data. */
38typedef struct TSTDEVDUTINT *PTSTDEVDUTINT;
39
40
41/**
42 * CFGM node structure.
43 */
44typedef struct CFGMNODE
45{
46 /** Device under test this CFGM node is for. */
47 PTSTDEVDUTINT pDut;
48 /** @todo: */
49} CFGMNODE;
50
51
52/**
53 * Private device instance data.
54 */
55typedef struct PDMDEVINSINTR3
56{
57 /** Pointer to the device under test the PDM device instance is for. */
58 PTSTDEVDUTINT pDut;
59} PDMDEVINSINTR3;
60AssertCompile(sizeof(PDMDEVINSINTR3) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
61
62/**
63 * Private device instance data.
64 */
65typedef struct PDMDEVINSINTR0
66{
67 /** Pointer to the device under test the PDM device instance is for. */
68 PTSTDEVDUTINT pDut;
69} PDMDEVINSINTR0;
70AssertCompile(sizeof(PDMDEVINSINTR0) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
71
72/**
73 * Private device instance data.
74 */
75typedef struct PDMDEVINSINTRC
76{
77 /** Pointer to the device under test the PDM device instance is for. */
78 PTSTDEVDUTINT pDut;
79} PDMDEVINSINTRC;
80AssertCompile(sizeof(PDMDEVINSINTRC) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
81
82typedef struct PDMPCIDEVINT
83{
84 bool fRegistered;
85} PDMPCIDEVINT;
86
87#define PDMDEVINSINT_DECLARED
88#define PDMPCIDEVINT_DECLARED
89#define VMM_INCLUDED_SRC_include_VMInternal_h
90#define VMM_INCLUDED_SRC_include_VMMInternal_h
91RT_C_DECLS_END
92#include <VBox/vmm/pdmdev.h>
93#include <VBox/vmm/pdmpci.h>
94#include <VBox/vmm/pdmdrv.h>
95RT_C_DECLS_BEGIN
96
97
98/**
99 * PDM module descriptor type.
100 */
101typedef enum TSTDEVPDMMODTYPE
102{
103 /** Invalid module type. */
104 TSTDEVPDMMODTYPE_INVALID = 0,
105 /** Ring 3 module. */
106 TSTDEVPDMMODTYPE_R3,
107 /** Ring 0 module. */
108 TSTDEVPDMMODTYPE_R0,
109 /** Raw context module. */
110 TSTDEVPDMMODTYPE_RC,
111 /** 32bit hack. */
112 TSTDEVPDMMODTYPE_32BIT_HACK = 0x7fffffff
113} TSTDEVPDMMODTYPE;
114
115/**
116 * Registered I/O port access handler.
117 */
118typedef struct RTDEVDUTIOPORT
119{
120 /** Node for the list of registered handlers. */
121 RTLISTNODE NdIoPorts;
122 /** Start I/O port the handler is for. */
123 RTIOPORT PortStart;
124 /** Number of ports handled. */
125 RTIOPORT cPorts;
126 /** Opaque user data - R3. */
127 void *pvUserR3;
128 /** Out handler - R3. */
129 PFNIOMIOPORTNEWOUT pfnOutR3;
130 /** In handler - R3. */
131 PFNIOMIOPORTNEWIN pfnInR3;
132 /** Out string handler - R3. */
133 PFNIOMIOPORTNEWOUTSTRING pfnOutStrR3;
134 /** In string handler - R3. */
135 PFNIOMIOPORTNEWINSTRING pfnInStrR3;
136
137 /** Opaque user data - R0. */
138 void *pvUserR0;
139 /** Out handler - R0. */
140 PFNIOMIOPORTNEWOUT pfnOutR0;
141 /** In handler - R0. */
142 PFNIOMIOPORTNEWIN pfnInR0;
143 /** Out string handler - R0. */
144 PFNIOMIOPORTNEWOUTSTRING pfnOutStrR0;
145 /** In string handler - R0. */
146 PFNIOMIOPORTNEWINSTRING pfnInStrR0;
147
148#ifdef TSTDEV_SUPPORTS_RC
149 /** Opaque user data - RC. */
150 void *pvUserRC;
151 /** Out handler - RC. */
152 PFNIOMIOPORTNEWOUT pfnOutRC;
153 /** In handler - RC. */
154 PFNIOMIOPORTNEWIN pfnInRC;
155 /** Out string handler - RC. */
156 PFNIOMIOPORTNEWOUTSTRING pfnOutStrRC;
157 /** In string handler - RC. */
158 PFNIOMIOPORTNEWINSTRING pfnInStrRC;
159#endif
160} RTDEVDUTIOPORT;
161/** Pointer to a registered I/O port handler. */
162typedef RTDEVDUTIOPORT *PRTDEVDUTIOPORT;
163/** Pointer to a const I/O port handler. */
164typedef const RTDEVDUTIOPORT *PCRTDEVDUTIOPORT;
165
166/**
167 * The Support Driver session state.
168 */
169typedef struct TSTDEVSUPDRVSESSION
170{
171 /** Pointer to the owning device under test instance. */
172 PTSTDEVDUTINT pDut;
173 /** List of event semaphores. */
174 RTLISTANCHOR LstSupSem;
175} TSTDEVSUPDRVSESSION;
176/** Pointer to the Support Driver session state. */
177typedef TSTDEVSUPDRVSESSION *PTSTDEVSUPDRVSESSION;
178
179/** Converts a Support Driver session handle to the internal state. */
180#define TSTDEV_PSUPDRVSESSION_2_PTSTDEVSUPDRVSESSION(a_pSession) ((PTSTDEVSUPDRVSESSION)(a_pSession))
181/** Converts the internal session state to a Support Driver session handle. */
182#define TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(a_pSession) ((PSUPDRVSESSION)(a_pSession))
183
184/**
185 * Support driver event semaphore.
186 */
187typedef struct TSTDEVSUPSEMEVENT
188{
189 /** Node for the event semaphore list. */
190 RTLISTNODE NdSupSem;
191 /** Flag whether this is multi event semaphore. */
192 bool fMulti;
193 /** Event smeaphore handles depending on the flag above. */
194 union
195 {
196 RTSEMEVENT hSemEvt;
197 RTSEMEVENTMULTI hSemEvtMulti;
198 } u;
199} TSTDEVSUPSEMEVENT;
200/** Pointer to a support event semaphore state. */
201typedef TSTDEVSUPSEMEVENT *PTSTDEVSUPSEMEVENT;
202
203/** Converts a Support event semaphore handle to the internal state. */
204#define TSTDEV_SUPSEMEVENT_2_PTSTDEVSUPSEMEVENT(a_pSupSemEvt) ((PTSTDEVSUPSEMEVENT)(a_pSupSemEvt))
205/** Converts the internal session state to a Support event semaphore handle. */
206#define TSTDEV_PTSTDEVSUPSEMEVENT_2_SUPSEMEVENT(a_pSupSemEvt) ((SUPSEMEVENT)(a_pSupSemEvt))
207
208/**
209 * The contex the device under test is currently in.
210 */
211typedef enum TSTDEVDUTCTX
212{
213 /** Invalid context. */
214 TSTDEVDUTCTX_INVALID = 0,
215 /** R3 context. */
216 TSTDEVDUTCTX_R3,
217 /** R0 context. */
218 TSTDEVDUTCTX_R0,
219 /** RC context. */
220 TSTDEVDUTCTX_RC,
221 /** 32bit hack. */
222 TSTDEVDUTCTX_32BIT_HACK = 0x7fffffff
223} TSTDEVDUTCTX;
224
225/**
226 * PCI region descriptor.
227 */
228typedef struct TSTDEVDUTPCIREGION
229{
230 /** Size of the region. */
231 RTGCPHYS cbRegion;
232 /** Address space type. */
233 PCIADDRESSSPACE enmType;
234 /** Region mapping callback. */
235 PFNPCIIOREGIONMAP pfnRegionMap;
236} TSTDEVDUTPCIREGION;
237/** Pointer to a PCI region descriptor. */
238typedef TSTDEVDUTPCIREGION *PTSTDEVDUTPCIREGION;
239/** Pointer to a const PCI region descriptor. */
240typedef const TSTDEVDUTPCIREGION *PCTSTDEVDUTPCIREGION;
241
242/**
243 * Device under test instance data.
244 */
245typedef struct TSTDEVDUTINT
246{
247 /** Pointer to the testcase this device is part of. */
248 PCTSTDEVTESTCASEREG pTestcaseReg;
249 /** Pointer to the PDM device instance. */
250 PPDMDEVINS pDevIns;
251 /** Current device context. */
252 TSTDEVDUTCTX enmCtx;
253 /** Critical section protecting the lists below. */
254 RTCRITSECTRW CritSectLists;
255 /** List of registered I/O port handlers. */
256 RTLISTANCHOR LstIoPorts;
257 /** List of timers registered. */
258 RTLISTANCHOR LstTimers;
259 /** List of registered MMIO regions. */
260 RTLISTANCHOR LstMmio;
261 /** List of MM Heap allocations. */
262 RTLISTANCHOR LstMmHeap;
263 /** List of PDM threads. */
264 RTLISTANCHOR LstPdmThreads;
265 /** The SUP session we emulate. */
266 TSTDEVSUPDRVSESSION SupSession;
267 /** The VM state associated with this device. */
268 PVM pVm;
269 /** The registered PCI device instance if this is a PCI device. */
270 PPDMPCIDEV pPciDev;
271 /** PCI Region descriptors. */
272 TSTDEVDUTPCIREGION aPciRegions[VBOX_PCI_NUM_REGIONS];
273} TSTDEVDUTINT;
274
275
276extern const PDMDEVHLPR3 g_tstDevPdmDevHlpR3;
277
278
279DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType,
280 const char *pszSymbol, PFNRT *ppfn);
281
282
283DECLINLINE(int) tstDevDutLockShared(PTSTDEVDUTINT pThis)
284{
285 return RTCritSectRwEnterShared(&pThis->CritSectLists);
286}
287
288DECLINLINE(int) tstDevDutUnlockShared(PTSTDEVDUTINT pThis)
289{
290 return RTCritSectRwLeaveShared(&pThis->CritSectLists);
291}
292
293DECLINLINE(int) tstDevDutLockExcl(PTSTDEVDUTINT pThis)
294{
295 return RTCritSectRwEnterExcl(&pThis->CritSectLists);
296}
297
298DECLINLINE(int) tstDevDutUnlockExcl(PTSTDEVDUTINT pThis)
299{
300 return RTCritSectRwLeaveExcl(&pThis->CritSectLists);
301}
302
303RT_C_DECLS_END
304
305#endif /* !VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h */
Note: See TracBrowser for help on using the repository browser.

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