VirtualBox

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

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

MMHyperR3ToGC

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

© 2023 Oracle
ContactPrivacy policyTerms of Use