VirtualBox

source: vbox/trunk/src/VBox/VMM/IOM.cpp@ 7749

Last change on this file since 7749 was 7749, checked in by vboxsync, 17 years ago

Relocate offMMIOHandlerGC. Fixes guru on windows bootup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 85.7 KB
Line 
1/* $Id: IOM.cpp 7749 2008-04-04 15:57:28Z vboxsync $ */
2/** @file
3 * IOM - Input / Output Monitor.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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
23 * virtual port I/O handler and memory mapped I/O handlers. A handler is
24 * PDM devices and a set of callback functions.
25 *
26 * Port I/O (PIO) is easily trapped by ensuring IOPL is 0, thus causing \#GP(0) on
27 * any access to I/O ports. Using the dissassembler (DIS) the faulting
28 * instruction will be interpreted determing the port and if there is a handler
29 * for it. If a handler exists it will be called, else default action will be
30 * performed.
31 *
32 * Memory Mapped I/O (MMIO) is gonna be worse since there are numerous instructions
33 * which can access memory. I'm afraid we might have to emulate each
34 * instruction which faults. The Execution Monitor (EM) will provide facilities
35 * for doing this using DIS.
36 *
37 * Emulating I/O port access is less complex and sligtly faster than emulating MMIO,
38 * so in most cases we should encourage the OS to use PIO. Devices which are freqently
39 * accessed should register GC handlers to speed up execution.
40 *
41 */
42
43
44/*******************************************************************************
45* Header Files *
46*******************************************************************************/
47#define LOG_GROUP LOG_GROUP_IOM
48#include <VBox/iom.h>
49#include <VBox/cpum.h>
50#include <VBox/pgm.h>
51#include <VBox/sup.h>
52#include <VBox/mm.h>
53#include <VBox/stam.h>
54#include <VBox/dbgf.h>
55#include <VBox/pdm.h>
56#include "IOMInternal.h"
57#include <VBox/vm.h>
58
59#include <VBox/param.h>
60#include <iprt/assert.h>
61#include <iprt/alloc.h>
62#include <iprt/string.h>
63#include <VBox/log.h>
64#include <VBox/err.h>
65
66
67/*******************************************************************************
68* Internal Functions *
69*******************************************************************************/
70static void iomR3FlushCache(PVM pVM);
71static DECLCALLBACK(int) iomr3RelocateIOPortCallback(PAVLROIOPORTNODECORE pNode, void *pvUser);
72static DECLCALLBACK(int) iomr3RelocateMMIOCallback(PAVLROGCPHYSNODECORE pNode, void *pvUser);
73static DECLCALLBACK(void) iomR3IOPortInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
74static DECLCALLBACK(void) iomR3MMIOInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
75static DECLCALLBACK(int) iomR3IOPortDummyIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
76static DECLCALLBACK(int) iomR3IOPortDummyOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
77static DECLCALLBACK(int) iomR3IOPortDummyInStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, unsigned *pcTransfer, unsigned cb);
78static DECLCALLBACK(int) iomR3IOPortDummyOutStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, unsigned *pcTransfer, unsigned cb);
79
80#ifdef VBOX_WITH_STATISTICS
81static const char *iomr3IOPortGetStandardName(RTIOPORT Port);
82#endif
83
84
85/**
86 * Initializes the IOM.
87 *
88 * @returns VBox status code.
89 * @param pVM The VM to operate on.
90 */
91IOMR3DECL(int) IOMR3Init(PVM pVM)
92{
93 LogFlow(("IOMR3Init:\n"));
94
95 /*
96 * Assert alignment and sizes.
97 */
98 AssertRelease(!(RT_OFFSETOF(VM, iom.s) & 31));
99 AssertRelease(sizeof(pVM->iom.s) <= sizeof(pVM->iom.padding));
100
101 /*
102 * Setup any fixed pointers and offsets.
103 */
104 pVM->iom.s.offVM = RT_OFFSETOF(VM, iom);
105
106 /*
107 * Allocate the trees structure.
108 */
109 int rc = MMHyperAlloc(pVM, sizeof(*pVM->iom.s.pTreesHC), 0, MM_TAG_IOM, (void **)&pVM->iom.s.pTreesHC);
110 if (VBOX_SUCCESS(rc))
111 {
112 pVM->iom.s.pTreesGC = MMHyperHC2GC(pVM, pVM->iom.s.pTreesHC);
113 pVM->iom.s.pfnMMIOHandlerGC = NIL_RTGCPTR;
114 pVM->iom.s.pfnMMIOHandlerR0 = NIL_RTR0PTR;
115
116 /*
117 * Info.
118 */
119 DBGFR3InfoRegisterInternal(pVM, "ioport", "Dumps all IOPort ranges. No arguments.", &iomR3IOPortInfo);
120 DBGFR3InfoRegisterInternal(pVM, "mmio", "Dumps all MMIO ranges. No arguments.", &iomR3MMIOInfo);
121
122 /*
123 * Statistics.
124 */
125 STAM_REG(pVM, &pVM->iom.s.StatGCMMIOHandler, STAMTYPE_PROFILE, "/IOM/GC/MMIOHandler", STAMUNIT_TICKS_PER_CALL, "Profiling of the IOMGCMMIOHandler() body, only success calls.");
126 STAM_REG(pVM, &pVM->iom.s.StatGCMMIOFailures, STAMTYPE_COUNTER, "/IOM/GC/MMIOFailures", STAMUNIT_OCCURENCES, "Number of times IOMGCMMIOHandler() didn't service the request.");
127 STAM_REG(pVM, &pVM->iom.s.StatGCInstMov, STAMTYPE_PROFILE, "/IOM/GC/Inst/MOV", STAMUNIT_TICKS_PER_CALL, "Profiling of the MOV instruction emulation.");
128 STAM_REG(pVM, &pVM->iom.s.StatGCInstCmp, STAMTYPE_PROFILE, "/IOM/GC/Inst/CMP", STAMUNIT_TICKS_PER_CALL, "Profiling of the CMP instruction emulation.");
129 STAM_REG(pVM, &pVM->iom.s.StatGCInstAnd, STAMTYPE_PROFILE, "/IOM/GC/Inst/AND", STAMUNIT_TICKS_PER_CALL, "Profiling of the AND instruction emulation.");
130 STAM_REG(pVM, &pVM->iom.s.StatGCInstTest, STAMTYPE_PROFILE, "/IOM/GC/Inst/TEST", STAMUNIT_TICKS_PER_CALL, "Profiling of the TEST instruction emulation.");
131 STAM_REG(pVM, &pVM->iom.s.StatGCInstXchg, STAMTYPE_PROFILE, "/IOM/GC/Inst/XCHG", STAMUNIT_TICKS_PER_CALL, "Profiling of the XCHG instruction emulation.");
132 STAM_REG(pVM, &pVM->iom.s.StatGCInstStos, STAMTYPE_PROFILE, "/IOM/GC/Inst/STOS", STAMUNIT_TICKS_PER_CALL, "Profiling of the STOS instruction emulation.");
133 STAM_REG(pVM, &pVM->iom.s.StatGCInstLods, STAMTYPE_PROFILE, "/IOM/GC/Inst/LODS", STAMUNIT_TICKS_PER_CALL, "Profiling of the LODS instruction emulation.");
134 STAM_REG(pVM, &pVM->iom.s.StatGCInstMovs, STAMTYPE_PROFILE, "/IOM/GC/Inst/MOVS", STAMUNIT_TICKS_PER_CALL, "Profiling of the MOVS instruction emulation.");
135 STAM_REG(pVM, &pVM->iom.s.StatGCInstMovsToMMIO, STAMTYPE_PROFILE, "/IOM/GC/Inst/MOVS/ToMMIO", STAMUNIT_TICKS_PER_CALL, "Profiling of the MOVS instruction emulation - Mem2MMIO.");
136 STAM_REG(pVM, &pVM->iom.s.StatGCInstMovsFromMMIO, STAMTYPE_PROFILE, "/IOM/GC/Inst/MOVS/FromMMIO", STAMUNIT_TICKS_PER_CALL, "Profiling of the MOVS instruction emulation - MMIO2Mem.");
137 STAM_REG(pVM, &pVM->iom.s.StatGCInstMovsMMIO, STAMTYPE_PROFILE, "/IOM/GC/Inst/MOVS/MMIO2MMIO", STAMUNIT_TICKS_PER_CALL, "Profiling of the MOVS instruction emulation - MMIO2MMIO.");
138 STAM_REG(pVM, &pVM->iom.s.StatGCInstOther, STAMTYPE_COUNTER, "/IOM/GC/Inst/Other", STAMUNIT_OCCURENCES, "Other instructions counter.");
139 STAM_REG(pVM, &pVM->iom.s.StatGCMMIO1Byte, STAMTYPE_COUNTER, "/IOM/GC/MMIO/Access1", STAMUNIT_OCCURENCES, "MMIO access by 1 byte counter.");
140 STAM_REG(pVM, &pVM->iom.s.StatGCMMIO2Bytes, STAMTYPE_COUNTER, "/IOM/GC/MMIO/Access2", STAMUNIT_OCCURENCES, "MMIO access by 2 bytes counter.");
141 STAM_REG(pVM, &pVM->iom.s.StatGCMMIO4Bytes, STAMTYPE_COUNTER, "/IOM/GC/MMIO/Access4", STAMUNIT_OCCURENCES, "MMIO access by 4 bytes counter.");
142 STAM_REG(pVM, &pVM->iom.s.StatGCIOPortHandler, STAMTYPE_PROFILE, "/IOM/GC/PortIOHandler", STAMUNIT_TICKS_PER_CALL, "Profiling of the IOMGCPortIOHandler() body, only success calls.");
143 STAM_REG(pVM, &pVM->iom.s.StatGCInstIn, STAMTYPE_COUNTER, "/IOM/GC/Inst/In", STAMUNIT_OCCURENCES, "Counter of any IN instructions.");
144 STAM_REG(pVM, &pVM->iom.s.StatGCInstOut, STAMTYPE_COUNTER, "/IOM/GC/Inst/Out", STAMUNIT_OCCURENCES, "Counter of any OUT instructions.");
145 STAM_REG(pVM, &pVM->iom.s.StatGCInstIns, STAMTYPE_COUNTER, "/IOM/GC/Inst/Ins", STAMUNIT_OCCURENCES, "Counter of any INS instructions.");
146 STAM_REG(pVM, &pVM->iom.s.StatGCInstOuts, STAMTYPE_COUNTER, "/IOM/GC/Inst/Outs", STAMUNIT_OCCURENCES, "Counter of any OUTS instructions.");
147 }
148
149 /* Redundant, but just in case we change something in the future */
150 iomR3FlushCache(pVM);
151
152 LogFlow(("IOMR3Init: returns %Vrc\n", rc));
153 return rc;
154}
155
156
157/**
158 * Flushes the IOM port & statistics lookup cache
159 *
160 * @param pVM The VM.
161 */
162static void iomR3FlushCache(PVM pVM)
163{
164 /*
165 * Caching of port and statistics (saves some time in rep outs/ins instruction emulation)
166 */
167 pVM->iom.s.pRangeLastReadGC = 0;
168 pVM->iom.s.pRangeLastWriteGC = 0;
169 pVM->iom.s.pStatsLastReadGC = 0;
170 pVM->iom.s.pStatsLastWriteGC = 0;
171
172 pVM->iom.s.pRangeLastReadR3 = 0;
173 pVM->iom.s.pRangeLastWriteR3 = 0;
174 pVM->iom.s.pStatsLastReadR3 = 0;
175 pVM->iom.s.pStatsLastWriteR3 = 0;
176
177 pVM->iom.s.pRangeLastReadR0 = 0;
178 pVM->iom.s.pRangeLastWriteR0 = 0;
179 pVM->iom.s.pStatsLastReadR0 = 0;
180 pVM->iom.s.pStatsLastWriteR0 = 0;
181}
182
183
184/**
185 * The VM is being reset.
186 *
187 * @param pVM VM handle.
188 */
189IOMR3DECL(void) IOMR3Reset(PVM pVM)
190{
191 iomR3FlushCache(pVM);
192}
193
194
195/**
196 * Applies relocations to data and code managed by this
197 * component. This function will be called at init and
198 * whenever the VMM need to relocate it self inside the GC.
199 *
200 * The IOM will update the addresses used by the switcher.
201 *
202 * @param pVM The VM.
203 * @param offDelta Relocation delta relative to old location.
204 */
205IOMR3DECL(void) IOMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
206{
207 LogFlow(("IOMR3Relocate: offDelta=%d\n", offDelta));
208
209 /*
210 * Apply relocations to the GC callbacks.
211 */
212 pVM->iom.s.pTreesGC = MMHyperHC2GC(pVM, pVM->iom.s.pTreesHC);
213 RTAvlroIOPortDoWithAll(&pVM->iom.s.pTreesHC->IOPortTreeGC, true, iomr3RelocateIOPortCallback, &offDelta);
214 RTAvlroGCPhysDoWithAll(&pVM->iom.s.pTreesHC->MMIOTreeGC, true, iomr3RelocateMMIOCallback, &offDelta);
215
216 if (pVM->iom.s.pfnMMIOHandlerGC)
217 pVM->iom.s.pfnMMIOHandlerGC += offDelta;
218
219 /*
220 * Apply relocations to the cached GC handlers
221 */
222 if (pVM->iom.s.pRangeLastReadGC)
223 pVM->iom.s.pRangeLastReadGC += offDelta;
224 if (pVM->iom.s.pRangeLastWriteGC)
225 pVM->iom.s.pRangeLastWriteGC += offDelta;
226 if (pVM->iom.s.pStatsLastReadGC)
227 pVM->iom.s.pStatsLastReadGC += offDelta;
228 if (pVM->iom.s.pStatsLastWriteGC)
229 pVM->iom.s.pStatsLastWriteGC += offDelta;
230}
231
232
233/**
234 * Callback function for relocating a I/O port range.
235 *
236 * @returns 0 (continue enum)
237 * @param pNode Pointer to a IOMIOPORTRANGEGC node.
238 * @param pvUser Pointer to the offDelta. This is a pointer to the delta since we're
239 * not certain the delta will fit in a void pointer for all possible configs.
240 */
241static DECLCALLBACK(int) iomr3RelocateIOPortCallback(PAVLROIOPORTNODECORE pNode, void *pvUser)
242{
243 PIOMIOPORTRANGEGC pRange = (PIOMIOPORTRANGEGC)pNode;
244 RTGCINTPTR offDelta = *(PRTGCINTPTR)pvUser;
245
246 Assert(pRange->pDevIns);
247 pRange->pDevIns += offDelta;
248 if (pRange->pfnOutCallback)
249 pRange->pfnOutCallback += offDelta;
250 if (pRange->pfnInCallback)
251 pRange->pfnInCallback += offDelta;
252 if (pRange->pfnOutStrCallback)
253 pRange->pfnOutStrCallback += offDelta;
254 if (pRange->pfnInStrCallback)
255 pRange->pfnInStrCallback += offDelta;
256 /** @todo IOMIOPORTRANGEGC::pvUser hack - relocate if 64KB or higher. This hack should be removed! */
257 if (pRange->pvUser > _64K)
258 pRange->pvUser += offDelta;
259 return 0;
260}
261
262
263/**
264 * Callback function for relocating a MMIO range.
265 *
266 * @returns 0 (continue enum)
267 * @param pNode Pointer to a IOMMMIORANGEGC node.
268 * @param pvUser Pointer to the offDelta. This is a pointer to the delta since we're
269 * not certain the delta will fit in a void pointer for all possible configs.
270 */
271static DECLCALLBACK(int) iomr3RelocateMMIOCallback(PAVLROGCPHYSNODECORE pNode, void *pvUser)
272{
273 PIOMMMIORANGEGC pRange = (PIOMMMIORANGEGC)pNode;
274 RTGCINTPTR offDelta = *(PRTGCINTPTR)pvUser;
275
276 Assert(pRange->pDevIns);
277 pRange->pDevIns += offDelta;
278
279 if (pRange->pfnWriteCallback)
280 pRange->pfnWriteCallback += offDelta;
281 if (pRange->pfnReadCallback)
282 pRange->pfnReadCallback += offDelta;
283 if (pRange->pfnFillCallback)
284 pRange->pfnFillCallback += offDelta;
285 /** @todo IOMMMIORANGEGC::pvUser hack - relocate if 64KB or higher. This hack should be removed! */
286 if (pRange->pvUser > _64K)
287 pRange->pvUser += offDelta;
288 return 0;
289}
290
291
292/**
293 * Terminates the IOM.
294 *
295 * Termination means cleaning up and freeing all resources,
296 * the VM it self is at this point powered off or suspended.
297 *
298 * @returns VBox status code.
299 * @param pVM The VM to operate on.
300 */
301IOMR3DECL(int) IOMR3Term(PVM pVM)
302{
303 /*
304 * IOM is not owning anything but automatically freed resources,
305 * so there's nothing to do here.
306 */
307 return VINF_SUCCESS;
308}
309
310
311#ifdef VBOX_WITH_STATISTICS
312/**
313 * Create the statistics node for an I/O port.
314 *
315 * @returns Pointer to new stats node.
316 *
317 * @param pVM VM handle.
318 * @param Port Port.
319 * @param pszDesc Description.
320 */
321PIOMIOPORTSTATS iomr3IOPortStatsCreate(PVM pVM, RTIOPORT Port, const char *pszDesc)
322{
323 /* check if it already exists. */
324 PIOMIOPORTSTATS pPort = (PIOMIOPORTSTATS)RTAvloIOPortGet(&pVM->iom.s.pTreesHC->IOPortStatTree, Port);
325 if (pPort)
326 return pPort;
327
328 /* allocate stats node. */
329 int rc = MMHyperAlloc(pVM, sizeof(*pPort), 0, MM_TAG_IOM_STATS, (void **)&pPort);
330 AssertRC(rc);
331 if (VBOX_SUCCESS(rc))
332 {
333 /* insert into the tree. */
334 pPort->Core.Key = Port;
335 if (RTAvloIOPortInsert(&pVM->iom.s.pTreesHC->IOPortStatTree, &pPort->Core))
336 {
337 /* put a name on common ports. */
338 if (!pszDesc)
339 pszDesc = iomr3IOPortGetStandardName(Port);
340
341 /* register the statistics counters. */
342 char szName[64];
343 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-R3", Port);
344 rc = STAMR3Register(pVM, &pPort->InR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
345 AssertRC(rc);
346
347 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-R3", Port);
348 rc = STAMR3Register(pVM, &pPort->OutR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
349 AssertRC(rc);
350
351 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-GC", Port);
352 rc = STAMR3Register(pVM, &pPort->InGC, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
353 AssertRC(rc);
354
355 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-GC", Port);
356 rc = STAMR3Register(pVM, &pPort->OutGC, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
357 AssertRC(rc);
358
359 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-GC-2-R3", Port);
360 rc = STAMR3Register(pVM, &pPort->InGCToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
361 AssertRC(rc);
362
363 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-GC-2-R3", Port);
364 rc = STAMR3Register(pVM, &pPort->OutGCToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
365 AssertRC(rc);
366
367 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-R0", Port);
368 rc = STAMR3Register(pVM, &pPort->InR0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
369 AssertRC(rc);
370
371 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-R0", Port);
372 rc = STAMR3Register(pVM, &pPort->OutR0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
373 AssertRC(rc);
374
375 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-R0-2-R3", Port);
376 rc = STAMR3Register(pVM, &pPort->InR0ToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
377 AssertRC(rc);
378
379 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-R0-2-R3", Port);
380 rc = STAMR3Register(pVM, &pPort->OutR0ToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
381 AssertRC(rc);
382
383 /* Profiling */
384 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-R3/Prof", Port);
385 rc = STAMR3Register(pVM, &pPort->ProfInR3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
386 AssertRC(rc);
387
388 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-R3/Prof", Port);
389 rc = STAMR3Register(pVM, &pPort->ProfOutR3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
390 AssertRC(rc);
391
392 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-GC/Prof", Port);
393 rc = STAMR3Register(pVM, &pPort->ProfInGC, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
394 AssertRC(rc);
395
396 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-GC/Prof", Port);
397 rc = STAMR3Register(pVM, &pPort->ProfOutGC, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
398 AssertRC(rc);
399
400 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-In-R0/Prof", Port);
401 rc = STAMR3Register(pVM, &pPort->ProfInR0, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
402 AssertRC(rc);
403
404 RTStrPrintf(szName, sizeof(szName), "/IOM/Ports/%04x-Out-R0/Prof", Port);
405 rc = STAMR3Register(pVM, &pPort->ProfOutR0, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
406 AssertRC(rc);
407
408 return pPort;
409 }
410 AssertMsgFailed(("what! Port=%d\n", Port));
411 MMHyperFree(pVM, pPort);
412 }
413 return NULL;
414}
415
416
417/**
418 * Create the statistics node for an MMIO address.
419 *
420 * @returns Pointer to new stats node.
421 *
422 * @param pVM VM handle.
423 * @param GCPhys The address.
424 * @param pszDesc Description.
425 */
426PIOMMMIOSTATS iomR3MMIOStatsCreate(PVM pVM, RTGCPHYS GCPhys, const char *pszDesc)
427{
428#ifdef DEBUG_sandervl
429 AssertGCPhys32(GCPhys);
430#endif
431 /* check if it already exists. */
432 PIOMMMIOSTATS pStats = (PIOMMMIOSTATS)RTAvloGCPhysGet(&pVM->iom.s.pTreesHC->MMIOStatTree, GCPhys);
433 if (pStats)
434 return pStats;
435#if 1
436 /* allocate stats node. */
437 int rc = MMHyperAlloc(pVM, sizeof(*pStats), 0, MM_TAG_IOM_STATS, (void **)&pStats);
438 AssertRC(rc);
439 if (VBOX_SUCCESS(rc))
440 {
441 /* insert into the tree. */
442 pStats->Core.Key = GCPhys;
443 if (RTAvloGCPhysInsert(&pVM->iom.s.pTreesHC->MMIOStatTree, &pStats->Core))
444 {
445 /* register the statistics counters. */
446 char szName[64];
447 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-R3", GCPhys);
448 rc = STAMR3Register(pVM, &pStats->ReadR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
449 AssertRC(rc);
450
451 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-R3", GCPhys);
452 rc = STAMR3Register(pVM, &pStats->WriteR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
453 AssertRC(rc);
454
455 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-GC", GCPhys);
456 rc = STAMR3Register(pVM, &pStats->ReadGC, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
457 AssertRC(rc);
458
459 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-GC", GCPhys);
460 rc = STAMR3Register(pVM, &pStats->WriteGC, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
461 AssertRC(rc);
462
463 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-GC-2-R3", GCPhys);
464 rc = STAMR3Register(pVM, &pStats->ReadGCToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
465 AssertRC(rc);
466
467 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-GC-2-R3", GCPhys);
468 rc = STAMR3Register(pVM, &pStats->WriteGCToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
469 AssertRC(rc);
470
471 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-R0", GCPhys);
472 rc = STAMR3Register(pVM, &pStats->ReadR0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
473 AssertRC(rc);
474
475 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-R0", GCPhys);
476 rc = STAMR3Register(pVM, &pStats->WriteR0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
477 AssertRC(rc);
478
479 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-R0-2-R3", GCPhys);
480 rc = STAMR3Register(pVM, &pStats->ReadR0ToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
481 AssertRC(rc);
482
483 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-R0-2-R3", GCPhys);
484 rc = STAMR3Register(pVM, &pStats->WriteR0ToR3, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, pszDesc);
485 AssertRC(rc);
486
487 /* Profiling */
488 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-R3/Prof", GCPhys);
489 rc = STAMR3Register(pVM, &pStats->ProfReadR3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
490 AssertRC(rc);
491
492 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-R3/Prof", GCPhys);
493 rc = STAMR3Register(pVM, &pStats->ProfWriteR3, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
494 AssertRC(rc);
495
496 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-GC/Prof", GCPhys);
497 rc = STAMR3Register(pVM, &pStats->ProfReadGC, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
498 AssertRC(rc);
499
500 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-GC/Prof", GCPhys);
501 rc = STAMR3Register(pVM, &pStats->ProfWriteGC, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
502 AssertRC(rc);
503
504 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Read-R0/Prof", GCPhys);
505 rc = STAMR3Register(pVM, &pStats->ProfReadR0, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
506 AssertRC(rc);
507
508 RTStrPrintf(szName, sizeof(szName), "/IOM/MMIO/%RGp-Write-R0/Prof", GCPhys);
509 rc = STAMR3Register(pVM, &pStats->ProfWriteR0, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szName, STAMUNIT_TICKS_PER_CALL, pszDesc);
510 AssertRC(rc);
511
512 return pStats;
513 }
514 AssertMsgFailed(("what! GCPhys=%RGp\n", GCPhys));
515 MMHyperFree(pVM, pStats);
516 }
517#endif
518 return NULL;
519}
520#endif /* VBOX_WITH_STATISTICS */
521
522
523/**
524 * Registers a I/O port ring-3 handler.
525 *
526 * This API is called by PDM on behalf of a device. Devices must first register
527 * ring-3 ranges before any GC and R0 ranges can be registerd using IOMR3IOPortRegisterGC()
528 * and IOMR3IOPortRegisterR0().
529 *
530 *
531 * @returns VBox status code.
532 *
533 * @param pVM VM handle.
534 * @param pDevIns PDM device instance owning the port range.
535 * @param PortStart First port number in the range.
536 * @param cPorts Number of ports to register.
537 * @param pvUser User argument for the callbacks.
538 * @param pfnOutCallback Pointer to function which is gonna handle OUT operations in R3.
539 * @param pfnInCallback Pointer to function which is gonna handle IN operations in R3.
540 * @param pfnOutStrCallback Pointer to function which is gonna handle string OUT operations in R3.
541 * @param pfnInStrCallback Pointer to function which is gonna handle string IN operations in R3.
542 * @param pszDesc Pointer to description string. This must not be freed.
543 */
544IOMR3DECL(int) IOMR3IOPortRegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
545 R3PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R3PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
546 R3PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, R3PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback, const char *pszDesc)
547{
548 LogFlow(("IOMR3IOPortRegisterR3: pDevIns=%p PortStart=%#x cPorts=%#x pvUser=%VHv pfnOutCallback=%#x pfnInCallback=%#x pfnOutStrCallback=%#x pfnInStrCallback=%#x pszDesc=%s\n",
549 pDevIns, PortStart, cPorts, pvUser, pfnOutCallback, pfnInCallback, pszDesc, pfnOutStrCallback, pfnInStrCallback));
550
551 /*
552 * Validate input.
553 */
554 if ( (RTUINT)PortStart + cPorts <= (RTUINT)PortStart
555 || (RTUINT)PortStart + cPorts > 0x10000)
556 {
557 AssertMsgFailed(("Invalid port range %#x-%#x (inclusive)! (%s)\n", PortStart, (RTUINT)PortStart + (cPorts - 1), pszDesc));
558 return VERR_IOM_INVALID_IOPORT_RANGE;
559 }
560 if (!pfnOutCallback && !pfnInCallback)
561 {
562 AssertMsgFailed(("no handlers specfied for %#x-%#x (inclusive)! (%s)\n", PortStart, (RTUINT)PortStart + (cPorts - 1), pszDesc));
563 return VERR_INVALID_PARAMETER;
564 }
565 if (!pfnOutCallback)
566 pfnOutCallback = iomR3IOPortDummyOut;
567 if (!pfnInCallback)
568 pfnInCallback = iomR3IOPortDummyIn;
569 if (!pfnOutStrCallback)
570 pfnOutStrCallback = iomR3IOPortDummyOutStr;
571 if (!pfnInStrCallback)
572 pfnInStrCallback = iomR3IOPortDummyInStr;
573
574 /* Flush the IO port lookup cache */
575 iomR3FlushCache(pVM);
576
577 /*
578 * Allocate new range record and initialize it.
579 */
580 PIOMIOPORTRANGER3 pRange;
581 int rc = MMHyperAlloc(pVM, sizeof(*pRange), 0, MM_TAG_IOM, (void **)&pRange);
582 if (VBOX_SUCCESS(rc))
583 {
584 pRange->Core.Key = PortStart;
585 pRange->Core.KeyLast = PortStart + (cPorts - 1);
586 pRange->Port = PortStart;
587 pRange->cPorts = cPorts;
588 pRange->pvUser = pvUser;
589 pRange->pDevIns = pDevIns;
590 pRange->pfnOutCallback = pfnOutCallback;
591 pRange->pfnInCallback = pfnInCallback;
592 pRange->pfnOutStrCallback = pfnOutStrCallback;
593 pRange->pfnInStrCallback = pfnInStrCallback;
594 pRange->pszDesc = pszDesc;
595
596 /*
597 * Try Insert it.
598 */
599 if (RTAvlroIOPortInsert(&pVM->iom.s.pTreesHC->IOPortTreeR3, &pRange->Core))
600 {
601 #ifdef VBOX_WITH_STATISTICS
602 for (unsigned iPort = 0; iPort < cPorts; iPort++)
603 iomr3IOPortStatsCreate(pVM, PortStart + iPort, pszDesc);
604 #endif
605 return VINF_SUCCESS;
606 }
607
608 /* conflict. */
609 DBGFR3Info(pVM, "ioport", NULL, NULL);
610 AssertMsgFailed(("Port range %#x-%#x (%s) conflicts with existing range(s)!\n", PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
611 MMHyperFree(pVM, pRange);
612 rc = VERR_IOM_IOPORT_RANGE_CONFLICT;
613 }
614
615 return rc;
616}
617
618
619/**
620 * Registers a Port IO GC handler.
621 *
622 * This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
623 * using IOMIOPortRegisterR3() before calling this function.
624 *
625 *
626 * @returns VBox status code.
627 *
628 * @param pVM VM handle.
629 * @param pDevIns PDM device instance owning the port range.
630 * @param PortStart First port number in the range.
631 * @param cPorts Number of ports to register.
632 * @param pvUser User argument for the callbacks.
633 * @param pfnOutCallback Pointer to function which is gonna handle OUT operations in GC.
634 * @param pfnInCallback Pointer to function which is gonna handle IN operations in GC.
635 * @param pfnOutStrCallback Pointer to function which is gonna handle string OUT operations in GC.
636 * @param pfnInStrCallback Pointer to function which is gonna handle string IN operations in GC.
637 * @param pszDesc Pointer to description string. This must not be freed.
638 */
639IOMR3DECL(int) IOMR3IOPortRegisterGC(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTGCPTR pvUser,
640 GCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, GCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
641 GCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, GCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback, const char *pszDesc)
642{
643 LogFlow(("IOMR3IOPortRegisterGC: pDevIns=%p PortStart=%#x cPorts=%#x pvUser=%VGv pfnOutCallback=%VGv pfnInCallback=%VGv pfnOutStrCallback=%VGv pfnInStrCallback=%VGv pszDesc=%s\n",
644 pDevIns, PortStart, cPorts, pvUser, pfnOutCallback, pfnInCallback, pfnOutStrCallback, pfnInStrCallback, pszDesc));
645
646 /*
647 * Validate input.
648 */
649 if ( (RTUINT)PortStart + cPorts <= (RTUINT)PortStart
650 || (RTUINT)PortStart + cPorts > 0x10000)
651 {
652 AssertMsgFailed(("Invalid port range %#x-%#x! (%s)\n", PortStart, (RTUINT)PortStart + (cPorts - 1), pszDesc));
653 return VERR_IOM_INVALID_IOPORT_RANGE;
654 }
655 RTIOPORT PortLast = PortStart + (cPorts - 1);
656 if (!pfnOutCallback && !pfnInCallback)
657 {
658 AssertMsgFailed(("Invalid port range %#x-%#x! No callbacks! (%s)\n", PortStart, PortLast, pszDesc));
659 return VERR_INVALID_PARAMETER;
660 }
661
662 /*
663 * Validate that there are ring-3 ranges for the ports.
664 */
665 RTIOPORT Port = PortStart;
666 while (Port <= PortLast && Port >= PortStart)
667 {
668 PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->IOPortTreeR3, Port);
669 if (!pRange)
670 {
671 AssertMsgFailed(("No R3! Port=#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
672 return VERR_IOM_NO_HC_IOPORT_RANGE;
673 }
674#ifndef IOM_NO_PDMINS_CHECKS
675# ifndef IN_GC
676 if (pRange->pDevIns != pDevIns)
677# else
678 if (pRange->pDevIns != MMHyperGC2HC(pVM, pDevIns))
679# endif
680 {
681 AssertMsgFailed(("Not owner! Port=%#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
682 return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
683 }
684#endif
685 Port = pRange->Core.KeyLast + 1;
686 }
687
688 /* Flush the IO port lookup cache */
689 iomR3FlushCache(pVM);
690
691 /*
692 * Allocate new range record and initialize it.
693 */
694 PIOMIOPORTRANGEGC pRange;
695 int rc = MMHyperAlloc(pVM, sizeof(*pRange), 0, MM_TAG_IOM, (void **)&pRange);
696 if (VBOX_SUCCESS(rc))
697 {
698 pRange->Core.Key = PortStart;
699 pRange->Core.KeyLast = PortLast;
700 pRange->Port = PortStart;
701 pRange->cPorts = cPorts;
702 pRange->pvUser = pvUser;
703 pRange->pfnOutCallback = pfnOutCallback;
704 pRange->pfnInCallback = pfnInCallback;
705 pRange->pfnOutStrCallback = pfnOutStrCallback;
706 pRange->pfnInStrCallback = pfnInStrCallback;
707#ifdef IN_GC
708 pRange->pDevIns = pDevIns;
709 pRange->pszDesc = MMHyperGC2HC(pVM, (void *)pszDesc);
710#else
711 pRange->pDevIns = MMHyperHC2GC(pVM, pDevIns);
712 pRange->pszDesc = pszDesc;
713#endif
714
715 /*
716 * Insert it.
717 */
718 if (RTAvlroIOPortInsert(&pVM->iom.s.CTXSUFF(pTrees)->IOPortTreeGC, &pRange->Core))
719 return VINF_SUCCESS;
720
721 /* conflict. */
722 AssertMsgFailed(("Port range %#x-%#x (%s) conflicts with existing range(s)!\n", PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
723 MMHyperFree(pVM, pRange);
724 rc = VERR_IOM_IOPORT_RANGE_CONFLICT;
725 }
726
727 return rc;
728}
729
730
731/**
732 * Registers a Port IO R0 handler.
733 *
734 * This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
735 * using IOMR3IOPortRegisterR3() before calling this function.
736 *
737 *
738 * @returns VBox status code.
739 *
740 * @param pVM VM handle.
741 * @param pDevIns PDM device instance owning the port range.
742 * @param PortStart First port number in the range.
743 * @param cPorts Number of ports to register.
744 * @param pvUser User argument for the callbacks.
745 * @param pfnOutCallback Pointer to function which is gonna handle OUT operations in GC.
746 * @param pfnInCallback Pointer to function which is gonna handle IN operations in GC.
747 * @param pfnOutStrCallback Pointer to function which is gonna handle OUT operations in GC.
748 * @param pfnInStrCallback Pointer to function which is gonna handle IN operations in GC.
749 * @param pszDesc Pointer to description string. This must not be freed.
750 */
751IOMR3DECL(int) IOMR3IOPortRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTR0PTR pvUser,
752 R0PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R0PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
753 R0PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, R0PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
754 const char *pszDesc)
755{
756 LogFlow(("IOMR3IOPortRegisterR0: pDevIns=%p PortStart=%#x cPorts=%#x pvUser=%VHv pfnOutCallback=%VGv pfnInCallback=%VGv pfnOutStrCallback=%VGv pfnInStrCallback=%VGv pszDesc=%s\n",
757 pDevIns, PortStart, cPorts, pvUser, pfnOutCallback, pfnInCallback, pfnOutStrCallback, pfnInStrCallback, pszDesc));
758
759 /*
760 * Validate input.
761 */
762 if ( (RTUINT)PortStart + cPorts <= (RTUINT)PortStart
763 || (RTUINT)PortStart + cPorts > 0x10000)
764 {
765 AssertMsgFailed(("Invalid port range %#x-%#x! (%s)\n", PortStart, (RTUINT)PortStart + (cPorts - 1), pszDesc));
766 return VERR_IOM_INVALID_IOPORT_RANGE;
767 }
768 RTIOPORT PortLast = PortStart + (cPorts - 1);
769 if (!pfnOutCallback && !pfnInCallback)
770 {
771 AssertMsgFailed(("Invalid port range %#x-%#x! No callbacks! (%s)\n", PortStart, PortLast, pszDesc));
772 return VERR_INVALID_PARAMETER;
773 }
774
775 /*
776 * Validate that there are ring-3 ranges for the ports.
777 */
778 RTIOPORT Port = PortStart;
779 while (Port <= PortLast && Port >= PortStart)
780 {
781 PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->IOPortTreeR3, Port);
782 if (!pRange)
783 {
784 AssertMsgFailed(("No R3! Port=#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
785 return VERR_IOM_NO_HC_IOPORT_RANGE;
786 }
787#ifndef IOM_NO_PDMINS_CHECKS
788# ifndef IN_GC
789 if (pRange->pDevIns != pDevIns)
790# else
791 if (pRange->pDevIns != MMHyperGC2HC(pVM, pDevIns))
792# endif
793 {
794 AssertMsgFailed(("Not owner! Port=%#x %#x-%#x! (%s)\n", Port, PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
795 return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
796 }
797#endif
798 Port = pRange->Core.KeyLast + 1;
799 }
800
801 /* Flush the IO port lookup cache */
802 iomR3FlushCache(pVM);
803
804 /*
805 * Allocate new range record and initialize it.
806 */
807 PIOMIOPORTRANGER0 pRange;
808 int rc = MMHyperAlloc(pVM, sizeof(*pRange), 0, MM_TAG_IOM, (void **)&pRange);
809 if (VBOX_SUCCESS(rc))
810 {
811 pRange->Core.Key = PortStart;
812 pRange->Core.KeyLast = PortLast;
813 pRange->Port = PortStart;
814 pRange->cPorts = cPorts;
815 pRange->pvUser = pvUser;
816 pRange->pfnOutCallback = pfnOutCallback;
817 pRange->pfnInCallback = pfnInCallback;
818 pRange->pfnOutStrCallback = pfnOutStrCallback;
819 pRange->pfnInStrCallback = pfnInStrCallback;
820#ifdef IN_GC
821 pRange->pDevIns = MMHyperGCToR0(pVM, pDevIns);
822 pRange->pszDesc = MMHyperGCToR3(pVM, (void *)pszDesc);
823#elif defined(IN_RING3)
824 pRange->pDevIns = MMHyperR3ToR0(pVM, pDevIns);
825 pRange->pszDesc = pszDesc;
826#else
827 pRange->pDevIns = pDevIns;
828 pRange->pszDesc = MMHyperR0ToR3(pVM, (RTR0PTR)pszDesc);
829#endif
830
831 /*
832 * Insert it.
833 */
834 if (RTAvlroIOPortInsert(&pVM->iom.s.CTXSUFF(pTrees)->IOPortTreeR0, &pRange->Core))
835 return VINF_SUCCESS;
836
837 /* conflict. */
838 AssertMsgFailed(("Port range %#x-%#x (%s) conflicts with existing range(s)!\n", PortStart, (unsigned)PortStart + cPorts - 1, pszDesc));
839 MMHyperFree(pVM, pRange);
840 rc = VERR_IOM_IOPORT_RANGE_CONFLICT;
841 }
842
843 return rc;
844}
845
846
847/**
848 * Deregisters a I/O Port range.
849 *
850 * The specified range must be registered using IOMR3IOPortRegister previous to
851 * this call. The range does can be a smaller part of the range specified to
852 * IOMR3IOPortRegister, but it can never be larger.
853 *
854 * This function will remove GC, R0 and R3 context port handlers for this range.
855 *
856 * @returns VBox status code.
857 *
858 * @param pVM The virtual machine.
859 * @param pDevIns The device instance associated with the range.
860 * @param PortStart First port number in the range.
861 * @param cPorts Number of ports to remove starting at PortStart.
862 *
863 * @remark This function mainly for PCI PnP Config and will not do
864 * all the checks you might expect it to do.
865 */
866IOMR3DECL(int) IOMR3IOPortDeregister(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts)
867{
868 LogFlow(("IOMR3IOPortDeregister: pDevIns=%p PortStart=%#x cPorts=%#x\n", pDevIns, PortStart, cPorts));
869
870 /*
871 * Validate input.
872 */
873 if ( (RTUINT)PortStart + cPorts < (RTUINT)PortStart
874 || (RTUINT)PortStart + cPorts > 0x10000)
875 {
876 AssertMsgFailed(("Invalid port range %#x-%#x!\n", PortStart, (unsigned)PortStart + cPorts - 1));
877 return VERR_IOM_INVALID_IOPORT_RANGE;
878 }
879
880 /* Flush the IO port lookup cache */
881 iomR3FlushCache(pVM);
882
883 /*
884 * Check ownership.
885 */
886 RTIOPORT PortLast = PortStart + (cPorts - 1);
887 RTIOPORT Port = PortStart;
888 while (Port <= PortLast && Port >= PortStart)
889 {
890 PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.pTreesHC->IOPortTreeR3, Port);
891 if (pRange)
892 {
893 Assert(Port <= pRange->Core.KeyLast);
894#ifndef IOM_NO_PDMINS_CHECKS
895 if (pRange->pDevIns != pDevIns)
896 {
897 AssertMsgFailed(("Removal of ports in range %#x-%#x rejected because not owner of %#x-%#x (%s)\n",
898 PortStart, PortLast, pRange->Core.Key, pRange->Core.KeyLast, pRange->pszDesc));
899 return VERR_IOM_NOT_IOPORT_RANGE_OWNER;
900 }
901#endif /* !IOM_NO_PDMINS_CHECKS */
902 Port = pRange->Core.KeyLast;
903 }
904 Port++;
905 }
906
907 /*
908 * Remove any GC ranges first.
909 */
910 int rc = VINF_SUCCESS;
911 Port = PortStart;
912 while (Port <= PortLast && Port >= PortStart)
913 {
914 /*
915 * Try find range.
916 */
917 PIOMIOPORTRANGEGC pRange = (PIOMIOPORTRANGEGC)RTAvlroIOPortRangeGet(&pVM->iom.s.pTreesHC->IOPortTreeGC, Port);
918 if (pRange)
919 {
920 if ( pRange->Core.Key == Port
921 && pRange->Core.KeyLast <= PortLast)
922 {
923 /*
924 * Kick out the entire range.
925 */
926 void *pv = RTAvlroIOPortRemove(&pVM->iom.s.pTreesHC->IOPortTreeGC, Port);
927 Assert(pv == (void *)pRange); NOREF(pv);
928 Port += pRange->cPorts;
929 MMHyperFree(pVM, pRange);
930 }
931 else if (pRange->Core.Key == Port)
932 {
933 /*
934 * Cut of the head of the range, done.
935 */
936 pRange->cPorts -= Port - pRange->Port;
937 pRange->Core.Key = Port;
938 pRange->Port = Port;
939 break;
940 }
941 else if (pRange->Core.KeyLast <= PortLast)
942 {
943 /*
944 * Just cut of the tail.
945 */
946 unsigned c = pRange->Core.KeyLast - Port + 1;
947 pRange->Core.KeyLast -= c;
948 pRange->cPorts -= c;
949 Port += c;
950 }
951 else
952 {
953 /*
954 * Split the range, done.
955 */
956 Assert(pRange->Core.KeyLast > PortLast && pRange->Core.Key < Port);
957 /* create tail. */
958 PIOMIOPORTRANGEGC pRangeNew;
959 int rc = MMHyperAlloc(pVM, sizeof(*pRangeNew), 0, MM_TAG_IOM, (void **)&pRangeNew);
960 if (VBOX_FAILURE(rc))
961 return rc;
962
963 *pRangeNew = *pRange;
964 pRangeNew->Core.Key = PortLast;
965 pRangeNew->Port = PortLast;
966 pRangeNew->cPorts = pRangeNew->Core.KeyLast - PortLast + 1;
967
968 /* adjust head */
969 pRange->Core.KeyLast = Port - 1;
970 pRange->cPorts = Port - pRange->Port;
971
972 /* insert */
973 if (!RTAvlroIOPortInsert(&pVM->iom.s.pTreesHC->IOPortTreeGC, &pRangeNew->Core))
974 {
975 AssertMsgFailed(("This cannot happen!\n"));
976 MMHyperFree(pVM, pRangeNew);
977 rc = VERR_INTERNAL_ERROR;
978 }
979 break;
980 }
981 }
982 else /* next port */
983 Port++;
984 } /* for all ports - GC. */
985
986
987 /*
988 * Remove any R0 ranges first.
989 */
990 rc = VINF_SUCCESS;
991 Port = PortStart;
992 while (Port <= PortLast && Port >= PortStart)
993 {
994 /*
995 * Try find range.
996 */
997 PIOMIOPORTRANGER0 pRange = (PIOMIOPORTRANGER0)RTAvlroIOPortRangeGet(&pVM->iom.s.pTreesHC->IOPortTreeR0, Port);
998 if (pRange)
999 {
1000 if ( pRange->Core.Key == Port
1001 && pRange->Core.KeyLast <= PortLast)
1002 {
1003 /*
1004 * Kick out the entire range.
1005 */
1006 void *pv = RTAvlroIOPortRemove(&pVM->iom.s.pTreesHC->IOPortTreeR0, Port);
1007 Assert(pv == (void *)pRange); NOREF(pv);
1008 Port += pRange->cPorts;
1009 MMHyperFree(pVM, pRange);
1010 }
1011 else if (pRange->Core.Key == Port)
1012 {
1013 /*
1014 * Cut of the head of the range, done.
1015 */
1016 pRange->cPorts -= Port - pRange->Port;
1017 pRange->Core.Key = Port;
1018 pRange->Port = Port;
1019 break;
1020 }
1021 else if (pRange->Core.KeyLast <= PortLast)
1022 {
1023 /*
1024 * Just cut of the tail.
1025 */
1026 unsigned c = pRange->Core.KeyLast - Port + 1;
1027 pRange->Core.KeyLast -= c;
1028 pRange->cPorts -= c;
1029 Port += c;
1030 }
1031 else
1032 {
1033 /*
1034 * Split the range, done.
1035 */
1036 Assert(pRange->Core.KeyLast > PortLast && pRange->Core.Key < Port);
1037 /* create tail. */
1038 PIOMIOPORTRANGER0 pRangeNew;
1039 int rc = MMHyperAlloc(pVM, sizeof(*pRangeNew), 0, MM_TAG_IOM, (void **)&pRangeNew);
1040 if (VBOX_FAILURE(rc))
1041 return rc;
1042
1043 *pRangeNew = *pRange;
1044 pRangeNew->Core.Key = PortLast;
1045 pRangeNew->Port = PortLast;
1046 pRangeNew->cPorts = pRangeNew->Core.KeyLast - PortLast + 1;
1047
1048 /* adjust head */
1049 pRange->Core.KeyLast = Port - 1;
1050 pRange->cPorts = Port - pRange->Port;
1051
1052 /* insert */
1053 if (!RTAvlroIOPortInsert(&pVM->iom.s.pTreesHC->IOPortTreeR0, &pRangeNew->Core))
1054 {
1055 AssertMsgFailed(("This cannot happen!\n"));
1056 MMHyperFree(pVM, pRangeNew);
1057 rc = VERR_INTERNAL_ERROR;
1058 }
1059 break;
1060 }
1061 }
1062 else /* next port */
1063 Port++;
1064 } /* for all ports - R0. */
1065
1066 /*
1067 * And the same procedure for ring-3 ranges.
1068 */
1069 Port = PortStart;
1070 while (Port <= PortLast && Port >= PortStart)
1071 {
1072 /*
1073 * Try find range.
1074 */
1075 PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)RTAvlroIOPortRangeGet(&pVM->iom.s.pTreesHC->IOPortTreeR3, Port);
1076 if (pRange)
1077 {
1078 if ( pRange->Core.Key == Port
1079 && pRange->Core.KeyLast <= PortLast)
1080 {
1081 /*
1082 * Kick out the entire range.
1083 */
1084 void *pv = RTAvlroIOPortRemove(&pVM->iom.s.pTreesHC->IOPortTreeR3, Port);
1085 Assert(pv == (void *)pRange); NOREF(pv);
1086 Port += pRange->cPorts;
1087 MMHyperFree(pVM, pRange);
1088 }
1089 else if (pRange->Core.Key == Port)
1090 {
1091 /*
1092 * Cut of the head of the range, done.
1093 */
1094 pRange->cPorts -= Port - pRange->Port;
1095 pRange->Core.Key = Port;
1096 pRange->Port = Port;
1097 break;
1098 }
1099 else if (pRange->Core.KeyLast <= PortLast)
1100 {
1101 /*
1102 * Just cut of the tail.
1103 */
1104 unsigned c = pRange->Core.KeyLast - Port + 1;
1105 pRange->Core.KeyLast -= c;
1106 pRange->cPorts -= c;
1107 Port += c;
1108 }
1109 else
1110 {
1111 /*
1112 * Split the range, done.
1113 */
1114 Assert(pRange->Core.KeyLast > PortLast && pRange->Core.Key < Port);
1115 /* create tail. */
1116 PIOMIOPORTRANGER3 pRangeNew;
1117 int rc = MMHyperAlloc(pVM, sizeof(*pRangeNew), 0, MM_TAG_IOM, (void **)&pRangeNew);
1118 if (VBOX_FAILURE(rc))
1119 return rc;
1120
1121 *pRangeNew = *pRange;
1122 pRangeNew->Core.Key = PortLast;
1123 pRangeNew->Port = PortLast;
1124 pRangeNew->cPorts = pRangeNew->Core.KeyLast - PortLast + 1;
1125
1126 /* adjust head */
1127 pRange->Core.KeyLast = Port - 1;
1128 pRange->cPorts = Port - pRange->Port;
1129
1130 /* insert */
1131 if (!RTAvlroIOPortInsert(&pVM->iom.s.pTreesHC->IOPortTreeR3, &pRangeNew->Core))
1132 {
1133 AssertMsgFailed(("This cannot happen!\n"));
1134 MMHyperFree(pVM, pRangeNew);
1135 rc = VERR_INTERNAL_ERROR;
1136 }
1137 break;
1138 }
1139 }
1140 else /* next port */
1141 Port++;
1142 } /* for all ports - ring-3. */
1143
1144 /* done */
1145 return rc;
1146}
1147
1148
1149/**
1150 * Dummy Port I/O Handler for IN operations.
1151 *
1152 * @returns VBox status code.
1153 *
1154 * @param pDevIns The device instance.
1155 * @param pvUser User argument.
1156 * @param Port Port number used for the IN operation.
1157 * @param pu32 Where to store the result.
1158 * @param cb Number of bytes read.
1159 */
1160static DECLCALLBACK(int) iomR3IOPortDummyIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
1161{
1162 switch (cb)
1163 {
1164 case 1: *pu32 = 0xff; break;
1165 case 2: *pu32 = 0xffff; break;
1166 case 4: *pu32 = 0xffffffff; break;
1167 default:
1168 AssertReleaseMsgFailed(("cb=%d\n", cb));
1169 return VERR_INTERNAL_ERROR;
1170 }
1171 return VINF_SUCCESS;
1172}
1173
1174
1175/**
1176 * Dummy Port I/O Handler for string IN operations.
1177 *
1178 * @returns VBox status code.
1179 *
1180 * @param pDevIns The device instance.
1181 * @param pvUser User argument.
1182 * @param Port Port number used for the string IN operation.
1183 * @param pGCPtrDst Pointer to the destination buffer (GC, incremented appropriately).
1184 * @param pcTransfer Pointer to the number of transfer units to read, on return remaining transfer units.
1185 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
1186 */
1187static DECLCALLBACK(int) iomR3IOPortDummyInStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, unsigned *pcTransfer, unsigned cb)
1188{
1189 return VINF_SUCCESS;
1190}
1191
1192
1193/**
1194 * Dummy Port I/O Handler for OUT operations.
1195 *
1196 * @returns VBox status code.
1197 *
1198 * @param pDevIns The device instance.
1199 * @param pvUser User argument.
1200 * @param Port Port number used for the OUT operation.
1201 * @param u32 The value to output.
1202 * @param cb The value size in bytes.
1203 */
1204static DECLCALLBACK(int) iomR3IOPortDummyOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
1205{
1206 return VINF_SUCCESS;
1207}
1208
1209
1210/**
1211 * Dummy Port I/O Handler for string OUT operations.
1212 *
1213 * @returns VBox status code.
1214 *
1215 * @param pDevIns The device instance.
1216 * @param pvUser User argument.
1217 * @param Port Port number used for the string OUT operation.
1218 * @param pGCPtrSrc Pointer to the source buffer (GC, incremented appropriately).
1219 * @param pcTransfer Pointer to the number of transfer units to write, on return remaining transfer units.
1220 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
1221 */
1222static DECLCALLBACK(int) iomR3IOPortDummyOutStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, unsigned *pcTransfer, unsigned cb)
1223{
1224 return VINF_SUCCESS;
1225}
1226
1227
1228/**
1229 * Display a single I/O port ring-3 range.
1230 *
1231 * @returns 0
1232 * @param pNode Pointer to I/O port HC range.
1233 * @param pvUser Pointer to info output callback structure.
1234 */
1235static DECLCALLBACK(int) iomR3IOPortInfoOneR3(PAVLROIOPORTNODECORE pNode, void *pvUser)
1236{
1237 PIOMIOPORTRANGER3 pRange = (PIOMIOPORTRANGER3)pNode;
1238 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
1239 pHlp->pfnPrintf(pHlp,
1240 "%04x-%04x %VHv %VHv %VHv %VHv %s\n",
1241 pRange->Core.Key,
1242 pRange->Core.KeyLast,
1243 pRange->pDevIns,
1244 pRange->pfnInCallback,
1245 pRange->pfnOutCallback,
1246 pRange->pvUser,
1247 pRange->pszDesc);
1248 return 0;
1249}
1250
1251
1252/**
1253 * Display a single I/O port GC range.
1254 *
1255 * @returns 0
1256 * @param pNode Pointer to IOPORT GC range.
1257 * @param pvUser Pointer to info output callback structure.
1258 */
1259static DECLCALLBACK(int) iomR3IOPortInfoOneGC(PAVLROIOPORTNODECORE pNode, void *pvUser)
1260{
1261 PIOMIOPORTRANGEGC pRange = (PIOMIOPORTRANGEGC)pNode;
1262 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
1263 pHlp->pfnPrintf(pHlp,
1264 "%04x-%04x %VGv %VGv %VGv %VGv %s\n",
1265 pRange->Core.Key,
1266 pRange->Core.KeyLast,
1267 pRange->pDevIns,
1268 pRange->pfnInCallback,
1269 pRange->pfnOutCallback,
1270 pRange->pvUser,
1271 pRange->pszDesc);
1272 return 0;
1273}
1274
1275
1276/**
1277 * Display all registered I/O port ranges.
1278 *
1279 * @param pVM VM Handle.
1280 * @param pHlp The info helpers.
1281 * @param pszArgs Arguments, ignored.
1282 */
1283static DECLCALLBACK(void) iomR3IOPortInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1284{
1285 NOREF(pszArgs);
1286 pHlp->pfnPrintf(pHlp,
1287 "I/O Port R3 ranges (pVM=%p)\n"
1288 "Range %.*s %.*s %.*s %.*s Description\n",
1289 pVM,
1290 sizeof(RTHCPTR) * 2, "pDevIns ",
1291 sizeof(RTHCPTR) * 2, "In ",
1292 sizeof(RTHCPTR) * 2, "Out ",
1293 sizeof(RTHCPTR) * 2, "pvUser ");
1294 RTAvlroIOPortDoWithAll(&pVM->iom.s.pTreesHC->IOPortTreeR3, true, iomR3IOPortInfoOneR3, (void *)pHlp);
1295
1296 pHlp->pfnPrintf(pHlp,
1297 "I/O Port R0 ranges (pVM=%p)\n"
1298 "Range %.*s %.*s %.*s %.*s Description\n",
1299 pVM,
1300 sizeof(RTHCPTR) * 2, "pDevIns ",
1301 sizeof(RTHCPTR) * 2, "In ",
1302 sizeof(RTHCPTR) * 2, "Out ",
1303 sizeof(RTHCPTR) * 2, "pvUser ");
1304 RTAvlroIOPortDoWithAll(&pVM->iom.s.pTreesHC->IOPortTreeR0, true, iomR3IOPortInfoOneR3, (void *)pHlp);
1305
1306 pHlp->pfnPrintf(pHlp,
1307 "I/O Port GC ranges (pVM=%p)\n"
1308 "Range %.*s %.*s %.*s %.*s Description\n",
1309 pVM,
1310 sizeof(RTGCPTR) * 2, "pDevIns ",
1311 sizeof(RTGCPTR) * 2, "In ",
1312 sizeof(RTGCPTR) * 2, "Out ",
1313 sizeof(RTGCPTR) * 2, "pvUser ");
1314 RTAvlroIOPortDoWithAll(&pVM->iom.s.pTreesHC->IOPortTreeGC, true, iomR3IOPortInfoOneGC, (void *)pHlp);
1315
1316 if (pVM->iom.s.pRangeLastReadGC)
1317 {
1318 PIOMIOPORTRANGEGC pRange = (PIOMIOPORTRANGEGC)MMHyperGC2HC(pVM, pVM->iom.s.pRangeLastReadGC);
1319 pHlp->pfnPrintf(pHlp, "GC Read Ports: %#04x-%#04x %VGv %s\n",
1320 pRange->Port, pRange->Port + pRange->cPorts, pVM->iom.s.pRangeLastReadGC, pRange->pszDesc);
1321 }
1322 if (pVM->iom.s.pStatsLastReadGC)
1323 {
1324 PIOMIOPORTSTATS pRange = (PIOMIOPORTSTATS)MMHyperGC2HC(pVM, pVM->iom.s.pStatsLastReadGC);
1325 pHlp->pfnPrintf(pHlp, "GC Read Stats: %#04x %VGv\n",
1326 pRange->Core.Key, pVM->iom.s.pStatsLastReadGC);
1327 }
1328
1329 if (pVM->iom.s.pRangeLastWriteGC)
1330 {
1331 PIOMIOPORTRANGEGC pRange = (PIOMIOPORTRANGEGC)MMHyperGC2HC(pVM, pVM->iom.s.pRangeLastWriteGC);
1332 pHlp->pfnPrintf(pHlp, "GC Write Ports: %#04x-%#04x %VGv %s\n",
1333 pRange->Port, pRange->Port + pRange->cPorts, pVM->iom.s.pRangeLastWriteGC, pRange->pszDesc);
1334 }
1335 if (pVM->iom.s.pStatsLastWriteGC)
1336 {
1337 PIOMIOPORTSTATS pRange = (PIOMIOPORTSTATS)MMHyperGC2HC(pVM, pVM->iom.s.pStatsLastWriteGC);
1338 pHlp->pfnPrintf(pHlp, "GC Write Stats: %#04x %VGv\n",
1339 pRange->Core.Key, pVM->iom.s.pStatsLastWriteGC);
1340 }
1341
1342 if (pVM->iom.s.pRangeLastReadR3)
1343 {
1344 PIOMIOPORTRANGER3 pRange = pVM->iom.s.pRangeLastReadR3;
1345 pHlp->pfnPrintf(pHlp, "HC Read Ports: %#04x-%#04x %VGv %s\n",
1346 pRange->Port, pRange->Port + pRange->cPorts, pRange, pRange->pszDesc);
1347 }
1348 if (pVM->iom.s.pStatsLastReadR3)
1349 {
1350 PIOMIOPORTSTATS pRange = pVM->iom.s.pStatsLastReadR3;
1351 pHlp->pfnPrintf(pHlp, "HC Read Stats: %#04x %VGv\n",
1352 pRange->Core.Key, pRange);
1353 }
1354
1355 if (pVM->iom.s.pRangeLastWriteR3)
1356 {
1357 PIOMIOPORTRANGER3 pRange = pVM->iom.s.pRangeLastWriteR3;
1358 pHlp->pfnPrintf(pHlp, "HC Write Ports: %#04x-%#04x %VGv %s\n",
1359 pRange->Port, pRange->Port + pRange->cPorts, pRange, pRange->pszDesc);
1360 }
1361 if (pVM->iom.s.pStatsLastWriteR3)
1362 {
1363 PIOMIOPORTSTATS pRange = pVM->iom.s.pStatsLastWriteR3;
1364 pHlp->pfnPrintf(pHlp, "HC Write Stats: %#04x %VGv\n",
1365 pRange->Core.Key, pRange);
1366 }
1367
1368 if (pVM->iom.s.pRangeLastReadR0)
1369 {
1370 PIOMIOPORTRANGER0 pRange = pVM->iom.s.pRangeLastReadR0;
1371 pHlp->pfnPrintf(pHlp, "R0 Read Ports: %#04x-%#04x %VGv %s\n",
1372 pRange->Port, pRange->Port + pRange->cPorts, pRange, pRange->pszDesc);
1373 }
1374 if (pVM->iom.s.pStatsLastReadR0)
1375 {
1376 PIOMIOPORTSTATS pRange = pVM->iom.s.pStatsLastReadR0;
1377 pHlp->pfnPrintf(pHlp, "R0 Read Stats: %#04x %VGv\n",
1378 pRange->Core.Key, pRange);
1379 }
1380
1381 if (pVM->iom.s.pRangeLastWriteR0)
1382 {
1383 PIOMIOPORTRANGER0 pRange = pVM->iom.s.pRangeLastWriteR0;
1384 pHlp->pfnPrintf(pHlp, "R0 Write Ports: %#04x-%#04x %VGv %s\n",
1385 pRange->Port, pRange->Port + pRange->cPorts, pRange, pRange->pszDesc);
1386 }
1387 if (pVM->iom.s.pStatsLastWriteR0)
1388 {
1389 PIOMIOPORTSTATS pRange = pVM->iom.s.pStatsLastWriteR0;
1390 pHlp->pfnPrintf(pHlp, "R0 Write Stats: %#04x %VGv\n",
1391 pRange->Core.Key, pRange);
1392 }
1393}
1394
1395
1396/**
1397 * Registers a Memory Mapped I/O R3 handler.
1398 *
1399 * This API is called by PDM on behalf of a device. Devices must register ring-3 ranges
1400 * before any GC and R0 ranges can be registered using IOMR3MMIORegisterGC() and IOMR3MMIORegisterR0().
1401 *
1402 * @returns VBox status code.
1403 *
1404 * @param pVM VM handle.
1405 * @param pDevIns PDM device instance owning the MMIO range.
1406 * @param GCPhysStart First physical address in the range.
1407 * @param cbRange The size of the range (in bytes).
1408 * @param pvUser User argument for the callbacks.
1409 * @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
1410 * @param pfnReadCallback Pointer to function which is gonna handle Read operations.
1411 * @param pfnFillCallback Pointer to function which is gonna handle Fill/memset operations.
1412 * @param pszDesc Pointer to description string. This must not be freed.
1413 */
1414IOMR3DECL(int) IOMR3MMIORegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
1415 R3PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback, R3PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
1416 R3PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc)
1417{
1418 LogFlow(("IOMR3MMIORegisterR3: pDevIns=%p GCPhysStart=%VGp cbRange=%#x pvUser=%VHv pfnWriteCallback=%#x pfnReadCallback=%#x pfnFillCallback=%#x pszDesc=%s\n",
1419 pDevIns, GCPhysStart, cbRange, pvUser, pfnWriteCallback, pfnReadCallback, pfnFillCallback, pszDesc));
1420 int rc;
1421
1422 /*
1423 * Validate input.
1424 */
1425 if (GCPhysStart + (cbRange - 1) < GCPhysStart)
1426 {
1427 AssertMsgFailed(("Wrapped! %VGp %#x bytes\n", GCPhysStart, cbRange));
1428 return VERR_IOM_INVALID_MMIO_RANGE;
1429 }
1430
1431 /*
1432 * Resolve the GC/R0 handler addresses lazily because of init order.
1433 */
1434 if (pVM->iom.s.pfnMMIOHandlerR0 == NIL_RTR0PTR)
1435 {
1436 rc = PDMR3GetSymbolGCLazy(pVM, NULL, "IOMMMIOHandler", &pVM->iom.s.pfnMMIOHandlerGC);
1437 AssertLogRelRCReturn(rc, rc);
1438 rc = PDMR3GetSymbolR0Lazy(pVM, NULL, "IOMMMIOHandler", &pVM->iom.s.pfnMMIOHandlerR0);
1439 AssertLogRelRCReturn(rc, rc);
1440 }
1441
1442 /*
1443 * Allocate new range record and initialize it.
1444 */
1445 PIOMMMIORANGER3 pRange;
1446 rc = MMHyperAlloc(pVM, sizeof(*pRange), 0, MM_TAG_IOM, (void **)&pRange);
1447 if (VBOX_SUCCESS(rc))
1448 {
1449 pRange->Core.Key = GCPhysStart;
1450 pRange->Core.KeyLast = GCPhysStart + (cbRange - 1);
1451 pRange->GCPhys = GCPhysStart;
1452 pRange->cb = cbRange;
1453 pRange->pvUser = pvUser;
1454 pRange->pDevIns = pDevIns;
1455 pRange->pfnReadCallback = pfnReadCallback;
1456 pRange->pfnWriteCallback= pfnWriteCallback;
1457 pRange->pfnFillCallback = pfnFillCallback;
1458 pRange->pszDesc = pszDesc;
1459
1460 /*
1461 * Try register it with PGM and then insert it into the tree.
1462 */
1463 rc = PGMR3PhysMMIORegister(pVM, GCPhysStart, cbRange,
1464 /*IOMR3MMIOHandler*/ NULL, pRange,
1465 pVM->iom.s.pfnMMIOHandlerR0, MMHyperR3ToR0(pVM, pRange),
1466 pVM->iom.s.pfnMMIOHandlerGC, MMHyperR3ToGC(pVM, pRange), pszDesc);
1467 if (RT_SUCCESS(rc))
1468 {
1469 if (RTAvlroGCPhysInsert(&pVM->iom.s.pTreesHC->MMIOTreeR3, &pRange->Core))
1470 return VINF_SUCCESS;
1471
1472 DBGFR3Info(pVM, "mmio", NULL, NULL);
1473 AssertMsgFailed(("This cannot happen!\n"));
1474 rc = VERR_INTERNAL_ERROR;
1475 }
1476 MMHyperFree(pVM, pRange);
1477 }
1478
1479 return rc;
1480}
1481
1482
1483/**
1484 * Registers a Memory Mapped I/O GC handler range.
1485 *
1486 * This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
1487 * using IOMMMIORegisterR3() before calling this function.
1488 *
1489 *
1490 * @returns VBox status code.
1491 *
1492 * @param pVM VM handle.
1493 * @param pDevIns PDM device instance owning the MMIO range.
1494 * @param GCPhysStart First physical address in the range.
1495 * @param cbRange The size of the range (in bytes).
1496 * @param pvUser User argument for the callbacks.
1497 * @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
1498 * @param pfnReadCallback Pointer to function which is gonna handle Read operations.
1499 * @param pfnFillCallback Pointer to function which is gonna handle Fill/memset operations.
1500 * @param pszDesc Pointer to description string. This must not be freed.
1501 */
1502IOMR3DECL(int) IOMR3MMIORegisterGC(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
1503 GCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback, GCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
1504 GCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc)
1505{
1506 LogFlow(("IOMR3MMIORegisterGC: pDevIns=%p GCPhysStart=%VGp cbRange=%#x pvUser=%VGv pfnWriteCallback=%#x pfnReadCallback=%#x pfnFillCallback=%#x pszDesc=%s\n",
1507 pDevIns, GCPhysStart, cbRange, pvUser, pfnWriteCallback, pfnReadCallback, pfnFillCallback, pszDesc));
1508
1509 /*
1510 * Validate input.
1511 */
1512 if (!pfnWriteCallback && !pfnReadCallback)
1513 {
1514 AssertMsgFailed(("No callbacks! %VGp LB%#x %s\n", GCPhysStart, cbRange, pszDesc));
1515 return VERR_INVALID_PARAMETER;
1516 }
1517 RTGCPHYS GCPhysLast = GCPhysStart + (cbRange - 1);
1518 if (GCPhysLast < GCPhysStart)
1519 {
1520 AssertMsgFailed(("Wrapped! %VGp LB%#x %s\n", GCPhysStart, cbRange, pszDesc));
1521 return VERR_IOM_INVALID_MMIO_RANGE;
1522 }
1523
1524 /*
1525 * Check that a ring-3 MMIO range exists.
1526 */
1527 RTGCPHYS GCPhys = GCPhysStart;
1528 while (GCPhys <= GCPhysLast && GCPhys >= GCPhysStart)
1529 {
1530 PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->MMIOTreeR3, GCPhys);
1531 if (!pRange)
1532 {
1533 AssertMsgFailed(("No R3 range! GCPhys=%VGp %VGp LB%#x %s\n", GCPhys, GCPhysStart, cbRange, pszDesc));
1534 return VERR_IOM_NO_HC_MMIO_RANGE;
1535 }
1536#ifndef IOM_NO_PDMINS_CHECKS
1537# ifndef IN_GC
1538 if (pRange->pDevIns != pDevIns)
1539# else
1540 if (pRange->pDevIns != MMHyperGC2HC(pVM, pDevIns))
1541# endif
1542 {
1543 AssertMsgFailed(("Not owner! GCPhys=%VGp %VGp LB%#x %s / %#x-%#x %s\n", GCPhys, GCPhysStart, cbRange, pszDesc,
1544 pRange->Core.Key, pRange->Core.KeyLast, MMHyper2HC(pVM, (uintptr_t)pRange->pszDesc)));
1545 return VERR_IOM_NOT_MMIO_RANGE_OWNER;
1546 }
1547#endif /* !IOM_NO_PDMINS_CHECKS */
1548 /* next */
1549 Assert(GCPhys <= pRange->Core.KeyLast);
1550 GCPhys = pRange->Core.KeyLast + 1;
1551 }
1552
1553
1554 /*
1555 * Allocate new range record and initialize it.
1556 */
1557 PIOMMMIORANGEGC pRange;
1558 int rc = MMHyperAlloc(pVM, sizeof(*pRange), 0, MM_TAG_IOM, (void **)&pRange);
1559 if (VBOX_SUCCESS(rc))
1560 {
1561 pRange->Core.Key = GCPhysStart;
1562 pRange->Core.KeyLast = GCPhysStart + (cbRange - 1);
1563 pRange->GCPhys = GCPhysStart;
1564 pRange->cb = cbRange;
1565 pRange->pvUser = pvUser;
1566 pRange->pfnReadCallback = pfnReadCallback;
1567 pRange->pfnWriteCallback= pfnWriteCallback;
1568 pRange->pfnFillCallback = pfnFillCallback;
1569#ifdef IN_GC
1570 pRange->pDevIns = pDevIns;
1571 pRange->pszDesc = MMHyperGC2HC(pVM, (void *)pszDesc);
1572#else
1573 pRange->pDevIns = MMHyperHC2GC(pVM, pDevIns);
1574 pRange->pszDesc = pszDesc;
1575#endif
1576
1577 /*
1578 * Try insert it.
1579 */
1580 if (RTAvlroGCPhysInsert(&pVM->iom.s.CTXSUFF(pTrees)->MMIOTreeGC, &pRange->Core))
1581 return VINF_SUCCESS;
1582
1583 AssertMsgFailed(("Conflict! %VGp LB%#x %s\n", GCPhysStart, cbRange, pszDesc));
1584 MMHyperFree(pVM, pRange);
1585 rc = VERR_IOM_MMIO_RANGE_CONFLICT;
1586 }
1587
1588 return rc;
1589}
1590
1591
1592/**
1593 * Registers a Memory Mapped I/O R0 handler range.
1594 *
1595 * This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
1596 * using IOMMR3MIORegisterHC() before calling this function.
1597 *
1598 *
1599 * @returns VBox status code.
1600 *
1601 * @param pVM VM handle.
1602 * @param pDevIns PDM device instance owning the MMIO range.
1603 * @param GCPhysStart First physical address in the range.
1604 * @param cbRange The size of the range (in bytes).
1605 * @param pvUser User argument for the callbacks.
1606 * @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
1607 * @param pfnReadCallback Pointer to function which is gonna handle Read operations.
1608 * @param pfnFillCallback Pointer to function which is gonna handle Fill/memset operations.
1609 * @param pszDesc Pointer to description string. This must not be freed.
1610 */
1611IOMR3DECL(int) IOMR3MMIORegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
1612 R0PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback, R0PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
1613 R0PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc)
1614{
1615 LogFlow(("IOMR3MMIORegisterR0: pDevIns=%p GCPhysStart=%VGp cbRange=%#x pvUser=%VHv pfnWriteCallback=%#x pfnReadCallback=%#x pfnFillCallback=%#x pszDesc=%s\n",
1616 pDevIns, GCPhysStart, cbRange, pvUser, pfnWriteCallback, pfnReadCallback, pfnFillCallback, pszDesc));
1617
1618 /*
1619 * Validate input.
1620 */
1621 if (!pfnWriteCallback && !pfnReadCallback)
1622 {
1623 AssertMsgFailed(("No callbacks! %VGp LB%#x %s\n", GCPhysStart, cbRange, pszDesc));
1624 return VERR_INVALID_PARAMETER;
1625 }
1626 RTGCPHYS GCPhysLast = GCPhysStart + (cbRange - 1);
1627 if (GCPhysLast < GCPhysStart)
1628 {
1629 AssertMsgFailed(("Wrapped! %VGp LB%#x %s\n", GCPhysStart, cbRange, pszDesc));
1630 return VERR_IOM_INVALID_MMIO_RANGE;
1631 }
1632
1633 /*
1634 * Check that a ring-3 MMIO range exists.
1635 */
1636 RTGCPHYS GCPhys = GCPhysStart;
1637 while (GCPhys <= GCPhysLast && GCPhys >= GCPhysStart)
1638 {
1639 PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)RTAvlroGCPhysRangeGet(&pVM->iom.s.CTXSUFF(pTrees)->MMIOTreeR3, GCPhys);
1640 if (!pRange)
1641 {
1642 AssertMsgFailed(("No R3 range! GCPhys=%VGp %VGp LB%#x %s\n", GCPhys, GCPhysStart, cbRange, pszDesc));
1643 return VERR_IOM_NO_HC_MMIO_RANGE;
1644 }
1645#ifndef IOM_NO_PDMINS_CHECKS
1646# ifndef IN_GC
1647 if (pRange->pDevIns != pDevIns)
1648# else
1649 if (pRange->pDevIns != MMHyperGC2HC(pVM, pDevIns))
1650# endif
1651 {
1652 AssertMsgFailed(("Not owner! GCPhys=%VGp %VGp LB%#x %s / %#x-%#x %s\n", GCPhys, GCPhysStart, cbRange, pszDesc,
1653 pRange->Core.Key, pRange->Core.KeyLast, MMHyper2HC(pVM, (uintptr_t)pRange->pszDesc)));
1654 return VERR_IOM_NOT_MMIO_RANGE_OWNER;
1655 }
1656#endif /* !IOM_NO_PDMINS_CHECKS */
1657 /* next */
1658 Assert(GCPhys <= pRange->Core.KeyLast);
1659 GCPhys = pRange->Core.KeyLast + 1;
1660 }
1661
1662
1663 /*
1664 * Allocate new range record and initialize it.
1665 */
1666 PIOMMMIORANGER0 pRange;
1667 int rc = MMHyperAlloc(pVM, sizeof(*pRange), 0, MM_TAG_IOM, (void **)&pRange);
1668 if (VBOX_SUCCESS(rc))
1669 {
1670 pRange->Core.Key = GCPhysStart;
1671 pRange->Core.KeyLast = GCPhysStart + (cbRange - 1);
1672 pRange->GCPhys = GCPhysStart;
1673 pRange->cb = cbRange;
1674 pRange->pvUser = pvUser;
1675 pRange->pfnReadCallback = pfnReadCallback;
1676 pRange->pfnWriteCallback= pfnWriteCallback;
1677 pRange->pfnFillCallback = pfnFillCallback;
1678#ifdef IN_GC
1679 pRange->pDevIns = MMHyperGCToR0(pVM, pDevIns);
1680 pRange->pszDesc = MMHyperGCToR3(pVM, (void *)pszDesc);
1681#elif defined(IN_RING3)
1682 pRange->pDevIns = MMHyperR3ToR0(pVM, pDevIns);
1683 pRange->pszDesc = pszDesc;
1684#else
1685 pRange->pDevIns = pDevIns;
1686 pRange->pszDesc = MMHyperR0ToR3(pVM, (RTR0PTR)pszDesc);
1687#endif
1688
1689 /*
1690 * Try insert it.
1691 */
1692 if (RTAvlroGCPhysInsert(&pVM->iom.s.CTXSUFF(pTrees)->MMIOTreeR0, &pRange->Core))
1693 return VINF_SUCCESS;
1694
1695 AssertMsgFailed(("Conflict! %VGp LB%#x %s\n", GCPhysStart, cbRange, pszDesc));
1696 MMHyperFree(pVM, pRange);
1697 rc = VERR_IOM_MMIO_RANGE_CONFLICT;
1698 }
1699
1700 return rc;
1701}
1702
1703
1704/**
1705 * Deregisters a Memory Mapped I/O handler range.
1706 *
1707 * Registered GC, R0, and R3 ranges are affected.
1708 *
1709 * @returns VBox status code.
1710 *
1711 * @param pVM The virtual machine.
1712 * @param pDevIns Device instance which the MMIO region is registered.
1713 * @param GCPhysStart First physical address (GC) in the range.
1714 * @param cbRange Number of bytes to deregister.
1715 *
1716 * @remark This function mainly for PCI PnP Config and will not do
1717 * all the checks you might expect it to do.
1718 */
1719IOMR3DECL(int) IOMR3MMIODeregister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange)
1720{
1721 LogFlow(("IOMR3MMIODeregister: pDevIns=%p GCPhysStart=%VGp cbRange=%#x\n", pDevIns, GCPhysStart, cbRange));
1722
1723 /*
1724 * Validate input.
1725 */
1726 RTGCPHYS GCPhysLast = GCPhysStart + (cbRange - 1);
1727 if (GCPhysLast < GCPhysStart)
1728 {
1729 AssertMsgFailed(("Wrapped! %#x LB%#x\n", GCPhysStart, cbRange));
1730 return VERR_IOM_INVALID_MMIO_RANGE;
1731 }
1732
1733 /*
1734 * Check ownership and such.
1735 */
1736 RTGCPHYS GCPhys = GCPhysStart;
1737 while (GCPhys <= GCPhysLast && GCPhys >= GCPhysStart)
1738 {
1739 PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)RTAvlroGCPhysGet(&pVM->iom.s.pTreesHC->MMIOTreeR3, GCPhys);
1740 if (!pRange)
1741 return VERR_IOM_MMIO_RANGE_NOT_FOUND;
1742#ifndef IOM_NO_PDMINS_CHECKS
1743 if (pRange->pDevIns != pDevIns)
1744 {
1745 AssertMsgFailed(("Not owner! GCPhys=%VGp %VGp LB%#x %s\n", GCPhys, GCPhysStart, cbRange, pRange->pszDesc));
1746 return VERR_IOM_NOT_MMIO_RANGE_OWNER;
1747 }
1748#endif /* !IOM_NO_PDMINS_CHECKS */
1749 if (pRange->Core.KeyLast > GCPhysLast)
1750 {
1751 AssertMsgFailed(("Incomplete R3 range! GCPhys=%VGp %VGp LB%#x %s\n", GCPhys, GCPhysStart, cbRange, pRange->pszDesc));
1752 return VERR_IOM_INCOMPLETE_MMIO_RANGE;
1753 }
1754 /* next */
1755 Assert(GCPhys <= pRange->Core.KeyLast);
1756 GCPhys = pRange->Core.KeyLast + 1;
1757 }
1758
1759 /*
1760 * Remove GC ranges.
1761 */
1762 GCPhys = GCPhysStart;
1763 while (GCPhys <= GCPhysLast && GCPhys >= GCPhysStart)
1764 {
1765 PIOMMMIORANGEGC pRange = (PIOMMMIORANGEGC)RTAvlroGCPhysRemove(&pVM->iom.s.pTreesHC->MMIOTreeGC, GCPhys);
1766 if (pRange)
1767 {
1768 Assert(pRange->Core.Key == GCPhys && pRange->Core.KeyLast <= GCPhysLast);
1769
1770 /* next and delete. */
1771 GCPhys = pRange->Core.KeyLast + 1;
1772 MMHyperFree(pVM, pRange);
1773 }
1774 else /* next - this'll be damned slow! */
1775 GCPhys++;
1776 }
1777
1778 /*
1779 * Remove R0 ranges.
1780 */
1781 GCPhys = GCPhysStart;
1782 while (GCPhys <= GCPhysLast && GCPhys >= GCPhysStart)
1783 {
1784 PIOMMMIORANGER0 pRange = (PIOMMMIORANGER0)RTAvlroGCPhysRemove(&pVM->iom.s.pTreesHC->MMIOTreeR0, GCPhys);
1785 if (pRange)
1786 {
1787 Assert(pRange->Core.Key == GCPhys && pRange->Core.KeyLast <= GCPhysLast);
1788
1789 /* next and delete. */
1790 GCPhys = pRange->Core.KeyLast + 1;
1791 MMHyperFree(pVM, pRange);
1792 }
1793 else /* next - this'll be damned slow! */
1794 GCPhys++;
1795 }
1796
1797 /*
1798 * Remove R3 ranges.
1799 */
1800 GCPhys = GCPhysStart;
1801 while (GCPhys <= GCPhysLast && GCPhys >= GCPhysStart)
1802 {
1803 PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)RTAvlroGCPhysRemove(&pVM->iom.s.pTreesHC->MMIOTreeR3, GCPhys);
1804 Assert(pRange);
1805 Assert(pRange->Core.Key == GCPhys && pRange->Core.KeyLast <= GCPhysLast);
1806
1807 /* remove it from PGM */
1808 int rc = PGMR3PhysMMIODeregister(pVM, GCPhys, pRange->cb);
1809 AssertRC(rc);
1810
1811 /* next and delete. */
1812 GCPhys = pRange->Core.KeyLast + 1;
1813 MMHyperFree(pVM, pRange);
1814 }
1815
1816 return VINF_SUCCESS;
1817}
1818
1819
1820/**
1821 * Display a single MMIO R3 range.
1822 *
1823 * @returns 0
1824 * @param pNode Pointer to MMIO R3 range.
1825 * @param pvUser Pointer to info output callback structure.
1826 */
1827static DECLCALLBACK(int) iomR3MMIOInfoOneR3(PAVLROGCPHYSNODECORE pNode, void *pvUser)
1828{
1829 PIOMMMIORANGER3 pRange = (PIOMMMIORANGER3)pNode;
1830 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
1831 pHlp->pfnPrintf(pHlp,
1832 "%VGp-%VGp %VHv %VHv %VHv %VHv %VHv %s\n",
1833 pRange->Core.Key,
1834 pRange->Core.KeyLast,
1835 pRange->pDevIns,
1836 pRange->pfnReadCallback,
1837 pRange->pfnWriteCallback,
1838 pRange->pfnFillCallback,
1839 pRange->pvUser,
1840 pRange->pszDesc);
1841 return 0;
1842}
1843
1844
1845/**
1846 * Display a single MMIO GC range.
1847 *
1848 * @returns 0
1849 * @param pNode Pointer to MMIO GC range.
1850 * @param pvUser Pointer to info output callback structure.
1851 */
1852static DECLCALLBACK(int) iomR3MMIOInfoOneGC(PAVLROGCPHYSNODECORE pNode, void *pvUser)
1853{
1854 PIOMMMIORANGEGC pRange = (PIOMMMIORANGEGC)pNode;
1855 PCDBGFINFOHLP pHlp = (PCDBGFINFOHLP)pvUser;
1856 pHlp->pfnPrintf(pHlp,
1857 "%VGp-%VGp %VGv %VGv %VGv %VGv %VGv %s\n",
1858 pRange->Core.Key,
1859 pRange->Core.KeyLast,
1860 pRange->pDevIns,
1861 pRange->pfnReadCallback,
1862 pRange->pfnWriteCallback,
1863 pRange->pfnFillCallback,
1864 pRange->pvUser,
1865 pRange->pszDesc);
1866 return 0;
1867}
1868
1869
1870/**
1871 * Display registered MMIO ranges to the log.
1872 *
1873 * @param pVM VM Handle.
1874 * @param pHlp The info helpers.
1875 * @param pszArgs Arguments, ignored.
1876 */
1877static DECLCALLBACK(void) iomR3MMIOInfo(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1878{
1879 NOREF(pszArgs);
1880 pHlp->pfnPrintf(pHlp,
1881 "MMIO R3 ranges (pVM=%p)\n"
1882 "%.*s %.*s %.*s %.*s %.*s %.*s %s\n",
1883 pVM,
1884 sizeof(RTGCPHYS) * 4 + 1, "GC Phys Range ",
1885 sizeof(RTHCPTR) * 2, "pDevIns ",
1886 sizeof(RTHCPTR) * 2, "Read ",
1887 sizeof(RTHCPTR) * 2, "Write ",
1888 sizeof(RTHCPTR) * 2, "Fill ",
1889 sizeof(RTHCPTR) * 2, "pvUser ",
1890 "Description");
1891 RTAvlroGCPhysDoWithAll(&pVM->iom.s.pTreesHC->MMIOTreeR3, true, iomR3MMIOInfoOneR3, (void *)pHlp);
1892
1893 pHlp->pfnPrintf(pHlp,
1894 "MMIO R0 ranges (pVM=%p)\n"
1895 "%.*s %.*s %.*s %.*s %.*s %.*s %s\n",
1896 pVM,
1897 sizeof(RTGCPHYS) * 4 + 1, "GC Phys Range ",
1898 sizeof(RTGCPTR) * 2, "pDevIns ",
1899 sizeof(RTGCPTR) * 2, "Read ",
1900 sizeof(RTGCPTR) * 2, "Write ",
1901 sizeof(RTGCPTR) * 2, "Fill ",
1902 sizeof(RTGCPTR) * 2, "pvUser ",
1903 "Description");
1904 RTAvlroGCPhysDoWithAll(&pVM->iom.s.pTreesHC->MMIOTreeR0, true, iomR3MMIOInfoOneR3, (void *)pHlp);
1905
1906 pHlp->pfnPrintf(pHlp,
1907 "MMIO GC ranges (pVM=%p)\n"
1908 "%.*s %.*s %.*s %.*s %.*s %.*s %s\n",
1909 pVM,
1910 sizeof(RTGCPHYS) * 4 + 1, "GC Phys Range ",
1911 sizeof(RTGCPTR) * 2, "pDevIns ",
1912 sizeof(RTGCPTR) * 2, "Read ",
1913 sizeof(RTGCPTR) * 2, "Write ",
1914 sizeof(RTGCPTR) * 2, "Fill ",
1915 sizeof(RTGCPTR) * 2, "pvUser ",
1916 "Description");
1917 RTAvlroGCPhysDoWithAll(&pVM->iom.s.pTreesHC->MMIOTreeGC, true, iomR3MMIOInfoOneGC, (void *)pHlp);
1918}
1919
1920
1921#ifdef VBOX_WITH_STATISTICS
1922/**
1923 * Tries to come up with the standard name for a port.
1924 *
1925 * @returns Pointer to readonly string if known.
1926 * @returns NULL if unknown port number.
1927 *
1928 * @param Port The port to name.
1929 */
1930static const char *iomr3IOPortGetStandardName(RTIOPORT Port)
1931{
1932 switch (Port)
1933 {
1934 case 0x00: case 0x10: case 0x20: case 0x30: case 0x40: case 0x50: case 0x70:
1935 case 0x01: case 0x11: case 0x21: case 0x31: case 0x41: case 0x51: case 0x61: case 0x71:
1936 case 0x02: case 0x12: case 0x22: case 0x32: case 0x42: case 0x52: case 0x62: case 0x72:
1937 case 0x03: case 0x13: case 0x23: case 0x33: case 0x43: case 0x53: case 0x63: case 0x73:
1938 case 0x04: case 0x14: case 0x24: case 0x34: case 0x44: case 0x54: case 0x74:
1939 case 0x05: case 0x15: case 0x25: case 0x35: case 0x45: case 0x55: case 0x65: case 0x75:
1940 case 0x06: case 0x16: case 0x26: case 0x36: case 0x46: case 0x56: case 0x66: case 0x76:
1941 case 0x07: case 0x17: case 0x27: case 0x37: case 0x47: case 0x57: case 0x67: case 0x77:
1942 case 0x08: case 0x18: case 0x28: case 0x38: case 0x48: case 0x58: case 0x68: case 0x78:
1943 case 0x09: case 0x19: case 0x29: case 0x39: case 0x49: case 0x59: case 0x69: case 0x79:
1944 case 0x0a: case 0x1a: case 0x2a: case 0x3a: case 0x4a: case 0x5a: case 0x6a: case 0x7a:
1945 case 0x0b: case 0x1b: case 0x2b: case 0x3b: case 0x4b: case 0x5b: case 0x6b: case 0x7b:
1946 case 0x0c: case 0x1c: case 0x2c: case 0x3c: case 0x4c: case 0x5c: case 0x6c: case 0x7c:
1947 case 0x0d: case 0x1d: case 0x2d: case 0x3d: case 0x4d: case 0x5d: case 0x6d: case 0x7d:
1948 case 0x0e: case 0x1e: case 0x2e: case 0x3e: case 0x4e: case 0x5e: case 0x6e: case 0x7e:
1949 case 0x0f: case 0x1f: case 0x2f: case 0x3f: case 0x4f: case 0x5f: case 0x6f: case 0x7f:
1950
1951 case 0x80: case 0x90: case 0xa0: case 0xb0: case 0xc0: case 0xd0: case 0xe0: case 0xf0:
1952 case 0x81: case 0x91: case 0xa1: case 0xb1: case 0xc1: case 0xd1: case 0xe1: case 0xf1:
1953 case 0x82: case 0x92: case 0xa2: case 0xb2: case 0xc2: case 0xd2: case 0xe2: case 0xf2:
1954 case 0x83: case 0x93: case 0xa3: case 0xb3: case 0xc3: case 0xd3: case 0xe3: case 0xf3:
1955 case 0x84: case 0x94: case 0xa4: case 0xb4: case 0xc4: case 0xd4: case 0xe4: case 0xf4:
1956 case 0x85: case 0x95: case 0xa5: case 0xb5: case 0xc5: case 0xd5: case 0xe5: case 0xf5:
1957 case 0x86: case 0x96: case 0xa6: case 0xb6: case 0xc6: case 0xd6: case 0xe6: case 0xf6:
1958 case 0x87: case 0x97: case 0xa7: case 0xb7: case 0xc7: case 0xd7: case 0xe7: case 0xf7:
1959 case 0x88: case 0x98: case 0xa8: case 0xb8: case 0xc8: case 0xd8: case 0xe8: case 0xf8:
1960 case 0x89: case 0x99: case 0xa9: case 0xb9: case 0xc9: case 0xd9: case 0xe9: case 0xf9:
1961 case 0x8a: case 0x9a: case 0xaa: case 0xba: case 0xca: case 0xda: case 0xea: case 0xfa:
1962 case 0x8b: case 0x9b: case 0xab: case 0xbb: case 0xcb: case 0xdb: case 0xeb: case 0xfb:
1963 case 0x8c: case 0x9c: case 0xac: case 0xbc: case 0xcc: case 0xdc: case 0xec: case 0xfc:
1964 case 0x8d: case 0x9d: case 0xad: case 0xbd: case 0xcd: case 0xdd: case 0xed: case 0xfd:
1965 case 0x8e: case 0x9e: case 0xae: case 0xbe: case 0xce: case 0xde: case 0xee: case 0xfe:
1966 case 0x8f: case 0x9f: case 0xaf: case 0xbf: case 0xcf: case 0xdf: case 0xef: case 0xff:
1967 return "System Reserved";
1968
1969 case 0x60:
1970 case 0x64:
1971 return "Keyboard & Mouse";
1972
1973 case 0x378:
1974 case 0x379:
1975 case 0x37a:
1976 case 0x37b:
1977 case 0x37c:
1978 case 0x37d:
1979 case 0x37e:
1980 case 0x37f:
1981 case 0x3bc:
1982 case 0x3bd:
1983 case 0x3be:
1984 case 0x3bf:
1985 case 0x278:
1986 case 0x279:
1987 case 0x27a:
1988 case 0x27b:
1989 case 0x27c:
1990 case 0x27d:
1991 case 0x27e:
1992 case 0x27f:
1993 return "LPT1/2/3";
1994
1995 case 0x3f8:
1996 case 0x3f9:
1997 case 0x3fa:
1998 case 0x3fb:
1999 case 0x3fc:
2000 case 0x3fd:
2001 case 0x3fe:
2002 case 0x3ff:
2003 return "COM1";
2004
2005 case 0x2f8:
2006 case 0x2f9:
2007 case 0x2fa:
2008 case 0x2fb:
2009 case 0x2fc:
2010 case 0x2fd:
2011 case 0x2fe:
2012 case 0x2ff:
2013 return "COM2";
2014
2015 case 0x3e8:
2016 case 0x3e9:
2017 case 0x3ea:
2018 case 0x3eb:
2019 case 0x3ec:
2020 case 0x3ed:
2021 case 0x3ee:
2022 case 0x3ef:
2023 return "COM3";
2024
2025 case 0x2e8:
2026 case 0x2e9:
2027 case 0x2ea:
2028 case 0x2eb:
2029 case 0x2ec:
2030 case 0x2ed:
2031 case 0x2ee:
2032 case 0x2ef:
2033 return "COM4";
2034
2035 case 0x200:
2036 case 0x201:
2037 case 0x202:
2038 case 0x203:
2039 case 0x204:
2040 case 0x205:
2041 case 0x206:
2042 case 0x207:
2043 return "Joystick";
2044
2045 case 0x3f0:
2046 case 0x3f1:
2047 case 0x3f2:
2048 case 0x3f3:
2049 case 0x3f4:
2050 case 0x3f5:
2051 case 0x3f6:
2052 case 0x3f7:
2053 return "Floppy";
2054
2055 case 0x1f0:
2056 case 0x1f1:
2057 case 0x1f2:
2058 case 0x1f3:
2059 case 0x1f4:
2060 case 0x1f5:
2061 case 0x1f6:
2062 case 0x1f7:
2063 //case 0x3f6:
2064 //case 0x3f7:
2065 return "IDE 1st";
2066
2067 case 0x170:
2068 case 0x171:
2069 case 0x172:
2070 case 0x173:
2071 case 0x174:
2072 case 0x175:
2073 case 0x176:
2074 case 0x177:
2075 case 0x376:
2076 case 0x377:
2077 return "IDE 2nd";
2078
2079 case 0x1e0:
2080 case 0x1e1:
2081 case 0x1e2:
2082 case 0x1e3:
2083 case 0x1e4:
2084 case 0x1e5:
2085 case 0x1e6:
2086 case 0x1e7:
2087 case 0x3e6:
2088 case 0x3e7:
2089 return "IDE 3rd";
2090
2091 case 0x160:
2092 case 0x161:
2093 case 0x162:
2094 case 0x163:
2095 case 0x164:
2096 case 0x165:
2097 case 0x166:
2098 case 0x167:
2099 case 0x366:
2100 case 0x367:
2101 return "IDE 4th";
2102
2103 case 0x130: case 0x140: case 0x150:
2104 case 0x131: case 0x141: case 0x151:
2105 case 0x132: case 0x142: case 0x152:
2106 case 0x133: case 0x143: case 0x153:
2107 case 0x134: case 0x144: case 0x154:
2108 case 0x135: case 0x145: case 0x155:
2109 case 0x136: case 0x146: case 0x156:
2110 case 0x137: case 0x147: case 0x157:
2111 case 0x138: case 0x148: case 0x158:
2112 case 0x139: case 0x149: case 0x159:
2113 case 0x13a: case 0x14a: case 0x15a:
2114 case 0x13b: case 0x14b: case 0x15b:
2115 case 0x13c: case 0x14c: case 0x15c:
2116 case 0x13d: case 0x14d: case 0x15d:
2117 case 0x13e: case 0x14e: case 0x15e:
2118 case 0x13f: case 0x14f: case 0x15f:
2119 case 0x220: case 0x230:
2120 case 0x221: case 0x231:
2121 case 0x222: case 0x232:
2122 case 0x223: case 0x233:
2123 case 0x224: case 0x234:
2124 case 0x225: case 0x235:
2125 case 0x226: case 0x236:
2126 case 0x227: case 0x237:
2127 case 0x228: case 0x238:
2128 case 0x229: case 0x239:
2129 case 0x22a: case 0x23a:
2130 case 0x22b: case 0x23b:
2131 case 0x22c: case 0x23c:
2132 case 0x22d: case 0x23d:
2133 case 0x22e: case 0x23e:
2134 case 0x22f: case 0x23f:
2135 case 0x330: case 0x340: case 0x350:
2136 case 0x331: case 0x341: case 0x351:
2137 case 0x332: case 0x342: case 0x352:
2138 case 0x333: case 0x343: case 0x353:
2139 case 0x334: case 0x344: case 0x354:
2140 case 0x335: case 0x345: case 0x355:
2141 case 0x336: case 0x346: case 0x356:
2142 case 0x337: case 0x347: case 0x357:
2143 case 0x338: case 0x348: case 0x358:
2144 case 0x339: case 0x349: case 0x359:
2145 case 0x33a: case 0x34a: case 0x35a:
2146 case 0x33b: case 0x34b: case 0x35b:
2147 case 0x33c: case 0x34c: case 0x35c:
2148 case 0x33d: case 0x34d: case 0x35d:
2149 case 0x33e: case 0x34e: case 0x35e:
2150 case 0x33f: case 0x34f: case 0x35f:
2151 return "SCSI (typically)";
2152
2153 case 0x320:
2154 case 0x321:
2155 case 0x322:
2156 case 0x323:
2157 case 0x324:
2158 case 0x325:
2159 case 0x326:
2160 case 0x327:
2161 return "XT HD";
2162
2163 case 0x3b0:
2164 case 0x3b1:
2165 case 0x3b2:
2166 case 0x3b3:
2167 case 0x3b4:
2168 case 0x3b5:
2169 case 0x3b6:
2170 case 0x3b7:
2171 case 0x3b8:
2172 case 0x3b9:
2173 case 0x3ba:
2174 case 0x3bb:
2175 return "VGA";
2176
2177 case 0x3c0: case 0x3d0:
2178 case 0x3c1: case 0x3d1:
2179 case 0x3c2: case 0x3d2:
2180 case 0x3c3: case 0x3d3:
2181 case 0x3c4: case 0x3d4:
2182 case 0x3c5: case 0x3d5:
2183 case 0x3c6: case 0x3d6:
2184 case 0x3c7: case 0x3d7:
2185 case 0x3c8: case 0x3d8:
2186 case 0x3c9: case 0x3d9:
2187 case 0x3ca: case 0x3da:
2188 case 0x3cb: case 0x3db:
2189 case 0x3cc: case 0x3dc:
2190 case 0x3cd: case 0x3dd:
2191 case 0x3ce: case 0x3de:
2192 case 0x3cf: case 0x3df:
2193 return "VGA/EGA";
2194
2195 case 0x240: case 0x260: case 0x280:
2196 case 0x241: case 0x261: case 0x281:
2197 case 0x242: case 0x262: case 0x282:
2198 case 0x243: case 0x263: case 0x283:
2199 case 0x244: case 0x264: case 0x284:
2200 case 0x245: case 0x265: case 0x285:
2201 case 0x246: case 0x266: case 0x286:
2202 case 0x247: case 0x267: case 0x287:
2203 case 0x248: case 0x268: case 0x288:
2204 case 0x249: case 0x269: case 0x289:
2205 case 0x24a: case 0x26a: case 0x28a:
2206 case 0x24b: case 0x26b: case 0x28b:
2207 case 0x24c: case 0x26c: case 0x28c:
2208 case 0x24d: case 0x26d: case 0x28d:
2209 case 0x24e: case 0x26e: case 0x28e:
2210 case 0x24f: case 0x26f: case 0x28f:
2211 case 0x300:
2212 case 0x301:
2213 case 0x388:
2214 case 0x389:
2215 case 0x38a:
2216 case 0x38b:
2217 return "Sound Card (typically)";
2218
2219 default:
2220 return NULL;
2221 }
2222}
2223#endif /* VBOX_WITH_STATISTICS */
2224
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