ReactOS 0.4.15-dev-8100-g1887773
mm.c File Reference
#include "bl.h"
#include "bcd.h"
Include dependency graph for mm.c:

Go to the source code of this file.

Functions

NTSTATUS TrpGenerateMappingTracker (_In_ PVOID VirtualAddress, _In_ ULONG Flags, _In_ LARGE_INTEGER PhysicalAddress, _In_ ULONGLONG Size)
 
NTSTATUS MmTrInitialize (VOID)
 
NTSTATUS BlMmRemoveBadMemory (VOID)
 
NTSTATUS BlMmMapPhysicalAddressEx (_In_ PVOID *VirtualAddress, _In_ ULONG Flags, _In_ ULONGLONG Size, _In_ PHYSICAL_ADDRESS PhysicalAddress)
 
NTSTATUS MmUnmapVirtualAddress (_Inout_ PVOID *VirtualAddress, _Inout_ PULONGLONG Size)
 
NTSTATUS BlMmUnmapVirtualAddressEx (_In_ PVOID VirtualAddress, _In_ ULONGLONG Size)
 
BOOLEAN BlMmTranslateVirtualAddress (_In_ PVOID VirtualAddress, _Out_ PPHYSICAL_ADDRESS PhysicalAddress)
 
NTSTATUS BlpMmInitialize (_In_ PBL_MEMORY_DATA MemoryData, _In_ BL_TRANSLATION_TYPE TranslationType, _In_ PBL_LIBRARY_PARAMETERS LibraryParameters)
 

Variables

BL_TRANSLATION_TYPE MmTranslationType = BlMax
 
BL_TRANSLATION_TYPE MmOriginalTranslationType
 
ULONG MmDescriptorCallTreeCount
 

Function Documentation

◆ BlMmMapPhysicalAddressEx()

