VirtualBox

Ignore:
Timestamp:
Mar 31, 2025 11:31:09 AM (2 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168237
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c

    r101291 r108794  
    9696  UINTN                      ProcessorNumber;
    9797  EFI_PROCESSOR_INFORMATION  ProcessorInfoBuffer;
     98  CPU_STATUS_INFORMATION     CpuStatusBackupBuffer;
    9899  CPU_FEATURES_ENTRY         *CpuFeature;
    99100  CPU_FEATURES_INIT_ORDER    *InitOrder;
     
    121122  Thread  = 0;
    122123
     124  CpuFeaturesData       = NULL;
     125  CpuStatus             = NULL;
     126  FirstCore             = NULL;
     127  InitOrder             = NULL;
     128  Location              = NULL;
     129  ThreadCountPerCore    = NULL;
     130  ThreadCountPerPackage = NULL;
     131
    123132  CpuFeaturesData = GetCpuFeaturesData ();
     133  if (CpuFeaturesData == NULL) {
     134    ASSERT (CpuFeaturesData != NULL);
     135    return;
     136  }
    124137
    125138  //
     
    131144
    132145  CpuFeaturesData->InitOrder = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (CPU_FEATURES_INIT_ORDER) * NumberOfCpus));
    133   ASSERT (CpuFeaturesData->InitOrder != NULL);
     146  if (CpuFeaturesData->InitOrder == NULL) {
     147    ASSERT (CpuFeaturesData->InitOrder != NULL);
     148    return;
     149  }
     150
    134151  ZeroMem (CpuFeaturesData->InitOrder, sizeof (CPU_FEATURES_INIT_ORDER) * NumberOfCpus);
    135152
     
    151168
    152169  AcpiCpuData = GetAcpiCpuData ();
    153   ASSERT (AcpiCpuData != NULL);
     170  if (AcpiCpuData == NULL) {
     171    ASSERT (AcpiCpuData != NULL);
     172    goto ExitOnError;
     173  }
     174
    154175  CpuFeaturesData->AcpiCpuData = AcpiCpuData;
    155176
    156177  CpuStatus = &AcpiCpuData->CpuFeatureInitData.CpuStatus;
    157   Location  = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));
    158   ASSERT (Location != NULL);
     178  CopyMem (&CpuStatusBackupBuffer, CpuStatus, sizeof (CpuStatusBackupBuffer));
     179  Location = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));
     180  if (Location == NULL) {
     181    ASSERT (Location != NULL);
     182    goto ExitOnError;
     183  }
     184
    159185  ZeroMem (Location, sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus);
    160186  AcpiCpuData->CpuFeatureInitData.ApLocation = (EFI_PHYSICAL_ADDRESS)(UINTN)Location;
     
    163189    InitOrder                        = &CpuFeaturesData->InitOrder[ProcessorNumber];
    164190    InitOrder->FeaturesSupportedMask = AllocateZeroPool (CpuFeaturesData->BitMaskSize);
    165     ASSERT (InitOrder->FeaturesSupportedMask != NULL);
     191    if (InitOrder->FeaturesSupportedMask == NULL) {
     192      ASSERT (InitOrder->FeaturesSupportedMask != NULL);
     193      goto ExitOnError;
     194    }
     195
    166196    InitializeListHead (&InitOrder->OrderList);
    167197    Status = GetProcessorInformation (ProcessorNumber, &ProcessorInfoBuffer);
     
    215245  //
    216246  ThreadCountPerPackage = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT32) * CpuStatus->PackageCount));
    217   ASSERT (ThreadCountPerPackage != NULL);
     247  if (ThreadCountPerPackage == NULL) {
     248    ASSERT (ThreadCountPerPackage != NULL);
     249    goto ExitOnError;
     250  }
     251
    218252  ZeroMem (ThreadCountPerPackage, sizeof (UINT32) * CpuStatus->PackageCount);
    219253  CpuStatus->ThreadCountPerPackage = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerPackage;
    220254
    221255  ThreadCountPerCore = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount));
    222   ASSERT (ThreadCountPerCore != NULL);
     256  if (ThreadCountPerCore == NULL) {
     257    ASSERT (ThreadCountPerCore != NULL);
     258    goto ExitOnError;
     259  }
     260
    223261  ZeroMem (ThreadCountPerCore, sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount);
    224262  CpuStatus->ThreadCountPerCore = (EFI_PHYSICAL_ADDRESS)(UINTN)ThreadCountPerCore;
     
    248286
    249287  CpuFeaturesData->CpuFlags.CoreSemaphoreCount = AllocateZeroPool (sizeof (UINT32) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount);
    250   ASSERT (CpuFeaturesData->CpuFlags.CoreSemaphoreCount != NULL);
     288  if (CpuFeaturesData->CpuFlags.CoreSemaphoreCount == NULL) {
     289    ASSERT (CpuFeaturesData->CpuFlags.CoreSemaphoreCount != NULL);
     290    goto ExitOnError;
     291  }
     292
    251293  CpuFeaturesData->CpuFlags.PackageSemaphoreCount = AllocateZeroPool (sizeof (UINT32) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount * CpuStatus->MaxThreadCount);
    252   ASSERT (CpuFeaturesData->CpuFlags.PackageSemaphoreCount != NULL);
     294  if (CpuFeaturesData->CpuFlags.PackageSemaphoreCount == NULL) {
     295    ASSERT (CpuFeaturesData->CpuFlags.PackageSemaphoreCount != NULL);
     296    goto ExitOnError;
     297  }
    253298
    254299  //
     
    258303  Pages     = EFI_SIZE_TO_PAGES (CpuStatus->PackageCount * sizeof (UINT32) + CpuStatus->PackageCount * CpuStatus->MaxCoreCount * sizeof (UINT32));
    259304  FirstCore = AllocatePages (Pages);
    260   ASSERT (FirstCore != NULL);
     305  if (FirstCore == NULL) {
     306    ASSERT (FirstCore != NULL);
     307    goto ExitOnError;
     308  }
     309
    261310  FirstThread = FirstCore + CpuStatus->PackageCount;
    262311
     
    318367
    319368  FreePages (FirstCore, Pages);
     369
     370  return;
     371
     372ExitOnError:
     373  if (FirstCore != NULL) {
     374    FreePages (FirstCore, Pages);
     375  }
     376
     377  if ((CpuFeaturesData != NULL) && (CpuFeaturesData->CpuFlags.PackageSemaphoreCount != NULL)) {
     378    FreePool ((VOID *)CpuFeaturesData->CpuFlags.PackageSemaphoreCount);
     379    CpuFeaturesData->CpuFlags.PackageSemaphoreCount = NULL;
     380  }
     381
     382  if ((CpuFeaturesData != NULL) && (CpuFeaturesData->CpuFlags.CoreSemaphoreCount != NULL)) {
     383    FreePool ((VOID *)CpuFeaturesData->CpuFlags.CoreSemaphoreCount);
     384    CpuFeaturesData->CpuFlags.CoreSemaphoreCount = NULL;
     385  }
     386
     387  if ((ThreadCountPerCore != NULL) && (CpuStatus != NULL)) {
     388    FreePages (
     389      ThreadCountPerCore,
     390      EFI_SIZE_TO_PAGES (sizeof (UINT8) * CpuStatus->PackageCount * CpuStatus->MaxCoreCount)
     391      );
     392  }
     393
     394  if ((ThreadCountPerPackage != NULL) && (CpuStatus != NULL)) {
     395    FreePages (
     396      ThreadCountPerPackage,
     397      EFI_SIZE_TO_PAGES (sizeof (UINT32) * CpuStatus->PackageCount)
     398      );
     399  }
     400
     401  if (InitOrder != NULL) {
     402    for (ProcessorNumber = 0; ProcessorNumber < NumberOfCpus; ProcessorNumber++) {
     403      InitOrder = &CpuFeaturesData->InitOrder[ProcessorNumber];
     404      if (InitOrder->FeaturesSupportedMask != NULL) {
     405        FreePool (InitOrder->FeaturesSupportedMask);
     406        InitOrder->FeaturesSupportedMask = NULL;
     407      }
     408    }
     409  }
     410
     411  if (Location != NULL) {
     412    FreePages (Location, EFI_SIZE_TO_PAGES (sizeof (EFI_CPU_PHYSICAL_LOCATION) * NumberOfCpus));
     413  }
     414
     415  if (CpuFeaturesData->InitOrder != NULL) {
     416    FreePages (CpuFeaturesData->InitOrder, EFI_SIZE_TO_PAGES (sizeof (CPU_FEATURES_INIT_ORDER) * NumberOfCpus));
     417    CpuFeaturesData->InitOrder = NULL;
     418  }
     419
     420  if (CpuStatus != NULL) {
     421    CopyMem (CpuStatus, &CpuStatusBackupBuffer, sizeof (*CpuStatus));
     422  }
    320423}
    321424
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette