2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/mm/descriptor.c
5 * PURPOSE: Boot Library Memory Manager Descriptor Manager
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
13 /* DATA VARIABLES ************************************************************/
15 BL_MEMORY_DESCRIPTOR MmStaticMemoryDescriptors
[512];
16 ULONG MmGlobalMemoryDescriptorCount
;
17 PBL_MEMORY_DESCRIPTOR MmGlobalMemoryDescriptors
;
18 BOOLEAN MmGlobalMemoryDescriptorsUsed
;
19 PBL_MEMORY_DESCRIPTOR MmDynamicMemoryDescriptors
;
20 ULONG MmDynamicMemoryDescriptorCount
;
22 /* FUNCTIONS *****************************************************************/
25 MmMdpSwitchToDynamicDescriptors (
29 EarlyPrint(L
"NOT SUPPORTED!!!\n");
35 _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor
40 /* Check if this is a valid static descriptor */
41 if (((MmDynamicMemoryDescriptors
) &&
42 (MemoryDescriptor
>= MmDynamicMemoryDescriptors
) &&
43 (MemoryDescriptor
< (MmDynamicMemoryDescriptors
+ MmDynamicMemoryDescriptorCount
))) ||
44 ((MemoryDescriptor
>= MmStaticMemoryDescriptors
) && (MemoryDescriptor
< &MmStaticMemoryDescriptors
[511])))
46 /* It's a global/static descriptor, so just zero it */
47 RtlZeroMemory(MemoryDescriptor
, sizeof(BL_MEMORY_DESCRIPTOR
));
48 Status
= STATUS_SUCCESS
;
52 /* It's a dynamic descriptor, so free it */
53 EarlyPrint(L
"Dynamic descriptors not yet supported\n");
54 Status
= STATUS_NOT_IMPLEMENTED
;
62 MmMdpSaveCurrentListPointer (
63 _In_ PBL_MEMORY_DESCRIPTOR_LIST MdList
,
64 _In_ PLIST_ENTRY Current
67 /* Make sure that this is not a global descriptor and not the first one */
68 if (((Current
< &MmGlobalMemoryDescriptors
->ListEntry
) ||
69 (Current
>= &MmGlobalMemoryDescriptors
[MmGlobalMemoryDescriptorCount
].ListEntry
)) &&
70 (Current
!= MdList
->First
))
72 /* Save this as the current pointer */
73 MdList
->This
= Current
;
78 MmMdRemoveDescriptorFromList (
79 _In_ PBL_MEMORY_DESCRIPTOR_LIST MdList
,
80 _In_ PBL_MEMORY_DESCRIPTOR Entry
83 /* Remove the entry */
84 RemoveEntryList(&Entry
->ListEntry
);
86 /* Check if this was the current link */
87 if (MdList
->This
== &Entry
->ListEntry
)
89 /* Remove the current link and set the next one */
91 MmMdpSaveCurrentListPointer(MdList
, Entry
->ListEntry
.Blink
);
97 _In_ PBL_MEMORY_DESCRIPTOR_LIST MdList
100 PLIST_ENTRY FirstEntry
, NextEntry
;
101 PBL_MEMORY_DESCRIPTOR Entry
;
103 /* Go over every descriptor from the top */
104 FirstEntry
= MdList
->First
;
105 NextEntry
= FirstEntry
->Flink
;
106 while (NextEntry
!= FirstEntry
)
108 /* Remove and free each one */
109 Entry
= CONTAINING_RECORD(NextEntry
, BL_MEMORY_DESCRIPTOR
, ListEntry
);
110 NextEntry
= NextEntry
->Flink
;
111 MmMdRemoveDescriptorFromList(MdList
, Entry
);
112 MmMdFreeDescriptor(Entry
);
119 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
122 /* Are we in phase 1? */
125 /* Switch to dynamic descriptors if we have too many */
126 if (LibraryParameters
->DescriptorCount
> RTL_NUMBER_OF(MmStaticMemoryDescriptors
))
128 MmMdpSwitchToDynamicDescriptors(LibraryParameters
->DescriptorCount
);
133 /* In phase 0, start with a pool of 512 static descriptors */
134 MmGlobalMemoryDescriptorCount
= RTL_NUMBER_OF(MmStaticMemoryDescriptors
);
135 MmGlobalMemoryDescriptors
= MmStaticMemoryDescriptors
;
136 RtlZeroMemory(MmStaticMemoryDescriptors
, sizeof(MmStaticMemoryDescriptors
));
137 MmGlobalMemoryDescriptorsUsed
= FALSE
;