Changeset 81720 in vbox for trunk/src/VBox/Devices/VirtIO/Virtio.h
- Timestamp:
- Nov 6, 2019 8:23:17 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/VirtIO/Virtio.h
r81703 r81720 25 25 26 26 27 /** Pointer to the core (/common) state of a VirtIO PCI device.*/27 /** Pointer to the core shared state of a VirtIO PCI device */ 28 28 typedef struct VPCISTATE *PVPCISTATE; 29 /** Pointer to the core ring-3 state of a VirtIO PCI device */ 30 typedef struct VPCISTATER3 *PVPCISTATER3; 31 /** Pointer to the core ring-0 state of a VirtIO PCI device */ 32 typedef struct VPCISTATER0 *PVPCISTATER0; 33 /** Pointer to the core raw-mode state of a VirtIO PCI device */ 34 typedef struct VPCISTATERC *PVPCISTATERC; 35 36 /** Pointer to the core current context state of a VirtIO PCI device */ 37 typedef CTX_SUFF(PVPCISTATE) PVPCISTATECC; 38 /** The core current context state of a VirtIO PCI device */ 39 typedef struct CTX_SUFF(VPCISTATE) VPCISTATECC; 29 40 30 41 … … 121 132 typedef VRING *PVRING; 122 133 134 typedef struct VQUEUE 135 { 136 VRING VRing; 137 uint16_t uNextAvailIndex; 138 uint16_t uNextUsedIndex; 139 uint32_t uPageNumber; 140 char szName[16]; 141 } VQUEUE; 142 typedef VQUEUE *PVQUEUE; 143 123 144 /** 124 145 * Queue callback (consumer?). 125 146 * 126 147 * @param pDevIns The device instance. 127 * @param pVPciState Pointer to the VirtIO PCI core state.128 148 * @param pQueue Pointer to the queue structure. 129 149 */ 130 typedef DECLCALLBACK(void) FNVPCIQUEUECALLBACK(PPDMDEVINS pDevIns, PV PCISTATE pVPciState, struct VQueue *pQueue);150 typedef DECLCALLBACK(void) FNVPCIQUEUECALLBACK(PPDMDEVINS pDevIns, PVQUEUE pQueue); 131 151 /** Pointer to a VQUEUE callback function. */ 132 152 typedef FNVPCIQUEUECALLBACK *PFNVPCIQUEUECALLBACK; 133 153 134 typedef struct VQueue 135 { 136 VRING VRing; 137 uint16_t uNextAvailIndex; 138 uint16_t uNextUsedIndex; 139 uint32_t uPageNumber; 154 typedef struct VQUEUER3 155 { 140 156 R3PTRTYPE(PFNVPCIQUEUECALLBACK) pfnCallback; 141 R3PTRTYPE(const char *) pcszName; 142 } VQUEUE; 143 typedef VQUEUE *PVQUEUE; 157 } VQUEUER3; 158 typedef VQUEUER3 *PVQUEUER3; 144 159 145 160 typedef struct VQueueElemSeg … … 170 185 171 186 /** 172 * The core (/common) state of the VirtIO PCI device 187 * The core shared state of a VirtIO PCI device 188 */ 189 typedef struct VPCISTATE 190 { 191 PDMCRITSECT cs; /**< Critical section - what is it protecting? */ 192 /** Read-only part, never changes after initialization. */ 193 char szInstance[8]; /**< Instance name, e.g. VNet#1. */ 194 195 /* Read/write part, protected with critical section. */ 196 /** Status LED. */ 197 PDMLED led; 198 199 uint32_t uGuestFeatures; 200 uint16_t uQueueSelector; /**< An index in aQueues array. */ 201 uint8_t uStatus; /**< Device Status (bits are device-specific). */ 202 uint8_t uISR; /**< Interrupt Status Register. */ 203 204 /** Number of queues actually used. */ 205 uint32_t cQueues; 206 uint32_t u32Padding; 207 /** Shared queue data. */ 208 VQUEUE Queues[VIRTIO_MAX_NQUEUES]; 209 210 #ifdef VBOX_WITH_STATISTICS 211 STAMPROFILEADV StatIOReadR3; 212 STAMPROFILEADV StatIOReadR0; 213 STAMPROFILEADV StatIOReadRC; 214 STAMPROFILEADV StatIOWriteR3; 215 STAMPROFILEADV StatIOWriteR0; 216 STAMPROFILEADV StatIOWriteRC; 217 STAMCOUNTER StatIntsRaised; 218 STAMCOUNTER StatIntsSkipped; 219 STAMPROFILE StatCsR3; 220 STAMPROFILE StatCsR0; 221 STAMPROFILE StatCsRC; 222 #endif 223 } VPCISTATE; 224 225 226 /** 227 * The core ring-3 state of a VirtIO PCI device 173 228 * 174 229 * @implements PDMILEDPORTS 175 230 */ 176 typedef struct VPCISTATE 177 { 178 PDMCRITSECT cs; /**< Critical section - what is it protecting? */ 179 /* Read-only part, never changes after initialization. */ 180 char szInstance[8]; /**< Instance name, e.g. VNet#1. */ 181 182 #if HC_ARCH_BITS != 64 183 uint32_t padding1; 184 #endif 185 231 typedef struct VPCISTATER3 232 { 186 233 /** Status LUN: Base interface. */ 187 PDMIBASE IBase;234 PDMIBASE IBase; 188 235 /** Status LUN: LED port interface. */ 189 PDMILEDPORTS ILeds;236 PDMILEDPORTS ILeds; 190 237 /** Status LUN: LED connector (peer). */ 191 R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector; 192 193 PPDMDEVINSR3 pDevInsR3; /**< Device instance - R3. */ 194 PPDMDEVINSR0 pDevInsR0; /**< Device instance - R0. */ 195 PPDMDEVINSRC pDevInsRC; /**< Device instance - RC. */ 196 197 #if HC_ARCH_BITS == 64 198 uint32_t padding2; 199 #endif 200 201 /** Base port of I/O space region. */ 202 RTIOPORT IOPortBase; 203 204 /* Read/write part, protected with critical section. */ 205 /** Status LED. */ 206 PDMLED led; 207 208 uint32_t uGuestFeatures; 209 uint16_t uQueueSelector; /**< An index in aQueues array. */ 210 uint8_t uStatus; /**< Device Status (bits are device-specific). */ 211 uint8_t uISR; /**< Interrupt Status Register. */ 212 213 #if HC_ARCH_BITS != 64 214 uint32_t padding3; 215 #endif 216 217 uint32_t nQueues; /**< Actual number of queues used. */ 218 VQUEUE Queues[VIRTIO_MAX_NQUEUES]; 219 220 #ifdef VBOX_WITH_STATISTICS 221 STAMPROFILEADV StatIOReadR3; 222 STAMPROFILEADV StatIOReadR0; 223 STAMPROFILEADV StatIOReadRC; 224 STAMPROFILEADV StatIOWriteR3; 225 STAMPROFILEADV StatIOWriteR0; 226 STAMPROFILEADV StatIOWriteRC; 227 STAMCOUNTER StatIntsRaised; 228 STAMCOUNTER StatIntsSkipped; 229 STAMPROFILE StatCsR3; 230 STAMPROFILE StatCsR0; 231 STAMPROFILE StatCsRC; 232 #endif 233 } VPCISTATE; 238 R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector; 239 /** Pointer to the shared state. */ 240 R3PTRTYPE(PVPCISTATE) pShared; 241 /** Ring-3 per-queue data. */ 242 VQUEUER3 Queues[VIRTIO_MAX_NQUEUES]; 243 } VPCISTATER3; 244 245 246 /** 247 * The core ring-0 state of a VirtIO PCI device 248 */ 249 typedef struct VPCISTATER0 250 { 251 uint64_t uUnused; 252 } VPCISTATER0; 253 254 255 /** 256 * The core raw-mode state of a VirtIO PCI device 257 */ 258 typedef struct VPCISTATERC 259 { 260 uint64_t uUnused; 261 } VPCISTATERC; 262 234 263 235 264 /** @name VirtIO port I/O callbacks. … … 242 271 DECLCALLBACKMEMBER(int, pfnGetConfig)(PVPCISTATE pVPciState, uint32_t offCfg, uint32_t cb, void *pvData); 243 272 DECLCALLBACKMEMBER(int, pfnSetConfig)(PVPCISTATE pVPciState, uint32_t offCfg, uint32_t cb, void *pvData); 244 DECLCALLBACKMEMBER(int, pfnReset)(P VPCISTATE pVPciState);245 DECLCALLBACKMEMBER(void, pfnReady)(P VPCISTATE pVPciState);273 DECLCALLBACKMEMBER(int, pfnReset)(PPDMDEVINS pDevIns); 274 DECLCALLBACKMEMBER(void, pfnReady)(PPDMDEVINS pDevIns); 246 275 } VPCIIOCALLBACKS; 247 276 /** Pointer to a const VirtIO port I/O callback structure. */ … … 249 278 /** @} */ 250 279 251 int vpciRaiseInterrupt(VPCISTATE *pState, int rcBusy, uint8_t u8IntCause); 252 int vpciIOPortIn(PPDMDEVINS pDevIns, 253 PVPCISTATE pState, 254 RTIOPORT port, 255 uint32_t *pu32, 256 unsigned cb, 257 PCVPCIIOCALLBACKS pCallbacks); 258 259 int vpciIOPortOut(PPDMDEVINS pDevIns, 260 PVPCISTATE pState, 261 RTIOPORT port, 262 uint32_t u32, 263 unsigned cb, 264 PCVPCIIOCALLBACKS pCallbacks); 265 266 void vpciSetWriteLed(PVPCISTATE pState, bool fOn); 267 void vpciSetReadLed(PVPCISTATE pState, bool fOn); 268 int vpciSaveExec(PVPCISTATE pState, PSSMHANDLE pSSM); 269 int vpciLoadExec(PVPCISTATE pState, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass, uint32_t nQueues); 270 int vpciConstruct(PPDMDEVINS pDevIns, VPCISTATE *pState, int iInstance, const char *pcszNameFmt, 271 uint16_t uDeviceId, uint16_t uClass, uint32_t nQueues); 272 int vpciDestruct(VPCISTATE* pState); 273 void vpciRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta); 274 void vpciReset(PVPCISTATE pState); 275 void *vpciQueryInterface(struct PDMIBASE *pInterface, const char *pszIID); 276 PVQUEUE vpciAddQueue(VPCISTATE* pState, unsigned uSize, PFNVPCIQUEUECALLBACK pfnCallback, const char *pcszName); 280 int vpciR3Init(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVPCISTATECC pThisCC, uint16_t uDeviceId, uint16_t uClass, uint32_t cQueues); 281 int vpciRZInit(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVPCISTATECC pThisCC); 282 int vpciR3Term(PPDMDEVINS pDevIns, PVPCISTATE pThis); 283 284 int vpciRaiseInterrupt(PPDMDEVINS pDevIns, PVPCISTATE pThis, int rcBusy, uint8_t u8IntCause); 285 int vpciIOPortIn(PPDMDEVINS pDevIns, PVPCISTATE pThis, RTIOPORT offPort, 286 uint32_t *pu32, unsigned cb,PCVPCIIOCALLBACKS pCallbacks); 287 int vpciIOPortOut(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVPCISTATECC pThisCC, RTIOPORT offPort, 288 uint32_t u32, unsigned cb, PCVPCIIOCALLBACKS pCallbacks); 289 290 void vpciR3SetWriteLed(PVPCISTATE pThis, bool fOn); 291 void vpciR3SetReadLed(PVPCISTATE pThis, bool fOn); 292 int vpciR3SaveExec(PCPDMDEVHLPR3 pHlp, PVPCISTATE pThis, PSSMHANDLE pSSM); 293 int vpciR3LoadExec(PCPDMDEVHLPR3 pHlp, PVPCISTATE pThis, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass, uint32_t cQueues); 294 void vpciReset(PPDMDEVINS pDevIns, PVPCISTATE pThis); 295 void *vpciR3QueryInterface(PVPCISTATECC pThisCC, const char *pszIID); 296 PVQUEUE vpciR3AddQueue(PVPCISTATE pThis, PVPCISTATECC pThisCC, unsigned uSize, PFNVPCIQUEUECALLBACK pfnCallback, const char *pcszName); 277 297 278 298 #define VPCI_CS 279 DECLINLINE(int) vpciCsEnter( VPCISTATE *pState, int rcBusy)299 DECLINLINE(int) vpciCsEnter(PPDMDEVINS pDevIns, PVPCISTATE pThis, int rcBusy) 280 300 { 281 301 #ifdef VPCI_CS 282 STAM_PROFILE_START(&p State->CTX_SUFF(StatCs), a);283 int rc = PDM CritSectEnter(&pState->cs, rcBusy);284 STAM_PROFILE_STOP(&p State->CTX_SUFF(StatCs), a);302 STAM_PROFILE_START(&pThis->CTX_SUFF(StatCs), a); 303 int rc = PDMDevHlpCritSectEnter(pDevIns, &pThis->cs, rcBusy); 304 STAM_PROFILE_STOP(&pThis->CTX_SUFF(StatCs), a); 285 305 return rc; 286 306 #else 307 RT_NOREF(pDevIns, pThis, rcBusy); 287 308 return VINF_SUCCESS; 288 309 #endif 289 310 } 290 311 291 DECLINLINE(void) vpciCsLeave( VPCISTATE *pState)312 DECLINLINE(void) vpciCsLeave(PPDMDEVINS pDevIns, PVPCISTATE pThis) 292 313 { 293 314 #ifdef VPCI_CS 294 PDM CritSectLeave(&pState->cs);315 PDMDevHlpCritSectLeave(pDevIns, &pThis->cs); 295 316 #endif 296 317 } 297 318 298 void vringSetNotification(PVPCISTATE pState, PVRING pVRing, bool fEnabled); 299 300 DECLINLINE(uint16_t) vringReadAvailIndex(PVPCISTATE pState, PVRING pVRing) 301 { 302 uint16_t tmp; 303 304 PDMDevHlpPhysRead(pState->CTX_SUFF(pDevIns), 305 pVRing->addrAvail + RT_UOFFSETOF(VRINGAVAIL, uNextFreeIndex), 306 &tmp, sizeof(tmp)); 307 return tmp; 308 } 309 310 bool vqueueSkip(PVPCISTATE pState, PVQUEUE pQueue); 311 bool vqueueGet(PVPCISTATE pState, PVQUEUE pQueue, PVQUEUEELEM pElem, bool fRemove = true); 312 void vqueuePut(PVPCISTATE pState, PVQUEUE pQueue, PVQUEUEELEM pElem, uint32_t uLen, uint32_t uReserved = 0); 313 void vqueueNotify(PVPCISTATE pState, PVQUEUE pQueue); 314 void vqueueSync(PVPCISTATE pState, PVQUEUE pQueue); 315 316 DECLINLINE(bool) vqueuePeek(PVPCISTATE pState, PVQUEUE pQueue, PVQUEUEELEM pElem) 317 { 318 return vqueueGet(pState, pQueue, pElem, /* fRemove */ false); 319 } 320 321 DECLINLINE(bool) vqueueIsReady(PVPCISTATE pState, PVQUEUE pQueue) 322 { 323 NOREF(pState); 319 void vringSetNotification(PPDMDEVINS pDevIns, PVRING pVRing, bool fEnabled); 320 321 DECLINLINE(uint16_t) vringReadAvailIndex(PPDMDEVINS pDevIns, PVRING pVRing) 322 { 323 uint16_t idx = 0; 324 PDMDevHlpPhysRead(pDevIns, pVRing->addrAvail + RT_UOFFSETOF(VRINGAVAIL, uNextFreeIndex), &idx, sizeof(idx)); 325 return idx; 326 } 327 328 bool vqueueSkip(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVQUEUE pQueue); 329 bool vqueueGet(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVQUEUE pQueue, PVQUEUEELEM pElem, bool fRemove = true); 330 void vqueuePut(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVQUEUE pQueue, PVQUEUEELEM pElem, uint32_t uLen, uint32_t uReserved = 0); 331 void vqueueNotify(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVQUEUE pQueue); 332 void vqueueSync(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVQUEUE pQueue); 333 334 DECLINLINE(bool) vqueuePeek(PPDMDEVINS pDevIns, PVPCISTATE pThis, PVQUEUE pQueue, PVQUEUEELEM pElem) 335 { 336 return vqueueGet(pDevIns, pThis, pQueue, pElem, /* fRemove */ false); 337 } 338 339 DECLINLINE(bool) vqueueIsReady(PVQUEUE pQueue) 340 { 324 341 return !!pQueue->VRing.addrAvail; 325 342 } 326 343 327 DECLINLINE(bool) vqueueIsEmpty(PVPCISTATE pState, PVQUEUE pQueue) 328 { 329 return (vringReadAvailIndex(pState, &pQueue->VRing) == pQueue->uNextAvailIndex); 330 } 344 DECLINLINE(bool) vqueueIsEmpty(PPDMDEVINS pDevIns, PVQUEUE pQueue) 345 { 346 return vringReadAvailIndex(pDevIns, &pQueue->VRing) == pQueue->uNextAvailIndex; 347 } 348 349 void vpcR3iDumpStateWorker(PVPCISTATE pThis, PCDBGFINFOHLP pHlp); 331 350 332 351 #endif /* !VBOX_INCLUDED_SRC_VirtIO_Virtio_h */
Note:
See TracChangeset
for help on using the changeset viewer.