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