PeiFspMiscUpdUpdateLib.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /** @file
  2. Implementation of Fsp Misc UPD Initialization.
  3. Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/PeiLib.h>
  9. #include <Library/ConfigBlockLib.h>
  10. #include <Library/PeiServicesLib.h>
  11. #include <FspEas.h>
  12. #include <FspmUpd.h>
  13. #include <FspsUpd.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/DebugPrintErrorLevelLib.h>
  16. #include <Library/PciLib.h>
  17. #include <Guid/MemoryOverwriteControl.h>
  18. #include <PchAccess.h>
  19. /**
  20. Performs FSP Misc UPD initialization.
  21. @param[in][out] FspmUpd Pointer to FSPM_UPD Data.
  22. @retval EFI_SUCCESS FSP UPD Data is updated.
  23. **/
  24. EFI_STATUS
  25. EFIAPI
  26. PeiFspMiscUpdUpdatePreMem (
  27. IN OUT FSPM_UPD *FspmUpd
  28. )
  29. {
  30. EFI_STATUS Status;
  31. EFI_BOOT_MODE BootMode;
  32. UINTN VariableSize;
  33. VOID *FspNvsBufferPtr;
  34. UINT8 MorControl;
  35. VOID *MorControlPtr;
  36. Status = PeiServicesGetBootMode (&BootMode);
  37. ASSERT_EFI_ERROR (Status);
  38. //
  39. // Initialize S3 Data variable (S3DataPtr). It may be used for warm and fast boot paths.
  40. //
  41. FspNvsBufferPtr = NULL;
  42. VariableSize = 0;
  43. Status = PeiGetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVariableGuid, &FspNvsBufferPtr, &VariableSize);
  44. if (Status == EFI_SUCCESS) {
  45. DEBUG ((DEBUG_INFO, "Get L\"FspNvsBuffer\" gFspNvsBufferVariableGuid - %r\n", Status));
  46. DEBUG ((DEBUG_INFO, "FspNvsBuffer Size - 0x%x\n", VariableSize));
  47. FspmUpd->FspmArchUpd.NvsBufferPtr = FspNvsBufferPtr;
  48. }
  49. if (FspmUpd->FspmArchUpd.NvsBufferPtr != NULL) {
  50. //
  51. // Set the DISB bit in PCH (DRAM Initialization Scratchpad Bit - GEN_PMCON_A[23]),
  52. // after memory Data is saved to NVRAM.
  53. //
  54. PciOr32 ((UINTN)PCI_LIB_ADDRESS (0, PCI_DEVICE_NUMBER_PCH_PMC, PCI_FUNCTION_NUMBER_PCH_PMC, R_PCH_PMC_GEN_PMCON_A), B_PCH_PMC_GEN_PMCON_A_DISB);
  55. }
  56. //
  57. // MOR
  58. //
  59. MorControl = 0;
  60. MorControlPtr = &MorControl;
  61. VariableSize = sizeof (MorControl);
  62. Status = PeiGetVariable (
  63. MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
  64. &gEfiMemoryOverwriteControlDataGuid,
  65. &MorControlPtr,
  66. &VariableSize
  67. );
  68. DEBUG ((DEBUG_INFO, "MorControl - 0x%x (%r)\n", MorControl, Status));
  69. //
  70. // Do not set CleanMemory on S3 resume
  71. // TODO: Handle advanced features later - capsule update is in-memory list
  72. //
  73. if (MOR_CLEAR_MEMORY_VALUE (MorControl) && BootMode != BOOT_ON_S3_RESUME) {
  74. FspmUpd->FspmConfig.CleanMemory = (BOOLEAN)(MorControl & MOR_CLEAR_MEMORY_BIT_MASK);
  75. }
  76. return EFI_SUCCESS;
  77. }