VirtualBox

source: vbox/trunk/include/VBox/vmm/iom.h@ 44539

Last change on this file since 44539 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 KB
Line 
1/** @file
2 * IOM - Input / Output Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2013 Oracle Corporation
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 (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_vmm_iom_h
27#define ___VBox_vmm_iom_h
28
29#include <VBox/types.h>
30#include <VBox/dis.h>
31
32RT_C_DECLS_BEGIN
33
34
35/** @defgroup grp_iom The Input / Ouput Monitor API
36 * @{
37 */
38
39/** @def IOM_NO_PDMINS_CHECKS
40 * Until all devices have been fully adjusted to PDM style, the pPdmIns
41 * parameter is not checked by IOM.
42 * @todo Check this again, now.
43 */
44#define IOM_NO_PDMINS_CHECKS
45
46/**
47 * Macro for checking if an I/O or MMIO emulation call succeeded.
48 *
49 * This macro shall only be used with the IOM APIs where it's mentioned
50 * in the return value description. And there it must be used to correctly
51 * determine if the call succeeded and things like the RIP needs updating.
52 *
53 *
54 * @returns Success indicator (true/false).
55 *
56 * @param rc The status code. This may be evaluated
57 * more than once!
58 *
59 * @remark To avoid making assumptions about the layout of the
60 * VINF_EM_FIRST...VINF_EM_LAST range we're checking
61 * explicitly for each for exach the exceptions.
62 * However, for efficieny we ASSUME that the
63 * VINF_EM_LAST is smaller than most of the relevant
64 * status codes. We also ASSUME that the
65 * VINF_EM_RESCHEDULE_REM status code is the most
66 * frequent status code we'll enounter in this range.
67 *
68 * @todo Will have to add VINF_EM_DBG_HYPER_BREAKPOINT if the
69 * I/O port and MMIO breakpoints should trigger before
70 * the I/O is done. Currently, we don't implement these
71 * kind of breakpoints.
72 */
73#define IOM_SUCCESS(rc) ( (rc) == VINF_SUCCESS \
74 || ( (rc) <= VINF_EM_LAST \
75 && (rc) != VINF_EM_RESCHEDULE_REM \
76 && (rc) >= VINF_EM_FIRST \
77 && (rc) != VINF_EM_RESCHEDULE_RAW \
78 && (rc) != VINF_EM_RESCHEDULE_HM \
79 ) \
80 )
81
82/** @name IOMMMIO_FLAGS_XXX
83 * @{ */
84/** Pass all reads thru unmodified. */
85#define IOMMMIO_FLAGS_READ_PASSTHRU UINT32_C(0x00000000)
86/** All read accesses are DWORD sized (32-bit). */
87#define IOMMMIO_FLAGS_READ_DWORD UINT32_C(0x00000001)
88/** All read accesses are DWORD (32-bit) or QWORD (64-bit) sized.
89 * Only accesses that are both QWORD sized and aligned are performed as QWORD.
90 * All other access will be done DWORD fashion (because it is way simpler). */
91#define IOMMMIO_FLAGS_READ_DWORD_QWORD UINT32_C(0x00000002)
92/** The read access mode mask. */
93#define IOMMMIO_FLAGS_READ_MODE UINT32_C(0x00000003)
94
95/** Pass all writes thru unmodified. */
96#define IOMMMIO_FLAGS_WRITE_PASSTHRU UINT32_C(0x00000000)
97/** All write accesses are DWORD (32-bit) sized and unspecified bytes are
98 * written as zero. */
99#define IOMMMIO_FLAGS_WRITE_DWORD_ZEROED UINT32_C(0x00000010)
100/** All write accesses are either DWORD (32-bit) or QWORD (64-bit) sized,
101 * missing bytes will be written as zero. Only accesses that are both QWORD
102 * sized and aligned are performed as QWORD, all other accesses will be done
103 * DWORD fashion (because it's way simpler). */
104#define IOMMMIO_FLAGS_WRITE_DWORD_QWORD_ZEROED UINT32_C(0x00000020)
105/** All write accesses are DWORD (32-bit) sized and unspecified bytes are
106 * read from the device first as DWORDs.
107 * @remarks This isn't how it happens on real hardware, but it allows
108 * simplifications of devices where reads doesn't change the device
109 * state in any way. */
110#define IOMMMIO_FLAGS_WRITE_DWORD_READ_MISSING UINT32_C(0x00000030)
111/** All write accesses are DWORD (32-bit) or QWORD (64-bit) sized and
112 * unspecified bytes are read from the device first as DWORDs. Only accesses
113 * that are both QWORD sized and aligned are performed as QWORD, all other
114 * accesses will be done DWORD fashion (because it's way simpler).
115 * @remarks This isn't how it happens on real hardware, but it allows
116 * simplifications of devices where reads doesn't change the device
117 * state in any way. */
118#define IOMMMIO_FLAGS_WRITE_DWORD_QWORD_READ_MISSING UINT32_C(0x00000040)
119/** The read access mode mask. */
120#define IOMMMIO_FLAGS_WRITE_MODE UINT32_C(0x00000070)
121
122/** Whether to do a DBGSTOP on complicated reads.
123 * What this includes depends on the read mode, but generally all misaligned
124 * reads as well as word and byte reads and maybe qword reads. */
125#define IOMMMIO_FLAGS_DBGSTOP_ON_COMPLICATED_READ UINT32_C(0x00000100)
126/** Whether to do a DBGSTOP on complicated writes.
127 * This depends on the write mode, but generally all writes where we have to
128 * supply bytes (zero them or read them). */
129#define IOMMMIO_FLAGS_DBGSTOP_ON_COMPLICATED_WRITE UINT32_C(0x00000200)
130
131/** Mask of valid flags. */
132#define IOMMMIO_FLAGS_VALID_MASK UINT32_C(0x00000373)
133/** @} */
134
135
136/**
137 * Port I/O Handler for IN operations.
138 *
139 * @returns VINF_SUCCESS or VINF_EM_*.
140 * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
141 *
142 * @param pDevIns The device instance.
143 * @param pvUser User argument.
144 * @param uPort Port number used for the IN operation.
145 * @param pu32 Where to store the result. This is always a 32-bit
146 * variable regardless of what @a cb might say.
147 * @param cb Number of bytes read.
148 * @remarks Caller enters the device critical section.
149 */
150typedef DECLCALLBACK(int) FNIOMIOPORTIN(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
151/** Pointer to a FNIOMIOPORTIN(). */
152typedef FNIOMIOPORTIN *PFNIOMIOPORTIN;
153
154/**
155 * Port I/O Handler for string IN operations.
156 *
157 * @returns VINF_SUCCESS or VINF_EM_*.
158 * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
159 *
160 * @param pDevIns The device instance.
161 * @param pvUser User argument.
162 * @param uPort Port number used for the IN operation.
163 * @param pGCPtrDst Pointer to the destination buffer (GC, incremented appropriately).
164 * @param pcTransfers Pointer to the number of transfer units to read, on return remaining transfer units.
165 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
166 * @remarks Caller enters the device critical section.
167 */
168typedef DECLCALLBACK(int) FNIOMIOPORTINSTRING(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb);
169/** Pointer to a FNIOMIOPORTINSTRING(). */
170typedef FNIOMIOPORTINSTRING *PFNIOMIOPORTINSTRING;
171
172/**
173 * Port I/O Handler for OUT operations.
174 *
175 * @returns VINF_SUCCESS or VINF_EM_*.
176 *
177 * @param pDevIns The device instance.
178 * @param pvUser User argument.
179 * @param uPort Port number used for the OUT operation.
180 * @param u32 The value to output.
181 * @param cb The value size in bytes.
182 * @remarks Caller enters the device critical section.
183 */
184typedef DECLCALLBACK(int) FNIOMIOPORTOUT(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
185/** Pointer to a FNIOMIOPORTOUT(). */
186typedef FNIOMIOPORTOUT *PFNIOMIOPORTOUT;
187
188/**
189 * Port I/O Handler for string OUT operations.
190 *
191 * @returns VINF_SUCCESS or VINF_EM_*.
192 *
193 * @param pDevIns The device instance.
194 * @param pvUser User argument.
195 * @param uPort Port number used for the OUT operation.
196 * @param pGCPtrSrc Pointer to the source buffer (GC, incremented appropriately).
197 * @param pcTransfers Pointer to the number of transfer units to write, on return remaining transfer units.
198 * @param cb Size of the transfer unit (1, 2 or 4 bytes).
199 * @remarks Caller enters the device critical section.
200 */
201typedef DECLCALLBACK(int) FNIOMIOPORTOUTSTRING(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb);
202/** Pointer to a FNIOMIOPORTOUTSTRING(). */
203typedef FNIOMIOPORTOUTSTRING *PFNIOMIOPORTOUTSTRING;
204
205
206/**
207 * Memory mapped I/O Handler for read operations.
208 *
209 * @returns VBox status code.
210 *
211 * @param pDevIns The device instance.
212 * @param pvUser User argument.
213 * @param GCPhysAddr Physical address (in GC) where the read starts.
214 * @param pv Where to store the result.
215 * @param cb Number of bytes read.
216 * @remarks Caller enters the device critical section.
217 */
218typedef DECLCALLBACK(int) FNIOMMMIOREAD(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
219/** Pointer to a FNIOMMMIOREAD(). */
220typedef FNIOMMMIOREAD *PFNIOMMMIOREAD;
221
222/**
223 * Port I/O Handler for write operations.
224 *
225 * @returns VBox status code.
226 *
227 * @param pDevIns The device instance.
228 * @param pvUser User argument.
229 * @param GCPhysAddr Physical address (in GC) where the read starts.
230 * @param pv Where to fetch the result.
231 * @param cb Number of bytes to write.
232 * @remarks Caller enters the device critical section.
233 */
234typedef DECLCALLBACK(int) FNIOMMMIOWRITE(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb);
235/** Pointer to a FNIOMMMIOWRITE(). */
236typedef FNIOMMMIOWRITE *PFNIOMMMIOWRITE;
237
238/**
239 * Port I/O Handler for memset operations, actually for REP STOS* instructions handling.
240 *
241 * @returns VBox status code.
242 *
243 * @param pDevIns The device instance.
244 * @param pvUser User argument.
245 * @param GCPhysAddr Physical address (in GC) where the write starts.
246 * @param u32Item Byte/Word/Dword data to fill.
247 * @param cbItem Size of data in u32Item parameter, restricted to 1/2/4 bytes.
248 * @param cItems Number of iterations.
249 * @remarks Caller enters the device critical section.
250 */
251typedef DECLCALLBACK(int) FNIOMMMIOFILL(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, uint32_t u32Item, unsigned cbItem, unsigned cItems);
252/** Pointer to a FNIOMMMIOFILL(). */
253typedef FNIOMMMIOFILL *PFNIOMMMIOFILL;
254
255VMMDECL(VBOXSTRICTRC) IOMIOPortRead(PVM pVM, RTIOPORT Port, uint32_t *pu32Value, size_t cbValue);
256VMMDECL(VBOXSTRICTRC) IOMIOPortWrite(PVM pVM, RTIOPORT Port, uint32_t u32Value, size_t cbValue);
257VMMDECL(VBOXSTRICTRC) IOMInterpretOUT(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
258VMMDECL(VBOXSTRICTRC) IOMInterpretIN(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
259VMMDECL(VBOXSTRICTRC) IOMIOPortReadString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb);
260VMMDECL(VBOXSTRICTRC) IOMIOPortWriteString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb);
261VMMDECL(VBOXSTRICTRC) IOMInterpretINS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
262VMMDECL(VBOXSTRICTRC) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, DISCPUMODE enmAddrMode, uint32_t cbTransfer);
263VMMDECL(VBOXSTRICTRC) IOMInterpretOUTS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
264VMMDECL(VBOXSTRICTRC) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, DISCPUMODE enmAddrMode, uint32_t cbTransfer);
265VMMDECL(VBOXSTRICTRC) IOMMMIORead(PVM pVM, RTGCPHYS GCPhys, uint32_t *pu32Value, size_t cbValue);
266VMMDECL(VBOXSTRICTRC) IOMMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue);
267VMMDECL(VBOXSTRICTRC) IOMMMIOPhysHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPHYS GCPhysFault);
268VMMDECL(VBOXSTRICTRC) IOMInterpretCheckPortIOAccess(PVM pVM, PCPUMCTXCORE pCtxCore, RTIOPORT Port, unsigned cb);
269VMMDECL(int) IOMMMIOMapMMIO2Page(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysRemapped, uint64_t fPageFlags);
270VMMDECL(int) IOMMMIOMapMMIOHCPage(PVM pVM, PVMCPU pVCpu, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint64_t fPageFlags);
271VMMDECL(int) IOMMMIOResetRegion(PVM pVM, RTGCPHYS GCPhys);
272VMMDECL(bool) IOMIsLockOwner(PVM pVM);
273
274#ifdef IN_RC
275/** @defgroup grp_iom_rc The IOM Raw-Mode Context API
276 * @ingroup grp_iom
277 * @{
278 */
279VMMRCDECL(VBOXSTRICTRC) IOMRCIOPortHandler(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
280/** @} */
281#endif /* IN_RC */
282
283
284
285#ifdef IN_RING3
286/** @defgroup grp_iom_r3 The IOM Host Context Ring-3 API
287 * @ingroup grp_iom
288 * @{
289 */
290VMMR3_INT_DECL(int) IOMR3Init(PVM pVM);
291VMMR3_INT_DECL(void) IOMR3Reset(PVM pVM);
292VMMR3_INT_DECL(void) IOMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
293VMMR3_INT_DECL(int) IOMR3Term(PVM pVM);
294VMMR3_INT_DECL(int) IOMR3IOPortRegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
295 R3PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R3PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
296 R3PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStringCallback, R3PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStringCallback,
297 const char *pszDesc);
298VMMR3_INT_DECL(int) IOMR3IOPortRegisterRC(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTRCPTR pvUser,
299 RCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, RCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
300 RCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, RCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
301 const char *pszDesc);
302VMMR3_INT_DECL(int) IOMR3IOPortRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTR0PTR pvUser,
303 R0PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R0PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
304 R0PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, R0PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
305 const char *pszDesc);
306VMMR3_INT_DECL(int) IOMR3IOPortDeregister(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts);
307
308VMMR3_INT_DECL(int) IOMR3MmioRegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
309 R3PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
310 R3PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
311 R3PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback,
312 uint32_t fFlags, const char *pszDesc);
313VMMR3_INT_DECL(int) IOMR3MmioRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
314 R0PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
315 R0PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
316 R0PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback);
317VMMR3_INT_DECL(int) IOMR3MmioRegisterRC(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTGCPTR pvUser,
318 RCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
319 RCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
320 RCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback);
321VMMR3_INT_DECL(int) IOMR3MmioDeregister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange);
322
323/** @} */
324#endif /* IN_RING3 */
325
326
327/** @} */
328
329RT_C_DECLS_END
330
331#endif
332
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