MemoryInitPeim.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /** @file
  2. Copyright (c) 2011, ARM Limited. All rights reserved.
  3. Copyright (c) 2022, Google LLC. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/ArmPlatformLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/HobLib.h>
  10. #include <Library/PeimEntryPoint.h>
  11. #include <Library/PeiServicesLib.h>
  12. #include <Library/PcdLib.h>
  13. #include <Guid/MemoryTypeInformation.h>
  14. EFI_STATUS
  15. EFIAPI
  16. MemoryPeim (
  17. IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,
  18. IN UINT64 UefiMemorySize
  19. );
  20. /**
  21. Build the memory type information HOB that describes how many pages of each
  22. type to preallocate when initializing the GCD memory map.
  23. **/
  24. VOID
  25. EFIAPI
  26. BuildMemoryTypeInformationHob (
  27. VOID
  28. )
  29. {
  30. EFI_MEMORY_TYPE_INFORMATION Info[10];
  31. Info[0].Type = EfiACPIReclaimMemory;
  32. Info[0].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);
  33. Info[1].Type = EfiACPIMemoryNVS;
  34. Info[1].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);
  35. Info[2].Type = EfiReservedMemoryType;
  36. Info[2].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType);
  37. Info[3].Type = EfiRuntimeServicesData;
  38. Info[3].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);
  39. Info[4].Type = EfiRuntimeServicesCode;
  40. Info[4].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);
  41. Info[5].Type = EfiBootServicesCode;
  42. Info[5].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiBootServicesCode);
  43. Info[6].Type = EfiBootServicesData;
  44. Info[6].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiBootServicesData);
  45. Info[7].Type = EfiLoaderCode;
  46. Info[7].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiLoaderCode);
  47. Info[8].Type = EfiLoaderData;
  48. Info[8].NumberOfPages = FixedPcdGet32 (PcdMemoryTypeEfiLoaderData);
  49. // Terminator for the list
  50. Info[9].Type = EfiMaxMemoryType;
  51. Info[9].NumberOfPages = 0;
  52. BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
  53. }
  54. /**
  55. Module entry point.
  56. @param[in] FileHandle Handle of the file being invoked.
  57. @param[in] PeiServices Describes the list of possible PEI Services.
  58. @return EFI_SUCCESS unless the operation failed.
  59. **/
  60. EFI_STATUS
  61. EFIAPI
  62. InitializeMemory (
  63. IN EFI_PEI_FILE_HANDLE FileHandle,
  64. IN CONST EFI_PEI_SERVICES **PeiServices
  65. )
  66. {
  67. UINTN UefiMemoryBase;
  68. EFI_STATUS Status;
  69. ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS);
  70. //
  71. // Put the permanent PEI memory in the first 128 MiB of DRAM so that
  72. // it is covered by the statically configured ID map.
  73. //
  74. UefiMemoryBase = (UINTN)FixedPcdGet64 (PcdSystemMemoryBase) + SIZE_128MB
  75. - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
  76. Status = PeiServicesInstallPeiMemory (
  77. UefiMemoryBase,
  78. FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
  79. );
  80. ASSERT_EFI_ERROR (Status);
  81. Status = MemoryPeim (
  82. UefiMemoryBase,
  83. FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
  84. );
  85. ASSERT_EFI_ERROR (Status);
  86. return Status;
  87. }