VirtualBox

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

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

fix debug builds

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