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