/* Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry. */
STATIC EFI_STATUS PlatformScanE820(IN E820_SCAN_CALLBACK Callback, IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob)
/* Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry. */
STATIC EFI_STATUS PlatformScanE820(IN E820_SCAN_CALLBACK Callback, IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob)
{
  EFI_STATUS            Status;
  FIRMWARE_CONFIG_ITEM  FwCfgItem;
  UINTN                 FwCfgSize;
  EFI_E820_ENTRY64      E820Entry;
  UINTN                 Processed;
  if (PlatformInfoHob->HostBridgeDevId == CLOUDHV_DEVICE_ID) {
    return PlatformScanE820Pvh (Callback, PlatformInfoHob);
  }
  Status = QemuFwCfgFindFile ("etc/e820", &FwCfgItem, &FwCfgSize);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  if (FwCfgSize % sizeof E820Entry != 0) {
    return EFI_PROTOCOL_ERROR;
  }
  QemuFwCfgSelectItem (FwCfgItem);
  for (Processed = 0; Processed < FwCfgSize; Processed += sizeof E820Entry) {
    QemuFwCfgReadBytes (sizeof E820Entry, &E820Entry);
    Callback (&E820Entry, PlatformInfoHob);
  }
  return EFI_SUCCESS;
}