NTSTATUS BlMmMapPhysicalAddressEx ( _In_ PVOID VirtualAddress,
_In_ ULONG  Flags,
_In_ ULONGLONG  Size,
_In_ PHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 192 of file mm.c.

198{
200 PVOID MappingAddress;
201 PHYSICAL_ADDRESS MappedAddress;
203 ULONGLONG MapSize;
204 UCHAR CacheAttributes;
205 ULONGLONG BasePage, EndPage, MappedPage, FoundBasePage;
206 ULONGLONG PageOffset, FoundPageCount;
209 ULONG AddPages;
210
211 /* Increase call depth */
213
214 /* Check if any parameters are missing */
215 if (!(VirtualAddress) || !(Size))
216 {
218 goto Quickie;
219 }
220
221 /* Check for fixed allocation without an actual address */
222 if ((Flags & BlMemoryFixed) &&
223 (PhysicalAddress.QuadPart == -1) &&
224 !(*VirtualAddress))
225 {
227 goto Quickie;
228 }
229
230 /* Check for invalid requirement flag, if one is present */
234 {
236 goto Quickie;
237 }
238
239 /* Check for invalid cache attribute flags */
242 {
244 goto Quickie;
245 }
246
247 /* Select an address to map this at */
248 Status = MmSelectMappingAddress(&MappingAddress,
250 Size,
252 Flags,
254 if (!NT_SUCCESS(Status))
255 {
256 goto Quickie;
257 }
258
259 /* Map the selected address, using the appropriate caching attributes */
260 MappedAddress = PhysicalAddress;
261 MapSize = Size;
262 CacheAttributes = ((Flags & BlMemoryValidCacheAttributeMask) != 0x20) ?
264 Status = MmMapPhysicalAddress(&MappedAddress,
265 &MappingAddress,
266 &MapSize,
267 CacheAttributes);
268 if (!NT_SUCCESS(Status))
269 {
270 goto Quickie;
271 }
272
273 /* Compute the final address where the mapping was made */
274 MappedBase = (PVOID)(ULONG_PTR)((ULONG_PTR)MappingAddress +
276 MappedAddress.QuadPart);
277 MappedAddress.QuadPart = (ULONG_PTR)MappedBase;
278
279 /* Check if we're in physical or virtual mode */
281 {
282 /* We are in physical mode -- just return this address directly */
285 goto Quickie;
286 }
287
288 /* Remove the mapping address from the list of free virtual memory */
291 (ULONG_PTR)MappingAddress >> PAGE_SHIFT,
292 MapSize >> PAGE_SHIFT,
293 NULL);
294 if (NT_SUCCESS(Status))
295 {
296 /* And then add an entry for the fact we mapped it */
298 CacheAttributes,
300 MapSize);
301 }
302
303 /* Abandon if we didn't update the memory map successfully */
304 if (!NT_SUCCESS(Status))
305 {
306 /* Unmap the virtual address so it can be used later */
307 MmUnmapVirtualAddress(MappingAddress, &MapSize);
308 goto Quickie;
309 }
310
311 /* Check if no real mapping into RAM was made */
312 if (PhysicalAddress.QuadPart == -1)
313 {
314 /* Then we're done here */
317 goto Quickie;
318 }
319
320
321 /* Loop over the entire allocation */
322 BasePage = MappedAddress.QuadPart >> PAGE_SHIFT;
323 EndPage = (MappedAddress.QuadPart + MapSize) >> PAGE_SHIFT;
324 MappedPage = (ULONG_PTR)MappingAddress >> PAGE_SHIFT;
325 do
326 {
327 /* Start with the unmapped allocated list */
331 BasePage);
332 if (!Descriptor)
333 {
334 /* Try persistent next */
338 BasePage);
339 }
340 if (!Descriptor)
341 {
342 /* Try unmapped, unallocated, next */
346 BasePage);
347 }
348 if (!Descriptor)
349 {
350 /* Try reserved next */
354 BasePage);
355 }
356
357 /* Check if we have a descriptor */
358 if (Descriptor)
359 {
360 /* Remove it from its list */
362
363 /* Check if it starts before our allocation */
364 FoundBasePage = Descriptor->BasePage;
365 if (FoundBasePage < BasePage)
366 {
367 /* Create a new descriptor to cover the gap before our allocation */
368 PageOffset = BasePage - FoundBasePage;
370 Descriptor->Type,
371 FoundBasePage,
372 0,
373 PageOffset);
374
375 /* Insert it */
377
378 /* Adjust ours to ignore that piece */
379 Descriptor->PageCount -= PageOffset;
380 Descriptor->BasePage = BasePage;
381 }
382
383 /* Check if it goes beyond our allocation */
384 FoundPageCount = Descriptor->PageCount;
385 if (EndPage < (FoundPageCount + Descriptor->BasePage))
386 {
387 /* Create a new descriptor to cover the range after our allocation */
388 PageOffset = EndPage - BasePage;
390 Descriptor->Type,
391 EndPage,
392 0,
393 FoundPageCount -
394 PageOffset);
395
396 /* Insert it */
398
399 /* Adjust ours to ignore that piece */
400 Descriptor->PageCount = PageOffset;
401 }
402
403 /* Update the descriptor to be mapepd at this virtual page */
404 Descriptor->VirtualPage = MappedPage;
405
406 /* Check if this was one of the regular lists */
407 if ((List != &MmMdlReservedAllocated) &&
409 {
410 /* Was it allocated, or unallocated? */
412 {
413 /* In which case use the unallocated mapped list */
415 }
416 else
417 {
418 /* Insert it into the mapped list */
420 }
421 }
422
423 /* Add the descriptor that was removed, into the right list */
425
426 /* Add the pages this descriptor had */
427 AddPages = Descriptor->PageCount;
428 }
429 else
430 {
431 /* Nope, so just add one page */
432 AddPages = 1;
433 }
434
435 /* Increment the number of pages the descriptor had */
436 MappedPage += AddPages;
437 BasePage += AddPages;
438 }
439 while (BasePage < EndPage);
440
441 /* We're done -- returned the address */
444
445Quickie:
446 /* Cleanup descriptors and reduce depth */
449 return Status;
450}
LONG NTSTATUS
Definition: precomp.h:26
BL_MEMORY_DESCRIPTOR_LIST MmMdlMappedUnallocated
Definition: pagealloc.c:36
NTSTATUS MmMdAddDescriptorToList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor, _In_ ULONG Flags)
Definition: descriptor.c:582
NTSTATUS MmMapPhysicalAddress(_Inout_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_ PVOID *VirtualAddress, _Inout_ PULONGLONG Size, _In_ ULONG CacheAttributes)
PBL_MEMORY_DESCRIPTOR MmMdInitByteGranularDescriptor(_In_ ULONG Flags, _In_ BL_MEMORY_TYPE Type, _In_ ULONGLONG BasePage, _In_ ULONGLONG VirtualPage, _In_ ULONGLONG PageCount)
Definition: descriptor.c:377
BL_MEMORY_DESCRIPTOR_LIST MmMdlReservedAllocated
Definition: pagealloc.c:40
@ BlNone
Definition: bl.h:230
#define BL_MM_INCLUDE_UNMAPPED_UNALLOCATED
Definition: bl.h:99
VOID MmMdRemoveDescriptorFromList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR Entry)
Definition: descriptor.c:338
BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedAllocated
Definition: pagealloc.c:38
#define BL_MM_REMOVE_PHYSICAL_REGION_FLAG
Definition: bl.h:124
VOID MmMdFreeGlobalDescriptors(VOID)
Definition: descriptor.c:1332
BL_MEMORY_DESCRIPTOR_LIST MmMdlMappedAllocated
Definition: pagealloc.c:35
BL_MEMORY_DESCRIPTOR_LIST MmMdlFreeVirtual
Definition: pagealloc.c:45
BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedUnallocated
Definition: pagealloc.c:39
#define BL_MM_INCLUDE_PERSISTENT_MEMORY
Definition: bl.h:104
NTSTATUS MmMdRemoveRegionFromMdlEx(__in PBL_MEMORY_DESCRIPTOR_LIST MdList, __in ULONG Flags, __in ULONGLONG BasePage, __in ULONGLONG PageCount, __in PBL_MEMORY_DESCRIPTOR_LIST NewMdList)
@ BlMemoryFixed
Definition: bl.h:368
@ BlMemoryKernelRange
Definition: bl.h:367
@ BlMemoryValidCacheAttributeMask
Definition: bl.h:352
@ BlMemoryValidAllocationAttributes
Definition: bl.h:370
#define BL_MM_INCLUDE_UNMAPPED_ALLOCATED
Definition: bl.h:98
#define BL_MM_INCLUDE_RESERVED_ALLOCATED
Definition: bl.h:100
NTSTATUS MmSelectMappingAddress(_Out_ PVOID *MappingAddress, _In_ PVOID PreferredAddress, _In_ ULONGLONG Size, _In_ ULONG AllocationAttributes, _In_ ULONG Flags, _In_ PHYSICAL_ADDRESS PhysicalAddress)
Definition: pagealloc.c:1625
BL_MEMORY_DESCRIPTOR_LIST MmMdlPersistentMemory
Definition: pagealloc.c:43
PBL_MEMORY_DESCRIPTOR MmMdFindDescriptor(_In_ ULONG WhichList, _In_ ULONG Flags, _In_ ULONGLONG Page)
Definition: descriptor.c:1049
#define BL_MM_REMOVE_VIRTUAL_REGION_FLAG
Definition: bl.h:125
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
BL_TRANSLATION_TYPE MmTranslationType
Definition: mm.c:17
ULONG MmDescriptorCallTreeCount
Definition: mm.c:19
NTSTATUS MmUnmapVirtualAddress(_Inout_ PVOID *VirtualAddress, _Inout_ PULONGLONG Size)
Definition: mm.c:453
NTSTATUS TrpGenerateMappingTracker(_In_ PVOID VirtualAddress, _In_ ULONG Flags, _In_ LARGE_INTEGER PhysicalAddress, _In_ ULONGLONG Size)
Definition: mm.c:24
Status
Definition: gdiplustypes.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
int WINAPI EndPage(_In_ HDC)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
_Must_inspect_result_ _Outptr_result_bytebuffer_ ViewSize PVOID * MappedBase
Definition: mmfuncs.h:492
_In_opt_ PSECURITY_DESCRIPTOR _Out_ PSECURITY_DESCRIPTOR * NewDescriptor
Definition: sefuncs.h:30
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by BlDisplayGetOemBitmap(), BlImgAllocateImageBuffer(), BlUtlGetAcpiTable(), ConsoleEfiGopEnable(), EfipGetRsdt(), EfiVmOpenProtocol(), and MmPapPageAllocatorExtend().

