예제 #1
0
파일: Platform.c 프로젝트: ChenFanFnst/edk2
VOID
AddMemoryRangeHob (
  EFI_PHYSICAL_ADDRESS        MemoryBase,
  EFI_PHYSICAL_ADDRESS        MemoryLimit
  )
{
  AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
}
/**
  Peform Memory Detection

  @return EFI_SUCCESS     The PEIM initialized successfully.

**/
EFI_PHYSICAL_ADDRESS
MemDetect (
  )
{
  EFI_STATUS                  Status;
  EFI_PHYSICAL_ADDRESS        MemoryBase;
  UINT64                      MemorySize;
  UINT64                      LowerMemorySize;
  UINT64                      UpperMemorySize;

  DEBUG ((EFI_D_ERROR, "MemDetect called\n"));

  //
  // Determine total memory size available
  //
  LowerMemorySize = GetSystemMemorySizeBelow4gb ();
  UpperMemorySize = GetSystemMemorySizeAbove4gb ();

  //
  // Determine the range of memory to use during PEI
  //
  MemoryBase = PcdGet32 (PcdOvmfMemFvBase) + PcdGet32 (PcdOvmfMemFvSize);
  MemorySize = LowerMemorySize - MemoryBase;
  if (MemorySize > SIZE_64MB) {
    MemoryBase = LowerMemorySize - SIZE_64MB;
    MemorySize = SIZE_64MB;
  }

  //
  // Publish this memory to the PEI Core
  //
  Status = PublishSystemMemory(MemoryBase, MemorySize);
  ASSERT_EFI_ERROR (Status);

  //
  // Create memory HOBs
  //
  AddMemoryBaseSizeHob (MemoryBase, MemorySize);
  AddMemoryRangeHob (BASE_1MB, MemoryBase);
  AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);

  MtrrSetMemoryAttribute (BASE_1MB, MemoryBase + MemorySize - BASE_1MB, CacheWriteBack);

  MtrrSetMemoryAttribute (0, BASE_512KB + BASE_128KB, CacheWriteBack);

  if (UpperMemorySize != 0) {
    AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);

    MtrrSetMemoryAttribute (BASE_4GB, UpperMemorySize, CacheWriteBack);
  }

  return MemoryBase + MemorySize;
}
예제 #3
0
파일: Platform.c 프로젝트: B-Rich/edk2
VOID
XenMemMapInitialization (
  VOID
  )
{
  EFI_E820_ENTRY64 *E820Map;
  UINT32 E820EntriesCount;
  EFI_STATUS Status;

  DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));

  //
  // Create Memory Type Information HOB
  //
  BuildGuidDataHob (
    &gEfiMemoryTypeInformationGuid,
    mDefaultMemoryTypeInformation,
    sizeof(mDefaultMemoryTypeInformation)
    );

  //
  // Add PCI IO Port space available for PCI resource allocations.
  //
  BuildResourceDescriptorHob (
    EFI_RESOURCE_IO,
    EFI_RESOURCE_ATTRIBUTE_PRESENT     |
    EFI_RESOURCE_ATTRIBUTE_INITIALIZED,
    0xC000,
    0x4000
    );

  //
  // Video memory + Legacy BIOS region
  //
  AddIoMemoryRangeHob (0x0A0000, BASE_1MB);

  //
  // Parse RAM in E820 map
  //
  Status = XenGetE820Map(&E820Map, &E820EntriesCount);

  ASSERT_EFI_ERROR (Status);

  if (E820EntriesCount > 0) {
    EFI_E820_ENTRY64 *Entry;
    UINT32 Loop;

    for (Loop = 0; Loop < E820EntriesCount; Loop++) {
      Entry = E820Map + Loop;

      //
      // Only care about RAM
      //
      if (Entry->Type != EfiAcpiAddressRangeMemory) {
        continue;
      }

      if (Entry->BaseAddr >= BASE_4GB) {
        AddUntestedMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
      } else {
        AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length);
      }

      MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBack);
    }
  }
}