Changeset 88530 in vbox
- Timestamp:
- Apr 15, 2021 12:05:36 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevLsiLogicSCSI.cpp
r87164 r88530 345 345 uint32_t u32Padding3; 346 346 347 /** Critical section protecting the memory regions. */ 348 RTCRITSECT CritSectMemRegns; 347 349 /** List of memory regions - PLSILOGICMEMREGN. */ 348 350 RTLISTANCHORR3 ListMemRegns; … … 601 603 pThis->u32DiagMemAddr = 0; 602 604 603 lsilogicR3ConfigurationPagesFree(pThis, pThisCC);604 605 lsilogicR3InitializeConfigurationPages(pDevIns, pThis, pThisCC); 605 606 606 607 /* Mark that we finished performing the reset. */ 607 608 pThis->enmState = LSILOGICSTATE_READY; 609 return VINF_SUCCESS; 610 } 611 612 /** 613 * Allocates the configuration pages based on the device. 614 * 615 * @returns nothing. 616 * @param pThis Pointer to the shared LsiLogic device state. 617 * @param pThisCC Pointer to the ring-3 LsiLogic device state. 618 */ 619 static int lsilogicR3ConfigurationPagesAlloc(PLSILOGICSCSI pThis, PLSILOGICSCSICC pThisCC) 620 { 621 pThisCC->pConfigurationPages = (PMptConfigurationPagesSupported)RTMemAllocZ(sizeof(MptConfigurationPagesSupported)); 622 if (!pThisCC->pConfigurationPages) 623 return VERR_NO_MEMORY; 624 625 if (pThis->enmCtrlType == LSILOGICCTRLTYPE_SCSI_SAS) 626 { 627 PMptConfigurationPagesSas pPages = &pThisCC->pConfigurationPages->u.SasPages; 628 629 pPages->cbManufacturingPage7 = LSILOGICSCSI_MANUFACTURING7_GET_SIZE(pThis->cPorts); 630 PMptConfigurationPageManufacturing7 pManufacturingPage7 = (PMptConfigurationPageManufacturing7)RTMemAllocZ(pPages->cbManufacturingPage7); 631 AssertPtrReturn(pManufacturingPage7, VERR_NO_MEMORY); 632 pPages->pManufacturingPage7 = pManufacturingPage7; 633 634 /* SAS I/O unit page 0 - Port specific information. */ 635 pPages->cbSASIOUnitPage0 = LSILOGICSCSI_SASIOUNIT0_GET_SIZE(pThis->cPorts); 636 PMptConfigurationPageSASIOUnit0 pSASPage0 = (PMptConfigurationPageSASIOUnit0)RTMemAllocZ(pPages->cbSASIOUnitPage0); 637 AssertPtrReturn(pSASPage0, VERR_NO_MEMORY); 638 pPages->pSASIOUnitPage0 = pSASPage0; 639 640 /* SAS I/O unit page 1 - Port specific settings. */ 641 pPages->cbSASIOUnitPage1 = LSILOGICSCSI_SASIOUNIT1_GET_SIZE(pThis->cPorts); 642 PMptConfigurationPageSASIOUnit1 pSASPage1 = (PMptConfigurationPageSASIOUnit1)RTMemAllocZ(pPages->cbSASIOUnitPage1); 643 AssertPtrReturn(pSASPage1, VERR_NO_MEMORY); 644 pPages->pSASIOUnitPage1 = pSASPage1; 645 646 pPages->cPHYs = pThis->cPorts; 647 pPages->paPHYs = (PMptPHY)RTMemAllocZ(pPages->cPHYs * sizeof(MptPHY)); 648 AssertPtrReturn(pPages->paPHYs, VERR_NO_MEMORY); 649 650 /* Initialize the PHY configuration */ 651 for (unsigned i = 0; i < pThis->cPorts; i++) 652 { 653 /* Settings for present devices. */ 654 if (pThisCC->paDeviceStates[i].pDrvBase) 655 { 656 PMptSASDevice pSASDevice = (PMptSASDevice)RTMemAllocZ(sizeof(MptSASDevice)); 657 AssertPtrReturn(pSASDevice, VERR_NO_MEMORY); 658 659 /* Link into device list. */ 660 if (!pPages->cDevices) 661 { 662 pPages->pSASDeviceHead = pSASDevice; 663 pPages->pSASDeviceTail = pSASDevice; 664 pPages->cDevices = 1; 665 } 666 else 667 { 668 pSASDevice->pPrev = pPages->pSASDeviceTail; 669 pPages->pSASDeviceTail->pNext = pSASDevice; 670 pPages->pSASDeviceTail = pSASDevice; 671 pPages->cDevices++; 672 } 673 } 674 } 675 } 676 608 677 return VINF_SUCCESS; 609 678 } … … 642 711 if (pSasPages->pSASIOUnitPage1) 643 712 RTMemFree(pSasPages->pSASIOUnitPage1); 713 714 pSasPages->pSASDeviceHead = NULL; 715 pSasPages->paPHYs = NULL; 716 pSasPages->pManufacturingPage7 = NULL; 717 pSasPages->pSASIOUnitPage0 = NULL; 718 pSasPages->pSASIOUnitPage1 = NULL; 644 719 } 645 720 646 721 RTMemFree(pThisCC->pConfigurationPages); 722 pThisCC->pConfigurationPages = NULL; 647 723 } 648 724 } … … 884 960 static void lsilogicR3DiagRegDataWrite(PLSILOGICSCSI pThis, PLSILOGICSCSICC pThisCC, uint32_t u32Data) 885 961 { 962 RTCritSectEnter(&pThisCC->CritSectMemRegns); 963 886 964 PLSILOGICMEMREGN pRegion = lsilogicR3MemRegionFindByAddr(pThisCC, pThis->u32DiagMemAddr); 887 888 965 if (pRegion) 889 966 { … … 960 1037 /* Memory access is always 32bit big. */ 961 1038 pThis->u32DiagMemAddr += sizeof(uint32_t); 1039 RTCritSectLeave(&pThisCC->CritSectMemRegns); 962 1040 } 963 1041 … … 972 1050 static void lsilogicR3DiagRegDataRead(PLSILOGICSCSI pThis, PLSILOGICSCSICC pThisCC, uint32_t *pu32Data) 973 1051 { 1052 RTCritSectEnter(&pThisCC->CritSectMemRegns); 1053 974 1054 PLSILOGICMEMREGN pRegion = lsilogicR3MemRegionFindByAddr(pThisCC, pThis->u32DiagMemAddr); 975 976 1055 if (pRegion) 977 1056 { … … 990 1069 /* Memory access is always 32bit big. */ 991 1070 pThis->u32DiagMemAddr += sizeof(uint32_t); 1071 RTCritSectLeave(&pThisCC->CritSectMemRegns); 992 1072 } 993 1073 … … 1123 1203 1124 1204 /* Check for a valid firmware image in the IOC memory which was downloaded by the guest earlier and use that. */ 1205 RTCritSectEnter(&pThisCC->CritSectMemRegns); 1125 1206 PLSILOGICMEMREGN pRegion = lsilogicR3MemRegionFindByAddr(pThisCC, LSILOGIC_FWIMGHDR_LOAD_ADDRESS); 1126 1207 if (pRegion) … … 1146 1227 } 1147 1228 } 1229 RTCritSectLeave(&pThisCC->CritSectMemRegns); 1148 1230 break; 1149 1231 } … … 3419 3501 3420 3502 /* Manufacturing Page 7 - Connector settings. */ 3421 pPages->cbManufacturingPage7 = LSILOGICSCSI_MANUFACTURING7_GET_SIZE(pThis->cPorts); 3422 PMptConfigurationPageManufacturing7 pManufacturingPage7 = (PMptConfigurationPageManufacturing7)RTMemAllocZ(pPages->cbManufacturingPage7); 3503 PMptConfigurationPageManufacturing7 pManufacturingPage7 = pPages->pManufacturingPage7; 3423 3504 AssertPtr(pManufacturingPage7); 3505 3424 3506 MPT_CONFIG_PAGE_HEADER_INIT_MANUFACTURING(pManufacturingPage7, 3425 3507 0, 7, … … 3431 3513 pManufacturingPage7->u.fields.Header.u8PageLength = pPages->cbManufacturingPage7 / 4; 3432 3514 pManufacturingPage7->u.fields.u8NumPhys = pThis->cPorts; 3433 pPages->pManufacturingPage7 = pManufacturingPage7;3434 3515 3435 3516 /* SAS I/O unit page 0 - Port specific information. */ 3436 pPages->cbSASIOUnitPage0 = LSILOGICSCSI_SASIOUNIT0_GET_SIZE(pThis->cPorts); 3437 PMptConfigurationPageSASIOUnit0 pSASPage0 = (PMptConfigurationPageSASIOUnit0)RTMemAllocZ(pPages->cbSASIOUnitPage0); 3517 PMptConfigurationPageSASIOUnit0 pSASPage0 = pPages->pSASIOUnitPage0; 3438 3518 AssertPtr(pSASPage0); 3439 3519 … … 3445 3525 3446 3526 /* SAS I/O unit page 1 - Port specific settings. */ 3447 pPages->cbSASIOUnitPage1 = LSILOGICSCSI_SASIOUNIT1_GET_SIZE(pThis->cPorts); 3448 PMptConfigurationPageSASIOUnit1 pSASPage1 = (PMptConfigurationPageSASIOUnit1)RTMemAllocZ(pPages->cbSASIOUnitPage1); 3527 PMptConfigurationPageSASIOUnit1 pSASPage1 = pPages->pSASIOUnitPage1; 3449 3528 AssertPtr(pSASPage1); 3450 3529 … … 3455 3534 pSASPage1->u.fields.u16ControlFlags = 0; 3456 3535 pSASPage1->u.fields.u16AdditionalControlFlags = 0; 3457 pPages->pSASIOUnitPage1 = pSASPage1;3458 3536 3459 3537 /* SAS I/O unit page 2 - Port specific information. */ … … 3471 3549 pPages->SASIOUnitPage3.u.fields.ExtHeader.u16ExtPageLength = sizeof(MptConfigurationPageSASIOUnit3) / 4; 3472 3550 3473 pPages->cPHYs = pThis->cPorts; 3474 pPages->paPHYs = (PMptPHY)RTMemAllocZ(pPages->cPHYs * sizeof(MptPHY)); 3551 Assert(pPages->cPHYs == pThis->cPorts); 3475 3552 AssertPtr(pPages->paPHYs); 3476 3553 3477 3554 /* Initialize the PHY configuration */ 3555 PMptSASDevice pSASDevice = pPages->pSASDeviceHead; 3478 3556 for (unsigned i = 0; i < pThis->cPorts; i++) 3479 3557 { … … 3524 3602 uint16_t u16DeviceHandle = lsilogicGetHandle(pThis); 3525 3603 SASADDRESS SASAddress; 3526 PMptSASDevice pSASDevice = (PMptSASDevice)RTMemAllocZ(sizeof(MptSASDevice));3527 3604 AssertPtr(pSASDevice); 3528 3605 … … 3582 3659 pSASDevice->SASDevicePage2.u.fields.SASAddress = SASAddress; 3583 3660 3584 /* Link into device list. */ 3585 if (!pPages->cDevices) 3586 { 3587 pPages->pSASDeviceHead = pSASDevice; 3588 pPages->pSASDeviceTail = pSASDevice; 3589 pPages->cDevices = 1; 3590 } 3591 else 3592 { 3593 pSASDevice->pPrev = pPages->pSASDeviceTail; 3594 pPages->pSASDeviceTail->pNext = pSASDevice; 3595 pPages->pSASDeviceTail = pSASDevice; 3596 pPages->cDevices++; 3597 } 3661 pSASDevice = pSASDevice->pNext; 3598 3662 } 3599 3663 } … … 3611 3675 { 3612 3676 /* Initialize the common pages. */ 3613 PMptConfigurationPagesSupported pPages = (PMptConfigurationPagesSupported)RTMemAllocZ(sizeof(MptConfigurationPagesSupported));3614 /** @todo r=bird: Missing alloc failure check. Why do we allocate this3615 * structure? It's fixed size... */3616 3617 pThisCC->pConfigurationPages = pPages;3618 3677 3619 3678 LogFlowFunc(("pThis=%#p\n", pThis)); 3620 3679 3621 3680 /* Clear everything first. */ 3681 AssertPtrReturnVoid(pThisCC->pConfigurationPages); 3682 PMptConfigurationPagesSupported pPages = pThisCC->pConfigurationPages; 3622 3683 memset(pPages, 0, sizeof(MptConfigurationPagesSupported)); 3623 3684 … … 5148 5209 PDMDevHlpCritSectDelete(pDevIns, &pThis->ReplyFreeQueueWriteCritSect); 5149 5210 5211 if (RTCritSectIsInitialized(&pThisCC->CritSectMemRegns)) 5212 RTCritSectDelete(&pThisCC->CritSectMemRegns); 5213 5150 5214 RTMemFree(pThisCC->paDeviceStates); 5151 5215 pThisCC->paDeviceStates = NULL; … … 5310 5374 if (RT_FAILURE(rc)) 5311 5375 return PDMDEV_SET_ERROR(pDevIns, rc, N_("LsiLogic: cannot create critical section for reply free queue write access")); 5376 5377 /* 5378 * Critical section protecting the memory regions. 5379 */ 5380 rc = RTCritSectInit(&pThisCC->CritSectMemRegns); 5381 if (RT_FAILURE(rc)) 5382 return PDMDEV_SET_ERROR(pDevIns, rc, N_("LsiLogic: Failed to initialize critical section protecting the memory regions")); 5312 5383 5313 5384 /* … … 5534 5605 ? "LsiLogic SPI info." 5535 5606 : "LsiLogic SAS info.", lsilogicR3Info); 5607 5608 /* Allocate configuration pages. */ 5609 rc = lsilogicR3ConfigurationPagesAlloc(pThis, pThisCC); 5610 if (RT_FAILURE(rc)) 5611 PDMDEV_SET_ERROR(pDevIns, rc, N_("LsiLogic: Failed to allocate memory for configuration pages")); 5536 5612 5537 5613 /* Perform hard reset. */
Note:
See TracChangeset
for help on using the changeset viewer.