◆ BlMmRemoveBadMemory()

NTSTATUS BlMmRemoveBadMemory ( VOID  )

Definition at line 155 of file mm.c.

158{
159 BOOLEAN AllowBad;
161 PULONGLONG BadPages;
162 ULONGLONG BadPageCount;
163
164 /* First check if bad memory access is allowed */
165 AllowBad = FALSE;
168 &AllowBad);
169 if ((NT_SUCCESS(Status)) && (AllowBad))
170 {
171 /* No point checking the list if it is */
172 return STATUS_SUCCESS;
173 }
174
175 /* Otherwise, check if there's a persisted bad page list */
178 &BadPages,
179 &BadPageCount,
180 TRUE);
181 if (NT_SUCCESS(Status))
182 {
183 EfiPrintf(L"Persistent bad page list not supported\r\n");
185 }
186
187 /* All done here */
188 return STATUS_SUCCESS;
189}
unsigned char BOOLEAN
@ BcdLibraryIntegerList_BadMemoryList
Definition: bcd.h:58
@ BcdLibraryBoolean_AllowBadMemoryAccess
Definition: bcd.h:59
NTSTATUS BlGetBootOptionBoolean(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PBOOLEAN Value)
Definition: bcdopt.c:504
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
NTSTATUS BlpGetBootOptionIntegerList(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PULONGLONG *Value, _Out_ PULONGLONG Count, _In_ BOOLEAN NoCopy)
Definition: bcdopt.c:541
BL_LOADED_APPLICATION_ENTRY BlpApplicationEntry
Definition: bootlib.c:19
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:383
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define L(x)
Definition: ntvdm.h:50
PBL_BCD_OPTION BcdData
Definition: bl.h:867

