1 | /* $Id: IOMInternal.h 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IOM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___IOMInternal_h
|
---|
19 | #define ___IOMInternal_h
|
---|
20 |
|
---|
21 | #include <VBox/cdefs.h>
|
---|
22 | #include <VBox/types.h>
|
---|
23 | #include <VBox/iom.h>
|
---|
24 | #include <VBox/stam.h>
|
---|
25 | #include <VBox/pgm.h>
|
---|
26 | #include <VBox/pdmcritsect.h>
|
---|
27 | #include <VBox/param.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/avl.h>
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | /** @defgroup grp_iom_int Internals
|
---|
34 | * @ingroup grp_iom
|
---|
35 | * @internal
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * MMIO range descriptor.
|
---|
41 | */
|
---|
42 | typedef struct IOMMMIORANGE
|
---|
43 | {
|
---|
44 | /** Avl node core with GCPhys as Key and GCPhys + cbSize - 1 as KeyLast. */
|
---|
45 | AVLROGCPHYSNODECORE Core;
|
---|
46 | /** Start physical address. */
|
---|
47 | RTGCPHYS GCPhys;
|
---|
48 | /** Size of the range. */
|
---|
49 | uint32_t cb;
|
---|
50 | uint32_t u32Alignment; /**< Alignment padding. */
|
---|
51 |
|
---|
52 | /** Pointer to user argument - R3. */
|
---|
53 | RTR3PTR pvUserR3;
|
---|
54 | /** Pointer to device instance - R3. */
|
---|
55 | PPDMDEVINSR3 pDevInsR3;
|
---|
56 | /** Pointer to write callback function - R3. */
|
---|
57 | R3PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallbackR3;
|
---|
58 | /** Pointer to read callback function - R3. */
|
---|
59 | R3PTRTYPE(PFNIOMMMIOREAD) pfnReadCallbackR3;
|
---|
60 | /** Pointer to fill (memset) callback function - R3. */
|
---|
61 | R3PTRTYPE(PFNIOMMMIOFILL) pfnFillCallbackR3;
|
---|
62 |
|
---|
63 | /** Pointer to user argument - R0. */
|
---|
64 | RTR0PTR pvUserR0;
|
---|
65 | /** Pointer to device instance - R0. */
|
---|
66 | PPDMDEVINSR0 pDevInsR0;
|
---|
67 | /** Pointer to write callback function - R0. */
|
---|
68 | R0PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallbackR0;
|
---|
69 | /** Pointer to read callback function - R0. */
|
---|
70 | R0PTRTYPE(PFNIOMMMIOREAD) pfnReadCallbackR0;
|
---|
71 | /** Pointer to fill (memset) callback function - R0. */
|
---|
72 | R0PTRTYPE(PFNIOMMMIOFILL) pfnFillCallbackR0;
|
---|
73 |
|
---|
74 | /** Pointer to user argument - RC. */
|
---|
75 | RTRCPTR pvUserRC;
|
---|
76 | /** Pointer to device instance - RC. */
|
---|
77 | PPDMDEVINSRC pDevInsRC;
|
---|
78 | /** Pointer to write callback function - RC. */
|
---|
79 | RCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallbackRC;
|
---|
80 | /** Pointer to read callback function - RC. */
|
---|
81 | RCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallbackRC;
|
---|
82 | /** Pointer to fill (memset) callback function - RC. */
|
---|
83 | RCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallbackRC;
|
---|
84 | /** Alignment padding. */
|
---|
85 | RTRCPTR RCPtrAlignment;
|
---|
86 |
|
---|
87 | /** Description / Name. For easing debugging. */
|
---|
88 | R3PTRTYPE(const char *) pszDesc;
|
---|
89 | } IOMMMIORANGE;
|
---|
90 | /** Pointer to a MMIO range descriptor, R3 version. */
|
---|
91 | typedef struct IOMMMIORANGE *PIOMMMIORANGE;
|
---|
92 |
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * MMIO address statistics. (one address)
|
---|
96 | *
|
---|
97 | * This is a simple way of making on demand statistics, however it's a
|
---|
98 | * bit free with the hypervisor heap memory.
|
---|
99 | */
|
---|
100 | typedef struct IOMMMIOSTATS
|
---|
101 | {
|
---|
102 | /** Avl node core with the address as Key. */
|
---|
103 | AVLOGCPHYSNODECORE Core;
|
---|
104 |
|
---|
105 | /** Number of reads to this address from R3. */
|
---|
106 | STAMCOUNTER ReadR3;
|
---|
107 | /** Profiling read handler overhead in R3. */
|
---|
108 | STAMPROFILEADV ProfReadR3;
|
---|
109 |
|
---|
110 | /** Number of writes to this address from R3. */
|
---|
111 | STAMCOUNTER WriteR3;
|
---|
112 | /** Profiling write handler overhead in R3. */
|
---|
113 | STAMPROFILEADV ProfWriteR3;
|
---|
114 |
|
---|
115 | /** Number of reads to this address from R0/RC. */
|
---|
116 | STAMCOUNTER ReadRZ;
|
---|
117 | /** Profiling read handler overhead in R0/RC. */
|
---|
118 | STAMPROFILEADV ProfReadRZ;
|
---|
119 | /** Number of reads to this address from R0/RC which was serviced in R3. */
|
---|
120 | STAMCOUNTER ReadRZToR3;
|
---|
121 |
|
---|
122 | /** Number of writes to this address from R0/RC. */
|
---|
123 | STAMCOUNTER WriteRZ;
|
---|
124 | /** Profiling write handler overhead in R0/RC. */
|
---|
125 | STAMPROFILEADV ProfWriteRZ;
|
---|
126 | /** Number of writes to this address from R0/RC which was serviced in R3. */
|
---|
127 | STAMCOUNTER WriteRZToR3;
|
---|
128 | } IOMMMIOSTATS;
|
---|
129 | AssertCompileMemberAlignment(IOMMMIOSTATS, ReadR3, 8);
|
---|
130 | /** Pointer to I/O port statistics. */
|
---|
131 | typedef IOMMMIOSTATS *PIOMMMIOSTATS;
|
---|
132 |
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * I/O port range descriptor, R3 version.
|
---|
136 | */
|
---|
137 | typedef struct IOMIOPORTRANGER3
|
---|
138 | {
|
---|
139 | /** Avl node core with Port as Key and Port + cPorts - 1 as KeyLast. */
|
---|
140 | AVLROIOPORTNODECORE Core;
|
---|
141 | #if HC_ARCH_BITS == 64 && !defined(RT_OS_WINDOWS)
|
---|
142 | uint32_t u32Alignment; /**< The sizeof(Core) differs. */
|
---|
143 | #endif
|
---|
144 | /** Start I/O port address. */
|
---|
145 | RTIOPORT Port;
|
---|
146 | /** Size of the range. */
|
---|
147 | uint16_t cPorts;
|
---|
148 | /** Pointer to user argument. */
|
---|
149 | RTR3PTR pvUser;
|
---|
150 | /** Pointer to the associated device instance. */
|
---|
151 | R3PTRTYPE(PPDMDEVINS) pDevIns;
|
---|
152 | /** Pointer to OUT callback function. */
|
---|
153 | R3PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback;
|
---|
154 | /** Pointer to IN callback function. */
|
---|
155 | R3PTRTYPE(PFNIOMIOPORTIN) pfnInCallback;
|
---|
156 | /** Pointer to string OUT callback function. */
|
---|
157 | R3PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback;
|
---|
158 | /** Pointer to string IN callback function. */
|
---|
159 | R3PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback;
|
---|
160 | /** Description / Name. For easing debugging. */
|
---|
161 | R3PTRTYPE(const char *) pszDesc;
|
---|
162 | } IOMIOPORTRANGER3;
|
---|
163 | /** Pointer to I/O port range descriptor, R3 version. */
|
---|
164 | typedef IOMIOPORTRANGER3 *PIOMIOPORTRANGER3;
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * I/O port range descriptor, R0 version.
|
---|
168 | */
|
---|
169 | typedef struct IOMIOPORTRANGER0
|
---|
170 | {
|
---|
171 | /** Avl node core with Port as Key and Port + cPorts - 1 as KeyLast. */
|
---|
172 | AVLROIOPORTNODECORE Core;
|
---|
173 | #if HC_ARCH_BITS == 64 && !defined(RT_OS_WINDOWS)
|
---|
174 | uint32_t u32Alignment; /**< The sizeof(Core) differs. */
|
---|
175 | #endif
|
---|
176 | /** Start I/O port address. */
|
---|
177 | RTIOPORT Port;
|
---|
178 | /** Size of the range. */
|
---|
179 | uint16_t cPorts;
|
---|
180 | /** Pointer to user argument. */
|
---|
181 | RTR0PTR pvUser;
|
---|
182 | /** Pointer to the associated device instance. */
|
---|
183 | R0PTRTYPE(PPDMDEVINS) pDevIns;
|
---|
184 | /** Pointer to OUT callback function. */
|
---|
185 | R0PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback;
|
---|
186 | /** Pointer to IN callback function. */
|
---|
187 | R0PTRTYPE(PFNIOMIOPORTIN) pfnInCallback;
|
---|
188 | /** Pointer to string OUT callback function. */
|
---|
189 | R0PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback;
|
---|
190 | /** Pointer to string IN callback function. */
|
---|
191 | R0PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback;
|
---|
192 | /** Description / Name. For easing debugging. */
|
---|
193 | R3PTRTYPE(const char *) pszDesc;
|
---|
194 | } IOMIOPORTRANGER0;
|
---|
195 | /** Pointer to I/O port range descriptor, R0 version. */
|
---|
196 | typedef IOMIOPORTRANGER0 *PIOMIOPORTRANGER0;
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * I/O port range descriptor, RC version.
|
---|
200 | */
|
---|
201 | typedef struct IOMIOPORTRANGERC
|
---|
202 | {
|
---|
203 | /** Avl node core with Port as Key and Port + cPorts - 1 as KeyLast. */
|
---|
204 | AVLROIOPORTNODECORE Core;
|
---|
205 | /** Start I/O port address. */
|
---|
206 | RTIOPORT Port;
|
---|
207 | /** Size of the range. */
|
---|
208 | uint16_t cPorts;
|
---|
209 | /** Pointer to user argument. */
|
---|
210 | RTRCPTR pvUser;
|
---|
211 | /** Pointer to the associated device instance. */
|
---|
212 | RCPTRTYPE(PPDMDEVINS) pDevIns;
|
---|
213 | /** Pointer to OUT callback function. */
|
---|
214 | RCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback;
|
---|
215 | /** Pointer to IN callback function. */
|
---|
216 | RCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback;
|
---|
217 | /** Pointer to string OUT callback function. */
|
---|
218 | RCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback;
|
---|
219 | /** Pointer to string IN callback function. */
|
---|
220 | RCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback;
|
---|
221 | #if HC_ARCH_BITS == 64
|
---|
222 | RTRCPTR RCPtrAlignment; /**< pszDesc is 8 byte aligned. */
|
---|
223 | #endif
|
---|
224 | /** Description / Name. For easing debugging. */
|
---|
225 | R3PTRTYPE(const char *) pszDesc;
|
---|
226 | } IOMIOPORTRANGERC;
|
---|
227 | /** Pointer to I/O port range descriptor, RC version. */
|
---|
228 | typedef IOMIOPORTRANGERC *PIOMIOPORTRANGERC;
|
---|
229 |
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * I/O port statistics. (one I/O port)
|
---|
233 | *
|
---|
234 | * This is a simple way of making on demand statistics, however it's a
|
---|
235 | * bit free with the hypervisor heap memory.
|
---|
236 | */
|
---|
237 | typedef struct IOMIOPORTSTATS
|
---|
238 | {
|
---|
239 | /** Avl node core with the port as Key. */
|
---|
240 | AVLOIOPORTNODECORE Core;
|
---|
241 | #if HC_ARCH_BITS != 64 || !defined(RT_OS_WINDOWS)
|
---|
242 | uint32_t u32Alignment; /**< The sizeof(Core) differs. */
|
---|
243 | #endif
|
---|
244 | /** Number of INs to this port from R3. */
|
---|
245 | STAMCOUNTER InR3;
|
---|
246 | /** Profiling IN handler overhead in R3. */
|
---|
247 | STAMPROFILE ProfInR3;
|
---|
248 | /** Number of OUTs to this port from R3. */
|
---|
249 | STAMCOUNTER OutR3;
|
---|
250 | /** Profiling OUT handler overhead in R3. */
|
---|
251 | STAMPROFILE ProfOutR3;
|
---|
252 |
|
---|
253 | /** Number of INs to this port from R0/RC. */
|
---|
254 | STAMCOUNTER InRZ;
|
---|
255 | /** Profiling IN handler overhead in R0/RC. */
|
---|
256 | STAMPROFILE ProfInRZ;
|
---|
257 | /** Number of INs to this port from R0/RC which was serviced in R3. */
|
---|
258 | STAMCOUNTER InRZToR3;
|
---|
259 |
|
---|
260 | /** Number of OUTs to this port from R0/RC. */
|
---|
261 | STAMCOUNTER OutRZ;
|
---|
262 | /** Profiling OUT handler overhead in R0/RC. */
|
---|
263 | STAMPROFILE ProfOutRZ;
|
---|
264 | /** Number of OUTs to this port from R0/RC which was serviced in R3. */
|
---|
265 | STAMCOUNTER OutRZToR3;
|
---|
266 | } IOMIOPORTSTATS;
|
---|
267 | AssertCompileMemberAlignment(IOMIOPORTSTATS, InR3, 8);
|
---|
268 | /** Pointer to I/O port statistics. */
|
---|
269 | typedef IOMIOPORTSTATS *PIOMIOPORTSTATS;
|
---|
270 |
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * The IOM trees.
|
---|
274 | * These are offset based the nodes and root must be in the same
|
---|
275 | * memory block in HC. The locations of IOM structure and the hypervisor heap
|
---|
276 | * are quite different in R3, R0 and RC.
|
---|
277 | */
|
---|
278 | typedef struct IOMTREES
|
---|
279 | {
|
---|
280 | /** Tree containing I/O port range descriptors registered for HC (IOMIOPORTRANGEHC). */
|
---|
281 | AVLROIOPORTTREE IOPortTreeR3;
|
---|
282 | /** Tree containing I/O port range descriptors registered for R0 (IOMIOPORTRANGER0). */
|
---|
283 | AVLROIOPORTTREE IOPortTreeR0;
|
---|
284 | /** Tree containing I/O port range descriptors registered for RC (IOMIOPORTRANGERC). */
|
---|
285 | AVLROIOPORTTREE IOPortTreeRC;
|
---|
286 |
|
---|
287 | /** Tree containing the MMIO range descriptors (IOMMMIORANGE). */
|
---|
288 | AVLROGCPHYSTREE MMIOTree;
|
---|
289 |
|
---|
290 | /** Tree containing I/O port statistics (IOMIOPORTSTATS). */
|
---|
291 | AVLOIOPORTTREE IOPortStatTree;
|
---|
292 | /** Tree containing MMIO statistics (IOMMMIOSTATS). */
|
---|
293 | AVLOGCPHYSTREE MMIOStatTree;
|
---|
294 | } IOMTREES;
|
---|
295 | /** Pointer to the IOM trees. */
|
---|
296 | typedef IOMTREES *PIOMTREES;
|
---|
297 |
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Converts an IOM pointer into a VM pointer.
|
---|
301 | * @returns Pointer to the VM structure the PGM is part of.
|
---|
302 | * @param pIOM Pointer to IOM instance data.
|
---|
303 | */
|
---|
304 | #define IOM2VM(pIOM) ( (PVM)((char*)pIOM - pIOM->offVM) )
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * IOM Data (part of VM)
|
---|
308 | */
|
---|
309 | typedef struct IOM
|
---|
310 | {
|
---|
311 | /** Offset to the VM structure. */
|
---|
312 | RTINT offVM;
|
---|
313 |
|
---|
314 | /** Pointer to the trees - RC ptr. */
|
---|
315 | RCPTRTYPE(PIOMTREES) pTreesRC;
|
---|
316 | /** Pointer to the trees - R3 ptr. */
|
---|
317 | R3PTRTYPE(PIOMTREES) pTreesR3;
|
---|
318 | /** Pointer to the trees - R0 ptr. */
|
---|
319 | R0PTRTYPE(PIOMTREES) pTreesR0;
|
---|
320 |
|
---|
321 | /** The ring-0 address of IOMMMIOHandler. */
|
---|
322 | R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnMMIOHandlerR0;
|
---|
323 | /** The RC address of IOMMMIOHandler. */
|
---|
324 | RCPTRTYPE(PFNPGMRCPHYSHANDLER) pfnMMIOHandlerRC;
|
---|
325 | #if HC_ARCH_BITS == 64
|
---|
326 | RTRCPTR padding;
|
---|
327 | #endif
|
---|
328 |
|
---|
329 | /** Lock serializing EMT access to IOM. */
|
---|
330 | PDMCRITSECT EmtLock;
|
---|
331 |
|
---|
332 | /** @name Caching of I/O Port and MMIO ranges and statistics.
|
---|
333 | * (Saves quite some time in rep outs/ins instruction emulation.)
|
---|
334 | * @{ */
|
---|
335 | R3PTRTYPE(PIOMIOPORTRANGER3) pRangeLastReadR3;
|
---|
336 | R3PTRTYPE(PIOMIOPORTRANGER3) pRangeLastWriteR3;
|
---|
337 | R3PTRTYPE(PIOMIOPORTSTATS) pStatsLastReadR3;
|
---|
338 | R3PTRTYPE(PIOMIOPORTSTATS) pStatsLastWriteR3;
|
---|
339 | R3PTRTYPE(PIOMMMIORANGE) pMMIORangeLastR3;
|
---|
340 | R3PTRTYPE(PIOMMMIOSTATS) pMMIOStatsLastR3;
|
---|
341 |
|
---|
342 | R0PTRTYPE(PIOMIOPORTRANGER0) pRangeLastReadR0;
|
---|
343 | R0PTRTYPE(PIOMIOPORTRANGER0) pRangeLastWriteR0;
|
---|
344 | R0PTRTYPE(PIOMIOPORTSTATS) pStatsLastReadR0;
|
---|
345 | R0PTRTYPE(PIOMIOPORTSTATS) pStatsLastWriteR0;
|
---|
346 | R0PTRTYPE(PIOMMMIORANGE) pMMIORangeLastR0;
|
---|
347 | R0PTRTYPE(PIOMMMIOSTATS) pMMIOStatsLastR0;
|
---|
348 |
|
---|
349 | RCPTRTYPE(PIOMIOPORTRANGERC) pRangeLastReadRC;
|
---|
350 | RCPTRTYPE(PIOMIOPORTRANGERC) pRangeLastWriteRC;
|
---|
351 | RCPTRTYPE(PIOMIOPORTSTATS) pStatsLastReadRC;
|
---|
352 | RCPTRTYPE(PIOMIOPORTSTATS) pStatsLastWriteRC;
|
---|
353 | RCPTRTYPE(PIOMMMIORANGE) pMMIORangeLastRC;
|
---|
354 | RCPTRTYPE(PIOMMMIOSTATS) pMMIOStatsLastRC;
|
---|
355 | /** @} */
|
---|
356 |
|
---|
357 | /** @name I/O Port statistics.
|
---|
358 | * @{ */
|
---|
359 | STAMCOUNTER StatInstIn;
|
---|
360 | STAMCOUNTER StatInstOut;
|
---|
361 | STAMCOUNTER StatInstIns;
|
---|
362 | STAMCOUNTER StatInstOuts;
|
---|
363 | /** @} */
|
---|
364 |
|
---|
365 | /** @name MMIO statistics.
|
---|
366 | * @{ */
|
---|
367 | STAMPROFILE StatRZMMIOHandler;
|
---|
368 | STAMCOUNTER StatRZMMIOFailures;
|
---|
369 |
|
---|
370 | STAMPROFILE StatRZInstMov;
|
---|
371 | STAMPROFILE StatRZInstCmp;
|
---|
372 | STAMPROFILE StatRZInstAnd;
|
---|
373 | STAMPROFILE StatRZInstOr;
|
---|
374 | STAMPROFILE StatRZInstXor;
|
---|
375 | STAMPROFILE StatRZInstBt;
|
---|
376 | STAMPROFILE StatRZInstTest;
|
---|
377 | STAMPROFILE StatRZInstXchg;
|
---|
378 | STAMPROFILE StatRZInstStos;
|
---|
379 | STAMPROFILE StatRZInstLods;
|
---|
380 | #ifdef IOM_WITH_MOVS_SUPPORT
|
---|
381 | STAMPROFILEADV StatRZInstMovs;
|
---|
382 | STAMPROFILE StatRZInstMovsToMMIO;
|
---|
383 | STAMPROFILE StatRZInstMovsFromMMIO;
|
---|
384 | STAMPROFILE StatRZInstMovsMMIO;
|
---|
385 | #endif
|
---|
386 | STAMCOUNTER StatRZInstOther;
|
---|
387 |
|
---|
388 | STAMCOUNTER StatRZMMIO1Byte;
|
---|
389 | STAMCOUNTER StatRZMMIO2Bytes;
|
---|
390 | STAMCOUNTER StatRZMMIO4Bytes;
|
---|
391 | STAMCOUNTER StatRZMMIO8Bytes;
|
---|
392 |
|
---|
393 | STAMCOUNTER StatR3MMIOHandler;
|
---|
394 |
|
---|
395 | RTUINT cMovsMaxBytes;
|
---|
396 | RTUINT cStosMaxBytes;
|
---|
397 | /** @} */
|
---|
398 | } IOM;
|
---|
399 | /** Pointer to IOM instance data. */
|
---|
400 | typedef IOM *PIOM;
|
---|
401 |
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * IOM per virtual CPU instance data.
|
---|
405 | */
|
---|
406 | typedef struct IOMCPU
|
---|
407 | {
|
---|
408 | /** For saving stack space, the disassembler state is allocated here instead of
|
---|
409 | * on the stack.
|
---|
410 | * @note The DISCPUSTATE structure is not R3/R0/RZ clean! */
|
---|
411 | union
|
---|
412 | {
|
---|
413 | /** The disassembler scratch space. */
|
---|
414 | DISCPUSTATE DisState;
|
---|
415 | /** Padding. */
|
---|
416 | uint8_t abDisStatePadding[DISCPUSTATE_PADDING_SIZE];
|
---|
417 | };
|
---|
418 | uint8_t Dummy[16];
|
---|
419 | } IOMCPU;
|
---|
420 | /** Pointer to IOM per virtual CPU instance data. */
|
---|
421 | typedef IOMCPU *PIOMCPU;
|
---|
422 |
|
---|
423 |
|
---|
424 | RT_C_DECLS_BEGIN
|
---|
425 |
|
---|
426 | #ifdef IN_RING3
|
---|
427 | PIOMIOPORTSTATS iomR3IOPortStatsCreate(PVM pVM, RTIOPORT Port, const char *pszDesc);
|
---|
428 | PIOMMMIOSTATS iomR3MMIOStatsCreate(PVM pVM, RTGCPHYS GCPhys, const char *pszDesc);
|
---|
429 | #endif /* IN_RING3 */
|
---|
430 |
|
---|
431 | VMMDECL(int) IOMMMIOHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
|
---|
432 | #ifdef IN_RING3
|
---|
433 | DECLCALLBACK(int) IOMR3MMIOHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
|
---|
434 | #endif
|
---|
435 |
|
---|
436 |
|
---|
437 | /**
|
---|
438 | * Gets the I/O port range for the specified I/O port in the current context.
|
---|
439 | *
|
---|
440 | * @returns Pointer to I/O port range.
|
---|
441 | * @returns NULL if no port registered.
|
---|
442 | *
|
---|
443 | * @param pIOM IOM instance data.
|
---|
444 | * @param Port Port to lookup.
|
---|
445 | */
|
---|
446 | DECLINLINE(CTX_SUFF(PIOMIOPORTRANGE)) iomIOPortGetRange(PIOM pIOM, RTIOPORT Port)
|
---|
447 | {
|
---|
448 | #ifdef IN_RING3
|
---|
449 | if (PDMCritSectIsInitialized(&pIOM->EmtLock))
|
---|
450 | #endif
|
---|
451 | Assert(IOMIsLockOwner(IOM2VM(pIOM)));
|
---|
452 | CTX_SUFF(PIOMIOPORTRANGE) pRange = (CTX_SUFF(PIOMIOPORTRANGE))RTAvlroIOPortRangeGet(&pIOM->CTX_SUFF(pTrees)->CTX_SUFF(IOPortTree), Port);
|
---|
453 | return pRange;
|
---|
454 | }
|
---|
455 |
|
---|
456 |
|
---|
457 | /**
|
---|
458 | * Gets the I/O port range for the specified I/O port in the HC.
|
---|
459 | *
|
---|
460 | * @returns Pointer to I/O port range.
|
---|
461 | * @returns NULL if no port registered.
|
---|
462 | *
|
---|
463 | * @param pIOM IOM instance data.
|
---|
464 | * @param Port Port to lookup.
|
---|
465 | */
|
---|
466 | DECLINLINE(PIOMIOPORTRANGER3) iomIOPortGetRangeR3(PIOM pIOM, RTIOPORT Port)
|
---|
467 | {
|
---|
468 | #ifdef IN_RING3
|
---|
469 | if (PDMCritSectIsInitialized(&pIOM->EmtLock))
|
---|
470 | #endif
|
---|
471 | Assert(IOMIsLockOwner(IOM2VM(pIOM)));
|
---|
472 | PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pIOM->CTX_SUFF(pTrees)->IOPortTreeR3, Port);
|
---|
473 | return pRange;
|
---|
474 | }
|
---|
475 |
|
---|
476 |
|
---|
477 | /**
|
---|
478 | * Gets the MMIO range for the specified physical address in the current context.
|
---|
479 | *
|
---|
480 | * @returns Pointer to MMIO range.
|
---|
481 | * @returns NULL if address not in a MMIO range.
|
---|
482 | *
|
---|
483 | * @param pIOM IOM instance data.
|
---|
484 | * @param GCPhys Physical address to lookup.
|
---|
485 | */
|
---|
486 | DECLINLINE(PIOMMMIORANGE) iomMMIOGetRange(PIOM pIOM, RTGCPHYS GCPhys)
|
---|
487 | {
|
---|
488 | #ifdef IN_RING3
|
---|
489 | if (PDMCritSectIsInitialized(&pIOM->EmtLock))
|
---|
490 | #endif
|
---|
491 | Assert(IOMIsLockOwner(IOM2VM(pIOM)));
|
---|
492 | PIOMMMIORANGE pRange = pIOM->CTX_SUFF(pMMIORangeLast);
|
---|
493 | if ( !pRange
|
---|
494 | || GCPhys - pRange->GCPhys >= pRange->cb)
|
---|
495 | pIOM->CTX_SUFF(pMMIORangeLast) = pRange = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pIOM->CTX_SUFF(pTrees)->MMIOTree, GCPhys);
|
---|
496 | return pRange;
|
---|
497 | }
|
---|
498 |
|
---|
499 | #ifdef VBOX_STRICT
|
---|
500 | /**
|
---|
501 | * Gets the MMIO range for the specified physical address in the current context.
|
---|
502 | *
|
---|
503 | * @returns Pointer to MMIO range.
|
---|
504 | * @returns NULL if address not in a MMIO range.
|
---|
505 | *
|
---|
506 | * @param pIOM IOM instance data.
|
---|
507 | * @param GCPhys Physical address to lookup.
|
---|
508 | */
|
---|
509 | DECLINLINE(PIOMMMIORANGE) iomMMIOGetRangeUnsafe(PIOM pIOM, RTGCPHYS GCPhys)
|
---|
510 | {
|
---|
511 | PIOMMMIORANGE pRange = pIOM->CTX_SUFF(pMMIORangeLast);
|
---|
512 | if ( !pRange
|
---|
513 | || GCPhys - pRange->GCPhys >= pRange->cb)
|
---|
514 | pIOM->CTX_SUFF(pMMIORangeLast) = pRange = (PIOMMMIORANGE)RTAvlroGCPhysRangeGet(&pIOM->CTX_SUFF(pTrees)->MMIOTree, GCPhys);
|
---|
515 | return pRange;
|
---|
516 | }
|
---|
517 | #endif
|
---|
518 |
|
---|
519 |
|
---|
520 | #ifdef VBOX_WITH_STATISTICS
|
---|
521 | /**
|
---|
522 | * Gets the MMIO statistics record.
|
---|
523 | *
|
---|
524 | * In ring-3 this will lazily create missing records, while in GC/R0 the caller has to
|
---|
525 | * return the appropriate status to defer the operation to ring-3.
|
---|
526 | *
|
---|
527 | * @returns Pointer to MMIO stats.
|
---|
528 | * @returns NULL if not found (R0/GC), or out of memory (R3).
|
---|
529 | *
|
---|
530 | * @param pIOM IOM instance data.
|
---|
531 | * @param GCPhys Physical address to lookup.
|
---|
532 | * @param pRange The MMIO range.
|
---|
533 | */
|
---|
534 | DECLINLINE(PIOMMMIOSTATS) iomMMIOGetStats(PIOM pIOM, RTGCPHYS GCPhys, PIOMMMIORANGE pRange)
|
---|
535 | {
|
---|
536 | Assert(IOMIsLockOwner(IOM2VM(pIOM)));
|
---|
537 | /* For large ranges, we'll put everything on the first byte. */
|
---|
538 | if (pRange->cb > PAGE_SIZE)
|
---|
539 | GCPhys = pRange->GCPhys;
|
---|
540 |
|
---|
541 | PIOMMMIOSTATS pStats = pIOM->CTX_SUFF(pMMIOStatsLast);
|
---|
542 | if ( !pStats
|
---|
543 | || pStats->Core.Key != GCPhys)
|
---|
544 | {
|
---|
545 | pStats = (PIOMMMIOSTATS)RTAvloGCPhysGet(&pIOM->CTX_SUFF(pTrees)->MMIOStatTree, GCPhys);
|
---|
546 | # ifdef IN_RING3
|
---|
547 | if (!pStats)
|
---|
548 | pStats = iomR3MMIOStatsCreate(IOM2VM(pIOM), GCPhys, pRange->pszDesc);
|
---|
549 | # endif
|
---|
550 | }
|
---|
551 | return pStats;
|
---|
552 | }
|
---|
553 | #endif
|
---|
554 |
|
---|
555 | /* IOM locking helpers. */
|
---|
556 | int iomLock(PVM pVM);
|
---|
557 | int iomTryLock(PVM pVM);
|
---|
558 | void iomUnlock(PVM pVM);
|
---|
559 |
|
---|
560 | /* Disassembly helpers used in IOMAll.cpp & IOMAllMMIO.cpp */
|
---|
561 | bool iomGetRegImmData(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, uint64_t *pu64Data, unsigned *pcbSize);
|
---|
562 | bool iomSaveDataToReg(PDISCPUSTATE pCpu, PCOP_PARAMETER pParam, PCPUMCTXCORE pRegFrame, uint64_t u32Data);
|
---|
563 |
|
---|
564 | RT_C_DECLS_END
|
---|
565 |
|
---|
566 |
|
---|
567 | #ifdef IN_RING3
|
---|
568 |
|
---|
569 | #endif
|
---|
570 |
|
---|
571 | /** @} */
|
---|
572 |
|
---|
573 | #endif /* ___IOMInternal_h */
|
---|