VirtualBox

source: vbox/trunk/include/VBox/iom.h@ 2135

Last change on this file since 2135 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 KB
Line 
1/** @file
2 * IOM - Input / Output Monitor.
3 */
4
5/*
6 * Copyright (C) 2006 InnoTek Systemberatung GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * If you received this file as part of a commercial VirtualBox
17 * distribution, then only the terms of your commercial VirtualBox
18 * license agreement apply instead of the previous paragraph.
19 */
20
21#ifndef __VBox_iom_h__
22#define __VBox_iom_h__
23
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <VBox/cpum.h>
28#include <VBox/dis.h>
29
30__BEGIN_DECLS
31
32
33/** @defgroup grp_iom The Input / Ouput Monitor API
34 * @{
35 */
36
37/** @def IOM_NO_PDMINS_CHECKS
38 * Untill all devices have been fully adjusted to PDM style, the pPdmIns parameter
39 * is not checked by IOM.
40 */
41#define IOM_NO_PDMINS_CHECKS
42
43
44/**
45 * Port I/O Handler for IN operations.
46 *
47 * @returns VINF_SUCCESS or VINF_EM_*.
48 * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
49 *
50 * @param pDevIns The device instance.
51 * @param pvUser User argument.
52 * @param uPort Port number used for the IN operation.
53 * @param pu32 Where to store the result.
54 * @param cb Number of bytes read.
55 */
56typedef DECLCALLBACK(int) FNIOMIOPORTIN(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
57/** Pointer to a FNIOMIOPORTIN(). */
58typedef FNIOMIOPORTIN *PFNIOMIOPORTIN;
59
60/**
61 * Port I/O Handler for string IN operations.
62 *
63 * @returns VINF_SUCCESS or VINF_EM_*.
64 * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
65 *
66 * @param pDevIns The device instance.
67 * @param pvUser User argument.
68 * @param uPort Port number used for the IN operation.
69 * @param pGCPtrDst Pointer to the destination buffer (GC, incremented appropriately).
70 * @param pcTransfers Pointer to the number of transfer units to read, on return remaining transfer units.
71 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
72 */
73typedef DECLCALLBACK(int) FNIOMIOPORTINSTRING(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, unsigned *pcTransfers, unsigned cb);
74/** Pointer to a FNIOMIOPORTINSTRING(). */
75typedef FNIOMIOPORTINSTRING *PFNIOMIOPORTINSTRING;
76
77/**
78 * Port I/O Handler for OUT operations.
79 *
80 * @returns VINF_SUCCESS or VINF_EM_*.
81 *
82 * @param pDevIns The device instance.
83 * @param pvUser User argument.
84 * @param uPort Port number used for the OUT operation.
85 * @param u32 The value to output.
86 * @param cb The value size in bytes.
87 */
88typedef DECLCALLBACK(int) FNIOMIOPORTOUT(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
89/** Pointer to a FNIOMIOPORTOUT(). */
90typedef FNIOMIOPORTOUT *PFNIOMIOPORTOUT;
91
92/**
93 * Port I/O Handler for string OUT operations.
94 *
95 * @returns VINF_SUCCESS or VINF_EM_*.
96 *
97 * @param pDevIns The device instance.
98 * @param pvUser User argument.
99 * @param uPort Port number used for the OUT operation.
100 * @param pGCPtrSrc Pointer to the source buffer (GC, incremented appropriately).
101 * @param pcTransfers Pointer to the number of transfer units to write, on return remaining transfer units.
102 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
103 */
104typedef DECLCALLBACK(int) FNIOMIOPORTOUTSTRING(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, unsigned *pcTransfers, unsigned cb);
105/** Pointer to a FNIOMIOPORTOUTSTRING(). */
106typedef FNIOMIOPORTOUTSTRING *PFNIOMIOPORTOUTSTRING;
107
108
109/**
110 * Memory mapped I/O Handler for read operations.
111 *
112 * @returns VBox status code.
113 *
114 * @param pDevIns The device instance.
115 * @param pvUser User argument.
116 * @param GCPhysAddr Physical address (in GC) where the read starts.
117 * @param pv Where to store the result.
118 * @param cb Number of bytes read.
119 *
120 * @remark wonder if we could merge the IOMMMIO* and IOMPORT* callbacks...
121 */
122typedef DECLCALLBACK(int) FNIOMMMIOREAD(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
123/** Pointer to a FNIOMMMIOREAD(). */
124typedef FNIOMMMIOREAD *PFNIOMMMIOREAD;
125
126/**
127 * Port I/O Handler for write operations.
128 *
129 * @returns VBox status code.
130 *
131 * @param pDevIns The device instance.
132 * @param pvUser User argument.
133 * @param GCPhysAddr Physical address (in GC) where the read starts.
134 * @param pv Where to fetch the result.
135 * @param cb Number of bytes to write.
136 *
137 * @remark wonder if we could merge the IOMMMIO* and IOMPORT* callbacks...
138 */
139typedef DECLCALLBACK(int) FNIOMMMIOWRITE(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
140/** Pointer to a FNIOMMMIOWRITE(). */
141typedef FNIOMMMIOWRITE *PFNIOMMMIOWRITE;
142
143/**
144 * Port I/O Handler for memset operations, actually for REP STOS* instructions handling.
145 *
146 * @returns VBox status code.
147 *
148 * @param pDevIns The device instance.
149 * @param pvUser User argument.
150 * @param GCPhysAddr Physical address (in GC) where the write starts.
151 * @param u32Item Byte/Word/Dword data to fill.
152 * @param cbItem Size of data in u32Item parameter, restricted to 1/2/4 bytes.
153 * @param cItems Number of iterations.
154 */
155typedef DECLCALLBACK(int) FNIOMMMIOFILL(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, uint32_t u32Item, unsigned cbItem, unsigned cItems);
156/** Pointer to a FNIOMMMIOFILL(). */
157typedef FNIOMMMIOFILL *PFNIOMMMIOFILL;
158
159
160
161/**
162 * Registers a Port IO GC handler.
163 *
164 * This API is called by PDM on behalf of a device. Devices must first register HC ranges
165 * using IOMR3IOPortRegisterHC() before calling this function.
166 *
167 *
168 * @returns VBox status code.
169 *
170 * @param pVM VM handle.
171 * @param pDevIns PDM device instance owning the port range.
172 * @param PortStart First port number in the range.
173 * @param cPorts Number of ports to register.
174 * @param pvUser User argument for the callbacks.
175 * @param pfnOutCallback Pointer to function which is gonna handle OUT operations in GC.
176 * @param pfnInCallback Pointer to function which is gonna handle IN operations in GC.
177 * @param pfnOutStrCallback Pointer to function which is gonna handle OUT operations in GC.
178 * @param pfnInStrCallback Pointer to function which is gonna handle IN operations in GC.
179 * @param pszDesc Pointer to description string. This must not be freed.
180 */
181IOMDECL(int) IOMIOPortRegisterGC(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTGCPTR pvUser,
182 GCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, GCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
183 GCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, GCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
184 const char *pszDesc);
185
186
187
188/**
189 * Registers a Memory Mapped I/O GC handler range.
190 *
191 * This API is called by PDM on behalf of a device. Devices must first register HC ranges
192 * using IOMMR3MIORegisterHC() before calling this function.
193 *
194 *
195 * @returns VBox status code.
196 *
197 * @param pVM VM handle.
198 * @param pDevIns PDM device instance owning the MMIO range.
199 * @param GCPhysStart First physical address in the range.
200 * @param cbRange The size of the range (in bytes).
201 * @param pvUser User argument for the callbacks.
202 * @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
203 * @param pfnReadCallback Pointer to function which is gonna handle Read operations.
204 * @param pfnFillCallback Pointer to function which is gonna handle Fill/memset operations.
205 * @param pszDesc Pointer to description string. This must not be freed.
206 */
207IOMDECL(int) IOMMMIORegisterGC(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
208 GCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback, GCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
209 GCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc);
210
211
212/**
213 * Registers a Port IO R0 handler.
214 *
215 * This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
216 * using IOMR3IOPortRegisterR3() before calling this function.
217 *
218 *
219 * @returns VBox status code.
220 *
221 * @param pVM VM handle.
222 * @param pDevIns PDM device instance owning the port range.
223 * @param PortStart First port number in the range.
224 * @param cPorts Number of ports to register.
225 * @param pvUser User argument for the callbacks.
226 * @param pfnOutCallback Pointer to function which is gonna handle OUT operations in GC.
227 * @param pfnInCallback Pointer to function which is gonna handle IN operations in GC.
228 * @param pfnOutStrCallback Pointer to function which is gonna handle OUT operations in GC.
229 * @param pfnInStrCallback Pointer to function which is gonna handle IN operations in GC.
230 * @param pszDesc Pointer to description string. This must not be freed.
231 */
232IOMDECL(int) IOMIOPortRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
233 HCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, HCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
234 HCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, HCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
235 const char *pszDesc);
236
237/**
238 * Registers a Memory Mapped I/O R0 handler range.
239 *
240 * This API is called by PDM on behalf of a device. Devices must first register ring-3 ranges
241 * using IOMMR3MIORegisterR3() before calling this function.
242 *
243 *
244 * @returns VBox status code.
245 *
246 * @param pVM VM handle.
247 * @param pDevIns PDM device instance owning the MMIO range.
248 * @param GCPhysStart First physical address in the range.
249 * @param cbRange The size of the range (in bytes).
250 * @param pvUser User argument for the callbacks.
251 * @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
252 * @param pfnReadCallback Pointer to function which is gonna handle Read operations.
253 * @param pfnFillCallback Pointer to function which is gonna handle Fill/memset operations.
254 * @param pszDesc Pointer to description string. This must not be freed.
255 */
256IOMDECL(int) IOMMMIORegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
257 HCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback, HCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
258 HCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc);
259
260
261/**
262 * Reads an I/O port register.
263 *
264 * @returns VBox status code.
265 *
266 * @param pVM VM handle.
267 * @param Port The port to read.
268 * @param pu32Value Where to store the value read.
269 * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
270 */
271IOMDECL(int) IOMIOPortRead(PVM pVM, RTIOPORT Port, uint32_t *pu32Value, size_t cbValue);
272
273/**
274 * Writes to an I/O port register.
275 *
276 * @returns VBox status code.
277 *
278 * @param pVM VM handle.
279 * @param Port The port to write to.
280 * @param u32Value The value to write.
281 * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
282 */
283IOMDECL(int) IOMIOPortWrite(PVM pVM, RTIOPORT Port, uint32_t u32Value, size_t cbValue);
284
285/**
286 * Reads the string buffer of an I/O port register.
287 *
288 * @returns VBox status code.
289 *
290 * @param pVM VM handle.
291 * @param Port The port to read.
292 * @param pGCPtrDst Pointer to the destination buffer (GC, incremented appropriately).
293 * @param pcTransfers Pointer to the number of transfer units to read, on return remaining transfer units.
294 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
295 */
296IOMDECL(int) IOMIOPortReadString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb);
297
298/**
299 * Writes the string buffer of an I/O port register.
300 *
301 * @returns VBox status code.
302 *
303 * @param pVM VM handle.
304 * @param Port The port to write.
305 * @param pGCPtrSrc Pointer to the source buffer (GC, incremented appropriately).
306 * @param pcTransfer Pointer to the number of transfer units to write, on return remaining transfer units.
307 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
308 */
309IOMDECL(int) IOMIOPortWriteString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb);
310
311/**
312 * Flushes the IOM port & statistics lookup cache
313 *
314 * @param pVM The VM.
315 */
316IOMDECL(void) IOMFlushCache(PVM pVM);
317
318/**
319 * Reads a MMIO register.
320 *
321 * @returns VBox status code.
322 *
323 * @param pVM VM handle.
324 * @param GCPhys The physical address to read.
325 * @param pu32Value Where to store the value read.
326 * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
327 */
328IOMDECL(int) IOMMMIORead(PVM pVM, RTGCPHYS GCPhys, uint32_t *pu32Value, size_t cbValue);
329
330/**
331 * Writes to a MMIO register.
332 *
333 * @returns VBox status code.
334 *
335 * @param pVM VM handle.
336 * @param GCPhys The physical address to write to.
337 * @param u32Value The value to write.
338 * @param cbValue The size of the register to read in bytes. 1, 2 or 4 bytes.
339 */
340IOMDECL(int) IOMMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue);
341
342
343/**
344 * Checks that the operation is allowed according to the IOPL
345 * level and I/O bitmap.
346 *
347 * @returns VBox status code.
348 * If not VINF_SUCCESS a \#GP(0) was raised or an error occured.
349 *
350 * @param pVM VM handle.
351 * @param pCtxCore Pointer to register frame.
352 * @param Port The I/O port number.
353 * @param cb The access size.
354 */
355IOMDECL(int) IOMInterpretCheckPortIOAccess(PVM pVM, PCPUMCTXCORE pCtxCore, RTIOPORT Port, unsigned cb);
356
357
358#ifdef IN_GC
359/** @defgroup grp_iom_gc The IOM Guest Context API
360 * @ingroup grp_iom
361 * @{
362 */
363
364/**
365 * Attempts to service an IN/OUT instruction.
366 *
367 * The \#GP trap handler in GC will call this function if the opcode causing the
368 * trap is a in or out type instruction.
369 *
370 * @returns VBox status code.
371 *
372 * @param pVM The virtual machine (GC pointer ofcourse).
373 * @param pRegFrame Pointer to CPUMCTXCORE guest registers structure.
374 * @param pCpu Disassembler CPU state.
375 */
376IOMGCDECL(int) IOMGCIOPortHandler(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
377
378/** @} */
379#endif
380
381
382
383#ifdef IN_RING3
384/** @defgroup grp_iom_r3 The IOM Host Context Ring-3 API
385 * @ingroup grp_iom
386 * @{
387 */
388
389/**
390 * Initializes the IOM.
391 *
392 * @returns VBox status code.
393 * @param pVM The VM to operate on.
394 */
395IOMR3DECL(int) IOMR3Init(PVM pVM);
396
397/**
398 * The VM is being reset.
399 *
400 * @param pVM VM handle.
401 */
402IOMR3DECL(void) IOMR3Reset(PVM pVM);
403
404/**
405 * Applies relocations to data and code managed by this
406 * component. This function will be called at init and
407 * whenever the VMM need to relocate it self inside the GC.
408 *
409 * The IOM will update the addresses used by the switcher.
410 *
411 * @param pVM The VM.
412 * @param offDelta Relocation delta relative to old location.
413 */
414IOMR3DECL(void) IOMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
415
416/**
417 * Terminates the IOM.
418 *
419 * Termination means cleaning up and freeing all resources,
420 * the VM it self is at this point powered off or suspended.
421 *
422 * @returns VBox status code.
423 * @param pVM The VM to operate on.
424 */
425IOMR3DECL(int) IOMR3Term(PVM pVM);
426
427/**
428 * Registers a I/O port R3 handler.
429 *
430 * This API is called by PDM on behalf of a device. Devices must first register
431 * ring-3 ranges before any GC and R0 ranges can be registered using IOMIOPortRegisterGC()
432 * and IOMIOPortRegisterR0().
433 *
434 * @returns VBox status code.
435 *
436 * @param pVM VM handle.
437 * @param pDevIns PDM device instance owning the port range.
438 * @param PortStart First port number in the range.
439 * @param cPorts Number of ports to register.
440 * @param pvUser User argument for the callbacks.
441 * @param pfnOutCallback Pointer to function which is gonna handle OUT operations in R3.
442 * @param pfnInCallback Pointer to function which is gonna handle IN operations in R3.
443 * @param pfnOutStringCallback Pointer to function which is gonna handle string OUT operations in R3.
444 * @param pfnInStringCallback Pointer to function which is gonna handle string IN operations in R3.
445 * @param pszDesc Pointer to description string. This must not be freed.
446 */
447IOMR3DECL(int) IOMR3IOPortRegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
448 HCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, HCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
449 HCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStringCallback, HCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStringCallback,
450 const char *pszDesc);
451
452/**
453 * Registers a Memory Mapped I/O R3 handler.
454 *
455 * This API is called by PDM on behalf of a device. Devices must register ring-3 ranges
456 * before any GC and R0 ranges can be registered using IOMMMIORegisterGC() and IOMMMIORegisterR0().
457 *
458 * @returns VBox status code.
459 *
460 * @param pVM VM handle.
461 * @param pDevIns PDM device instance owning the MMIO range.
462 * @param GCPhysStart First physical address in the range.
463 * @param cbRange The size of the range (in bytes).
464 * @param pvUser User argument for the callbacks.
465 * @param pfnWriteCallback Pointer to function which is gonna handle Write operations.
466 * @param pfnReadCallback Pointer to function which is gonna handle Read operations.
467 * @param pfnFillCallback Pointer to function which is gonna handle Fill/memset operations.
468 * @param pszDesc Pointer to description string. This must not be freed.
469 */
470IOMR3DECL(int) IOMR3MMIORegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
471 HCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback, HCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
472 HCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc);
473
474
475
476/**
477 * Deregisters a I/O Port range.
478 *
479 * The specified range must be registered using IOMR3IOPortRegister previous to
480 * this call. The range does can be a smaller part of the range specified to
481 * IOMR3IOPortRegister, but it can never be larger.
482 *
483 * This function will remove GC, R0 and R3 context port handlers for this range.
484 *
485 * @returns VBox status code.
486 *
487 * @param pVM The virtual machine.
488 * @param pDevIns The device instance associated with the range.
489 * @param PortStart First port number in the range.
490 * @param cPorts Number of ports to remove starting at PortStart.
491 */
492IOMR3DECL(int) IOMR3IOPortDeregister(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts);
493
494
495/**
496 * Deregisters a Memory Mapped I/O handler range.
497 *
498 * Registered GC, R0, and R3 ranges are affected.
499 *
500 * @returns VBox status code.
501 *
502 * @param pVM The virtual machine.
503 * @param pDevIns Device instance which the MMIO region is registered.
504 * @param GCPhysStart First physical address (GC) in the range.
505 * @param cbRange Number of bytes to deregister.
506 *
507 *
508 * @remark This function mainly for PCI PnP Config and will not do
509 * all the checks you might expect it to do.
510 */
511IOMR3DECL(int) IOMR3MMIODeregister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange);
512
513
514/** @} */
515#endif
516
517
518/** @} */
519
520__END_DECLS
521
522#endif
523
Note: See TracBrowser for help on using the repository browser.

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