Referenced by BlInitializeLibrary(), and BlpMmInitialize().

◆ BlMmTranslateVirtualAddress()

BOOLEAN BlMmTranslateVirtualAddress ( _In_ PVOID  VirtualAddress,
_Out_ PPHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 525 of file mm.c.

529{
530 /* Make sure arguments are present */
531 if (!(VirtualAddress) || !(PhysicalAddress))
532 {
533 return FALSE;
534 }
535
536 /* Do the architecture-specific translation */
538}
BOOLEAN MmArchTranslateVirtualAddress(_In_ PVOID VirtualAddress, _Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_opt_ PULONG CachingFlags)
Definition: mmx86.c:108

Referenced by BlImgUnallocateImageBuffer(), EfiAllocatePages(), EfiConInExSetState(), EfiGetMemoryMap(), EfiGopGetCurrentMode(), EfiGopGetFrameBuffer(), EfiLocateHandleBuffer(), EfiVmOpenProtocol(), ImgpLoadPEImage(), and OslDrawLogo().

◆ BlMmUnmapVirtualAddressEx()

NTSTATUS BlMmUnmapVirtualAddressEx ( _In_ PVOID  VirtualAddress,
_In_ ULONGLONG  Size 
)

Definition at line 487 of file mm.c.

491{
493
494 /* Increment call depth */
496
497 /* Make sure all parameters are there */
498 if ((VirtualAddress) && (Size))
499 {
500 /* Unmap the virtual address */
502
503 /* Check if we actually had a virtual mapping active */
505 {
506 /* We don't support virtual memory yet @TODO */
507 EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__);
508 EfiStall(1000000);
510 }
511 }
512 else
513 {
514 /* Fail */
516 }
517
518 /* Cleanup descriptors and reduce depth */
521 return Status;
522}
NTSTATUS EfiStall(_In_ ULONG StallTime)
Definition: firmware.c:1003
#define __FUNCTION__
Definition: types.h:116

