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 | __BEGIN_DECLS
|
---|
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 | IOMDECL(int) IOMIOPortRead(PVM pVM, RTIOPORT Port, uint32_t *pu32Value, size_t cbValue);
|
---|
204 | IOMDECL(int) IOMIOPortWrite(PVM pVM, RTIOPORT Port, uint32_t u32Value, size_t cbValue);
|
---|
205 | IOMDECL(int) IOMInterpretOUT(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
206 | IOMDECL(int) IOMInterpretIN(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
207 | IOMDECL(int) IOMIOPortReadString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb);
|
---|
208 | IOMDECL(int) IOMIOPortWriteString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb);
|
---|
209 | IOMDECL(int) IOMInterpretINS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
210 | IOMDECL(int) IOMInterpretINSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer);
|
---|
211 | IOMDECL(int) IOMInterpretOUTS(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
212 | IOMDECL(int) IOMInterpretOUTSEx(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t uPort, uint32_t uPrefix, uint32_t cbTransfer);
|
---|
213 | IOMDECL(int) IOMMMIORead(PVM pVM, RTGCPHYS GCPhys, uint32_t *pu32Value, size_t cbValue);
|
---|
214 | IOMDECL(int) IOMMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue);
|
---|
215 | IOMDECL(int) IOMInterpretCheckPortIOAccess(PVM pVM, PCPUMCTXCORE pCtxCore, RTIOPORT Port, unsigned cb);
|
---|
216 |
|
---|
217 |
|
---|
218 | #ifdef IN_GC
|
---|
219 | /** @defgroup grp_iom_gc The IOM Guest Context API
|
---|
220 | * @ingroup grp_iom
|
---|
221 | * @{
|
---|
222 | */
|
---|
223 | IOMGCDECL(int) IOMGCIOPortHandler(PVM pVM, PCPUMCTXCORE pRegFrame, PDISCPUSTATE pCpu);
|
---|
224 | /** @} */
|
---|
225 | #endif /* IN_GC */
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 | #ifdef IN_RING3
|
---|
230 | /** @defgroup grp_iom_r3 The IOM Host Context Ring-3 API
|
---|
231 | * @ingroup grp_iom
|
---|
232 | * @{
|
---|
233 | */
|
---|
234 | IOMR3DECL(int) IOMR3Init(PVM pVM);
|
---|
235 | IOMR3DECL(void) IOMR3Reset(PVM pVM);
|
---|
236 | IOMR3DECL(void) IOMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
237 | IOMR3DECL(int) IOMR3Term(PVM pVM);
|
---|
238 | IOMR3DECL(int) IOMR3IOPortRegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTHCPTR pvUser,
|
---|
239 | R3PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R3PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
|
---|
240 | R3PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStringCallback, R3PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStringCallback,
|
---|
241 | const char *pszDesc);
|
---|
242 | IOMR3DECL(int) IOMR3IOPortRegisterRC(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTRCPTR pvUser,
|
---|
243 | RCPTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, RCPTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
|
---|
244 | RCPTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, RCPTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
|
---|
245 | const char *pszDesc);
|
---|
246 | IOMR3DECL(int) IOMR3IOPortRegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts, RTR0PTR pvUser,
|
---|
247 | R0PTRTYPE(PFNIOMIOPORTOUT) pfnOutCallback, R0PTRTYPE(PFNIOMIOPORTIN) pfnInCallback,
|
---|
248 | R0PTRTYPE(PFNIOMIOPORTOUTSTRING) pfnOutStrCallback, R0PTRTYPE(PFNIOMIOPORTINSTRING) pfnInStrCallback,
|
---|
249 | const char *pszDesc);
|
---|
250 | IOMR3DECL(int) IOMR3IOPortDeregister(PVM pVM, PPDMDEVINS pDevIns, RTIOPORT PortStart, RTUINT cPorts);
|
---|
251 |
|
---|
252 | IOMR3DECL(int) IOMR3MMIORegisterR3(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
|
---|
253 | R3PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
|
---|
254 | R3PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
|
---|
255 | R3PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback, const char *pszDesc);
|
---|
256 | IOMR3DECL(int) IOMR3MMIORegisterR0(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
|
---|
257 | R0PTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
|
---|
258 | R0PTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
|
---|
259 | R0PTRTYPE(PFNIOMMMIOFILL) pfnFillCallback);
|
---|
260 | IOMR3DECL(int) IOMR3MMIORegisterRC(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
|
---|
261 | RCPTRTYPE(PFNIOMMMIOWRITE) pfnWriteCallback,
|
---|
262 | RCPTRTYPE(PFNIOMMMIOREAD) pfnReadCallback,
|
---|
263 | RCPTRTYPE(PFNIOMMMIOFILL) pfnFillCallback);
|
---|
264 | IOMR3DECL(int) IOMR3MMIODeregister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange);
|
---|
265 | /** @} */
|
---|
266 | #endif /* IN_RING3 */
|
---|
267 |
|
---|
268 |
|
---|
269 | /** @} */
|
---|
270 |
|
---|
271 | __END_DECLS
|
---|
272 |
|
---|
273 | #endif
|
---|
274 |
|
---|