TianoCore EDK2 master
Loading...
Searching...
No Matches
Page.c
Go to the documentation of this file.
1
9#include "PiSmmCore.h"
11
12#define TRUNCATE_TO_PAGES(a) ((a) >> EFI_PAGE_SHIFT)
13
14LIST_ENTRY mSmmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mSmmMemoryMap);
15
16//
17// For GetMemoryMap()
18//
19
20#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
21typedef struct {
22 UINTN Signature;
23 LIST_ENTRY Link;
24
25 BOOLEAN FromStack;
26 EFI_MEMORY_TYPE Type;
27 UINT64 Start;
28 UINT64 End;
30
31LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
32
33#define MAX_MAP_DEPTH 6
34
42MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
43UINTN mFreeMapStack = 0;
48
71 IN EFI_MEMORY_TYPE MemoryType,
72 IN UINTN NumberOfPages,
74 IN BOOLEAN AddRegion,
75 IN BOOLEAN NeedGuard
76 );
77
89 VOID
90 )
91{
93 EFI_STATUS Status;
94 MEMORY_MAP *FreeDescriptorEntries;
95 MEMORY_MAP *Entry;
96 UINTN Index;
97
98 // DEBUG((DEBUG_INFO, "AllocateMemoryMapEntry\n"));
99
101 // DEBUG((DEBUG_INFO, "mFreeMemoryMapEntryList is empty\n"));
102 //
103 // The list is empty, to allocate one page to refuel the list
104 //
108 EFI_SIZE_TO_PAGES (RUNTIME_PAGE_ALLOCATION_GRANULARITY),
109 &Mem,
110 TRUE,
111 FALSE
112 );
113 ASSERT_EFI_ERROR (Status);
114 if (!EFI_ERROR (Status)) {
115 FreeDescriptorEntries = (MEMORY_MAP *)(UINTN)Mem;
116 // DEBUG((DEBUG_INFO, "New FreeDescriptorEntries - 0x%x\n", FreeDescriptorEntries));
117 //
118 // Enqueue the free memory map entries into the list
119 //
120 for (Index = 0; Index < RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof (MEMORY_MAP); Index++) {
121 FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
122 InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
123 }
124 } else {
125 return NULL;
126 }
127 }
128
129 //
130 // dequeue the first descriptor from the list
131 //
132 Entry = CR (mFreeMemoryMapEntryList.ForwardLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
133 RemoveEntryList (&Entry->Link);
134
135 return Entry;
136}
137
143VOID
145 VOID
146 )
147{
148 MEMORY_MAP *Entry;
149
150 //
151 // If already freeing the map stack, then return
152 //
153 if (mFreeMapStack != 0) {
154 ASSERT (FALSE);
155 return;
156 }
157
158 //
159 // Move the temporary memory descriptor stack into pool
160 //
161 mFreeMapStack += 1;
162
163 while (mMapDepth != 0) {
164 //
165 // Deque an memory map entry from mFreeMemoryMapEntryList
166 //
167 Entry = AllocateMemoryMapEntry ();
168 if (Entry == NULL) {
169 ASSERT (Entry);
170 mFreeMapStack -= 1;
171 return;
172 }
173
174 //
175 // Update to proper entry
176 //
177 mMapDepth -= 1;
178
179 if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {
180 CopyMem (Entry, &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
181 Entry->FromStack = FALSE;
182
183 //
184 // Move this entry to general memory
185 //
186 InsertTailList (&mMapStack[mMapDepth].Link, &Entry->Link);
188 mMapStack[mMapDepth].Link.ForwardLink = NULL;
189 }
190 }
191
192 mFreeMapStack -= 1;
193}
194
205VOID
207 IN LIST_ENTRY *Link,
208 IN UINT64 Start,
209 IN UINT64 End,
210 IN EFI_MEMORY_TYPE Type,
211 IN BOOLEAN Next,
212 IN BOOLEAN AddRegion
213 )
214{
215 MEMORY_MAP *Entry;
216
217 Entry = &mMapStack[mMapDepth];
218 mMapDepth += 1;
219 ASSERT (mMapDepth < MAX_MAP_DEPTH);
220 Entry->FromStack = TRUE;
221
222 Entry->Signature = MEMORY_MAP_SIGNATURE;
223 Entry->Type = Type;
224 Entry->Start = Start;
225 Entry->End = End;
226 if (Next) {
227 InsertHeadList (Link, &Entry->Link);
228 } else {
229 InsertTailList (Link, &Entry->Link);
230 }
231}
232
238VOID
240 IN MEMORY_MAP *Entry
241 )
242{
243 RemoveEntryList (&Entry->Link);
244 Entry->Link.ForwardLink = NULL;
245
246 if (!Entry->FromStack) {
248 }
249}
250
259VOID
261 IN EFI_MEMORY_TYPE Type,
263 IN UINTN NumberOfPages,
264 IN BOOLEAN AddRegion
265 )
266{
267 LIST_ENTRY *Link;
268 MEMORY_MAP *Entry;
269 MEMORY_MAP *NextEntry;
270 LIST_ENTRY *NextLink;
271 MEMORY_MAP *PreviousEntry;
272 LIST_ENTRY *PreviousLink;
275
276 Start = Memory;
277 End = Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1;
278
279 //
280 // Exclude memory region
281 //
282 Link = gMemoryMap.ForwardLink;
283 while (Link != &gMemoryMap) {
284 Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
285 Link = Link->ForwardLink;
286
287 //
288 // ---------------------------------------------------
289 // | +----------+ +------+ +------+ +------+ |
290 // ---|gMemoryMap|---|Entry1|---|Entry2|---|Entry3|---
291 // +----------+ ^ +------+ +------+ +------+
292 // |
293 // +------+
294 // |EntryX|
295 // +------+
296 //
297 if (Entry->Start > End) {
298 if ((Entry->Start == End + 1) && (Entry->Type == Type)) {
299 Entry->Start = Start;
300 return;
301 }
302
304 &Entry->Link,
305 Start,
306 End,
307 Type,
308 FALSE,
309 AddRegion
310 );
311 return;
312 }
313
314 if ((Entry->Start <= Start) && (Entry->End >= End)) {
315 if (Entry->Type != Type) {
316 if (Entry->Start < Start) {
317 //
318 // ---------------------------------------------------
319 // | +----------+ +------+ +------+ +------+ |
320 // ---|gMemoryMap|---|Entry1|---|EntryX|---|Entry3|---
321 // +----------+ +------+ ^ +------+ +------+
322 // |
323 // +------+
324 // |EntryA|
325 // +------+
326 //
328 &Entry->Link,
329 Entry->Start,
330 Start - 1,
331 Entry->Type,
332 FALSE,
333 AddRegion
334 );
335 }
336
337 if (Entry->End > End) {
338 //
339 // ---------------------------------------------------
340 // | +----------+ +------+ +------+ +------+ |
341 // ---|gMemoryMap|---|Entry1|---|EntryX|---|Entry3|---
342 // +----------+ +------+ +------+ ^ +------+
343 // |
344 // +------+
345 // |EntryZ|
346 // +------+
347 //
349 &Entry->Link,
350 End + 1,
351 Entry->End,
352 Entry->Type,
353 TRUE,
354 AddRegion
355 );
356 }
357
358 //
359 // Update this node
360 //
361 Entry->Start = Start;
362 Entry->End = End;
363 Entry->Type = Type;
364
365 //
366 // Check adjacent
367 //
368 NextLink = Entry->Link.ForwardLink;
369 if (NextLink != &gMemoryMap) {
370 NextEntry = CR (NextLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
371 //
372 // ---------------------------------------------------
373 // | +----------+ +------+ +-----------------+ |
374 // ---|gMemoryMap|---|Entry1|---|EntryX Entry3|---
375 // +----------+ +------+ +-----------------+
376 //
377 if ((Entry->Type == NextEntry->Type) && (Entry->End + 1 == NextEntry->Start)) {
378 Entry->End = NextEntry->End;
379 RemoveOldEntry (NextEntry);
380 }
381 }
382
383 PreviousLink = Entry->Link.BackLink;
384 if (PreviousLink != &gMemoryMap) {
385 PreviousEntry = CR (PreviousLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
386 //
387 // ---------------------------------------------------
388 // | +----------+ +-----------------+ +------+ |
389 // ---|gMemoryMap|---|Entry1 EntryX|---|Entry3|---
390 // +----------+ +-----------------+ +------+
391 //
392 if ((PreviousEntry->Type == Entry->Type) && (PreviousEntry->End + 1 == Entry->Start)) {
393 PreviousEntry->End = Entry->End;
394 RemoveOldEntry (Entry);
395 }
396 }
397 }
398
399 return;
400 }
401 }
402
403 //
404 // ---------------------------------------------------
405 // | +----------+ +------+ +------+ +------+ |
406 // ---|gMemoryMap|---|Entry1|---|Entry2|---|Entry3|---
407 // +----------+ +------+ +------+ +------+ ^
408 // |
409 // +------+
410 // |EntryX|
411 // +------+
412 //
413 Link = gMemoryMap.BackLink;
414 if (Link != &gMemoryMap) {
415 Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
416 if ((Entry->End + 1 == Start) && (Entry->Type == Type)) {
417 Entry->End = End;
418 return;
419 }
420 }
421
423 &gMemoryMap,
424 Start,
425 End,
426 Type,
427 FALSE,
428 AddRegion
429 );
430 return;
431}
432
438UINTN
440 VOID
441 )
442{
443 LIST_ENTRY *Link;
444 UINTN Count;
445
446 Count = 0;
447 Link = gMemoryMap.ForwardLink;
448 while (Link != &gMemoryMap) {
449 Link = Link->ForwardLink;
450 Count++;
451 }
452
453 return Count;
454}
455
466UINTN
468 IN OUT FREE_PAGE_LIST *Pages,
469 IN UINTN NumberOfPages,
470 IN UINTN MaxAddress
471 )
472{
473 UINTN Top;
474 UINTN Bottom;
475 FREE_PAGE_LIST *Node;
476
477 Top = TRUNCATE_TO_PAGES (MaxAddress + 1 - (UINTN)Pages);
478 if (Top > Pages->NumberOfPages) {
479 Top = Pages->NumberOfPages;
480 }
481
482 Bottom = Top - NumberOfPages;
483
484 if (Top < Pages->NumberOfPages) {
485 Node = (FREE_PAGE_LIST *)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top));
486 Node->NumberOfPages = Pages->NumberOfPages - Top;
487 InsertHeadList (&Pages->Link, &Node->Link);
488 }
489
490 if (Bottom > 0) {
491 Pages->NumberOfPages = Bottom;
492 } else {
493 RemoveEntryList (&Pages->Link);
494 }
495
496 return (UINTN)Pages + EFI_PAGES_TO_SIZE (Bottom);
497}
498
509UINTN
511 IN OUT LIST_ENTRY *FreePageList,
512 IN UINTN NumberOfPages,
513 IN UINTN MaxAddress
514 )
515{
516 LIST_ENTRY *Node;
517 FREE_PAGE_LIST *Pages;
518
519 for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
520 Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
521 if ((Pages->NumberOfPages >= NumberOfPages) &&
522 ((UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress))
523 {
524 return InternalAllocPagesOnOneNode (Pages, NumberOfPages, MaxAddress);
525 }
526 }
527
528 return (UINTN)(-1);
529}
530
541UINTN
543 IN OUT LIST_ENTRY *FreePageList,
544 IN UINTN NumberOfPages,
545 IN UINTN Address
546 )
547{
548 UINTN EndAddress;
549 LIST_ENTRY *Node;
550 FREE_PAGE_LIST *Pages;
551
552 if ((Address & EFI_PAGE_MASK) != 0) {
553 return ~Address;
554 }
555
556 EndAddress = Address + EFI_PAGES_TO_SIZE (NumberOfPages);
557 for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
558 Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
559 if ((UINTN)Pages <= Address) {
560 if ((UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages) < EndAddress) {
561 break;
562 }
563
564 return InternalAllocPagesOnOneNode (Pages, NumberOfPages, EndAddress);
565 }
566 }
567
568 return ~Address;
569}
570
593 IN EFI_MEMORY_TYPE MemoryType,
594 IN UINTN NumberOfPages,
596 IN BOOLEAN AddRegion,
597 IN BOOLEAN NeedGuard
598 )
599{
600 UINTN RequestedAddress;
601
602 if ((MemoryType != EfiRuntimeServicesCode) &&
603 (MemoryType != EfiRuntimeServicesData))
604 {
605 return EFI_INVALID_PARAMETER;
606 }
607
608 if (NumberOfPages > TRUNCATE_TO_PAGES ((UINTN)-1) + 1) {
609 return EFI_OUT_OF_RESOURCES;
610 }
611
612 //
613 // We don't track memory type in SMM
614 //
615 RequestedAddress = (UINTN)*Memory;
616 switch (Type) {
617 case AllocateAnyPages:
618 RequestedAddress = (UINTN)(-1);
620 if (NeedGuard) {
622 &mSmmMemoryMap,
623 NumberOfPages,
624 RequestedAddress,
625 MemoryType
626 );
627 if (*Memory == (UINTN)-1) {
628 return EFI_OUT_OF_RESOURCES;
629 } else {
630 ASSERT (VerifyMemoryGuard (*Memory, NumberOfPages) == TRUE);
631 return EFI_SUCCESS;
632 }
633 }
634
635 *Memory = InternalAllocMaxAddress (
636 &mSmmMemoryMap,
637 NumberOfPages,
638 RequestedAddress
639 );
640 if (*Memory == (UINTN)-1) {
641 return EFI_OUT_OF_RESOURCES;
642 }
643
644 break;
645 case AllocateAddress:
646 *Memory = InternalAllocAddress (
647 &mSmmMemoryMap,
648 NumberOfPages,
649 RequestedAddress
650 );
651 if (*Memory != RequestedAddress) {
652 return EFI_NOT_FOUND;
653 }
654
655 break;
656 default:
657 return EFI_INVALID_PARAMETER;
658 }
659
660 //
661 // Update SmmMemoryMap here.
662 //
663 ConvertSmmMemoryMapEntry (MemoryType, *Memory, NumberOfPages, AddRegion);
664 if (!AddRegion) {
666 }
667
668 return EFI_SUCCESS;
669}
670
690EFIAPI
693 IN EFI_MEMORY_TYPE MemoryType,
694 IN UINTN NumberOfPages,
696 IN BOOLEAN NeedGuard
697 )
698{
700 Type,
701 MemoryType,
702 NumberOfPages,
703 Memory,
704 FALSE,
705 NeedGuard
706 );
707}
708
726EFIAPI
729 IN EFI_MEMORY_TYPE MemoryType,
730 IN UINTN NumberOfPages,
732 )
733{
734 EFI_STATUS Status;
735 BOOLEAN NeedGuard;
736
737 NeedGuard = IsPageTypeToGuard (MemoryType, Type);
738 Status = SmmInternalAllocatePages (
739 Type,
740 MemoryType,
741 NumberOfPages,
742 Memory,
743 NeedGuard
744 );
745 if (!EFI_ERROR (Status)) {
748 MemoryProfileActionAllocatePages,
749 MemoryType,
750 EFI_PAGES_TO_SIZE (NumberOfPages),
751 (VOID *)(UINTN)*Memory,
752 NULL
753 );
754 }
755
756 return Status;
757}
758
769 IN FREE_PAGE_LIST *First
770 )
771{
772 FREE_PAGE_LIST *Next;
773
774 Next = BASE_CR (First->Link.ForwardLink, FREE_PAGE_LIST, Link);
775 ASSERT (
776 TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages
777 );
778
779 if (TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) == First->NumberOfPages) {
780 First->NumberOfPages += Next->NumberOfPages;
781 RemoveEntryList (&Next->Link);
782 Next = First;
783 }
784
785 return Next;
786}
787
803 IN UINTN NumberOfPages,
804 IN BOOLEAN AddRegion
805 )
806{
807 LIST_ENTRY *Node;
808 FREE_PAGE_LIST *Pages;
809
810 if (((Memory & EFI_PAGE_MASK) != 0) || (Memory == 0) || (NumberOfPages == 0)) {
811 return EFI_INVALID_PARAMETER;
812 }
813
814 Pages = NULL;
815 Node = mSmmMemoryMap.ForwardLink;
816 while (Node != &mSmmMemoryMap) {
817 Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
818 if (Memory < (UINTN)Pages) {
819 break;
820 }
821
822 Node = Node->ForwardLink;
823 }
824
825 if ((Node != &mSmmMemoryMap) &&
826 (Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages))
827 {
828 return EFI_INVALID_PARAMETER;
829 }
830
831 if (Node->BackLink != &mSmmMemoryMap) {
832 Pages = BASE_CR (Node->BackLink, FREE_PAGE_LIST, Link);
833 if ((UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages) > Memory) {
834 return EFI_INVALID_PARAMETER;
835 }
836 }
837
838 Pages = (FREE_PAGE_LIST *)(UINTN)Memory;
839 Pages->NumberOfPages = NumberOfPages;
840 InsertTailList (Node, &Pages->Link);
841
842 if (Pages->Link.BackLink != &mSmmMemoryMap) {
843 Pages = InternalMergeNodes (
844 BASE_CR (Pages->Link.BackLink, FREE_PAGE_LIST, Link)
845 );
846 }
847
848 if (Node != &mSmmMemoryMap) {
849 InternalMergeNodes (Pages);
850 }
851
852 //
853 // Update SmmMemoryMap here.
854 //
855 ConvertSmmMemoryMapEntry (EfiConventionalMemory, Memory, NumberOfPages, AddRegion);
856 if (!AddRegion) {
858 }
859
860 return EFI_SUCCESS;
861}
862
876EFIAPI
879 IN UINTN NumberOfPages,
880 IN BOOLEAN IsGuarded
881 )
882{
883 if (IsGuarded) {
884 return SmmInternalFreePagesExWithGuard (Memory, NumberOfPages, FALSE);
885 }
886
887 return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE);
888}
889
900BOOLEAN
903 IN UINTN NumberOfPages
904 )
905{
906 LIST_ENTRY *Link;
907 MEMORY_MAP *Entry;
909
910 Last = Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1;
911
912 Link = gMemoryMap.ForwardLink;
913 while (Link != &gMemoryMap) {
914 Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
915 Link = Link->ForwardLink;
916
917 if ((Entry->Start <= Memory) && (Entry->End >= Last)) {
918 return TRUE;
919 }
920 }
921
922 return FALSE;
923}
924
937EFIAPI
940 IN UINTN NumberOfPages
941 )
942{
943 EFI_STATUS Status;
944 BOOLEAN IsGuarded;
945
946 if (!InMemMap (Memory, NumberOfPages)) {
947 return EFI_NOT_FOUND;
948 }
949
950 IsGuarded = IsHeapGuardEnabled () && IsMemoryGuarded (Memory);
951 Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
952 if (!EFI_ERROR (Status)) {
955 MemoryProfileActionFreePages,
956 EfiMaxMemoryType,
957 EFI_PAGES_TO_SIZE (NumberOfPages),
958 (VOID *)(UINTN)Memory,
959 NULL
960 );
961 }
962
963 return Status;
964}
965
975VOID
977 IN EFI_PHYSICAL_ADDRESS MemBase,
978 IN UINT64 MemLength,
979 IN EFI_MEMORY_TYPE Type,
980 IN UINT64 Attributes
981 )
982{
983 UINTN AlignedMemBase;
984
985 //
986 // Add EfiRuntimeServicesData for memory regions that is already allocated, needs testing, or needs ECC initialization
987 //
988 if ((Attributes & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
990 } else {
992 }
993
994 DEBUG ((DEBUG_INFO, "SmmAddMemoryRegion\n"));
995 DEBUG ((DEBUG_INFO, " MemBase - 0x%lx\n", MemBase));
996 DEBUG ((DEBUG_INFO, " MemLength - 0x%lx\n", MemLength));
997 DEBUG ((DEBUG_INFO, " Type - 0x%x\n", Type));
998 DEBUG ((DEBUG_INFO, " Attributes - 0x%lx\n", Attributes));
999
1000 //
1001 // Align range on an EFI_PAGE_SIZE boundary
1002 //
1003 AlignedMemBase = (UINTN)(MemBase + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
1004 MemLength -= AlignedMemBase - MemBase;
1005 if (Type == EfiConventionalMemory) {
1006 SmmInternalFreePagesEx (AlignedMemBase, TRUNCATE_TO_PAGES ((UINTN)MemLength), TRUE);
1007 } else {
1008 ConvertSmmMemoryMapEntry (EfiRuntimeServicesData, AlignedMemBase, TRUNCATE_TO_PAGES ((UINTN)MemLength), TRUE);
1009 }
1010
1012}
1013
1045EFIAPI
1047 IN OUT UINTN *MemoryMapSize,
1048 IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
1049 OUT UINTN *MapKey,
1050 OUT UINTN *DescriptorSize,
1051 OUT UINT32 *DescriptorVersion
1052 )
1053{
1054 UINTN Count;
1055 LIST_ENTRY *Link;
1056 MEMORY_MAP *Entry;
1057 UINTN Size;
1058 UINTN BufferSize;
1059
1060 Size = sizeof (EFI_MEMORY_DESCRIPTOR);
1061
1062 //
1063 // Make sure Size != sizeof(EFI_MEMORY_DESCRIPTOR). This will
1064 // prevent people from having pointer math bugs in their code.
1065 // now you have to use *DescriptorSize to make things work.
1066 //
1067 Size += sizeof (UINT64) - (Size % sizeof (UINT64));
1068
1069 if (DescriptorSize != NULL) {
1070 *DescriptorSize = Size;
1071 }
1072
1073 if (DescriptorVersion != NULL) {
1074 *DescriptorVersion = EFI_MEMORY_DESCRIPTOR_VERSION;
1075 }
1076
1077 Count = GetSmmMemoryMapEntryCount ();
1078 BufferSize = Size * Count;
1079 if (*MemoryMapSize < BufferSize) {
1080 *MemoryMapSize = BufferSize;
1081 return EFI_BUFFER_TOO_SMALL;
1082 }
1083
1084 *MemoryMapSize = BufferSize;
1085 if (MemoryMap == NULL) {
1086 return EFI_INVALID_PARAMETER;
1087 }
1088
1089 ZeroMem (MemoryMap, BufferSize);
1090 Link = gMemoryMap.ForwardLink;
1091 while (Link != &gMemoryMap) {
1092 Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
1093 Link = Link->ForwardLink;
1094
1095 MemoryMap->Type = Entry->Type;
1096 MemoryMap->PhysicalStart = Entry->Start;
1097 MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
1098
1099 MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
1100 }
1101
1102 return EFI_SUCCESS;
1103}
UINT64 UINTN
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:218
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: RShiftU64.c:28
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
Definition: BaseLib.h:2884
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN IsHeapGuardEnabled(UINT8 GuardType)
Definition: HeapGuard.c:674
BOOLEAN EFIAPI IsMemoryGuarded(IN EFI_PHYSICAL_ADDRESS Address)
Definition: HeapGuard.c:486
BOOLEAN IsPageTypeToGuard(IN EFI_MEMORY_TYPE MemoryType, IN EFI_ALLOCATE_TYPE AllocateType)
Definition: HeapGuard.c:658
VOID CoreFreeMemoryMapStack(VOID)
Definition: Page.c:314
UINTN mMapDepth
Definition: Page.c:37
LIST_ENTRY mFreeMemoryMapEntryList
Definition: Page.c:46
MEMORY_MAP * AllocateMemoryMapEntry(VOID)
Definition: Page.c:268
MEMORY_MAP mMapStack[MAX_MAP_DEPTH]
Definition: Page.c:41
UINTN InternalAllocAddress(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN Address)
Definition: Page.c:542
EFI_STATUS EFIAPI SmmFreePages(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
Definition: Page.c:938
BOOLEAN InMemMap(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
Definition: Page.c:901
UINTN InternalAllocPagesOnOneNode(IN OUT FREE_PAGE_LIST *Pages, IN UINTN NumberOfPages, IN UINTN MaxAddress)
Definition: Page.c:467
EFI_STATUS SmmInternalFreePagesEx(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN AddRegion)
Definition: Page.c:801
VOID ConvertSmmMemoryMapEntry(IN EFI_MEMORY_TYPE Type, IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN AddRegion)
Definition: Page.c:260
VOID RemoveOldEntry(IN MEMORY_MAP *Entry)
Definition: Page.c:239
FREE_PAGE_LIST * InternalMergeNodes(IN FREE_PAGE_LIST *First)
Definition: Page.c:768
UINTN InternalAllocMaxAddress(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN MaxAddress)
Definition: Page.c:510
VOID InsertNewEntry(IN LIST_ENTRY *Link, IN UINT64 Start, IN UINT64 End, IN EFI_MEMORY_TYPE Type, IN BOOLEAN Next, IN BOOLEAN AddRegion)
Definition: Page.c:206
EFI_STATUS EFIAPI SmmInternalAllocatePages(IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory, IN BOOLEAN NeedGuard)
Definition: Page.c:691
EFI_STATUS SmmInternalAllocatePagesEx(IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory, IN BOOLEAN AddRegion, IN BOOLEAN NeedGuard)
Definition: Page.c:591
EFI_STATUS EFIAPI SmmAllocatePages(IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory)
Definition: Page.c:727
EFI_STATUS EFIAPI SmmInternalFreePages(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN IsGuarded)
Definition: Page.c:877
VOID SmmAddMemoryRegion(IN EFI_PHYSICAL_ADDRESS MemBase, IN UINT64 MemLength, IN EFI_MEMORY_TYPE Type, IN UINT64 Attributes)
Definition: Page.c:976
UINTN GetSmmMemoryMapEntryCount(VOID)
Definition: Page.c:439
EFI_STATUS EFIAPI SmmCoreGetMemoryMap(IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, OUT UINTN *MapKey, OUT UINTN *DescriptorSize, OUT UINT32 *DescriptorVersion)
Definition: Page.c:1046
#define NULL
Definition: Base.h:319
#define RETURN_ADDRESS(L)
Definition: Base.h:1379
#define VOID
Definition: Base.h:269
#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 BASE_CR(Record, TYPE, Field)
Definition: Base.h:891
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:463
#define DEBUG(Expression)
Definition: DebugLib.h:435
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:660
BOOLEAN VerifyMemoryGuard(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN NumberOfPages)
Definition: HeapGuard.c:1381
UINTN InternalAllocMaxAddressWithGuard(IN OUT LIST_ENTRY *FreePageList, IN UINTN NumberOfPages, IN UINTN MaxAddress, IN EFI_MEMORY_TYPE MemoryType)
Definition: HeapGuard.c:1007
EFI_STATUS SmmInternalFreePagesExWithGuard(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages, IN BOOLEAN AddRegion)
Definition: HeapGuard.c:1086
EFI_STATUS EFIAPI SmmCoreUpdateProfile(IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_ACTION Action, IN EFI_MEMORY_TYPE MemoryType, IN UINTN Size, IN VOID *Buffer, IN CHAR8 *ActionString OPTIONAL)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_MEMORY_TYPE
@ EfiConventionalMemory
@ EfiRuntimeServicesCode
@ EfiRuntimeServicesData
#define EFI_MEMORY_DESCRIPTOR_VERSION
Definition: UefiSpec.h:148
EFI_ALLOCATE_TYPE
Definition: UefiSpec.h:29
@ AllocateMaxAddress
Definition: UefiSpec.h:38
@ AllocateAddress
Definition: UefiSpec.h:42
@ AllocateAnyPages
Definition: UefiSpec.h:33