2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/mm/mm.c
5 * PURPOSE: Boot Library Memory Manager Core
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
13 /* DATA VARIABLES ************************************************************/
15 BL_TRANSLATION_TYPE MmTranslationType
, MmOriginalTranslationType
;
16 ULONG MmDescriptorCallTreeCount
;
18 /* FUNCTIONS *****************************************************************/
25 /* Nothing to track if we're using physical memory */
26 if (MmTranslationType
== BlNone
)
28 return STATUS_SUCCESS
;
32 EarlyPrint(L
"Required for protected mode\n");
33 return STATUS_NOT_IMPLEMENTED
;
41 /* FIXME: Read BCD option to see what bad memory to remove */
42 return STATUS_SUCCESS
;
47 _In_ PBL_MEMORY_DATA MemoryData
,
48 _In_ BL_TRANSLATION_TYPE TranslationType
,
49 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
54 /* Take a reference */
55 MmDescriptorCallTreeCount
= 1;
57 /* Only support valid translation types */
58 if ((TranslationType
> BlPae
) || (LibraryParameters
->TranslationType
> BlPae
))
61 EarlyPrint(L
"Invalid translation types present\n");
62 Status
= STATUS_INVALID_PARAMETER
;
66 /* Initialize memory descriptors */
67 MmMdInitialize(0, LibraryParameters
);
69 /* Remember the page type we came in with */
70 MmOriginalTranslationType
= TranslationType
;
72 /* Initialize the physical page allocator */
73 Status
= MmPaInitialize(MemoryData
,
74 LibraryParameters
->MinimumAllocationCount
);
75 if (!NT_SUCCESS(Status
))
80 /* Initialize the memory tracker */
81 Status
= MmTrInitialize();
82 if (!NT_SUCCESS(Status
))
89 /* Initialize paging, large pages, self-mapping, PAE, if needed */
90 Status
= MmArchInitialize(1,
93 LibraryParameters
->TranslationType
);
94 if (NT_SUCCESS(Status
))
96 /* Save the newly active transation type */
97 MmTranslationType
= LibraryParameters
->TranslationType
;
99 /* Initialize the heap allocator now */
100 Status
= MmHaInitialize(LibraryParameters
->MinimumHeapSize
,
101 LibraryParameters
->HeapAllocationAttributes
);
104 /* If Phase 1 init failed, bail out */
105 if (!NT_SUCCESS(Status
))
107 /* Kill everything set setup so far */
115 /* Do we have too many descriptors? */
116 if (LibraryParameters
->DescriptorCount
> 512)
118 /* Switch to using a dynamic buffer instead */
119 EarlyPrint(L
"Warning: too many descriptors\n");
120 Status
= STATUS_NOT_IMPLEMENTED
;
122 //MmMdpSwitchToDynamicDescriptors(LibraryParameters->DescriptorCount);
125 /* Remove memory that the BCD says is bad */
126 BlMmRemoveBadMemory();
128 /* Now map all the memory regions as needed */
129 Status
= MmArchInitialize(2,
132 LibraryParameters
->TranslationType
);
133 if (NT_SUCCESS(Status
))
135 /* Initialize the block allocator */
136 Status
= MmBaInitialize();
139 /* Check if anything in phase 2 failed */
140 if (!NT_SUCCESS(Status
))
142 /* Go back to static descriptors and kill the heap */
143 //MmMdpSwitchToStaticDescriptors();
144 //HapInitializationStatus = 0;
145 ++MmDescriptorCallTreeCount
;
147 /* Destroy the Phase 1 initialization */
155 /* Free the memory descriptors and return the initialization state */
156 //MmMdFreeGlobalDescriptors();
157 --MmDescriptorCallTreeCount
;