1 | /* $Id: IOMInternal.h 82380 2019-12-04 12:41:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IOM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 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 VMM_INCLUDED_SRC_include_IOMInternal_h
|
---|
19 | #define VMM_INCLUDED_SRC_include_IOMInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #define IOM_WITH_CRIT_SECT_RW
|
---|
25 |
|
---|
26 | #include <VBox/cdefs.h>
|
---|
27 | #include <VBox/types.h>
|
---|
28 | #include <VBox/vmm/iom.h>
|
---|
29 | #include <VBox/vmm/stam.h>
|
---|
30 | #include <VBox/vmm/pgm.h>
|
---|
31 | #include <VBox/vmm/pdmcritsect.h>
|
---|
32 | #ifdef IOM_WITH_CRIT_SECT_RW
|
---|
33 | # include <VBox/vmm/pdmcritsectrw.h>
|
---|
34 | #endif
|
---|
35 | #include <VBox/param.h>
|
---|
36 | #include <iprt/assert.h>
|
---|
37 | #include <iprt/avl.h>
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | /** @defgroup grp_iom_int Internals
|
---|
42 | * @ingroup grp_iom
|
---|
43 | * @internal
|
---|
44 | * @{
|
---|
45 | */
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * I/O port lookup table entry.
|
---|
49 | */
|
---|
50 | typedef struct IOMIOPORTLOOKUPENTRY
|
---|
51 | {
|
---|
52 | /** The first port in the range. */
|
---|
53 | RTIOPORT uFirstPort;
|
---|
54 | /** The last port in the range (inclusive). */
|
---|
55 | RTIOPORT uLastPort;
|
---|
56 | /** The registration handle/index. */
|
---|
57 | uint16_t idx;
|
---|
58 | } IOMIOPORTLOOKUPENTRY;
|
---|
59 | /** Pointer to an I/O port lookup table entry. */
|
---|
60 | typedef IOMIOPORTLOOKUPENTRY *PIOMIOPORTLOOKUPENTRY;
|
---|
61 | /** Pointer to a const I/O port lookup table entry. */
|
---|
62 | typedef IOMIOPORTLOOKUPENTRY const *PCIOMIOPORTLOOKUPENTRY;
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Ring-0 I/O port handle table entry.
|
---|
66 | */
|
---|
67 | typedef struct IOMIOPORTENTRYR0
|
---|
68 | {
|
---|
69 | /** Pointer to user argument. */
|
---|
70 | RTR0PTR pvUser;
|
---|
71 | /** Pointer to the associated device instance, NULL if entry not used. */
|
---|
72 | R0PTRTYPE(PPDMDEVINS) pDevIns;
|
---|
73 | /** Pointer to OUT callback function. */
|
---|
74 | R0PTRTYPE(PFNIOMIOPORTNEWOUT) pfnOutCallback;
|
---|
75 | /** Pointer to IN callback function. */
|
---|
76 | R0PTRTYPE(PFNIOMIOPORTNEWIN) pfnInCallback;
|
---|
77 | /** Pointer to string OUT callback function. */
|
---|
78 | R0PTRTYPE(PFNIOMIOPORTNEWOUTSTRING) pfnOutStrCallback;
|
---|
79 | /** Pointer to string IN callback function. */
|
---|
80 | R0PTRTYPE(PFNIOMIOPORTNEWINSTRING) pfnInStrCallback;
|
---|
81 | /** The entry of the first statistics entry, UINT16_MAX if no stats. */
|
---|
82 | uint16_t idxStats;
|
---|
83 | /** The number of ports covered by this entry, 0 if entry not used. */
|
---|
84 | RTIOPORT cPorts;
|
---|
85 | /** Same as the handle index. */
|
---|
86 | uint16_t idxSelf;
|
---|
87 | /** IOM_IOPORT_F_XXX (copied from ring-3). */
|
---|
88 | uint16_t fFlags;
|
---|
89 | } IOMIOPORTENTRYR0;
|
---|
90 | /** Pointer to a ring-0 I/O port handle table entry. */
|
---|
91 | typedef IOMIOPORTENTRYR0 *PIOMIOPORTENTRYR0;
|
---|
92 | /** Pointer to a const ring-0 I/O port handle table entry. */
|
---|
93 | typedef IOMIOPORTENTRYR0 const *PCIOMIOPORTENTRYR0;
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Ring-3 I/O port handle table entry.
|
---|
97 | */
|
---|
98 | typedef struct IOMIOPORTENTRYR3
|
---|
99 | {
|
---|
100 | /** Pointer to user argument. */
|
---|
101 | RTR3PTR pvUser;
|
---|
102 | /** Pointer to the associated device instance. */
|
---|
103 | R3PTRTYPE(PPDMDEVINS) pDevIns;
|
---|
104 | /** Pointer to OUT callback function. */
|
---|
105 | R3PTRTYPE(PFNIOMIOPORTNEWOUT) pfnOutCallback;
|
---|
106 | /** Pointer to IN callback function. */
|
---|
107 | R3PTRTYPE(PFNIOMIOPORTNEWIN) pfnInCallback;
|
---|
108 | /** Pointer to string OUT callback function. */
|
---|
109 | R3PTRTYPE(PFNIOMIOPORTNEWOUTSTRING) pfnOutStrCallback;
|
---|
110 | /** Pointer to string IN callback function. */
|
---|
111 | R3PTRTYPE(PFNIOMIOPORTNEWINSTRING) pfnInStrCallback;
|
---|
112 | /** Description / Name. For easing debugging. */
|
---|
113 | R3PTRTYPE(const char *) pszDesc;
|
---|
114 | /** Extended port description table, optional. */
|
---|
115 | R3PTRTYPE(PCIOMIOPORTDESC) paExtDescs;
|
---|
116 | /** PCI device the registration is associated with. */
|
---|
117 | R3PTRTYPE(PPDMPCIDEV) pPciDev;
|
---|
118 | /** The PCI device region (high 16-bit word) and subregion (low word),
|
---|
119 | * UINT32_MAX if not applicable. */
|
---|
120 | uint32_t iPciRegion;
|
---|
121 | /** The number of ports covered by this entry. */
|
---|
122 | RTIOPORT cPorts;
|
---|
123 | /** The current port mapping (duplicates lookup table). */
|
---|
124 | RTIOPORT uPort;
|
---|
125 | /** The entry of the first statistics entry, UINT16_MAX if no stats. */
|
---|
126 | uint16_t idxStats;
|
---|
127 | /** Set if mapped, clear if not.
|
---|
128 | * Only updated when critsect is held exclusively. */
|
---|
129 | bool fMapped;
|
---|
130 | /** Set if there is an ring-0 entry too. */
|
---|
131 | bool fRing0;
|
---|
132 | /** Set if there is an raw-mode entry too. */
|
---|
133 | bool fRawMode;
|
---|
134 | /** IOM_IOPORT_F_XXX */
|
---|
135 | uint8_t fFlags;
|
---|
136 | /** Same as the handle index. */
|
---|
137 | uint16_t idxSelf;
|
---|
138 | } IOMIOPORTENTRYR3;
|
---|
139 | AssertCompileSize(IOMIOPORTENTRYR3, 9 * sizeof(RTR3PTR) + 16);
|
---|
140 | /** Pointer to a ring-3 I/O port handle table entry. */
|
---|
141 | typedef IOMIOPORTENTRYR3 *PIOMIOPORTENTRYR3;
|
---|
142 | /** Pointer to a const ring-3 I/O port handle table entry. */
|
---|
143 | typedef IOMIOPORTENTRYR3 const *PCIOMIOPORTENTRYR3;
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * I/O port statistics entry (one I/O port).
|
---|
147 | */
|
---|
148 | typedef struct IOMIOPORTSTATSENTRY
|
---|
149 | {
|
---|
150 | /** All accesses (only updated for the first port in a range). */
|
---|
151 | STAMCOUNTER Total;
|
---|
152 |
|
---|
153 | /** Number of INs to this port from R3. */
|
---|
154 | STAMCOUNTER InR3;
|
---|
155 | /** Profiling IN handler overhead in R3. */
|
---|
156 | STAMPROFILE ProfInR3;
|
---|
157 | /** Number of OUTs to this port from R3. */
|
---|
158 | STAMCOUNTER OutR3;
|
---|
159 | /** Profiling OUT handler overhead in R3. */
|
---|
160 | STAMPROFILE ProfOutR3;
|
---|
161 |
|
---|
162 | /** Number of INs to this port from R0/RC. */
|
---|
163 | STAMCOUNTER InRZ;
|
---|
164 | /** Profiling IN handler overhead in R0/RC. */
|
---|
165 | STAMPROFILE ProfInRZ;
|
---|
166 | /** Number of INs to this port from R0/RC which was serviced in R3. */
|
---|
167 | STAMCOUNTER InRZToR3;
|
---|
168 |
|
---|
169 | /** Number of OUTs to this port from R0/RC. */
|
---|
170 | STAMCOUNTER OutRZ;
|
---|
171 | /** Profiling OUT handler overhead in R0/RC. */
|
---|
172 | STAMPROFILE ProfOutRZ;
|
---|
173 | /** Number of OUTs to this port from R0/RC which was serviced in R3. */
|
---|
174 | STAMCOUNTER OutRZToR3;
|
---|
175 | } IOMIOPORTSTATSENTRY;
|
---|
176 | /** Pointer to I/O port statistics entry. */
|
---|
177 | typedef IOMIOPORTSTATSENTRY *PIOMIOPORTSTATSENTRY;
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * MMIO lookup table entry.
|
---|
183 | */
|
---|
184 | typedef struct IOMMMIOLOOKUPENTRY
|
---|
185 | {
|
---|
186 | /** The first port in the range. */
|
---|
187 | RTGCPHYS GCPhysFirst;
|
---|
188 | /** The last port in the range (inclusive). */
|
---|
189 | RTGCPHYS GCPhysLast;
|
---|
190 | /** The registration handle/index.
|
---|
191 | * @todo bake this into the lower/upper bits of GCPhysFirst & GCPhysLast. */
|
---|
192 | uint16_t idx;
|
---|
193 | uint16_t abPadding[3];
|
---|
194 | } IOMMMIOLOOKUPENTRY;
|
---|
195 | /** Pointer to an MMIO lookup table entry. */
|
---|
196 | typedef IOMMMIOLOOKUPENTRY *PIOMMMIOLOOKUPENTRY;
|
---|
197 | /** Pointer to a const MMIO lookup table entry. */
|
---|
198 | typedef IOMMMIOLOOKUPENTRY const *PCIOMMMIOLOOKUPENTRY;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Ring-0 MMIO handle table entry.
|
---|
202 | */
|
---|
203 | typedef struct IOMMMIOENTRYR0
|
---|
204 | {
|
---|
205 | /** The number of bytes covered by this entry, 0 if entry not used. */
|
---|
206 | RTGCPHYS cbRegion;
|
---|
207 | /** Pointer to user argument. */
|
---|
208 | RTR0PTR pvUser;
|
---|
209 | /** Pointer to the associated device instance, NULL if entry not used. */
|
---|
210 | R0PTRTYPE(PPDMDEVINS) pDevIns;
|
---|
211 | /** Pointer to the write callback function. */
|
---|
212 | R0PTRTYPE(PFNIOMMMIONEWWRITE) pfnWriteCallback;
|
---|
213 | /** Pointer to the read callback function. */
|
---|
214 | R0PTRTYPE(PFNIOMMMIONEWREAD) pfnReadCallback;
|
---|
215 | /** Pointer to the fill callback function. */
|
---|
216 | R0PTRTYPE(PFNIOMMMIONEWFILL) pfnFillCallback;
|
---|
217 | /** The entry of the first statistics entry, UINT16_MAX if no stats.
|
---|
218 | * @note For simplicity, this is always copied from ring-3 for all entries at
|
---|
219 | * the end of VM creation. */
|
---|
220 | uint16_t idxStats;
|
---|
221 | /** Same as the handle index. */
|
---|
222 | uint16_t idxSelf;
|
---|
223 | /** IOM_MMIO_F_XXX (copied from ring-3). */
|
---|
224 | uint32_t fFlags;
|
---|
225 | } IOMMMIOENTRYR0;
|
---|
226 | /** Pointer to a ring-0 MMIO handle table entry. */
|
---|
227 | typedef IOMMMIOENTRYR0 *PIOMMMIOENTRYR0;
|
---|
228 | /** Pointer to a const ring-0 MMIO handle table entry. */
|
---|
229 | typedef IOMMMIOENTRYR0 const *PCIOMMMIOENTRYR0;
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Ring-3 MMIO handle table entry.
|
---|
233 | */
|
---|
234 | typedef struct IOMMMIOENTRYR3
|
---|
235 | {
|
---|
236 | /** The number of bytes covered by this entry. */
|
---|
237 | RTGCPHYS cbRegion;
|
---|
238 | /** The current mapping address (duplicates lookup table).
|
---|
239 | * This is set to NIL_RTGCPHYS if not mapped (exclusive lock + atomic). */
|
---|
240 | RTGCPHYS volatile GCPhysMapping;
|
---|
241 | /** Pointer to user argument. */
|
---|
242 | RTR3PTR pvUser;
|
---|
243 | /** Pointer to the associated device instance. */
|
---|
244 | R3PTRTYPE(PPDMDEVINS) pDevIns;
|
---|
245 | /** Pointer to the write callback function. */
|
---|
246 | R3PTRTYPE(PFNIOMMMIONEWWRITE) pfnWriteCallback;
|
---|
247 | /** Pointer to the read callback function. */
|
---|
248 | R3PTRTYPE(PFNIOMMMIONEWREAD) pfnReadCallback;
|
---|
249 | /** Pointer to the fill callback function. */
|
---|
250 | R3PTRTYPE(PFNIOMMMIONEWFILL) pfnFillCallback;
|
---|
251 | /** Description / Name. For easing debugging. */
|
---|
252 | R3PTRTYPE(const char *) pszDesc;
|
---|
253 | /** PCI device the registration is associated with. */
|
---|
254 | R3PTRTYPE(PPDMPCIDEV) pPciDev;
|
---|
255 | /** The PCI device region (high 16-bit word) and subregion (low word),
|
---|
256 | * UINT32_MAX if not applicable. */
|
---|
257 | uint32_t iPciRegion;
|
---|
258 | /** IOM_MMIO_F_XXX */
|
---|
259 | uint32_t fFlags;
|
---|
260 | /** The entry of the first statistics entry, UINT16_MAX if no stats. */
|
---|
261 | uint16_t idxStats;
|
---|
262 | /** Set if mapped, clear if not.
|
---|
263 | * Only updated when critsect is held exclusively.
|
---|
264 | * @todo remove as GCPhysMapping != NIL_RTGCPHYS serves the same purpose. */
|
---|
265 | bool volatile fMapped;
|
---|
266 | /** Set if there is an ring-0 entry too. */
|
---|
267 | bool fRing0;
|
---|
268 | /** Set if there is an raw-mode entry too. */
|
---|
269 | bool fRawMode;
|
---|
270 | uint8_t bPadding;
|
---|
271 | /** Same as the handle index. */
|
---|
272 | uint16_t idxSelf;
|
---|
273 | } IOMMMIOENTRYR3;
|
---|
274 | AssertCompileSize(IOMMMIOENTRYR3, sizeof(RTGCPHYS) * 2 + 7 * sizeof(RTR3PTR) + 16);
|
---|
275 | /** Pointer to a ring-3 MMIO handle table entry. */
|
---|
276 | typedef IOMMMIOENTRYR3 *PIOMMMIOENTRYR3;
|
---|
277 | /** Pointer to a const ring-3 MMIO handle table entry. */
|
---|
278 | typedef IOMMMIOENTRYR3 const *PCIOMMMIOENTRYR3;
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * MMIO statistics entry (one MMIO).
|
---|
282 | */
|
---|
283 | typedef struct IOMMMIOSTATSENTRY
|
---|
284 | {
|
---|
285 | /** Counting and profiling reads in R0/RC. */
|
---|
286 | STAMPROFILE ProfReadRZ;
|
---|
287 | /** Number of successful read accesses. */
|
---|
288 | STAMCOUNTER Reads;
|
---|
289 | /** Number of reads to this address from R0/RC which was serviced in R3. */
|
---|
290 | STAMCOUNTER ReadRZToR3;
|
---|
291 | /** Number of complicated reads. */
|
---|
292 | STAMCOUNTER ComplicatedReads;
|
---|
293 | /** Number of reads of 0xff or 0x00. */
|
---|
294 | STAMCOUNTER FFor00Reads;
|
---|
295 | /** Profiling read handler overhead in R3. */
|
---|
296 | STAMPROFILE ProfReadR3;
|
---|
297 |
|
---|
298 | /** Counting and profiling writes in R0/RC. */
|
---|
299 | STAMPROFILE ProfWriteRZ;
|
---|
300 | /** Number of successful read accesses. */
|
---|
301 | STAMCOUNTER Writes;
|
---|
302 | /** Number of writes to this address from R0/RC which was serviced in R3. */
|
---|
303 | STAMCOUNTER WriteRZToR3;
|
---|
304 | /** Number of writes to this address from R0/RC which was committed in R3. */
|
---|
305 | STAMCOUNTER CommitRZToR3;
|
---|
306 | /** Number of complicated writes. */
|
---|
307 | STAMCOUNTER ComplicatedWrites;
|
---|
308 | /** Profiling write handler overhead in R3. */
|
---|
309 | STAMPROFILE ProfWriteR3;
|
---|
310 | } IOMMMIOSTATSENTRY;
|
---|
311 | /** Pointer to MMIO statistics entry. */
|
---|
312 | typedef IOMMMIOSTATSENTRY *PIOMMMIOSTATSENTRY;
|
---|
313 |
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * IOM per virtual CPU instance data.
|
---|
317 | */
|
---|
318 | typedef struct IOMCPU
|
---|
319 | {
|
---|
320 | /** For saving stack space, the disassembler state is allocated here instead of
|
---|
321 | * on the stack. */
|
---|
322 | DISCPUSTATE DisState;
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Pending I/O port write commit (VINF_IOM_R3_IOPORT_COMMIT_WRITE).
|
---|
326 | *
|
---|
327 | * This is a converted VINF_IOM_R3_IOPORT_WRITE handler return that lets the
|
---|
328 | * execution engine commit the instruction and then return to ring-3 to complete
|
---|
329 | * the I/O port write there. This avoids having to decode the instruction again
|
---|
330 | * in ring-3.
|
---|
331 | */
|
---|
332 | struct
|
---|
333 | {
|
---|
334 | /** The value size (0 if not pending). */
|
---|
335 | uint16_t cbValue;
|
---|
336 | /** The I/O port. */
|
---|
337 | RTIOPORT IOPort;
|
---|
338 | /** The value. */
|
---|
339 | uint32_t u32Value;
|
---|
340 | } PendingIOPortWrite;
|
---|
341 |
|
---|
342 | /**
|
---|
343 | * Pending MMIO write commit (VINF_IOM_R3_MMIO_COMMIT_WRITE).
|
---|
344 | *
|
---|
345 | * This is a converted VINF_IOM_R3_MMIO_WRITE handler return that lets the
|
---|
346 | * execution engine commit the instruction, stop any more REPs, and return to
|
---|
347 | * ring-3 to complete the MMIO write there. The avoid the tedious decoding of
|
---|
348 | * the instruction again once we're in ring-3, more importantly it allows us to
|
---|
349 | * correctly deal with read-modify-write instructions like XCHG, OR, and XOR.
|
---|
350 | */
|
---|
351 | struct
|
---|
352 | {
|
---|
353 | /** Guest physical MMIO address. */
|
---|
354 | RTGCPHYS GCPhys;
|
---|
355 | /** The number of bytes to write (0 if nothing pending). */
|
---|
356 | uint32_t cbValue;
|
---|
357 | /** Hint. */
|
---|
358 | uint32_t idxMmioRegionHint;
|
---|
359 | /** The value to write. */
|
---|
360 | uint8_t abValue[128];
|
---|
361 | } PendingMmioWrite;
|
---|
362 |
|
---|
363 | /** @name Caching of I/O Port and MMIO ranges and statistics.
|
---|
364 | * (Saves quite some time in rep outs/ins instruction emulation.)
|
---|
365 | * @{ */
|
---|
366 | /** I/O port registration index for the last read operation. */
|
---|
367 | uint16_t idxIoPortLastRead;
|
---|
368 | /** I/O port registration index for the last write operation. */
|
---|
369 | uint16_t idxIoPortLastWrite;
|
---|
370 | /** I/O port registration index for the last read string operation. */
|
---|
371 | uint16_t idxIoPortLastReadStr;
|
---|
372 | /** I/O port registration index for the last write string operation. */
|
---|
373 | uint16_t idxIoPortLastWriteStr;
|
---|
374 |
|
---|
375 | /** MMIO port registration index for the last IOMR3MmioPhysHandler call.
|
---|
376 | * @note pretty static as only used by APIC on AMD-V. */
|
---|
377 | uint16_t idxMmioLastPhysHandler;
|
---|
378 | uint16_t au16Padding[3];
|
---|
379 | /** @} */
|
---|
380 | } IOMCPU;
|
---|
381 | /** Pointer to IOM per virtual CPU instance data. */
|
---|
382 | typedef IOMCPU *PIOMCPU;
|
---|
383 |
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * IOM Data (part of VM)
|
---|
387 | */
|
---|
388 | typedef struct IOM
|
---|
389 | {
|
---|
390 | /** @name I/O ports
|
---|
391 | * @note The updating of these variables is done exclusively from EMT(0).
|
---|
392 | * @{ */
|
---|
393 | /** Number of I/O port registrations. */
|
---|
394 | uint32_t cIoPortRegs;
|
---|
395 | /** The size of the paIoPortRegs allocation (in entries). */
|
---|
396 | uint32_t cIoPortAlloc;
|
---|
397 | /** I/O port registration table for ring-3.
|
---|
398 | * There is a parallel table in ring-0, IOMR0PERVM::paIoPortRegs. */
|
---|
399 | R3PTRTYPE(PIOMIOPORTENTRYR3) paIoPortRegs;
|
---|
400 | /** Number of entries in the lookup table. */
|
---|
401 | uint32_t cIoPortLookupEntries;
|
---|
402 | uint32_t u32Padding1;
|
---|
403 | /** I/O port lookup table. */
|
---|
404 | R3PTRTYPE(PIOMIOPORTLOOKUPENTRY) paIoPortLookup;
|
---|
405 |
|
---|
406 | /** The number of valid entries in paioPortStats. */
|
---|
407 | uint32_t cIoPortStats;
|
---|
408 | /** The size of the paIoPortStats allocation (in entries). */
|
---|
409 | uint32_t cIoPortStatsAllocation;
|
---|
410 | /** I/O port lookup table. */
|
---|
411 | R3PTRTYPE(PIOMIOPORTSTATSENTRY) paIoPortStats;
|
---|
412 | /** Dummy stats entry so we don't need to check for NULL pointers so much. */
|
---|
413 | IOMIOPORTSTATSENTRY IoPortDummyStats;
|
---|
414 | /** @} */
|
---|
415 |
|
---|
416 | /** @name MMIO ports
|
---|
417 | * @note The updating of these variables is done exclusively from EMT(0).
|
---|
418 | * @{ */
|
---|
419 | /** MMIO physical access handler type, new style. */
|
---|
420 | PGMPHYSHANDLERTYPE hNewMmioHandlerType;
|
---|
421 | /** Number of MMIO registrations. */
|
---|
422 | uint32_t cMmioRegs;
|
---|
423 | /** The size of the paMmioRegs allocation (in entries). */
|
---|
424 | uint32_t cMmioAlloc;
|
---|
425 | /** MMIO registration table for ring-3.
|
---|
426 | * There is a parallel table in ring-0, IOMR0PERVM::paMmioRegs. */
|
---|
427 | R3PTRTYPE(PIOMMMIOENTRYR3) paMmioRegs;
|
---|
428 | /** Number of entries in the lookup table. */
|
---|
429 | uint32_t cMmioLookupEntries;
|
---|
430 | uint32_t u32Padding2;
|
---|
431 | /** MMIO lookup table. */
|
---|
432 | R3PTRTYPE(PIOMMMIOLOOKUPENTRY) paMmioLookup;
|
---|
433 |
|
---|
434 | /** The number of valid entries in paioPortStats. */
|
---|
435 | uint32_t cMmioStats;
|
---|
436 | /** The size of the paMmioStats allocation (in entries). */
|
---|
437 | uint32_t cMmioStatsAllocation;
|
---|
438 | /** MMIO lookup table. */
|
---|
439 | R3PTRTYPE(PIOMMMIOSTATSENTRY) paMmioStats;
|
---|
440 | /** Dummy stats entry so we don't need to check for NULL pointers so much. */
|
---|
441 | IOMMMIOSTATSENTRY MmioDummyStats;
|
---|
442 | /** @} */
|
---|
443 |
|
---|
444 |
|
---|
445 | /** Lock serializing EMT access to IOM. */
|
---|
446 | #ifdef IOM_WITH_CRIT_SECT_RW
|
---|
447 | PDMCRITSECTRW CritSect;
|
---|
448 | #else
|
---|
449 | PDMCRITSECT CritSect;
|
---|
450 | #endif
|
---|
451 |
|
---|
452 | /** @name I/O Port statistics.
|
---|
453 | * @{ */
|
---|
454 | STAMCOUNTER StatIoPortIn;
|
---|
455 | STAMCOUNTER StatIoPortOut;
|
---|
456 | STAMCOUNTER StatIoPortInS;
|
---|
457 | STAMCOUNTER StatIoPortOutS;
|
---|
458 | STAMCOUNTER StatIoPortCommits;
|
---|
459 | /** @} */
|
---|
460 |
|
---|
461 | /** @name MMIO statistics.
|
---|
462 | * @{ */
|
---|
463 | STAMPROFILE StatMmioPfHandler;
|
---|
464 | STAMPROFILE StatMmioPhysHandler;
|
---|
465 | STAMCOUNTER StatMmioHandlerR3;
|
---|
466 | STAMCOUNTER StatMmioHandlerR0;
|
---|
467 | STAMCOUNTER StatMmioReadsR0ToR3;
|
---|
468 | STAMCOUNTER StatMmioWritesR0ToR3;
|
---|
469 | STAMCOUNTER StatMmioCommitsR0ToR3;
|
---|
470 | STAMCOUNTER StatMmioCommitsDirect;
|
---|
471 | STAMCOUNTER StatMmioCommitsPgm;
|
---|
472 | STAMCOUNTER StatMmioStaleMappings;
|
---|
473 | STAMCOUNTER StatMmioDevLockContentionR0;
|
---|
474 | /** @} */
|
---|
475 | } IOM;
|
---|
476 | /** Pointer to IOM instance data. */
|
---|
477 | typedef IOM *PIOM;
|
---|
478 |
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * IOM data kept in the ring-0 GVM.
|
---|
482 | */
|
---|
483 | typedef struct IOMR0PERVM
|
---|
484 | {
|
---|
485 | /** @name I/O ports
|
---|
486 | * @{ */
|
---|
487 | /** The higest ring-0 I/O port registration plus one. */
|
---|
488 | uint32_t cIoPortMax;
|
---|
489 | /** The size of the paIoPortRegs allocation (in entries). */
|
---|
490 | uint32_t cIoPortAlloc;
|
---|
491 | /** I/O port registration table for ring-0.
|
---|
492 | * There is a parallel table for ring-3, paIoPortRing3Regs. */
|
---|
493 | R0PTRTYPE(PIOMIOPORTENTRYR0) paIoPortRegs;
|
---|
494 | /** I/O port lookup table. */
|
---|
495 | R0PTRTYPE(PIOMIOPORTLOOKUPENTRY) paIoPortLookup;
|
---|
496 | /** I/O port registration table for ring-3.
|
---|
497 | * Also mapped to ring-3 as IOM::paIoPortRegs. */
|
---|
498 | R0PTRTYPE(PIOMIOPORTENTRYR3) paIoPortRing3Regs;
|
---|
499 | /** Handle to the allocation backing both the ring-0 and ring-3 registration
|
---|
500 | * tables as well as the lookup table. */
|
---|
501 | RTR0MEMOBJ hIoPortMemObj;
|
---|
502 | /** Handle to the ring-3 mapping of the lookup and ring-3 registration table. */
|
---|
503 | RTR0MEMOBJ hIoPortMapObj;
|
---|
504 | #ifdef VBOX_WITH_STATISTICS
|
---|
505 | /** The size of the paIoPortStats allocation (in entries). */
|
---|
506 | uint32_t cIoPortStatsAllocation;
|
---|
507 | /** Prevents paIoPortStats from growing, set by IOMR0IoPortSyncStatisticsIndices(). */
|
---|
508 | bool fIoPortStatsFrozen;
|
---|
509 | /** I/O port lookup table. */
|
---|
510 | R0PTRTYPE(PIOMIOPORTSTATSENTRY) paIoPortStats;
|
---|
511 | /** Handle to the allocation backing the I/O port statistics. */
|
---|
512 | RTR0MEMOBJ hIoPortStatsMemObj;
|
---|
513 | /** Handle to the ring-3 mapping of the I/O port statistics. */
|
---|
514 | RTR0MEMOBJ hIoPortStatsMapObj;
|
---|
515 | #endif
|
---|
516 | /** @} */
|
---|
517 |
|
---|
518 | /** @name MMIO
|
---|
519 | * @{ */
|
---|
520 | /** The higest ring-0 MMIO registration plus one. */
|
---|
521 | uint32_t cMmioMax;
|
---|
522 | /** The size of the paMmioRegs allocation (in entries). */
|
---|
523 | uint32_t cMmioAlloc;
|
---|
524 | /** MMIO registration table for ring-0.
|
---|
525 | * There is a parallel table for ring-3, paMmioRing3Regs. */
|
---|
526 | R0PTRTYPE(PIOMMMIOENTRYR0) paMmioRegs;
|
---|
527 | /** MMIO lookup table. */
|
---|
528 | R0PTRTYPE(PIOMMMIOLOOKUPENTRY) paMmioLookup;
|
---|
529 | /** MMIO registration table for ring-3.
|
---|
530 | * Also mapped to ring-3 as IOM::paMmioRegs. */
|
---|
531 | R0PTRTYPE(PIOMMMIOENTRYR3) paMmioRing3Regs;
|
---|
532 | /** Handle to the allocation backing both the ring-0 and ring-3 registration
|
---|
533 | * tables as well as the lookup table. */
|
---|
534 | RTR0MEMOBJ hMmioMemObj;
|
---|
535 | /** Handle to the ring-3 mapping of the lookup and ring-3 registration table. */
|
---|
536 | RTR0MEMOBJ hMmioMapObj;
|
---|
537 | #ifdef VBOX_WITH_STATISTICS
|
---|
538 | /** The size of the paMmioStats allocation (in entries). */
|
---|
539 | uint32_t cMmioStatsAllocation;
|
---|
540 | /* Prevents paMmioStats from growing, set by IOMR0MmioSyncStatisticsIndices(). */
|
---|
541 | bool fMmioStatsFrozen;
|
---|
542 | /** MMIO lookup table. */
|
---|
543 | R0PTRTYPE(PIOMMMIOSTATSENTRY) paMmioStats;
|
---|
544 | /** Handle to the allocation backing the MMIO statistics. */
|
---|
545 | RTR0MEMOBJ hMmioStatsMemObj;
|
---|
546 | /** Handle to the ring-3 mapping of the MMIO statistics. */
|
---|
547 | RTR0MEMOBJ hMmioStatsMapObj;
|
---|
548 | #endif
|
---|
549 | /** @} */
|
---|
550 |
|
---|
551 | } IOMR0PERVM;
|
---|
552 |
|
---|
553 |
|
---|
554 | RT_C_DECLS_BEGIN
|
---|
555 |
|
---|
556 | #ifdef IN_RING3
|
---|
557 | DECLCALLBACK(void) iomR3IoPortInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
558 | void iomR3IoPortRegStats(PVM pVM, PIOMIOPORTENTRYR3 pRegEntry);
|
---|
559 | DECLCALLBACK(void) iomR3MmioInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
560 | void iomR3MmioRegStats(PVM pVM, PIOMMMIOENTRYR3 pRegEntry);
|
---|
561 | VBOXSTRICTRC iomR3MmioCommitWorker(PVM pVM, PVMCPU pVCpu, PIOMMMIOENTRYR3 pRegEntry, RTGCPHYS offRegion); /* IOMAllMmioNew.cpp */
|
---|
562 | #endif /* IN_RING3 */
|
---|
563 | #ifdef IN_RING0
|
---|
564 | void iomR0IoPortCleanupVM(PGVM pGVM);
|
---|
565 | void iomR0IoPortInitPerVMData(PGVM pGVM);
|
---|
566 | void iomR0MmioCleanupVM(PGVM pGVM);
|
---|
567 | void iomR0MmioInitPerVMData(PGVM pGVM);
|
---|
568 | #endif
|
---|
569 |
|
---|
570 | #ifndef IN_RING3
|
---|
571 | DECLEXPORT(FNPGMRZPHYSPFHANDLER) iomMmioPfHandlerNew;
|
---|
572 | #endif
|
---|
573 | PGM_ALL_CB2_PROTO(FNPGMPHYSHANDLER) iomMmioHandlerNew;
|
---|
574 |
|
---|
575 | /* IOM locking helpers. */
|
---|
576 | #ifdef IOM_WITH_CRIT_SECT_RW
|
---|
577 | # define IOM_LOCK_EXCL(a_pVM) PDMCritSectRwEnterExcl(&(a_pVM)->iom.s.CritSect, VERR_SEM_BUSY)
|
---|
578 | # define IOM_UNLOCK_EXCL(a_pVM) do { PDMCritSectRwLeaveExcl(&(a_pVM)->iom.s.CritSect); } while (0)
|
---|
579 | # if 0 /* (in case needed for debugging) */
|
---|
580 | # define IOM_LOCK_SHARED_EX(a_pVM, a_rcBusy) PDMCritSectRwEnterExcl(&(a_pVM)->iom.s.CritSect, (a_rcBusy))
|
---|
581 | # define IOM_UNLOCK_SHARED(a_pVM) do { PDMCritSectRwLeaveExcl(&(a_pVM)->iom.s.CritSect); } while (0)
|
---|
582 | # define IOM_IS_SHARED_LOCK_OWNER(a_pVM) PDMCritSectRwIsWriteOwner(&(a_pVM)->iom.s.CritSect)
|
---|
583 | # else
|
---|
584 | # define IOM_LOCK_SHARED_EX(a_pVM, a_rcBusy) PDMCritSectRwEnterShared(&(a_pVM)->iom.s.CritSect, (a_rcBusy))
|
---|
585 | # define IOM_UNLOCK_SHARED(a_pVM) do { PDMCritSectRwLeaveShared(&(a_pVM)->iom.s.CritSect); } while (0)
|
---|
586 | # define IOM_IS_SHARED_LOCK_OWNER(a_pVM) PDMCritSectRwIsReadOwner(&(a_pVM)->iom.s.CritSect, true)
|
---|
587 | # endif
|
---|
588 | # define IOM_IS_EXCL_LOCK_OWNER(a_pVM) PDMCritSectRwIsWriteOwner(&(a_pVM)->iom.s.CritSect)
|
---|
589 | #else
|
---|
590 | # define IOM_LOCK_EXCL(a_pVM) PDMCritSectEnter(&(a_pVM)->iom.s.CritSect, VERR_SEM_BUSY)
|
---|
591 | # define IOM_UNLOCK_EXCL(a_pVM) do { PDMCritSectLeave(&(a_pVM)->iom.s.CritSect); } while (0)
|
---|
592 | # define IOM_LOCK_SHARED_EX(a_pVM, a_rcBusy) PDMCritSectEnter(&(a_pVM)->iom.s.CritSect, (a_rcBusy))
|
---|
593 | # define IOM_UNLOCK_SHARED(a_pVM) do { PDMCritSectLeave(&(a_pVM)->iom.s.CritSect); } while (0)
|
---|
594 | # define IOM_IS_SHARED_LOCK_OWNER(a_pVM) PDMCritSectIsOwner(&(a_pVM)->iom.s.CritSect)
|
---|
595 | # define IOM_IS_EXCL_LOCK_OWNER(a_pVM) PDMCritSectIsOwner(&(a_pVM)->iom.s.CritSect)
|
---|
596 | #endif
|
---|
597 | #define IOM_LOCK_SHARED(a_pVM) IOM_LOCK_SHARED_EX(a_pVM, VERR_SEM_BUSY)
|
---|
598 |
|
---|
599 |
|
---|
600 | RT_C_DECLS_END
|
---|
601 |
|
---|
602 |
|
---|
603 | #ifdef IN_RING3
|
---|
604 |
|
---|
605 | #endif
|
---|
606 |
|
---|
607 | /** @} */
|
---|
608 |
|
---|
609 | #endif /* !VMM_INCLUDED_SRC_include_IOMInternal_h */
|
---|
610 |
|
---|