QemuFlashSmm.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /** @file
  2. Define the module hooks used while probing the QEMU flash device.
  3. Copyright (C) 2018, Advanced Micro Devices. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Library/BaseMemoryLib.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/PcdLib.h>
  9. #include <Library/MemEncryptSevLib.h>
  10. #include "QemuFlash.h"
  11. VOID
  12. QemuFlashBeforeProbe (
  13. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  14. IN UINTN FdBlockSize,
  15. IN UINTN FdBlockCount
  16. )
  17. {
  18. EFI_STATUS Status;
  19. ASSERT (FeaturePcdGet (PcdSmmSmramRequire));
  20. if (!MemEncryptSevIsEnabled ()) {
  21. return;
  22. }
  23. //
  24. // When SEV is enabled, AmdSevDxe runs early in DXE phase and clears the
  25. // C-bit from the NonExistent entry -- which is later split and accommodate
  26. // the flash MMIO but the driver runs in non SMM context hence it cleared the
  27. // flash ranges from non SMM page table. When SMM is enabled, the flash
  28. // services are accessed from the SMM mode hence we explicitly clear the
  29. // C-bit on flash ranges from SMM page table.
  30. //
  31. Status = MemEncryptSevClearMmioPageEncMask (
  32. 0,
  33. BaseAddress,
  34. EFI_SIZE_TO_PAGES (FdBlockSize * FdBlockCount)
  35. );
  36. ASSERT_EFI_ERROR (Status);
  37. }
  38. /**
  39. Write to QEMU Flash
  40. @param[in] Ptr Pointer to the location to write.
  41. @param[in] Value The value to write.
  42. **/
  43. VOID
  44. QemuFlashPtrWrite (
  45. IN volatile UINT8 *Ptr,
  46. IN UINT8 Value
  47. )
  48. {
  49. *Ptr = Value;
  50. }