Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c
VOID
InitializeRamRegions (
  VOID
  )
{
  EFI_STATUS           Status;
  FIRMWARE_CONFIG_ITEM FwCfgItem;
  UINTN                FwCfgSize;
  LOONGARCH_MEMMAP_ENTRY  MemoryMapEntry;
  LOONGARCH_MEMMAP_ENTRY  *StartEntry;
  LOONGARCH_MEMMAP_ENTRY  *pEntry;
  UINTN                Processed;

  Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __func__, __LINE__, Status));
    return ;
  }
  if (FwCfgSize % sizeof MemoryMapEntry != 0) {
    DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize));
    return ;
  }

  QemuFwCfgSelectItem (FwCfgItem);
  StartEntry = AllocatePages  (EFI_SIZE_TO_PAGES (FwCfgSize));
  QemuFwCfgReadBytes (FwCfgSize, StartEntry);
  for (Processed = 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); Processed++) {
    pEntry = StartEntry + Processed;
    if (pEntry->Length == 0) {
      continue;
    }

    DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p  type %d\n", pEntry->BaseAddr, pEntry->Length, pEntry->Type));
    if (pEntry->Type != EfiAcpiAddressRangeMemory) {
      continue;
    }

    AddMemoryRangeHob ( pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Length);
  }

  //
  // Lock the scope of the cache.
  //
  BuildMemoryAllocationHob (
    PcdGet64 (PcdSecPeiTempRamBase),
    PcdGet32 (PcdSecPeiTempRamSize),
    EfiACPIMemoryNVS
    );

  //
  // SEC stores its table of GUIDed section handlers here.
  //
  BuildMemoryAllocationHob (
    PcdGet64 (PcdGuidedExtractHandlerTableAddress),
    PcdGet32 (PcdGuidedExtractHandlerTableSize),
    EfiACPIMemoryNVS
    );
}
/**
  Peform Memory Detection
  Publish system RAM and reserve memory regions
**/
Peform Memory Detection
Publish system RAM and reserve memory regions
Peform Memory Detection Publish system RAM and reserve memory regions
VOID
InitializeRamRegions (
  VOID
  )
{
  EFI_STATUS           Status;
  FIRMWARE_CONFIG_ITEM FwCfgItem;
  UINTN                FwCfgSize;
  LOONGARCH_MEMMAP_ENTRY  MemoryMapEntry;
  LOONGARCH_MEMMAP_ENTRY  *StartEntry;
  LOONGARCH_MEMMAP_ENTRY  *pEntry;
  UINTN                Processed;
  Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a %d read etc/memmap error Status %d \n", __func__, __LINE__, Status));
    return ;
  }
  if (FwCfgSize % sizeof MemoryMapEntry != 0) {
    DEBUG ((DEBUG_ERROR, "no MemoryMapEntry FwCfgSize:%d\n", FwCfgSize));
    return ;
  }
  QemuFwCfgSelectItem (FwCfgItem);
  StartEntry = AllocatePages  (EFI_SIZE_TO_PAGES (FwCfgSize));
  QemuFwCfgReadBytes (FwCfgSize, StartEntry);
  for (Processed = 0; Processed < (FwCfgSize / sizeof MemoryMapEntry); Processed++) {
    pEntry = StartEntry + Processed;
    if (pEntry->Length == 0) {
      continue;
    }
    DEBUG ((DEBUG_INFO, "MemmapEntry Base %p length %p  type %d\n", pEntry->BaseAddr, pEntry->Length, pEntry->Type));
    if (pEntry->Type != EfiAcpiAddressRangeMemory) {
      continue;
    }
    AddMemoryRangeHob ( pEntry->BaseAddr, pEntry->BaseAddr + pEntry->Length);
  }
  BuildMemoryAllocationHob (
    PcdGet64 (PcdSecPeiTempRamBase),
    PcdGet32 (PcdSecPeiTempRamSize),
    EfiACPIMemoryNVS
    );
  BuildMemoryAllocationHob (
    PcdGet64 (PcdGuidedExtractHandlerTableAddress),
    PcdGet32 (PcdGuidedExtractHandlerTableSize),
    EfiACPIMemoryNVS
    );
}
VOID InitializeRamRegions ( VOID ) { EFI_STATUS Status ; FIRMWARE_CONFIG_ITEM FwCfgItem ; UINTN FwCfgSize ; LOONGARCH_MEMMAP_ENTRY MemoryMapEntry ; LOONGARCH_MEMMAP_ENTRY * StartEntry ; LOONGARCH_MEMMAP_ENTRY * pEntry ; UINTN Processed ; Status = QemuFwCfgFindFile ( " " , & FwCfgItem , & FwCfgSize ) ; if ( EFI_ERROR ( Status ) ) { DEBUG ( ( DEBUG_ERROR , " \n " , __func__ , __LINE__ , Status ) ) ; return ; } if ( FwCfgSize % sizeof MemoryMapEntry != 0 ) { DEBUG ( ( DEBUG_ERROR , " \n " , FwCfgSize ) ) ; return ; } QemuFwCfgSelectItem ( FwCfgItem ) ; StartEntry = AllocatePages ( EFI_SIZE_TO_PAGES ( FwCfgSize ) ) ; QemuFwCfgReadBytes ( FwCfgSize , StartEntry ) ; for ( Processed = 0 ; Processed < ( FwCfgSize / sizeof MemoryMapEntry ) ; Processed ++ ) { pEntry = StartEntry + Processed ; if ( pEntry -> Length == 0 ) { continue ; } DEBUG ( ( DEBUG_INFO , " \n " , pEntry -> BaseAddr , pEntry -> Length , pEntry -> Type ) ) ; if ( pEntry -> Type != EfiAcpiAddressRangeMemory ) { continue ; } AddMemoryRangeHob ( pEntry -> BaseAddr , pEntry -> BaseAddr + pEntry -> Length ) ; } BuildMemoryAllocationHob ( PcdGet64 ( PcdSecPeiTempRamBase ) , PcdGet32 ( PcdSecPeiTempRamSize ) , EfiACPIMemoryNVS ) ; BuildMemoryAllocationHob ( PcdGet64 ( PcdGuidedExtractHandlerTableAddress ) , PcdGet32 ( PcdGuidedExtractHandlerTableSize ) , EfiACPIMemoryNVS ) ; }
Peform Memory Detection
Publish system RAM and reserve memory regions
Peform Memory Detection Publish system RAM and reserve memory regions
//
 // Lock the scope of the cache.
 //
 //
 // SEC stores its table of GUIDed section handlers here.
 //