Referenced by BlDisplayGetOemBitmap(), BlDisplayInvalidateOemBitmap(), BlDisplayValidOemBitmap(), BlImgLoadImageWithProgress2(), BlImgUnallocateImageBuffer(), BlUtlGetAcpiTable(), ConsoleFirmwareGraphicalDisable(), EfipGetRsdt(), EfiVmOpenProtocol(), EfiVmpFreeInterfaceEntry(), and ImgpLoadPEImage().

◆ BlpMmInitialize()

NTSTATUS BlpMmInitialize ( _In_ PBL_MEMORY_DATA  MemoryData,
_In_ BL_TRANSLATION_TYPE  TranslationType,
_In_ PBL_LIBRARY_PARAMETERS  LibraryParameters 
)

Definition at line 541 of file mm.c.

546{
548
549 /* Take a reference */
551
552 /* Only support valid translation types */
553 if ((TranslationType > BlPae) || (LibraryParameters->TranslationType > BlPae))
554 {
555 /* Bail out */
556 EfiPrintf(L"Invalid translation types present\r\n");
558 goto Quickie;
559 }
560
561 /* Initialize memory descriptors */
562 MmMdInitialize(0, LibraryParameters);
563
564 /* Remember the page type we came in with */
565 MmOriginalTranslationType = TranslationType;
566
567 /* Initialize the physical page allocator */
568 Status = MmPaInitialize(MemoryData,
569 LibraryParameters->MinimumAllocationCount);
570 if (!NT_SUCCESS(Status))
571 {
572 goto Quickie;
573 }
574
575 /* Initialize the memory tracker */
577 if (!NT_SUCCESS(Status))
578 {
579 EfiPrintf(L"TR Mm init failed: %lx\r\n", Status);
580 //MmArchDestroy();
581 //MmPaDestroy(1);
582 goto Quickie;
583 }
584
585 /* Initialize paging, large pages, self-mapping, PAE, if needed */
587 MemoryData,
588 TranslationType,
589 LibraryParameters->TranslationType);
590 if (NT_SUCCESS(Status))
591 {
592 /* Save the newly active transation type */
593 MmTranslationType = LibraryParameters->TranslationType;
594
595 /* Initialize the heap allocator now */
596 Status = MmHaInitialize(LibraryParameters->MinimumHeapSize,
597 LibraryParameters->HeapAllocationAttributes);
598 }
599
600 /* If Phase 1 init failed, bail out */
601 if (!NT_SUCCESS(Status))
602 {
603 /* Kill everything set setup so far */
604 EfiPrintf(L"Phase 1 Mm init failed: %lx\r\n", Status);
605 //MmPaDestroy(0);
606 //MmTrDestroy();
607 //MmArchDestroy();
608 //MmPaDestroy(1);
609 goto Quickie;
610 }
611
612 /* Do we have too many descriptors? */
613 if (LibraryParameters->DescriptorCount > 512)
614 {
615 /* Switch to using a dynamic buffer instead */
616 EfiPrintf(L"Warning: too many descriptors\r\n");
618 goto Quickie;
619 //MmMdpSwitchToDynamicDescriptors(LibraryParameters->DescriptorCount);
620 }
621
622 /* Remove memory that the BCD says is bad */
624
625 /* Now map all the memory regions as needed */
627 MemoryData,
628 TranslationType,
629 LibraryParameters->TranslationType);
630 if (NT_SUCCESS(Status))
631 {
632 /* Initialize the block allocator */
634 }
635
636 /* Check if anything in phase 2 failed */
637 if (!NT_SUCCESS(Status))
638 {
639 /* Go back to static descriptors and kill the heap */
640 EfiPrintf(L"Phase 2 Mm init failed: %lx\r\n", Status);
641 //MmMdpSwitchToStaticDescriptors();
642 //HapInitializationStatus = 0;
643 //++MmDescriptorCallTreeCount;
644
645 /* Destroy the Phase 1 initialization */
646 //MmPaDestroy(0);
647 //MmTrDestroy();
648 //MmArchDestroy();
649 //MmPaDestroy(1);
650 }
651
652Quickie:
653 /* Free the memory descriptors and return the initialization state */
656 return Status;
657}
NTSTATUS MmPaInitialize(_In_ PBL_MEMORY_DATA MemoryData, _In_ ULONG MinimumPages)
NTSTATUS MmArchInitialize(_In_ ULONG Phase, _In_ PBL_MEMORY_DATA MemoryData, _In_ BL_TRANSLATION_TYPE TranslationType, _In_ BL_TRANSLATION_TYPE LibraryTranslationType)
Definition: mmx86.c:1028
@ BlPae
Definition: bl.h:232
NTSTATUS MmHaInitialize(_In_ ULONG HeapSize, _In_ ULONG HeapAttributes)
Definition: heapalloc.c:538
VOID MmMdInitialize(_In_ ULONG Phase, _In_ PBL_LIBRARY_PARAMETERS LibraryParameters)
Definition: descriptor.c:1384
NTSTATUS MmBaInitialize(VOID)
Definition: blkalloc.c:271
NTSTATUS BlMmRemoveBadMemory(VOID)
Definition: mm.c:155
NTSTATUS MmTrInitialize(VOID)
Definition: mm.c:84
BL_TRANSLATION_TYPE MmOriginalTranslationType
Definition: mm.c:18

