3 Secure Encrypted Virtualization (SEV) library helper function
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemEncryptSevLib.h>
14 #include <Register/Amd/Cpuid.h>
15 #include <Register/Amd/Msr.h>
16 #include <Register/Cpuid.h>
19 This function clears memory encryption bit for the memory region specified by
20 BaseAddress and NumPages from the current page table context.
22 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
24 @param[in] BaseAddress The physical address that is the start
25 address of a memory region.
26 @param[in] NumPages The number of pages from start memory
28 @param[in] Flush Flush the caches before clearing the bit
29 (mostly TRUE except MMIO addresses)
31 @retval RETURN_SUCCESS The attributes were cleared for the
33 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
34 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
39 MemEncryptSevClearPageEncMask (
40 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
41 IN PHYSICAL_ADDRESS BaseAddress
,
47 // Memory encryption bit is not accessible in 32-bit mode
49 return RETURN_UNSUPPORTED
;
53 This function sets memory encryption bit for the memory region specified by
54 BaseAddress and NumPages from the current page table context.
56 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
58 @param[in] BaseAddress The physical address that is the start
59 address of a memory region.
60 @param[in] NumPages The number of pages from start memory
62 @param[in] Flush Flush the caches before setting the bit
63 (mostly TRUE except MMIO addresses)
65 @retval RETURN_SUCCESS The attributes were set for the memory
67 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
68 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
73 MemEncryptSevSetPageEncMask (
74 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
75 IN PHYSICAL_ADDRESS BaseAddress
,
81 // Memory encryption bit is not accessible in 32-bit mode
83 return RETURN_UNSUPPORTED
;