VirtualBox

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

Last change on this file since 10377 was 9776, checked in by vboxsync, 16 years ago

Stat updates

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette