MemoryCallback.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /** @file
  2. Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. This file includes a memory call back function notified when MRC is done,
  5. following action is performed in this file,
  6. 1. ICH initialization after MRC.
  7. 2. SIO initialization.
  8. 3. Install ResetSystem and FinvFv PPI.
  9. 4. Set MTRR for PEI
  10. 5. Create FV HOB and Flash HOB
  11. **/
  12. #include "CommonHeader.h"
  13. #include "Platform.h"
  14. #include <Library/BaseCryptLib.h>
  15. #include <Library/PciLib.h>
  16. #include "VlvAccess.h"
  17. EFI_PEI_PPI_DESCRIPTOR mPpiListRecoveryBootMode[] = {
  18. { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
  19. &gEfiPeiBootInRecoveryModePpiGuid,
  20. NULL
  21. }
  22. };
  23. #if 0
  24. STATIC
  25. EFI_STATUS
  26. GetMemorySize (
  27. IN CONST EFI_PEI_SERVICES **PeiServices,
  28. OUT UINT64 *LowMemoryLength,
  29. OUT UINT64 *HighMemoryLength
  30. )
  31. {
  32. EFI_STATUS Status;
  33. EFI_PEI_HOB_POINTERS Hob;
  34. *HighMemoryLength = 0;
  35. *LowMemoryLength = 0x100000;
  36. //
  37. // Get the HOB list for processing
  38. //
  39. Status = (*PeiServices)->GetHobList (PeiServices, (void **)&Hob.Raw);
  40. if (EFI_ERROR(Status)) {
  41. return Status;
  42. }
  43. //
  44. // Collect memory ranges
  45. //
  46. while (!END_OF_HOB_LIST (Hob)) {
  47. if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
  48. if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {
  49. //
  50. // Need memory above 1MB to be collected here
  51. //
  52. if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000 &&
  53. Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) 0x100000000) {
  54. *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);
  55. } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) 0x100000000) {
  56. *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);
  57. }
  58. }
  59. }
  60. Hob.Raw = GET_NEXT_HOB (Hob);
  61. }
  62. return EFI_SUCCESS;
  63. }
  64. #endif
  65. /**
  66. This function will be called when MRC is done.
  67. @param PeiServices General purpose services available to every PEIM.
  68. @param NotifyDescriptor Information about the notify event..
  69. @param Ppi The notify context.
  70. @retval EFI_SUCCESS If the function completed successfully.
  71. **/
  72. EFI_STATUS
  73. EFIAPI
  74. MemoryDiscoveredPpiNotifyCallback (
  75. IN EFI_PEI_SERVICES **PeiServices,
  76. IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
  77. IN VOID *Ppi
  78. )
  79. {
  80. EFI_BOOT_MODE BootMode;
  81. UINT32 Pages;
  82. VOID* Memory;
  83. UINTN Size;
  84. //
  85. // Allocate LM memory and configure PDM if enabled by user.
  86. // ConfigureLM(PeiServices);
  87. //
  88. (*PeiServices)->GetBootMode (
  89. (const EFI_PEI_SERVICES **)PeiServices,
  90. &BootMode
  91. );
  92. if (BootMode != BOOT_ON_S3_RESUME) {
  93. Size = (PcdGet32 (PcdFlashFvRecovery2Base) - PcdGet32 (PcdFlashFvMainBase)) + FixedPcdGet32(PcdFlashFvRecovery2Size);
  94. Pages= Size/0x1000;
  95. Memory = AllocatePages ( Pages );
  96. CopyMem(Memory , (VOID *) FixedPcdGet32(PcdFlashFvMainBase) , Size);
  97. //
  98. // We don't verify just load
  99. //
  100. PeiServicesInstallFvInfoPpi (
  101. NULL,
  102. (VOID *) ((UINTN) Memory + (PcdGet32 (PcdFlashFvRecovery2Base) - PcdGet32 (PcdFlashFvMainBase))),
  103. PcdGet32 (PcdFlashFvRecovery2Size),
  104. NULL,
  105. NULL
  106. );
  107. PeiServicesInstallFvInfoPpi (
  108. NULL,
  109. (VOID *) Memory,
  110. PcdGet32 (PcdFlashFvMainSize),
  111. NULL,
  112. NULL
  113. );
  114. }
  115. if (BootMode == BOOT_ON_S3_RESUME) {
  116. PeiServicesInstallFvInfoPpi (
  117. NULL,
  118. (VOID *) (UINTN) (PcdGet32 (PcdFlashFvRecovery2Base)),
  119. PcdGet32 (PcdFlashFvRecovery2Size),
  120. NULL,
  121. NULL
  122. );
  123. }
  124. return EFI_SUCCESS;
  125. }