Referenced by InitializeLibrary().

◆ MmTrInitialize()

NTSTATUS MmTrInitialize ( VOID  )

Definition at line 84 of file mm.c.

87{
90 PLIST_ENTRY NextEntry;
91
92 /* Nothing to track if we're using physical memory */
94 {
95 return STATUS_SUCCESS;
96 }
97
98 /* Initialize all the virtual lists */
103
104 /* Initialize a 4GB free descriptor */
107 0,
108 0,
109 ((ULONGLONG)4 * 1024 * 1024 * 1024) >>
110 PAGE_SHIFT);
111 if (!Descriptor)
112 {
114 goto Quickie;
115 }
116
117 /* Add this 4GB region to the free virtual address space list */
121 if (!NT_SUCCESS(Status))
122 {
124 goto Quickie;
125 }
126
127 /* Remove any reserved regions of virtual address space */
129 while (NextEntry != MmMdlReservedAllocated.First)
130 {
131 /* Grab the descriptor and see if it's mapped */
132 Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, ListEntry);
133 if (Descriptor->VirtualPage)
134 {
135 EfiPrintf(L"Need to handle reserved allocation: %llx %llx\r\n",
136 Descriptor->VirtualPage, Descriptor->PageCount);
137 EfiStall(100000);
139 goto Quickie;
140 }
141
142 /* Next entry */
143 NextEntry = NextEntry->Flink;
144 }
145
146 /* Set success if we made it */
148
149Quickie:
150 /* Return back to caller */
151 return Status;
152}
@ BlConventionalMemory
Definition: bl.h:327
FORCEINLINE VOID MmMdInitializeListHead(_In_ PBL_MEMORY_DESCRIPTOR_LIST List)
Definition: bl.h:1376
@ BlMdTracker
Definition: bl.h:225
@ BlMdVirtual
Definition: bl.h:224
BL_MEMORY_DESCRIPTOR_LIST MmMdlMappingTrackers
Definition: pagealloc.c:46
#define BL_MM_ADD_DESCRIPTOR_COALESCE_FLAG
Definition: bl.h:89
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
PLIST_ENTRY First
Definition: bl.h:1007
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by BlpMmInitialize().

