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