VirtualBox

Ignore:
Timestamp:
Aug 14, 2024 1:16:30 PM (4 months ago)
Author:
vboxsync
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, 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/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c

    r101291 r105670  
    66
    77  Copyright (c) 2010 - 2023, Intel Corporation. All rights reserved.<BR>
    8   Copyright (c) 2017 - 2020, AMD Inc. All rights reserved.<BR>
     8  Copyright (c) 2017 - 2024, AMD Inc. All rights reserved.<BR>
    99
    1010  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    12951295      );
    12961296    //
    1297     // If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for
    1298     // basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not
    1299     // supported on that processor.
    1300     //
    1301     if (ExtendedTopologyEbx.Uint32 != 0) {
     1297    // Quoting Intel SDM:
     1298    // Software must detect the presence of CPUID leaf 0BH by
     1299    // verifying (a) the highest leaf index supported by CPUID is >=
     1300    // 0BH, and (b) CPUID.0BH:EBX[15:0] reports a non-zero value.
     1301    //
     1302    if (ExtendedTopologyEbx.Bits.LogicalProcessors != 0) {
    13021303      TopologyLeafSupported = TRUE;
    13031304
     
    13971398
    13981399/**
     1400  Get Package ID/Die ID/Module ID/Core ID/Thread ID of a AMD processor family.
     1401
     1402  The algorithm assumes the target system has symmetry across physical
     1403  package boundaries with respect to the number of threads per core, number of
     1404  cores per module, number of modules per die, number
     1405  of dies per package.
     1406
     1407  @param[in]   InitialApicId Initial APIC ID of the target logical processor.
     1408  @param[out]  Package       Returns the processor package ID.
     1409  @param[out]  Die           Returns the processor die ID.
     1410  @param[out]  Tile          Returns zero.
     1411  @param[out]  Module        Returns the processor module ID.
     1412  @param[out]  Core          Returns the processor core ID.
     1413  @param[out]  Thread        Returns the processor thread ID.
     1414**/
     1415VOID
     1416AmdGetProcessorLocation2ByApicId (
     1417  IN  UINT32  InitialApicId,
     1418  OUT UINT32  *Package  OPTIONAL,
     1419  OUT UINT32  *Die      OPTIONAL,
     1420  OUT UINT32  *Tile     OPTIONAL,
     1421  OUT UINT32  *Module   OPTIONAL,
     1422  OUT UINT32  *Core     OPTIONAL,
     1423  OUT UINT32  *Thread   OPTIONAL
     1424  )
     1425{
     1426  CPUID_EXTENDED_TOPOLOGY_EAX  ExtendedTopologyEax;
     1427  CPUID_EXTENDED_TOPOLOGY_EBX  ExtendedTopologyEbx;
     1428  CPUID_EXTENDED_TOPOLOGY_ECX  ExtendedTopologyEcx;
     1429  UINT32                       MaxExtendedCpuIdIndex;
     1430  UINT32                       TopologyLevel;
     1431  UINT32                       PreviousLevel;
     1432  UINT32                       Data;
     1433
     1434  if (Die != NULL) {
     1435    *Die = 0;
     1436  }
     1437
     1438  if (Tile != NULL) {
     1439    *Tile = 0;
     1440  }
     1441
     1442  if (Module != NULL) {
     1443    *Module = 0;
     1444  }
     1445
     1446  PreviousLevel = 0;
     1447  TopologyLevel = 0;
     1448
     1449  /// Check if extended toplogy supported
     1450  AsmCpuid (CPUID_EXTENDED_FUNCTION, &MaxExtendedCpuIdIndex, NULL, NULL, NULL);
     1451  if (MaxExtendedCpuIdIndex >= AMD_CPUID_EXTENDED_TOPOLOGY) {
     1452    do {
     1453      AsmCpuidEx (
     1454        AMD_CPUID_EXTENDED_TOPOLOGY,
     1455        TopologyLevel,
     1456        &ExtendedTopologyEax.Uint32,
     1457        &ExtendedTopologyEbx.Uint32,
     1458        &ExtendedTopologyEcx.Uint32,
     1459        NULL
     1460        );
     1461
     1462      if (ExtendedTopologyEbx.Bits.LogicalProcessors == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID) {
     1463        /// if this fails at first level
     1464        /// then will fall back to non-extended topology
     1465        break;
     1466      }
     1467
     1468      Data  = InitialApicId >> PreviousLevel;
     1469      Data &= (1 << (ExtendedTopologyEax.Bits.ApicIdShift - PreviousLevel)) - 1;
     1470
     1471      switch (ExtendedTopologyEcx.Bits.LevelType) {
     1472        case CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT:
     1473          if (Thread != NULL) {
     1474            *Thread = Data;
     1475          }
     1476
     1477          break;
     1478        case CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE:
     1479          if (Core != NULL) {
     1480            *Core = Data;
     1481          }
     1482
     1483          break;
     1484        case CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_MODULE:
     1485          if (Module != NULL) {
     1486            *Module = Data;
     1487          }
     1488
     1489          break;
     1490        case CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE:
     1491          if (Die != NULL) {
     1492            *Die = Data;
     1493          }
     1494
     1495          break;
     1496        default:
     1497          break;
     1498      }
     1499
     1500      TopologyLevel++;
     1501      PreviousLevel = ExtendedTopologyEax.Bits.ApicIdShift;
     1502    } while (ExtendedTopologyEbx.Bits.LogicalProcessors != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID);
     1503
     1504    if (Package != NULL) {
     1505      *Package = InitialApicId >> PreviousLevel;
     1506    }
     1507  }
     1508
     1509  /// If extended topology CPUID is not supported
     1510  /// OR, execution of AMD_CPUID_EXTENDED_TOPOLOGY at level 0 fails(return 0).
     1511  if (TopologyLevel == 0) {
     1512    GetProcessorLocationByApicId (InitialApicId, Package, Core, Thread);
     1513  }
     1514
     1515  return;
     1516}
     1517
     1518/**
    13991519  Get Package ID/Die ID/Tile ID/Module ID/Core ID/Thread ID of a processor.
    14001520
     
    14251545{
    14261546  CPUID_EXTENDED_TOPOLOGY_EAX  ExtendedTopologyEax;
     1547  CPUID_EXTENDED_TOPOLOGY_EBX  ExtendedTopologyEbx;
    14271548  CPUID_EXTENDED_TOPOLOGY_ECX  ExtendedTopologyEcx;
    14281549  UINT32                       MaxStandardCpuIdIndex;
     
    14321553  UINT32                       *Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
    14331554
     1555  if (StandardSignatureIsAuthenticAMD ()) {
     1556    AmdGetProcessorLocation2ByApicId (InitialApicId, Package, Die, Tile, Module, Core, Thread);
     1557    return;
     1558  }
     1559
    14341560  for (LevelType = 0; LevelType < ARRAY_SIZE (Bits); LevelType++) {
    14351561    Bits[LevelType] = 0;
     
    14371563
    14381564  //
    1439   // Get max index of CPUID
     1565  // Quoting Intel SDM:
     1566  // Software must detect the presence of CPUID leaf 1FH by verifying
     1567  // (a) the highest leaf index supported by CPUID is >= 1FH, and (b)
     1568  // CPUID.1FH:EBX[15:0] reports a non-zero value.
    14401569  //
    14411570  AsmCpuid (CPUID_SIGNATURE, &MaxStandardCpuIdIndex, NULL, NULL, NULL);
    14421571  if (MaxStandardCpuIdIndex < CPUID_V2_EXTENDED_TOPOLOGY) {
     1572    ExtendedTopologyEbx.Bits.LogicalProcessors = 0;
     1573  } else {
     1574    AsmCpuidEx (CPUID_V2_EXTENDED_TOPOLOGY, 0, NULL, &ExtendedTopologyEbx.Uint32, NULL, NULL);
     1575  }
     1576
     1577  if (ExtendedTopologyEbx.Bits.LogicalProcessors == 0) {
    14431578    if (Die != NULL) {
    14441579      *Die = 0;
Note: See TracChangeset for help on using the changeset viewer.

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