1 | /** @file
|
---|
2 | * IOM - Input / Output Monitor.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___VBox_iom_h
|
---|
31 | #define ___VBox_iom_h
|
---|
32 |
|
---|
33 | #include <VBox/cdefs.h>
|
---|
34 | #include <VBox/types.h>
|
---|
35 | #include <VBox/dis.h>
|
---|
36 |
|
---|
37 | RT_C_DECLS_BEGIN
|
---|
38 |
|
---|
39 |
|
---|
40 | /** @defgroup grp_iom The Input / Ouput Monitor API
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** @def IOM_NO_PDMINS_CHECKS
|
---|
45 | * Until all devices have been fully adjusted to PDM style, the pPdmIns
|
---|
46 | * parameter is not checked by IOM.
|
---|
47 | * @todo Check this again, now.
|
---|
48 | */
|
---|
49 | #define IOM_NO_PDMINS_CHECKS
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Macro for checking if an I/O or MMIO emulation call succeeded.
|
---|
53 | *
|
---|
54 | * This macro shall only be used with the IOM APIs where it's mentioned
|
---|
55 | * in the return value description. And there is must be used to correctly
|
---|
56 | * determin if the call succeeded and things like the EIP needs updating.
|
---|
57 | *
|
---|
58 | *
|
---|
59 | * @returns Success indicator (true/false).
|
---|
60 | *
|
---|
61 | * @param rc The status code. This may be evaluated
|
---|
62 | * more than once!
|
---|
63 | *
|
---|
64 | * @remark To avoid making assumptions about the layout of the
|
---|
65 | * VINF_EM_FIRST...VINF_EM_LAST range we're checking
|
---|
66 | * explicitly for each for exach the exceptions.
|
---|
67 | * However, for efficieny we ASSUME that the
|
---|
68 | * VINF_EM_LAST is smaller than most of the relevant
|
---|
69 | * status codes. We also ASSUME that the
|
---|
70 | * VINF_EM_RESCHEDULE_REM status code is the most
|
---|
71 | * frequent status code we'll enounter in this range.
|
---|
72 | *
|
---|
73 | * @todo Will have to add VINF_EM_DBG_HYPER_BREAKPOINT if the
|
---|
74 | * I/O port and MMIO breakpoints should trigger before
|
---|
75 | * the I/O is done. Currently, we don't implement these
|
---|
76 | * kind of breakpoints.
|
---|
77 | */
|
---|
78 | #define IOM_SUCCESS(rc) ( (rc) == VINF_SUCCESS \
|
---|
79 | || ( (rc) <= VINF_EM_LAST \
|
---|
80 | && (rc) != VINF_EM_RESCHEDULE_REM \
|
---|
81 | && (rc) >= VINF_EM_FIRST \
|
---|
82 | && (rc) != VINF_EM_RESCHEDULE_RAW \
|
---|
83 | && (rc) != VINF_EM_RESCHEDULE_HWACC \
|
---|
84 | ) \
|
---|
85 | )
|
---|
86 |
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Port I/O Handler for IN operations.
|
---|
90 | *
|
---|
91 | * @returns VINF_SUCCESS or VINF_EM_*.
|
---|
92 | * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
|
---|
93 | *
|
---|
94 | * @param pDevIns The device instance.
|
---|
95 | * @param pvUser User argument.
|
---|
96 | * @param uPort Port number used for the IN operation.
|
---|
97 | * @param pu32 Where to store the result.
|
---|
98 | * @param cb Number of bytes read.
|
---|
99 | */
|
---|
100 | typedef DECLCALLBACK(int) FNIOMIOPORTIN(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
|
---|
101 | /** Pointer to a FNIOMIOPORTIN(). */
|
---|
102 | typedef FNIOMIOPORTIN *PFNIOMIOPORTIN;
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Port I/O Handler for string IN operations.
|
---|
106 | *
|
---|
107 | * @returns VINF_SUCCESS or VINF_EM_*.
|
---|
108 | * @returns VERR_IOM_IOPORT_UNUSED if the port is really unused and a ~0 value should be returned.
|
---|
109 | *
|
---|
110 | * @param pDevIns The device instance.
|
---|
111 | * @param pvUser User argument.
|
---|
112 | * @param uPort Port number used for the IN operation.
|
---|
113 | * @param pGCPtrDst Pointer to the destination buffer (GC, incremented appropriately).
|
---|
114 | * @param pcTransfers Pointer to the number of transfer units to read, on return remaining transfer units.
|
---|
115 | * @param cb Size of the transfer unit (1, 2 or 4 bytes).
|
---|
116 | */
|
---|
117 | typedef DECLCALLBACK(int) FNIOMIOPORTINSTRING(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb);
|
---|
118 | /** Pointer to a FNIOMIOPORTINSTRING(). */
|
---|
119 | typedef FNIOMIOPORTINSTRING *PFNIOMIOPORTINSTRING;
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Port I/O Handler for OUT operations.
|
---|
123 | *
|
---|
124 | * @returns VINF_SUCCESS or VINF_EM_*.
|
---|
125 | *
|
---|
126 | * @param pDevIns The device instance.
|
---|
127 | * @param pvUser User argument.
|
---|
128 | * @param uPort Port number used for the OUT operation.
|
---|
129 | * @param u32 The value to output.
|
---|
130 | * @param cb The value size in bytes.
|
---|
131 | */
|
---|
132 | typedef DECLCALLBACK(int) FNIOMIOPORTOUT(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
|
---|
133 | /** Pointer to a FNIOMIOPORTOUT(). */
|
---|
134 | typedef FNIOMIOPORTOUT *PFNIOMIOPORTOUT;
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Port I/O Handler for string OUT operations.
|
---|
138 | *
|
---|
139 | * @returns VINF_SUCCESS or VINF_EM_*.
|
---|
140 | *
|
---|
141 | * @param pDevIns The device instance.
|
---|
142 | * @param pvUser User argument.
|
---|
143 | * @param uPort Port number used for the OUT operation.
|
---|
144 | * @param pGCPtrSrc Pointer to the source buffer (GC, incremented appropriately).
|
---|
145 | * @param pcTransfers Pointer to the number of transfer units to write, on return remaining transfer units.
|
---|
146 | * @param cb Size of the transfer unit (1, 2 or 4 bytes).
|
---|
147 | */
|
---|
148 | typedef DECLCALLBACK(int) FNIOMIOPORTOUTSTRING(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb);
|
---|
149 | /** Pointer to a FNIOMIOPORTOUTSTRING(). */
|
---|
150 | typedef FNIOMIOPORTOUTSTRING *PFNIOMIOPORTOUTSTRING;
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Memory mapped I/O Handler for read operations.
|
---|
155 | *
|
---|
156 | * @returns VBox status code.
|
---|
157 | *
|
---|
158 | * @param pDevIns The device instance.
|
---|
159 | * @param pvUser User argument.
|
---|
160 | * @param GCPhysAddr Physical address (in GC) where the read starts.
|
---|
161 | * @param pv Where to store the result.
|
---|
162 | * @param cb Number of bytes read.
|
---|
163 | *
|
---|
164 | * @remark wonder if we could merge the IOMMMIO* and IOMPORT* callbacks...
|
---|
165 | */
|
---|
166 | typedef DECLCALLBACK(int) FNIOMMMIOREAD(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
|
---|
167 | /** Pointer to a FNIOMMMIOREAD(). */
|
---|
168 | typedef FNIOMMMIOREAD *PFNIOMMMIOREAD;
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Port I/O Handler for write operations.
|
---|
172 | *
|
---|
173 | * @returns VBox status code.
|
---|
174 | *
|
---|
175 | * @param pDevIns The device instance.
|
---|
176 | * @param pvUser User argument.
|
---|
177 | * @param GCPhysAddr Physical address (in GC) where the read starts.
|
---|
178 | * @param pv Where to fetch the result.
|
---|
179 | * @param cb Number of bytes to write.
|
---|
180 | *
|
---|
181 | * @remark wonder if we could merge the IOMMMIO* and IOMPORT* callbacks...
|
---|
182 | */
|
---|
183 | typedef DECLCALLBACK(int) FNIOMMMIOWRITE(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb);
|
---|
184 | /** Pointer to a FNIOMMMIOWRITE(). */
|
---|
185 | typedef FNIOMMMIOWRITE *PFNIOMMMIOWRITE;
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Port I/O Handler for memset operations, actually for REP STOS* instructions handling.
|
---|
189 | *
|
---|
190 | * @returns VBox status code.
|
---|
191 | *
|
---|
192 | * @param pDevIns The device instance.
|
---|
193 | * @param pvUser User argument.
|
---|
194 | * @param GCPhysAddr Physical address (in GC) where the write starts.
|
---|
195 | * @param u32Item Byte/Word/Dword data to fill.
|
---|
196 | * @param cbItem Size of data in u32Item parameter, restricted to 1/2/4 bytes.
|
---|
197 | * @param cItems Number of iterations.
|
---|
198 | */
|
---|
199 | typedef DECLCALLBACK(int) FNIOMMMIOFILL(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, uint32_t u32Item, unsigned cbItem, unsigned cItems);
|
---|
200 | /** Pointer to a FNIOMMMIOFILL(). */
|
---|
201 | typedef FNIOMMMIOFILL *PFNIOMMMIOFILL;
|
---|
202 |
|
---|
203 | VMMDECL(int) IOMIOPortRead(PVM pVM, RTIOPORT Port, uint32_t *pu32Value, size_t cbValue);
|
---|
204 | VMMDECL(int) IOMIOPortWrite(PVM pVM, RTIOPORT Port, uint32_t u32Value, size_t cbValue);
|
---|
205 | VMMDECL(int) IOMInterpretOUT(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
206 | VMMDECL(int) IOMInterpretIN(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
207 | VMMDECL(int) IOMIOPortReadString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb);
|
---|
208 | VMMDECL(int) IOMIOPortWriteString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb);
|
---|
209 | VMMDECL(int) IOMInterpretINS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
210 | VMMDECL(int) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer);
|
---|
211 | VMMDECL(int) IOMInterpretOUTS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
212 | VMMDECL(int) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer);
|
---|
213 | VMMDECL(int) IOMMMIORead(PVM pVM, RTGCPHYS GCPhys, uint32_t *pu32Value, size_t cbValue);
|
---|
214 | VMMDECL(int) IOMMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue);
|
---|
215 | VMMDECL(int) IOMMMIOPhysHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore, RTGCPHYS GCPhysFault);
|
---|
216 | VMMDECL(int) IOMInterpretCheckPortIOAccess(PVM pVM, PCPUMCTXCORE pCtxCore, RTIOPORT Port, unsigned cb);
|
---|
217 | VMMDECL(int) IOMMMIOMapMMIO2Page(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysRemapped, uint64_t fPageFlags);
|
---|
218 | VMMDECL(int) IOMMMIOMapMMIOHCPage(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint64_t fPageFlags);
|
---|
219 | VMMDECL(int) IOMMMIOResetRegion(PVM pVM, RTGCPHYS GCPhys);
|
---|
220 | VMMDECL(bool) IOMIsLockOwner(PVM pVM);
|
---|
221 |
|
---|
222 | #ifdef IN_RC
|
---|
223 | /** @defgroup grp_iom_gc The IOM Guest Context API
|
---|
224 | * @ingroup grp_iom
|
---|
225 | * @{
|
---|
226 | */
|
---|
227 | VMMRCDECL(int) IOMGCIOPortHandler(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
228 | /** @} */
|
---|
229 | #endif /* IN_RC */
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 | #ifdef IN_RING3
|
---|
234 | /** @defgroup grp_iom_r3 The IOM Host Context Ring-3 API
|
---|
235 | * @ingroup grp_iom
|
---|
236 | * @{
|
---|
237 | */
|
---|
238 | VMMR3DECL(int) IOMR3Init(PVM pVM);
|
---|
239 | VMMR3DECL(void) IOMR3Reset(PVM pVM);
|
---|
240 | VMMR3DECL(void) IOMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
241 | VMMR3DECL(int) IOMR3Term(PVM pVM);
|
---|
242 | VMMR3DECL(int) IOMR3IOPortRegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
|
---|
243 | R3PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R3PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
|
---|
244 | R3PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStringCallback, R3PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStringCallback,
|
---|
245 | const char *pszDesc);
|
---|
246 | VMMR3DECL(int) IOMR3IOPortRegisterRC(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTRCPTR pvUser,
|
---|
247 | RCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, RCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
|
---|
248 | RCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, RCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
|
---|
249 | const char *pszDesc);
|
---|
250 | VMMR3DECL(int) IOMR3IOPortRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTR0PTR pvUser,
|
---|
251 | R0PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R0PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
|
---|
252 | R0PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, R0PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
|
---|
253 | const char *pszDesc);
|
---|
254 | VMMR3DECL(int) IOMR3IOPortDeregister(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts);
|
---|
255 |
|
---|
256 | VMMR3DECL(int) IOMR3MMIORegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
|
---|
257 | R3PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
|
---|
258 | R3PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
|
---|
259 | R3PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc);
|
---|
260 | VMMR3DECL(int) IOMR3MMIORegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
|
---|
261 | R0PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
|
---|
262 | R0PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
|
---|
263 | R0PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback);
|
---|
264 | VMMR3DECL(int) IOMR3MMIORegisterRC(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
|
---|
265 | RCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
|
---|
266 | RCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
|
---|
267 | RCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback);
|
---|
268 | VMMR3DECL(int) IOMR3MMIODeregister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange);
|
---|
269 |
|
---|
270 | VMMR3DECL(void) IOMR3ReleaseOwnedLocks(PVM pVM);
|
---|
271 | VMMR3DECL(PPDMCRITSECT) IOMR3GetCritSect(PVM pVM);
|
---|
272 |
|
---|
273 | /** @} */
|
---|
274 | #endif /* IN_RING3 */
|
---|
275 |
|
---|
276 |
|
---|
277 | /** @} */
|
---|
278 |
|
---|
279 | RT_C_DECLS_END
|
---|
280 |
|
---|
281 | #endif
|
---|
282 |
|
---|