3 Secure Encrypted Virtualization (SEV) library helper function
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD
9 License which accompanies this distribution. The full text of the license may
10 be found at http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Register/Cpuid.h>
20 #include <Register/Amd/Cpuid.h>
21 #include <Register/Amd/Msr.h>
22 #include <Library/MemEncryptSevLib.h>
25 This function clears memory encryption bit for the memory region specified
26 by BaseAddress and Number of pages from the current page table context.
28 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)
29 @param[in] BaseAddress The physical address that is the start address
31 @param[in] NumberOfPages The number of pages from start memory region.
32 @param[in] Flush Flush the caches before clearing the bit
33 (mostly TRUE except MMIO addresses)
35 @retval RETURN_SUCCESS The attributes were cleared for the memory region.
36 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
37 @retval RETURN_UNSUPPORTED Clearing memory encryption attribute is not
42 MemEncryptSevClearPageEncMask (
43 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
44 IN PHYSICAL_ADDRESS BaseAddress
,
45 IN UINTN NumberOfPages
,
50 // Memory encryption bit is not accessible in 32-bit mode
52 return RETURN_UNSUPPORTED
;
56 This function sets memory encryption bit for the memory region specified by
57 BaseAddress and Number of pages from the current page table context.
59 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)
60 @param[in] BaseAddress The physical address that is the start address
62 @param[in] NumberOfPages The number of pages from start memory region.
63 @param[in] Flush Flush the caches before clearing the bit
64 (mostly TRUE except MMIO addresses)
66 @retval RETURN_SUCCESS The attributes were set for the memory region.
67 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
68 @retval RETURN_UNSUPPORTED Clearing memory encryption attribute is not
73 MemEncryptSevSetPageEncMask (
74 IN PHYSICAL_ADDRESS Cr3BaseAddress
,
75 IN PHYSICAL_ADDRESS BaseAddress
,
76 IN UINTN NumberOfPages
,
81 // Memory encryption bit is not accessible in 32-bit mode
83 return RETURN_UNSUPPORTED
;