Changeset 79535 in vbox
- Timestamp:
- Jul 5, 2019 6:05:14 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp
r79494 r79535 71 71 bool fPresent; 72 72 73 /** Media port interface. */ 74 PDMIMEDIAPORT IMediaPort; 75 /** Extended media port interface. */ 76 PDMIMEDIAEXPORT IMediaExPort; 73 77 /** Led interface. */ 74 78 PDMILEDPORTS ILed; … … 76 80 /** The status LED state for this device. */ 77 81 PDMLED Led; 82 83 /** Number of outstanding tasks on the port. */ 84 volatile uint32_t cOutstandingRequests; 78 85 79 86 } VIRTIOSCSITARGET; … … 132 139 RTGCPHYS MMIOBase; 133 140 141 /** Status LUN: Media Notifys. */ 142 R3PTRTYPE(PPDMIMEDIANOTIFY) pMediaNotify; 143 134 144 /** Partner of ILeds. */ 135 145 R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector; 146 147 /** Indicates that PDMDevHlpAsyncNotificationCompleted should be called when 148 * a port is entering the idle state. */ 149 bool volatile fSignalIdle; 136 150 137 151 } VIRTIOSCSI, *PVIRTIOSCSI; … … 293 307 Assert(cb == 1); 294 308 295 // return buslogicRegisterRead(p BusLogic, iRegister, pu32);309 // return buslogicRegisterRead(pVirtioScsi, iRegister, pu32); 296 310 return 0; 297 311 } … … 321 335 Assert(cb == 1); 322 336 323 // int rc = buslogicRegisterWrite(p BusLogic, iRegister, (uint8_t)uVal);337 // int rc = buslogicRegisterWrite(pVirtioScsi, iRegister, (uint8_t)uVal); 324 338 int rc = 0; 325 339 Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x uPort=%#x rc=%Rrc\n", … … 332 346 * @callback_method_impl{FNPCIIOREGIONMAP} 333 347 */ 334 static DECLCALLBACK(int) devVirtioScsiR3MmioMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,348 static DECLCALLBACK(int) virtioScsiR3MmioMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, 335 349 RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType) 336 350 { … … 416 430 PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[i]; 417 431 pTarget->pVirtioScsiR3 = pThis;; 418 419 } 420 421 } 432 } 433 434 } 435 436 static DECLCALLBACK(int) virtioScsiR3QueryDeviceLocation(PPDMIMEDIAPORT pInterface, const char **ppcszController, 437 uint32_t *piInstance, uint32_t *piLUN) 438 { 439 PVIRTIOSCSITARGET pVirtioScsiTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaPort); 440 PPDMDEVINS pDevIns = pVirtioScsiTarget->CTX_SUFF(pVirtioScsi)->CTX_SUFF(pDevIns); 441 442 AssertPtrReturn(ppcszController, VERR_INVALID_POINTER); 443 AssertPtrReturn(piInstance, VERR_INVALID_POINTER); 444 AssertPtrReturn(piLUN, VERR_INVALID_POINTER); 445 446 *ppcszController = pDevIns->pReg->szName; 447 *piInstance = pDevIns->iInstance; 448 *piLUN = pVirtioScsiTarget->iLUN; 449 450 return VINF_SUCCESS; 451 } 452 453 /** 454 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyFromBuf} 455 */ 456 static DECLCALLBACK(int) virtioScsiR3IoReqCopyFromBuf(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq, 457 void *pvIoReqAlloc, uint32_t offDst, PRTSGBUF pSgBuf, 458 size_t cbCopy) 459 { 460 NOREF(pInterface); 461 NOREF(pvIoReqAlloc); 462 NOREF(offDst); 463 NOREF(pSgBuf); 464 465 RT_NOREF1(hIoReq); 466 // PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort); 467 // PVIRTIOSCSIREQ pReq = (PVIRTIOSCSIREQ)pvIoReqAlloc; 468 469 size_t cbCopied = 0; 470 /* 471 if (RT_UNLIKELY(pReq->fBIOS)) 472 cbCopied = vboxscsiCopyToBuf(&pTarget->CTX_SUFF(pVirtioScsi)->VBoxSCSI, pSgBuf, offDst, cbCopy); 473 else 474 cbCopied = virtioScsiR3CopySgBufToGuest(pTarget->CTX_SUFF(pVirtioScsi), pReq, pSgBuf, offDst, cbCopy); 475 */ 476 return cbCopied == cbCopy ? VINF_SUCCESS : VERR_PDM_MEDIAEX_IOBUF_OVERFLOW; 477 } 478 479 /** 480 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyToBuf} 481 */ 482 static DECLCALLBACK(int) virtioScsiR3IoReqCopyToBuf(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq, 483 void *pvIoReqAlloc, uint32_t offSrc, PRTSGBUF pSgBuf, 484 size_t cbCopy) 485 { 486 NOREF(pInterface); 487 NOREF(pvIoReqAlloc); 488 NOREF(offSrc); 489 NOREF(pSgBuf); 490 491 RT_NOREF1(hIoReq); 492 // PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort); 493 // PVIRTIOSCSIREQ pReq = (PVIRTIOSCSIREQ)pvIoReqAlloc; 494 495 size_t cbCopied = 0; 496 /* 497 if (RT_UNLIKELY(pReq->fBIOS)) 498 cbCopied = vboxscsiCopyFromBuf(&pTarget->CTX_SUFF(pVirtioScsi)->VBoxSCSI, pSgBuf, offSrc, cbCopy); 499 else 500 cbCopied = vboxscsiR3CopySgBufFromGuest(pTarget->CTX_SUFF(pVirtioScsi), pReq, pSgBuf, offSrc, cbCopy); 501 */ 502 return cbCopied == cbCopy ? VINF_SUCCESS : VERR_PDM_MEDIAEX_IOBUF_UNDERRUN; 503 } 504 505 /** 506 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCompleteNotify} 507 */ 508 static DECLCALLBACK(int) virtioScsiR3IoReqCompleteNotify(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq, 509 void *pvIoReqAlloc, int rcReq) 510 { 511 NOREF(pInterface); 512 NOREF(pvIoReqAlloc); 513 NOREF(rcReq); 514 RT_NOREF(hIoReq); 515 // PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort); 516 // virtioScsiR3ReqComplete(pTarget->CTX_SUFF(pVirtioScsi), (VIRTIOSCSIREQ)pvIoReqAlloc, rcReq); 517 return VINF_SUCCESS; 518 } 519 520 /** 521 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqStateChanged} 522 */ 523 static DECLCALLBACK(void) virtioScsiR3IoReqStateChanged(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq, 524 void *pvIoReqAlloc, PDMMEDIAEXIOREQSTATE enmState) 525 { 526 527 NOREF(pInterface); 528 NOREF(hIoReq); 529 NOREF(enmState); 530 RT_NOREF3(hIoReq, pvIoReqAlloc, enmState); 531 PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort); 532 533 switch (enmState) 534 { 535 case PDMMEDIAEXIOREQSTATE_SUSPENDED: 536 { 537 /* Make sure the request is not accounted for so the VM can suspend successfully. */ 538 uint32_t cTasksActive = ASMAtomicDecU32(&pTarget->cOutstandingRequests); 539 if (!cTasksActive && pTarget->CTX_SUFF(pVirtioScsi)->fSignalIdle) 540 PDMDevHlpAsyncNotificationCompleted(pTarget->CTX_SUFF(pVirtioScsi)->pDevInsR3); 541 break; 542 } 543 case PDMMEDIAEXIOREQSTATE_ACTIVE: 544 /* Make sure the request is accounted for so the VM suspends only when the request is complete. */ 545 ASMAtomicIncU32(&pTarget->cOutstandingRequests); 546 break; 547 default: 548 AssertMsgFailed(("Invalid request state given %u\n", enmState)); 549 } 550 } 551 552 /** 553 * Gets the pointer to the status LED of a device - called from the SCSI driver. 554 * 555 * @returns VBox status code. 556 * @param pInterface Pointer to the interface structure containing the called function pointer. 557 * @param iLUN The unit which status LED we desire. Always 0 here as the driver 558 * doesn't know about other LUN's. 559 * @param ppLed Where to store the LED pointer. 560 */ 561 static DECLCALLBACK(int) virtioScsiR3DeviceQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed) 562 { 563 PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, ILed); 564 if (iLUN == 0) 565 { 566 *ppLed = &pTarget->Led; 567 Assert((*ppLed)->u32Magic == PDMLED_MAGIC); 568 return VINF_SUCCESS; 569 } 570 return VERR_PDM_LUN_NOT_FOUND; 571 } 572 573 /** 574 * @interface_method_impl{PDMIMEDIAEXPORT,pfnMediumEjected} 575 */ 576 static DECLCALLBACK(void) virtioScsiR3MediumEjected(PPDMIMEDIAEXPORT pInterface) 577 { 578 PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort); 579 PVIRTIOSCSI pThis = pTarget->CTX_SUFF(pVirtioScsi); 580 581 if (pThis->pMediaNotify) 582 { 583 int rc = VMR3ReqCallNoWait(PDMDevHlpGetVM(pThis->CTX_SUFF(pDevIns)), VMCPUID_ANY, 584 (PFNRT)pThis->pMediaNotify->pfnEjected, 2, 585 pThis->pMediaNotify, pTarget->iLUN); 586 AssertRC(rc); 587 } 588 } 589 422 590 423 591 /** … … 428 596 PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IBase); 429 597 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pTarget->IBase); 430 //PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pTarget->IMediaPort);431 //PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAEXPORT, &pTarget->IMediaExPort);598 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pTarget->IMediaPort); 599 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAEXPORT, &pTarget->IMediaExPort); 432 600 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pTarget->ILed); 433 601 return NULL; … … 454 622 } 455 623 456 static DECLCALLBACK(int) devVirtIoScsiDestruct(PPDMDEVINS pDevIns)624 static DECLCALLBACK(int) virtioScsiDestruct(PPDMDEVINS pDevIns) 457 625 { 458 626 /* … … 464 632 } 465 633 466 static DECLCALLBACK(int) devVirtioScsiConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)634 static DECLCALLBACK(int) virtioScsiConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 467 635 { 468 636 … … 531 699 532 700 LogFunc(("Register io region\n")); 533 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 32, PCI_ADDRESS_SPACE_IO, devVirtioScsiR3MmioMap);701 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 32, PCI_ADDRESS_SPACE_IO, virtioScsiR3MmioMap); 534 702 if (RT_FAILURE(rc)) 535 703 return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi cannot register PCI I/O address space")); 536 704 LogFunc(("Register mmio region\n")); 537 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, 32, PCI_ADDRESS_SPACE_MEM, devVirtioScsiR3MmioMap);705 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, 32, PCI_ADDRESS_SPACE_MEM, virtioScsiR3MmioMap); 538 706 if (RT_FAILURE(rc)) 539 707 return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi cannot register PCI mmio address space")); 540 541 708 #if 0 542 709 if (fBootable) … … 551 718 } 552 719 #endif 553 554 720 /* Initialize task queue. */ 555 721 rc = PDMDevHlpQueueCreate(pDevIns, sizeof(PDMQUEUEITEMCORE), 5, 0, … … 576 742 pTarget->Led.u32Magic = PDMLED_MAGIC; 577 743 pTarget->IBase.pfnQueryInterface = virtioScsiR3DeviceQueryInterface; 578 /*pTarget->IMediaPort.pfnQueryDeviceLocation = virtioScsiR3QueryDeviceLocation;744 pTarget->IMediaPort.pfnQueryDeviceLocation = virtioScsiR3QueryDeviceLocation; 579 745 pTarget->IMediaExPort.pfnIoReqCompleteNotify = virtioScsiR3IoReqCompleteNotify; 580 746 pTarget->IMediaExPort.pfnIoReqCopyFromBuf = virtioScsiR3IoReqCopyFromBuf; … … 585 751 pTarget->IMediaExPort.pfnMediumEjected = virtioScsiR3MediumEjected; 586 752 pTarget->ILed.pfnQueryStatusLed = virtioScsiR3DeviceQueryStatusLed; 587 */ 753 588 754 LogFunc(("Attaching: Lun=%d, pszName=%s\n", pTarget->iLUN, pszName)); 589 755 /* Attach SCSI driver. */ … … 606 772 } 607 773 608 #if 0609 774 /* 610 775 * Attach status driver (optional). 611 776 */ 612 777 /* 613 778 PPDMIBASE pBase; 614 779 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port"); … … 620 785 return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi cannot attach to status driver")); 621 786 } 622 #endif 623 787 */ 624 788 rc = PDMDevHlpSSMRegisterEx(pDevIns, VIRTIOSCSI_SAVED_STATE_MINOR_VERSION, sizeof(*pThis), NULL, 625 789 NULL, virtioScsiR3LiveExec, NULL, … … 649 813 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines. 650 814 */ 651 static DECLCALLBACK(void) devVirtioScsiR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)815 static DECLCALLBACK(void) virtioScsiR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags) 652 816 { 653 817 RT_NOREF(fFlags); … … 678 842 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines. 679 843 */ 680 static DECLCALLBACK(int) devVirtioScsiR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)844 static DECLCALLBACK(int) virtioScsiR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags) 681 845 { 682 846 PVIRTIOSCSI pThis = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI); … … 737 901 sizeof(VIRTIOSCSI), 738 902 /* pfnConstruct */ 739 devVirtioScsiConstruct,903 virtioScsiConstruct, 740 904 /* pfnDestruct */ 741 devVirtIoScsiDestruct,905 virtioScsiDestruct, 742 906 /* pfnRelocate */ 743 907 virtioScsiR3Relocate, … … 753 917 NULL, 754 918 /* pfnAttach */ 755 devVirtioScsiR3Attach,919 virtioScsiR3Attach, 756 920 /* pfnDetach */ 757 devVirtioScsiR3Detach,921 virtioScsiR3Detach, 758 922 /* pfnQueryInterface */ 759 923 NULL,
Note:
See TracChangeset
for help on using the changeset viewer.