AmdSev.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**@file
  2. Initialize Secure Encrypted Virtualization (SEV) support
  3. Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<BR>
  4. Copyright (c) 2019, Citrix Systems, Inc.
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. //
  8. // The package level header files this module uses
  9. //
  10. #include <Library/DebugLib.h>
  11. #include <Library/MemEncryptSevLib.h>
  12. #include <Library/PcdLib.h>
  13. #include <PiPei.h>
  14. #include "Platform.h"
  15. /**
  16. Function checks if SEV support is available, if present then it sets
  17. the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption mask.
  18. **/
  19. VOID
  20. AmdSevInitialize (
  21. VOID
  22. )
  23. {
  24. UINT64 EncryptionMask;
  25. RETURN_STATUS PcdStatus;
  26. //
  27. // Check if SEV is enabled
  28. //
  29. if (!MemEncryptSevIsEnabled ()) {
  30. return;
  31. }
  32. //
  33. // Set Memory Encryption Mask PCD
  34. //
  35. EncryptionMask = MemEncryptSevGetEncryptionMask ();
  36. PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask);
  37. ASSERT_RETURN_ERROR (PcdStatus);
  38. DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask));
  39. //
  40. // Set Pcd to Deny the execution of option ROM when security
  41. // violation.
  42. //
  43. PcdStatus = PcdSet32S (PcdOptionRomImageVerificationPolicy, 0x4);
  44. ASSERT_RETURN_ERROR (PcdStatus);
  45. }