]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / X64 / SecVirtualMemory.c
1 /** @file
2
3 Virtual Memory Management Services to set or clear the memory encryption bit
4
5 Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/CpuLib.h>
12 #include <Library/MemEncryptSevLib.h>
13
14 #include "VirtualMemory.h"
15
16 /**
17 Return the pagetable memory encryption mask.
18
19 @return The pagetable memory encryption mask.
20
21 **/
22 UINT64
23 EFIAPI
24 InternalGetMemEncryptionAddressMask (
25 VOID
26 )
27 {
28 UINT64 EncryptionMask;
29
30 EncryptionMask = MemEncryptSevGetEncryptionMask ();
31 EncryptionMask &= PAGING_1G_ADDRESS_MASK_64;
32
33 return EncryptionMask;
34 }
35
36 /**
37 This function clears memory encryption bit for the memory region specified by
38 PhysicalAddress and Length from the current page table context.
39
40 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
41 current CR3)
42 @param[in] PhysicalAddress The physical address that is the start
43 address of a memory region.
44 @param[in] Length The length of memory region
45
46 @retval RETURN_SUCCESS The attributes were cleared for the
47 memory region.
48 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
49 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
50 is not supported
51 **/
52 RETURN_STATUS
53 EFIAPI
54 InternalMemEncryptSevSetMemoryDecrypted (
55 IN PHYSICAL_ADDRESS Cr3BaseAddress,
56 IN PHYSICAL_ADDRESS PhysicalAddress,
57 IN UINTN Length
58 )
59 {
60 //
61 // This function is not available during SEC.
62 //
63 return RETURN_UNSUPPORTED;
64 }
65
66 /**
67 This function sets memory encryption bit for the memory region specified by
68 PhysicalAddress and Length from the current page table context.
69
70 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
71 current CR3)
72 @param[in] PhysicalAddress The physical address that is the start
73 address of a memory region.
74 @param[in] Length The length of memory region
75 @param[in] Flush Flush the caches before applying the
76 encryption mask
77
78 @retval RETURN_SUCCESS The attributes were set for the memory
79 region.
80 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
81 @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute
82 is not supported
83 **/
84 RETURN_STATUS
85 EFIAPI
86 InternalMemEncryptSevSetMemoryEncrypted (
87 IN PHYSICAL_ADDRESS Cr3BaseAddress,
88 IN PHYSICAL_ADDRESS PhysicalAddress,
89 IN UINTN Length
90 )
91 {
92 //
93 // This function is not available during SEC.
94 //
95 return RETURN_UNSUPPORTED;
96 }
97
98 /**
99 This function clears memory encryption bit for the MMIO region specified by
100 PhysicalAddress and Length.
101
102 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
103 current CR3)
104 @param[in] PhysicalAddress The physical address that is the start
105 address of a MMIO region.
106 @param[in] Length The length of memory region
107
108 @retval RETURN_SUCCESS The attributes were cleared for the
109 memory region.
110 @retval RETURN_INVALID_PARAMETER Length is zero.
111 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
112 is not supported
113 **/
114 RETURN_STATUS
115 EFIAPI
116 InternalMemEncryptSevClearMmioPageEncMask (
117 IN PHYSICAL_ADDRESS Cr3BaseAddress,
118 IN PHYSICAL_ADDRESS PhysicalAddress,
119 IN UINTN Length
120 )
121 {
122 //
123 // This function is not available during SEC.
124 //
125 return RETURN_UNSUPPORTED;
126 }