◆ MmUnmapVirtualAddress()

NTSTATUS MmUnmapVirtualAddress ( _Inout_ PVOID VirtualAddress,
_Inout_ PULONGLONG  Size 
)

Definition at line 453 of file mm.c.

457{
459
460 /* Make sure parameters were passed in and are valid */
461 if ((VirtualAddress) && (Size) && (*Size <= 0xFFFFFFFF))
462 {
463 /* Nothing to do if translation isn't active */
465 {
467 }
468 else
469 {
470 /* We don't support virtual memory yet @TODO */
471 EfiPrintf(L"unmap not yet implemented in %S\r\n", __FUNCTION__);
472 EfiStall(1000000);
474 }
475 }
476 else
477 {
478 /* Fail */
480 }
481
482 /* All done */
483 return Status;
484}

Referenced by BlMmMapPhysicalAddressEx(), BlMmUnmapVirtualAddressEx(), and Mmx86MapInitStructure().

◆ TrpGenerateMappingTracker()

NTSTATUS TrpGenerateMappingTracker ( _In_ PVOID  VirtualAddress,
_In_ ULONG  Flags,
_In_ LARGE_INTEGER  PhysicalAddress,
_In_ ULONGLONG  Size 
)

Definition at line 24 of file mm.c.

30{
31 PBL_MEMORY_DESCRIPTOR Descriptor, NextDescriptor;
32 PLIST_ENTRY ListHead, NextEntry;
33
34 /* Increment descriptor call count */
36
37 /* Initialize a descriptor for this allocation */
39 0,
42 Size);
43
44 /* Loop the current tracker list */
45 ListHead = MmMdlMappingTrackers.First;
46 NextEntry = ListHead->Flink;
47 if (IsListEmpty(ListHead))
48 {
49 /* If it's empty, just add the descriptor at the end */
50 InsertTailList(ListHead, &Descriptor->ListEntry);
51 goto Quickie;
52 }
53
54 /* Otherwise, go to the last descriptor */
55 NextDescriptor = CONTAINING_RECORD(NextEntry,
57 ListEntry);
58 while (NextDescriptor->VirtualPage < Descriptor->VirtualPage)
59 {
60 /* Keep going... */
61 NextEntry = NextEntry->Flink;
62 NextDescriptor = CONTAINING_RECORD(NextEntry,
64 ListEntry);
65
66 /* If we hit the end of the list, just add it at the end */
67 if (NextEntry == ListHead)
68 {
69 goto Quickie;
70 }
71
72 /* Otherwise, add it right after this descriptor */
73 InsertTailList(&NextDescriptor->ListEntry, &Descriptor->ListEntry);
74 }
75
76Quickie:
77 /* Release any global descriptors allocated */
80 return STATUS_SUCCESS;
81}
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
ULONGLONG VirtualPage
Definition: bl.h:831
LIST_ENTRY ListEntry
Definition: bl.h:825

Referenced by BlMmMapPhysicalAddressEx().

Variable Documentation

◆ MmDescriptorCallTreeCount

◆ MmOriginalTranslationType

BL_TRANSLATION_TYPE MmOriginalTranslationType

Definition at line 18 of file mm.c.

Referenced by BlpMmInitialize().

◆ MmTranslationType