1 | /* $Id: IOM.cpp 93650 2022-02-08 10:43:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IOM - Input / Output Monitor.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 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 |
|
---|
19 | /** @page pg_iom IOM - The Input / Output Monitor
|
---|
20 | *
|
---|
21 | * The input/output monitor will handle I/O exceptions routing them to the
|
---|
22 | * appropriate device. It implements an API to register and deregister virtual
|
---|
23 | * I/0 port handlers and memory mapped I/O handlers. A handler is PDM devices
|
---|
24 | * and a set of callback functions.
|
---|
25 | *
|
---|
26 | * @see grp_iom
|
---|
27 | *
|
---|
28 | *
|
---|
29 | * @section sec_iom_rawmode Raw-Mode
|
---|
30 | *
|
---|
31 | * In raw-mode I/O port access is trapped (\#GP(0)) by ensuring that the actual
|
---|
32 | * IOPL is 0 regardless of what the guest IOPL is. The \#GP handler use the
|
---|
33 | * disassembler (DIS) to figure which instruction caused it (there are a number
|
---|
34 | * of instructions in addition to the I/O ones) and if it's an I/O port access
|
---|
35 | * it will hand it to IOMRCIOPortHandler (via EMInterpretPortIO).
|
---|
36 | * IOMRCIOPortHandler will lookup the port in the AVL tree of registered
|
---|
37 | * handlers. If found, the handler will be called otherwise default action is
|
---|
38 | * taken. (Default action is to write into the void and read all set bits.)
|
---|
39 | *
|
---|
40 | * Memory Mapped I/O (MMIO) is implemented as a slightly special case of PGM
|
---|
41 | * access handlers. An MMIO range is registered with IOM which then registers it
|
---|
42 | * with the PGM access handler sub-system. The access handler catches all
|
---|
43 | * access and will be called in the context of a \#PF handler. In RC and R0 this
|
---|
44 | * handler is iomMmioPfHandler while in ring-3 it's iomR3MmioHandler (although
|
---|
45 | * in ring-3 there can be alternative ways). iomMmioPfHandler will attempt to
|
---|
46 | * emulate the instruction that is doing the access and pass the corresponding
|
---|
47 | * reads / writes to the device.
|
---|
48 | *
|
---|
49 | * Emulating I/O port access is less complex and should be slightly faster than
|
---|
50 | * emulating MMIO, so in most cases we should encourage the OS to use port I/O.
|
---|
51 | * Devices which are frequently accessed should register GC handlers to speed up
|
---|
52 | * execution.
|
---|
53 | *
|
---|
54 | *
|
---|
55 | * @section sec_iom_hm Hardware Assisted Virtualization Mode
|
---|
56 | *
|
---|
57 | * When running in hardware assisted virtualization mode we'll be doing much the
|
---|
58 | * same things as in raw-mode. The main difference is that we're running in the
|
---|
59 | * host ring-0 context and that we don't get faults (\#GP(0) and \#PG) but
|
---|
60 | * exits.
|
---|
61 | *
|
---|
62 | *
|
---|
63 | * @section sec_iom_rem Recompiled Execution Mode
|
---|
64 | *
|
---|
65 | * When running in the recompiler things are different. I/O port access is
|
---|
66 | * handled by calling IOMIOPortRead and IOMIOPortWrite directly. While MMIO can
|
---|
67 | * be handled in one of two ways. The normal way is that we have a registered a
|
---|
68 | * special RAM range with the recompiler and in the three callbacks (for byte,
|
---|
69 | * word and dword access) we call IOMMMIORead and IOMMMIOWrite directly. The
|
---|
70 | * alternative ways that the physical memory access which goes via PGM will take
|
---|
71 | * care of it by calling iomR3MmioHandler via the PGM access handler machinery
|
---|
72 | * - this shouldn't happen but it is an alternative...
|
---|
73 | *
|
---|
74 | *
|
---|
75 | * @section sec_iom_other Other Accesses
|
---|
76 | *
|
---|
77 | * I/O ports aren't really exposed in any other way, unless you count the
|
---|
78 | * instruction interpreter in EM, but that's just what we're doing in the
|
---|
79 | * raw-mode \#GP(0) case really. Now, it's possible to call IOMIOPortRead and
|
---|
80 | * IOMIOPortWrite directly to talk to a device, but this is really bad behavior
|
---|
81 | * and should only be done as temporary hacks (the PC BIOS device used to setup
|
---|
82 | * the CMOS this way back in the dark ages).
|
---|
83 | *
|
---|
84 | * MMIO has similar direct routes as the I/O ports and these shouldn't be used
|
---|
85 | * for the same reasons and with the same restrictions. OTOH since MMIO is
|
---|
86 | * mapped into the physical memory address space, it can be accessed in a number
|
---|
87 | * of ways thru PGM.
|
---|
88 | *
|
---|
89 | *
|
---|
90 | * @section sec_iom_logging Logging Levels
|
---|
91 | *
|
---|
92 | * Following assignments:
|
---|
93 | * - Level 5 is used for defering I/O port and MMIO writes to ring-3.
|
---|
94 | *
|
---|
95 | */
|
---|
96 |
|
---|
97 | /** @todo MMIO - simplifying the device end.
|
---|
98 | * - Add a return status for doing DBGFSTOP on access where there are no known
|
---|
99 | * registers.
|
---|
100 | * -
|
---|
101 | *
|
---|
102 | * */
|
---|
103 |
|
---|
104 |
|
---|
105 | /*********************************************************************************************************************************
|
---|
106 | * Header Files *
|
---|
107 | *********************************************************************************************************************************/
|
---|
108 | #define LOG_GROUP LOG_GROUP_IOM
|
---|
109 | #include <VBox/vmm/iom.h>
|
---|
110 | #include <VBox/vmm/cpum.h>
|
---|
111 | #include <VBox/vmm/pgm.h>
|
---|
112 | #include <VBox/sup.h>
|
---|
113 | #include <VBox/vmm/hm.h>
|
---|
114 | #include <VBox/vmm/mm.h>
|
---|
115 | #include <VBox/vmm/stam.h>
|
---|
116 | #include <VBox/vmm/dbgf.h>
|
---|
117 | #include <VBox/vmm/pdmapi.h>
|
---|
118 | #include <VBox/vmm/pdmdev.h>
|
---|
119 | #include "IOMInternal.h"
|
---|
120 | #include <VBox/vmm/vm.h>
|
---|
121 |
|
---|
122 | #include <VBox/param.h>
|
---|
123 | #include <iprt/assert.h>
|
---|
124 | #include <iprt/alloc.h>
|
---|
125 | #include <iprt/string.h>
|
---|
126 | #include <VBox/log.h>
|
---|
127 | #include <VBox/err.h>
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Initializes the IOM.
|
---|
133 | *
|
---|
134 | * @returns VBox status code.
|
---|
135 | * @param pVM The cross context VM structure.
|
---|
136 | */
|
---|
137 | VMMR3_INT_DECL(int) IOMR3Init(PVM pVM)
|
---|
138 | {
|
---|
139 | LogFlow(("IOMR3Init:\n"));
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Assert alignment and sizes.
|
---|
143 | */
|
---|
144 | AssertCompileMemberAlignment(VM, iom.s, 32);
|
---|
145 | AssertCompile(sizeof(pVM->iom.s) <= sizeof(pVM->iom.padding));
|
---|
146 | AssertCompileMemberAlignment(IOM, CritSect, sizeof(uintptr_t));
|
---|
147 |
|
---|
148 | /*
|
---|
149 | * Initialize the REM critical section.
|
---|
150 | */
|
---|
151 | #ifdef IOM_WITH_CRIT_SECT_RW
|
---|
152 | int rc = PDMR3CritSectRwInit(pVM, &pVM->iom.s.CritSect, RT_SRC_POS, "IOM Lock");
|
---|
153 | #else
|
---|
154 | int rc = PDMR3CritSectInit(pVM, &pVM->iom.s.CritSect, RT_SRC_POS, "IOM Lock");
|
---|
155 | #endif
|
---|
156 | AssertRCReturn(rc, rc);
|
---|
157 |
|
---|
158 | /*
|
---|
159 | * Register the MMIO access handler type.
|
---|
160 | */
|
---|
161 | rc = PGMR3HandlerPhysicalTypeRegister(pVM, PGMPHYSHANDLERKIND_MMIO, 0 /*fFlags*/,
|
---|
162 | iomMmioHandlerNew, "MMIO", &pVM->iom.s.hNewMmioHandlerType);
|
---|
163 | AssertRCReturn(rc, rc);
|
---|
164 |
|
---|
165 | /*
|
---|
166 | * Info.
|
---|
167 | */
|
---|
168 | DBGFR3InfoRegisterInternal(pVM, "ioport", "Dumps all IOPort ranges. No arguments.", &iomR3IoPortInfo);
|
---|
169 | DBGFR3InfoRegisterInternal(pVM, "mmio", "Dumps all MMIO ranges. No arguments.", &iomR3MmioInfo);
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * Statistics (names are somewhat contorted to make the registration
|
---|
173 | * sub-trees appear at the end of each group).
|
---|
174 | */
|
---|
175 | STAM_REG(pVM, &pVM->iom.s.StatIoPortCommits, STAMTYPE_COUNTER, "/IOM/IoPortCommits", STAMUNIT_OCCURENCES, "Number of ring-3 I/O port commits.");
|
---|
176 | STAM_REG(pVM, &pVM->iom.s.StatIoPortIn, STAMTYPE_COUNTER, "/IOM/IoPortIN", STAMUNIT_OCCURENCES, "Number of IN instructions (attempts)");
|
---|
177 | STAM_REG(pVM, &pVM->iom.s.StatIoPortInS, STAMTYPE_COUNTER, "/IOM/IoPortINS", STAMUNIT_OCCURENCES, "Number of INS instructions (attempts)");
|
---|
178 | STAM_REG(pVM, &pVM->iom.s.StatIoPortOutS, STAMTYPE_COUNTER, "/IOM/IoPortOUT", STAMUNIT_OCCURENCES, "Number of OUT instructions (attempts)");
|
---|
179 | STAM_REG(pVM, &pVM->iom.s.StatIoPortOutS, STAMTYPE_COUNTER, "/IOM/IoPortOUTS", STAMUNIT_OCCURENCES, "Number of OUTS instructions (attempts)");
|
---|
180 |
|
---|
181 | STAM_REG(pVM, &pVM->iom.s.StatMmioHandlerR3, STAMTYPE_COUNTER, "/IOM/MmioHandlerR3", STAMUNIT_OCCURENCES, "Number of calls to iomMmioHandlerNew from ring-3.");
|
---|
182 | STAM_REG(pVM, &pVM->iom.s.StatMmioHandlerR0, STAMTYPE_COUNTER, "/IOM/MmioHandlerR0", STAMUNIT_OCCURENCES, "Number of calls to iomMmioHandlerNew from ring-0.");
|
---|
183 | STAM_REG(pVM, &pVM->iom.s.StatMmioReadsR0ToR3, STAMTYPE_COUNTER, "/IOM/MmioR0ToR3Reads", STAMUNIT_OCCURENCES, "Number of reads deferred to ring-3.");
|
---|
184 | STAM_REG(pVM, &pVM->iom.s.StatMmioWritesR0ToR3, STAMTYPE_COUNTER, "/IOM/MmioR0ToR3Writes", STAMUNIT_OCCURENCES, "Number of writes deferred to ring-3.");
|
---|
185 | STAM_REG(pVM, &pVM->iom.s.StatMmioCommitsR0ToR3,STAMTYPE_COUNTER, "/IOM/MmioR0ToR3Commits", STAMUNIT_OCCURENCES, "Number of commits deferred to ring-3.");
|
---|
186 | STAM_REG(pVM, &pVM->iom.s.StatMmioPfHandler, STAMTYPE_PROFILE, "/IOM/MmioPfHandler", STAMUNIT_TICKS_PER_CALL, "Number of calls to iomMmioPfHandlerNew.");
|
---|
187 | STAM_REG(pVM, &pVM->iom.s.StatMmioPhysHandler, STAMTYPE_PROFILE, "/IOM/MmioPhysHandler", STAMUNIT_TICKS_PER_CALL, "Number of calls to IOMR0MmioPhysHandler.");
|
---|
188 | STAM_REG(pVM, &pVM->iom.s.StatMmioCommitsDirect,STAMTYPE_COUNTER, "/IOM/MmioCommitsDirect", STAMUNIT_OCCURENCES, "Number of ring-3 MMIO commits direct to handler via handle hint.");
|
---|
189 | STAM_REG(pVM, &pVM->iom.s.StatMmioCommitsPgm, STAMTYPE_COUNTER, "/IOM/MmioCommitsPgm", STAMUNIT_OCCURENCES, "Number of ring-3 MMIO commits via PGM.");
|
---|
190 | STAM_REL_REG(pVM, &pVM->iom.s.StatMmioStaleMappings, STAMTYPE_COUNTER, "/IOM/MmioMappingsStale", STAMUNIT_TICKS_PER_CALL, "Number of times iomMmioHandlerNew got a call for a remapped range at the old mapping.");
|
---|
191 | STAM_REG(pVM, &pVM->iom.s.StatMmioDevLockContentionR0, STAMTYPE_COUNTER, "/IOM/MmioDevLockContentionR0", STAMUNIT_OCCURENCES, "Number of device lock contention force return to ring-3.");
|
---|
192 |
|
---|
193 | LogFlow(("IOMR3Init: returns VINF_SUCCESS\n"));
|
---|
194 | return VINF_SUCCESS;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Called when a VM initialization stage is completed.
|
---|
200 | *
|
---|
201 | * @returns VBox status code.
|
---|
202 | * @param pVM The cross context VM structure.
|
---|
203 | * @param enmWhat The initialization state that was completed.
|
---|
204 | */
|
---|
205 | VMMR3_INT_DECL(int) IOMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat)
|
---|
206 | {
|
---|
207 | #ifdef VBOX_WITH_STATISTICS
|
---|
208 | if (enmWhat == VMINITCOMPLETED_RING0)
|
---|
209 | {
|
---|
210 | /*
|
---|
211 | * Synchronize the ring-3 I/O port and MMIO statistics indices into the
|
---|
212 | * ring-0 tables to simplify ring-0 code. This also make sure that any
|
---|
213 | * later calls to grow the statistics tables will fail.
|
---|
214 | */
|
---|
215 | if (!SUPR3IsDriverless())
|
---|
216 | {
|
---|
217 | int rc = VMMR3CallR0Emt(pVM, pVM->apCpusR3[0], VMMR0_DO_IOM_SYNC_STATS_INDICES, 0, NULL);
|
---|
218 | AssertLogRelRCReturn(rc, rc);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /*
|
---|
222 | * Register I/O port and MMIO stats now that we're done registering MMIO
|
---|
223 | * regions and won't grow the table again.
|
---|
224 | */
|
---|
225 | for (uint32_t i = 0; i < pVM->iom.s.cIoPortRegs; i++)
|
---|
226 | {
|
---|
227 | PIOMIOPORTENTRYR3 pRegEntry = &pVM->iom.s.paIoPortRegs[i];
|
---|
228 | if ( pRegEntry->fMapped
|
---|
229 | && pRegEntry->idxStats != UINT16_MAX)
|
---|
230 | iomR3IoPortRegStats(pVM, pRegEntry);
|
---|
231 | }
|
---|
232 |
|
---|
233 | for (uint32_t i = 0; i < pVM->iom.s.cMmioRegs; i++)
|
---|
234 | {
|
---|
235 | PIOMMMIOENTRYR3 pRegEntry = &pVM->iom.s.paMmioRegs[i];
|
---|
236 | if ( pRegEntry->fMapped
|
---|
237 | && pRegEntry->idxStats != UINT16_MAX)
|
---|
238 | iomR3MmioRegStats(pVM, pRegEntry);
|
---|
239 | }
|
---|
240 | }
|
---|
241 | #else
|
---|
242 | RT_NOREF(pVM, enmWhat);
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * Freeze I/O port and MMIO registrations.
|
---|
247 | */
|
---|
248 | pVM->iom.s.fIoPortsFrozen = true;
|
---|
249 | pVM->iom.s.fMmioFrozen = true;
|
---|
250 | return VINF_SUCCESS;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * The VM is being reset.
|
---|
256 | *
|
---|
257 | * @param pVM The cross context VM structure.
|
---|
258 | */
|
---|
259 | VMMR3_INT_DECL(void) IOMR3Reset(PVM pVM)
|
---|
260 | {
|
---|
261 | RT_NOREF(pVM);
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Applies relocations to data and code managed by this
|
---|
267 | * component. This function will be called at init and
|
---|
268 | * whenever the VMM need to relocate it self inside the GC.
|
---|
269 | *
|
---|
270 | * The IOM will update the addresses used by the switcher.
|
---|
271 | *
|
---|
272 | * @param pVM The cross context VM structure.
|
---|
273 | * @param offDelta Relocation delta relative to old location.
|
---|
274 | */
|
---|
275 | VMMR3_INT_DECL(void) IOMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
|
---|
276 | {
|
---|
277 | RT_NOREF(pVM, offDelta);
|
---|
278 | }
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Terminates the IOM.
|
---|
282 | *
|
---|
283 | * Termination means cleaning up and freeing all resources,
|
---|
284 | * the VM it self is at this point powered off or suspended.
|
---|
285 | *
|
---|
286 | * @returns VBox status code.
|
---|
287 | * @param pVM The cross context VM structure.
|
---|
288 | */
|
---|
289 | VMMR3_INT_DECL(int) IOMR3Term(PVM pVM)
|
---|
290 | {
|
---|
291 | /*
|
---|
292 | * IOM is not owning anything but automatically freed resources,
|
---|
293 | * so there's nothing to do here.
|
---|
294 | */
|
---|
295 | NOREF(pVM);
|
---|
296 | return VINF_SUCCESS;
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Handles the unlikely and probably fatal merge cases.
|
---|
302 | *
|
---|
303 | * @returns Merged status code.
|
---|
304 | * @param rcStrict Current EM status code.
|
---|
305 | * @param rcStrictCommit The IOM I/O or MMIO write commit status to merge
|
---|
306 | * with @a rcStrict.
|
---|
307 | * @param rcIom For logging purposes only.
|
---|
308 | * @param pVCpu The cross context virtual CPU structure of the
|
---|
309 | * calling EMT. For logging purposes.
|
---|
310 | */
|
---|
311 | DECL_NO_INLINE(static, VBOXSTRICTRC) iomR3MergeStatusSlow(VBOXSTRICTRC rcStrict, VBOXSTRICTRC rcStrictCommit,
|
---|
312 | int rcIom, PVMCPU pVCpu)
|
---|
313 | {
|
---|
314 | if (RT_FAILURE_NP(rcStrict))
|
---|
315 | return rcStrict;
|
---|
316 |
|
---|
317 | if (RT_FAILURE_NP(rcStrictCommit))
|
---|
318 | return rcStrictCommit;
|
---|
319 |
|
---|
320 | if (rcStrict == rcStrictCommit)
|
---|
321 | return rcStrictCommit;
|
---|
322 |
|
---|
323 | AssertLogRelMsgFailed(("rcStrictCommit=%Rrc rcStrict=%Rrc IOPort={%#06x<-%#xx/%u} MMIO={%RGp<-%.*Rhxs} (rcIom=%Rrc)\n",
|
---|
324 | VBOXSTRICTRC_VAL(rcStrictCommit), VBOXSTRICTRC_VAL(rcStrict),
|
---|
325 | pVCpu->iom.s.PendingIOPortWrite.IOPort,
|
---|
326 | pVCpu->iom.s.PendingIOPortWrite.u32Value, pVCpu->iom.s.PendingIOPortWrite.cbValue,
|
---|
327 | pVCpu->iom.s.PendingMmioWrite.GCPhys,
|
---|
328 | pVCpu->iom.s.PendingMmioWrite.cbValue, &pVCpu->iom.s.PendingMmioWrite.abValue[0], rcIom));
|
---|
329 | return VERR_IOM_FF_STATUS_IPE;
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Helper for IOMR3ProcessForceFlag.
|
---|
335 | *
|
---|
336 | * @returns Merged status code.
|
---|
337 | * @param rcStrict Current EM status code.
|
---|
338 | * @param rcStrictCommit The IOM I/O or MMIO write commit status to merge
|
---|
339 | * with @a rcStrict.
|
---|
340 | * @param rcIom Either VINF_IOM_R3_IOPORT_COMMIT_WRITE or
|
---|
341 | * VINF_IOM_R3_MMIO_COMMIT_WRITE.
|
---|
342 | * @param pVCpu The cross context virtual CPU structure of the
|
---|
343 | * calling EMT.
|
---|
344 | */
|
---|
345 | DECLINLINE(VBOXSTRICTRC) iomR3MergeStatus(VBOXSTRICTRC rcStrict, VBOXSTRICTRC rcStrictCommit, int rcIom, PVMCPU pVCpu)
|
---|
346 | {
|
---|
347 | /* Simple. */
|
---|
348 | if (RT_LIKELY(rcStrict == rcIom || rcStrict == VINF_EM_RAW_TO_R3 || rcStrict == VINF_SUCCESS))
|
---|
349 | return rcStrictCommit;
|
---|
350 |
|
---|
351 | if (RT_LIKELY(rcStrictCommit == VINF_SUCCESS))
|
---|
352 | return rcStrict;
|
---|
353 |
|
---|
354 | /* EM scheduling status codes. */
|
---|
355 | if (RT_LIKELY( rcStrict >= VINF_EM_FIRST
|
---|
356 | && rcStrict <= VINF_EM_LAST))
|
---|
357 | {
|
---|
358 | if (RT_LIKELY( rcStrictCommit >= VINF_EM_FIRST
|
---|
359 | && rcStrictCommit <= VINF_EM_LAST))
|
---|
360 | return rcStrict < rcStrictCommit ? rcStrict : rcStrictCommit;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /* Unlikely */
|
---|
364 | return iomR3MergeStatusSlow(rcStrict, rcStrictCommit, rcIom, pVCpu);
|
---|
365 | }
|
---|
366 |
|
---|
367 |
|
---|
368 | /**
|
---|
369 | * Called by force-flag handling code when VMCPU_FF_IOM is set.
|
---|
370 | *
|
---|
371 | * @returns Merge between @a rcStrict and what the commit operation returned.
|
---|
372 | * @param pVM The cross context VM structure.
|
---|
373 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
374 | * @param rcStrict The status code returned by ring-0 or raw-mode.
|
---|
375 | * @thread EMT(pVCpu)
|
---|
376 | *
|
---|
377 | * @remarks The VMCPU_FF_IOM flag is handled before the status codes by EM, so
|
---|
378 | * we're very likely to see @a rcStrict set to
|
---|
379 | * VINF_IOM_R3_IOPORT_COMMIT_WRITE and VINF_IOM_R3_MMIO_COMMIT_WRITE
|
---|
380 | * here.
|
---|
381 | */
|
---|
382 | VMMR3_INT_DECL(VBOXSTRICTRC) IOMR3ProcessForceFlag(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rcStrict)
|
---|
383 | {
|
---|
384 | VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_IOM);
|
---|
385 | Assert(pVCpu->iom.s.PendingIOPortWrite.cbValue || pVCpu->iom.s.PendingMmioWrite.cbValue);
|
---|
386 |
|
---|
387 | if (pVCpu->iom.s.PendingIOPortWrite.cbValue)
|
---|
388 | {
|
---|
389 | Log5(("IOM: Dispatching pending I/O port write: %#x LB %u -> %RTiop\n", pVCpu->iom.s.PendingIOPortWrite.u32Value,
|
---|
390 | pVCpu->iom.s.PendingIOPortWrite.cbValue, pVCpu->iom.s.PendingIOPortWrite.IOPort));
|
---|
391 | STAM_COUNTER_INC(&pVM->iom.s.StatIoPortCommits);
|
---|
392 | VBOXSTRICTRC rcStrictCommit = IOMIOPortWrite(pVM, pVCpu, pVCpu->iom.s.PendingIOPortWrite.IOPort,
|
---|
393 | pVCpu->iom.s.PendingIOPortWrite.u32Value,
|
---|
394 | pVCpu->iom.s.PendingIOPortWrite.cbValue);
|
---|
395 | pVCpu->iom.s.PendingIOPortWrite.cbValue = 0;
|
---|
396 | rcStrict = iomR3MergeStatus(rcStrict, rcStrictCommit, VINF_IOM_R3_IOPORT_COMMIT_WRITE, pVCpu);
|
---|
397 | }
|
---|
398 |
|
---|
399 |
|
---|
400 | if (pVCpu->iom.s.PendingMmioWrite.cbValue)
|
---|
401 | {
|
---|
402 | Log5(("IOM: Dispatching pending MMIO write: %RGp LB %#x\n",
|
---|
403 | pVCpu->iom.s.PendingMmioWrite.GCPhys, pVCpu->iom.s.PendingMmioWrite.cbValue));
|
---|
404 |
|
---|
405 | /* Use new MMIO handle hint and bypass PGM if it still looks right. */
|
---|
406 | size_t idxMmioRegionHint = pVCpu->iom.s.PendingMmioWrite.idxMmioRegionHint;
|
---|
407 | if (idxMmioRegionHint < pVM->iom.s.cMmioRegs)
|
---|
408 | {
|
---|
409 | PIOMMMIOENTRYR3 pRegEntry = &pVM->iom.s.paMmioRegs[idxMmioRegionHint];
|
---|
410 | RTGCPHYS const GCPhysMapping = pRegEntry->GCPhysMapping;
|
---|
411 | RTGCPHYS const offRegion = pVCpu->iom.s.PendingMmioWrite.GCPhys - GCPhysMapping;
|
---|
412 | if (offRegion < pRegEntry->cbRegion && GCPhysMapping != NIL_RTGCPHYS)
|
---|
413 | {
|
---|
414 | STAM_COUNTER_INC(&pVM->iom.s.StatMmioCommitsDirect);
|
---|
415 | VBOXSTRICTRC rcStrictCommit = iomR3MmioCommitWorker(pVM, pVCpu, pRegEntry, offRegion);
|
---|
416 | pVCpu->iom.s.PendingMmioWrite.cbValue = 0;
|
---|
417 | return iomR3MergeStatus(rcStrict, rcStrictCommit, VINF_IOM_R3_MMIO_COMMIT_WRITE, pVCpu);
|
---|
418 | }
|
---|
419 | }
|
---|
420 |
|
---|
421 | /* Fall back on PGM. */
|
---|
422 | STAM_COUNTER_INC(&pVM->iom.s.StatMmioCommitsPgm);
|
---|
423 | VBOXSTRICTRC rcStrictCommit = PGMPhysWrite(pVM, pVCpu->iom.s.PendingMmioWrite.GCPhys,
|
---|
424 | pVCpu->iom.s.PendingMmioWrite.abValue, pVCpu->iom.s.PendingMmioWrite.cbValue,
|
---|
425 | PGMACCESSORIGIN_IOM);
|
---|
426 | pVCpu->iom.s.PendingMmioWrite.cbValue = 0;
|
---|
427 | rcStrict = iomR3MergeStatus(rcStrict, rcStrictCommit, VINF_IOM_R3_MMIO_COMMIT_WRITE, pVCpu);
|
---|
428 | }
|
---|
429 |
|
---|
430 | return rcStrict;
|
---|
431 | }
|
---|
432 |
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * Notification from DBGF that the number of active I/O port or MMIO
|
---|
436 | * breakpoints has change.
|
---|
437 | *
|
---|
438 | * For performance reasons, IOM will only call DBGF before doing I/O and MMIO
|
---|
439 | * accesses where there are armed breakpoints.
|
---|
440 | *
|
---|
441 | * @param pVM The cross context VM structure.
|
---|
442 | * @param fPortIo True if there are armed I/O port breakpoints.
|
---|
443 | * @param fMmio True if there are armed MMIO breakpoints.
|
---|
444 | */
|
---|
445 | VMMR3_INT_DECL(void) IOMR3NotifyBreakpointCountChange(PVM pVM, bool fPortIo, bool fMmio)
|
---|
446 | {
|
---|
447 | /** @todo I/O breakpoints. */
|
---|
448 | RT_NOREF3(pVM, fPortIo, fMmio);
|
---|
449 | }
|
---|
450 |
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Notification from DBGF that an event has been enabled or disabled.
|
---|
454 | *
|
---|
455 | * For performance reasons, IOM may cache the state of events it implements.
|
---|
456 | *
|
---|
457 | * @param pVM The cross context VM structure.
|
---|
458 | * @param enmEvent The event.
|
---|
459 | * @param fEnabled The new state.
|
---|
460 | */
|
---|
461 | VMMR3_INT_DECL(void) IOMR3NotifyDebugEventChange(PVM pVM, DBGFEVENT enmEvent, bool fEnabled)
|
---|
462 | {
|
---|
463 | /** @todo IOM debug events. */
|
---|
464 | RT_NOREF3(pVM, enmEvent, fEnabled);
|
---|
465 | }
|
---|
466 |
|
---|