TianoCore EDK2 master
Loading...
Searching...
No Matches
SmmAccessDxe.c
Go to the documentation of this file.
1
9#include "SmmAccessDxe.h"
10
12
20VOID
22 IN BOOLEAN OrLogic,
23 IN UINT64 Value
24 )
25{
26 UINT32 Index;
27
28 for (Index = 0; Index < mSmmAccess.NumberRegions; Index++) {
29 if (OrLogic) {
30 mSmmAccess.SmramDesc[Index].RegionState |= Value;
31 } else {
32 mSmmAccess.SmramDesc[Index].RegionState &= Value;
33 }
34 }
35}
36
51EFIAPI
54 )
55{
56 if ((mSmmAccess.SmmRegionState & EFI_SMRAM_LOCKED) != 0) {
57 //
58 // Cannot open a "locked" region
59 //
60 DEBUG ((DEBUG_INFO, "Cannot open the locked SMRAM Region\n"));
61 return EFI_DEVICE_ERROR;
62 }
63
64 mSmmAccess.SmmRegionState &= ~(EFI_SMRAM_CLOSED | EFI_ALLOCATED);
65 SyncRegionState2SmramDesc (FALSE, (UINT64)(UINTN)(~(EFI_SMRAM_CLOSED | EFI_ALLOCATED)));
66
67 mSmmAccess.SmmRegionState |= EFI_SMRAM_OPEN;
68 SyncRegionState2SmramDesc (TRUE, EFI_SMRAM_OPEN);
69 mSmmAccess.SmmAccess.OpenState = TRUE;
70
71 return EFI_SUCCESS;
72}
73
89EFIAPI
92 )
93{
94 if ((mSmmAccess.SmmRegionState & EFI_SMRAM_LOCKED) != 0) {
95 //
96 // Cannot close a "locked" region
97 //
98 DEBUG ((DEBUG_INFO, "Cannot close the locked SMRAM Region\n"));
99 return EFI_DEVICE_ERROR;
100 }
101
102 if ((mSmmAccess.SmmRegionState & EFI_SMRAM_CLOSED) != 0) {
103 return EFI_DEVICE_ERROR;
104 }
105
106 mSmmAccess.SmmRegionState &= ~EFI_SMRAM_OPEN;
107 SyncRegionState2SmramDesc (FALSE, (UINT64)(UINTN)(~EFI_SMRAM_OPEN));
108
109 mSmmAccess.SmmRegionState |= (EFI_SMRAM_CLOSED | EFI_ALLOCATED);
110 SyncRegionState2SmramDesc (TRUE, EFI_SMRAM_CLOSED | EFI_ALLOCATED);
111
112 mSmmAccess.SmmAccess.OpenState = FALSE;
113
114 return EFI_SUCCESS;
115}
116
132EFIAPI
135 )
136{
137 if (mSmmAccess.SmmAccess.OpenState) {
138 DEBUG ((DEBUG_INFO, "Cannot lock SMRAM when it is still open\n"));
139 return EFI_DEVICE_ERROR;
140 }
141
142 mSmmAccess.SmmRegionState |= EFI_SMRAM_LOCKED;
143 SyncRegionState2SmramDesc (TRUE, EFI_SMRAM_LOCKED);
144 mSmmAccess.SmmAccess.LockState = TRUE;
145 return EFI_SUCCESS;
146}
147
165EFIAPI
168 IN OUT UINTN *SmramMapSize,
169 IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap
170 )
171{
172 EFI_STATUS Status;
173 UINTN NecessaryBufferSize;
174
175 NecessaryBufferSize = mSmmAccess.NumberRegions * sizeof (EFI_SMRAM_DESCRIPTOR);
176 if (*SmramMapSize < NecessaryBufferSize) {
177 Status = EFI_BUFFER_TOO_SMALL;
178 } else {
179 CopyMem (SmramMap, mSmmAccess.SmramDesc, NecessaryBufferSize);
180 Status = EFI_SUCCESS;
181 }
182
183 *SmramMapSize = NecessaryBufferSize;
184 return Status;
185}
186
198EFIAPI
200 IN EFI_HANDLE ImageHandle,
201 IN EFI_SYSTEM_TABLE *SystemTable
202 )
203{
204 EFI_STATUS Status;
205 EFI_HOB_GUID_TYPE *GuidHob;
206 UINT32 SmmRegionNum;
208 UINT32 Index;
209
210 //
211 // Get SMRAM info HOB
212 //
213 GuidHob = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid);
214 if (GuidHob == NULL) {
215 DEBUG ((DEBUG_INFO, "SMRAM HOB NOT found\n"));
216 return EFI_NOT_FOUND;
217 }
218
219 SmramHob = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)GET_GUID_HOB_DATA (GuidHob);
220 SmmRegionNum = SmramHob->NumberOfSmmReservedRegions;
221 mSmmAccess.SmramDesc = AllocateZeroPool (sizeof (EFI_SMRAM_DESCRIPTOR) * SmmRegionNum);
222 if (mSmmAccess.SmramDesc == NULL) {
223 return EFI_OUT_OF_RESOURCES;
224 }
225
226 CopyMem (mSmmAccess.SmramDesc, &SmramHob->Descriptor, sizeof (EFI_SMRAM_DESCRIPTOR) * SmmRegionNum);
227
228 DEBUG ((DEBUG_INFO, "NumberOfSmmReservedRegions = 0x%x\n", SmmRegionNum));
229 for (Index = 0; Index < SmmRegionNum; Index++) {
230 DEBUG ((
231 DEBUG_INFO,
232 "%d: base=0x%x, size = 0x%x, State=0x%x\n",
233 Index,
234 SmramHob->Descriptor[Index].PhysicalStart,
235 SmramHob->Descriptor[Index].PhysicalSize,
236 SmramHob->Descriptor[Index].RegionState
237 ));
238 mSmmAccess.SmramDesc[Index].RegionState &= EFI_ALLOCATED;
239 mSmmAccess.SmramDesc[Index].RegionState |= EFI_SMRAM_CLOSED | EFI_CACHEABLE;
240 }
241
242 mSmmAccess.Signature = SMM_ACCESS_PRIVATE_DATA_SIGNATURE;
243 mSmmAccess.NumberRegions = SmmRegionNum;
244 mSmmAccess.SmmAccess.Open = Open;
245 mSmmAccess.SmmAccess.Close = Close;
246 mSmmAccess.SmmAccess.Lock = Lock;
247 mSmmAccess.SmmAccess.GetCapabilities = GetCapabilities;
248 mSmmAccess.SmmAccess.LockState = FALSE;
249 mSmmAccess.SmmAccess.OpenState = FALSE;
250 mSmmAccess.SmmRegionState = EFI_SMRAM_CLOSED;
251
252 Status = gBS->InstallMultipleProtocolInterfaces (
253 &mSmmAccess.Handle,
254 &gEfiSmmAccess2ProtocolGuid,
255 &mSmmAccess.SmmAccess,
256 NULL
257 );
258
259 return Status;
260}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI GetCapabilities(IN CONST EFI_SMM_ACCESS2_PROTOCOL *This, IN OUT UINTN *SmramMapSize, IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap)
Definition: SmmAccessDxe.c:166
EFI_STATUS EFIAPI Lock(IN EFI_SMM_ACCESS2_PROTOCOL *This)
Definition: SmmAccessDxe.c:133
EFI_STATUS EFIAPI Close(IN EFI_SMM_ACCESS2_PROTOCOL *This)
Definition: SmmAccessDxe.c:90
VOID SyncRegionState2SmramDesc(IN BOOLEAN OrLogic, IN UINT64 Value)
Definition: SmmAccessDxe.c:21
EFI_STATUS EFIAPI SmmAccessEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SmmAccessDxe.c:199
EFI_STATUS EFIAPI Open(IN EFI_SMM_ACCESS2_PROTOCOL *This)
Definition: SmmAccessDxe.c:52
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: PiMultiPhase.h:122
EFI_SMRAM_DESCRIPTOR Descriptor[1]