PeiFspMiscUpdUpdateLib.c 2.7 KB

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