Changeset 19472 in vbox
- Timestamp:
- May 7, 2009 9:21:39 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/IOMAll.cpp
r19263 r19472 41 41 42 42 /** 43 * Try take the EMT/IOM lock, wait in ring-3 return VERR_SEM_BUSY in R0/RC. 44 * 45 * @retval VINF_SUCCESS on success (always in ring-3). 46 * @retval VERR_SEM_BUSY in RC and R0 if the semaphore is busy. 47 * 48 * @param pVM VM handle. 49 */ 50 int iomLock(PVM pVM) 51 { 52 Assert(!PGMIsLocked(pVM)); 53 int rc = PDMCritSectEnter(&pVM->iom.s.EmtLock, VERR_SEM_BUSY); 54 return rc; 55 } 56 57 58 /** 59 * Try take the EMT/IOM lock, no waiting. 60 * 61 * @retval VINF_SUCCESS on success. 62 * @retval VERR_SEM_BUSY if busy. 63 * 64 * @param pVM VM handle. 65 */ 66 int iomTryLock(PVM pVM) 67 { 68 int rc = PDMCritSectTryEnter(&pVM->iom.s.EmtLock); 69 return rc; 70 } 71 72 73 /** 74 * Release EMT/IOM lock. 75 * 76 * @param pVM VM handle. 77 */ 78 void iomUnlock(PVM pVM) 79 { 80 PDMCritSectLeave(&pVM->iom.s.EmtLock); 81 } 82 83 /** 43 84 * Returns the contents of register or immediate data of instruction's parameter. 44 85 * … … 208 249 VMMDECL(int) IOMIOPortRead(PVM pVM, RTIOPORT Port, uint32_t *pu32Value, size_t cbValue) 209 250 { 251 /* Take the IOM lock before performing any device I/O. */ 252 int rc = iomLock(pVM); 253 #ifndef IN_RING3 254 if (rc == VERR_SEM_BUSY) 255 return VINF_IOM_HC_IOPORT_READ; 256 #else 257 AssertRC(rc); 258 #endif 259 210 260 #ifdef VBOX_WITH_STATISTICS 211 261 /* … … 245 295 STAM_COUNTER_INC(&pStats->CTX_MID_Z(In,ToR3)); 246 296 # endif 297 iomUnlock(pVM); 247 298 return VINF_IOM_HC_IOPORT_READ; 248 299 } … … 253 304 STAM_PROFILE_ADV_START(&pStats->CTX_SUFF_Z(ProfIn), a); 254 305 #endif 255 intrc = pRange->pfnInCallback(pRange->pDevIns, pRange->pvUser, Port, pu32Value, (unsigned)cbValue);306 rc = pRange->pfnInCallback(pRange->pDevIns, pRange->pvUser, Port, pu32Value, (unsigned)cbValue); 256 307 #ifdef VBOX_WITH_STATISTICS 257 308 if (pStats) … … 275 326 default: 276 327 AssertMsgFailed(("Invalid I/O port size %d. Port=%d\n", cbValue, Port)); 328 iomUnlock(pVM); 277 329 return VERR_IOM_INVALID_IOPORT_SIZE; 278 330 } 279 331 } 280 332 Log3(("IOMIOPortRead: Port=%RTiop *pu32=%08RX32 cb=%d rc=%Rrc\n", Port, *pu32Value, cbValue, rc)); 333 iomUnlock(pVM); 281 334 return rc; 282 335 } … … 293 346 STAM_COUNTER_INC(&pStats->CTX_MID_Z(In,ToR3)); 294 347 # endif 348 iomUnlock(pVM); 295 349 return VINF_IOM_HC_IOPORT_READ; 296 350 } … … 307 361 # ifndef IN_RING3 308 362 /* Ring-3 will have to create the statistics record. */ 363 iomUnlock(pVM); 309 364 return VINF_IOM_HC_IOPORT_READ; 310 365 # else … … 324 379 default: 325 380 AssertMsgFailed(("Invalid I/O port size %d. Port=%d\n", cbValue, Port)); 381 iomUnlock(pVM); 326 382 return VERR_IOM_INVALID_IOPORT_SIZE; 327 383 } 328 384 Log3(("IOMIOPortRead: Port=%RTiop *pu32=%08RX32 cb=%d rc=VINF_SUCCESS\n", Port, *pu32Value, cbValue)); 385 iomUnlock(pVM); 329 386 return VINF_SUCCESS; 330 387 } … … 349 406 VMMDECL(int) IOMIOPortReadString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrDst, PRTGCUINTREG pcTransfers, unsigned cb) 350 407 { 408 /* Take the IOM lock before performing any device I/O. */ 409 int rc = iomLock(pVM); 410 #ifndef IN_RING3 411 if (rc == VERR_SEM_BUSY) 412 return VINF_IOM_HC_IOPORT_READ; 413 #endif 414 AssertRC(rc); 415 351 416 #ifdef LOG_ENABLED 352 417 const RTGCUINTREG cTransfers = *pcTransfers; … … 389 454 STAM_COUNTER_INC(&pStats->CTX_MID_Z(In,ToR3)); 390 455 # endif 456 iomUnlock(pVM); 391 457 return VINF_IOM_HC_IOPORT_READ; 392 458 } … … 411 477 Log3(("IOMIOPortReadStr: Port=%RTiop pGCPtrDst=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=%Rrc\n", 412 478 Port, pGCPtrDst, pcTransfers, cTransfers, *pcTransfers, cb, rc)); 479 iomUnlock(pVM); 413 480 return rc; 414 481 } … … 425 492 STAM_COUNTER_INC(&pStats->CTX_MID_Z(In,ToR3)); 426 493 # endif 494 iomUnlock(pVM); 427 495 return VINF_IOM_HC_IOPORT_READ; 428 496 } … … 439 507 # ifndef IN_RING3 440 508 /* Ring-3 will have to create the statistics record. */ 509 iomUnlock(pVM); 441 510 return VINF_IOM_HC_IOPORT_READ; 442 511 # else … … 450 519 Log3(("IOMIOPortReadStr: Port=%RTiop pGCPtrDst=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=VINF_SUCCESS\n", 451 520 Port, pGCPtrDst, pcTransfers, cTransfers, *pcTransfers, cb)); 521 iomUnlock(pVM); 452 522 return VINF_SUCCESS; 453 523 } … … 471 541 VMMDECL(int) IOMIOPortWrite(PVM pVM, RTIOPORT Port, uint32_t u32Value, size_t cbValue) 472 542 { 543 /* Take the IOM lock before performing any device I/O. */ 544 int rc = iomLock(pVM); 545 #ifndef IN_RING3 546 if (rc == VERR_SEM_BUSY) 547 return VINF_IOM_HC_IOPORT_WRITE; 548 #endif 549 AssertRC(rc); 550 473 551 /** @todo bird: When I get time, I'll remove the GC tree and link the GC entries to the ring-3 node. */ 474 552 #ifdef VBOX_WITH_STATISTICS … … 509 587 STAM_COUNTER_INC(&pStats->CTX_MID_Z(Out,ToR3)); 510 588 # endif 589 iomUnlock(pVM); 511 590 return VINF_IOM_HC_IOPORT_WRITE; 512 591 } … … 530 609 #endif 531 610 Log3(("IOMIOPortWrite: Port=%RTiop u32=%08RX32 cb=%d rc=%Rrc\n", Port, u32Value, cbValue, rc)); 611 iomUnlock(pVM); 532 612 return rc; 533 613 } … … 544 624 STAM_COUNTER_INC(&pStats->CTX_MID_Z(Out,ToR3)); 545 625 # endif 626 iomUnlock(pVM); 546 627 return VINF_IOM_HC_IOPORT_WRITE; 547 628 } … … 559 640 # ifndef IN_RING3 560 641 /* R3 will have to create the statistics record. */ 642 iomUnlock(pVM); 561 643 return VINF_IOM_HC_IOPORT_WRITE; 562 644 # else … … 568 650 #endif 569 651 Log3(("IOMIOPortWrite: Port=%RTiop u32=%08RX32 cb=%d nop\n", Port, u32Value, cbValue)); 652 iomUnlock(pVM); 570 653 return VINF_SUCCESS; 571 654 } … … 590 673 VMMDECL(int) IOMIOPortWriteString(PVM pVM, RTIOPORT Port, PRTGCPTR pGCPtrSrc, PRTGCUINTREG pcTransfers, unsigned cb) 591 674 { 675 /* Take the IOM lock before performing any device I/O. */ 676 int rc = iomLock(pVM); 677 #ifndef IN_RING3 678 if (rc == VERR_SEM_BUSY) 679 return VINF_IOM_HC_IOPORT_WRITE; 680 #endif 681 AssertRC(rc); 682 592 683 #ifdef LOG_ENABLED 593 684 const RTGCUINTREG cTransfers = *pcTransfers; … … 630 721 STAM_COUNTER_INC(&pStats->CTX_MID_Z(Out,ToR3)); 631 722 # endif 723 iomUnlock(pVM); 632 724 return VINF_IOM_HC_IOPORT_WRITE; 633 725 } … … 651 743 Log3(("IOMIOPortWriteStr: Port=%RTiop pGCPtrSrc=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=%Rrc\n", 652 744 Port, pGCPtrSrc, pcTransfers, cTransfers, *pcTransfers, cb, rc)); 745 iomUnlock(pVM); 653 746 return rc; 654 747 } … … 665 758 STAM_COUNTER_INC(&pStats->CTX_MID_Z(Out,ToR3)); 666 759 # endif 760 iomUnlock(pVM); 667 761 return VINF_IOM_HC_IOPORT_WRITE; 668 762 } … … 679 773 # ifndef IN_RING3 680 774 /* Ring-3 will have to create the statistics record. */ 775 iomUnlock(pVM); 681 776 return VINF_IOM_HC_IOPORT_WRITE; 682 777 # else … … 690 785 Log3(("IOMIOPortWriteStr: Port=%RTiop pGCPtrSrc=%p pcTransfer=%p:{%#x->%#x} cb=%d rc=VINF_SUCCESS\n", 691 786 Port, pGCPtrSrc, pcTransfers, cTransfers, *pcTransfers, cb)); 787 iomUnlock(pVM); 692 788 return VINF_SUCCESS; 693 789 }
Note:
See TracChangeset
for help on using the changeset viewer.