Cleanup hardware allocation memory pool related code
This commit is contained in:
parent
abb65b99fe
commit
6176ca38a8
@ -45,13 +45,13 @@
|
||||
#define MM_DEFAULT_SECONDARY_COLORS 64
|
||||
|
||||
/* Number of HAL allocation descriptors */
|
||||
#define MM_HAL_ALLOCATION_DESCRIPTORS 64
|
||||
#define MM_HARDWARE_ALLOCATION_DESCRIPTORS 64
|
||||
|
||||
/* Kernel HAL heap initial start address */
|
||||
#define MM_HAL_HEAP_START_ADDRESS ((PVOID)(((ULONG_PTR)MM_HAL_VA_START) + 1024 * 1024))
|
||||
#define MM_HARDWARE_HEAP_START_ADDRESS ((PVOID)(((ULONG_PTR)MM_HARDWARE_VA_START) + 1024 * 1024))
|
||||
|
||||
/* HAL memory pool virtual address start */
|
||||
#define MM_HAL_VA_START 0xFFFFFFFFFFC00000ULL
|
||||
#define MM_HARDWARE_VA_START 0xFFFFFFFFFFC00000ULL
|
||||
|
||||
/* Maximum physical address used by HAL allocations */
|
||||
#define MM_MAXIMUM_PHYSICAL_ADDRESS 0x00000000FFFFFFFF
|
||||
|
@ -38,13 +38,13 @@
|
||||
#define MM_DEFAULT_SECONDARY_COLORS 64
|
||||
|
||||
/* Number of HAL allocation descriptors */
|
||||
#define MM_HAL_ALLOCATION_DESCRIPTORS 64
|
||||
#define MM_HARDWARE_ALLOCATION_DESCRIPTORS 64
|
||||
|
||||
/* Kernel HAL heap initial start address */
|
||||
#define MM_HAL_HEAP_START_ADDRESS ((PVOID)(((ULONG_PTR)MM_HAL_VA_START) + 1024 * 1024))
|
||||
#define MM_HARDWARE_HEAP_START_ADDRESS ((PVOID)(((ULONG_PTR)MM_HARDWARE_VA_START) + 1024 * 1024))
|
||||
|
||||
/* HAL memory pool virtual address start */
|
||||
#define MM_HAL_VA_START 0xFFC00000
|
||||
#define MM_HARDWARE_VA_START 0xFFC00000
|
||||
|
||||
/* Maximum physical address used by HAL allocations */
|
||||
#define MM_MAXIMUM_PHYSICAL_ADDRESS 0xFFFFFFFF
|
||||
|
@ -48,7 +48,7 @@ typedef enum _LOADER_MEMORY_TYPE
|
||||
LoaderBBTMemory,
|
||||
LoaderReserve,
|
||||
LoaderXIPRom,
|
||||
LoaderHALCachedMemory,
|
||||
LoaderHardwareCachedMemory,
|
||||
LoaderMaximum
|
||||
} LOADER_MEMORY_TYPE, *PLOADER_MEMORY_TYPE;
|
||||
|
||||
|
@ -38,7 +38,7 @@ XtMapHalMemory(IN PXTBL_PAGE_MAPPING PageMap)
|
||||
PxeBase = ((PHARDWARE_PTE)(PageMap->PtePointer));
|
||||
|
||||
/* Check if PXE entry already exists */
|
||||
if(!PxeBase[(MM_HAL_VA_START >> MM_PXI_SHIFT) & 0x1FF].Valid)
|
||||
if(!PxeBase[(MM_HARDWARE_VA_START >> MM_PXI_SHIFT) & 0x1FF].Valid)
|
||||
{
|
||||
/* No valid PXE, allocate memory */
|
||||
Status = XtLdrProtocol->Memory.AllocatePages(1, &Address);
|
||||
@ -52,9 +52,9 @@ XtMapHalMemory(IN PXTBL_PAGE_MAPPING PageMap)
|
||||
RtlZeroMemory((PVOID)Address, EFI_PAGE_SIZE);
|
||||
|
||||
/* Make PXE valid */
|
||||
PxeBase[(MM_HAL_VA_START >> MM_PXI_SHIFT) & 0x1FF].Valid = 1;
|
||||
PxeBase[(MM_HAL_VA_START >> MM_PXI_SHIFT) & 0x1FF].PageFrameNumber = Address / EFI_PAGE_SIZE;
|
||||
PxeBase[(MM_HAL_VA_START >> MM_PXI_SHIFT) & 0x1FF].Writable = 1;
|
||||
PxeBase[(MM_HARDWARE_VA_START >> MM_PXI_SHIFT) & 0x1FF].Valid = 1;
|
||||
PxeBase[(MM_HARDWARE_VA_START >> MM_PXI_SHIFT) & 0x1FF].PageFrameNumber = Address / EFI_PAGE_SIZE;
|
||||
PxeBase[(MM_HARDWARE_VA_START >> MM_PXI_SHIFT) & 0x1FF].Writable = 1;
|
||||
|
||||
/* Set PPE base address */
|
||||
PpeBase = (PHARDWARE_PTE)(UINT_PTR)Address;
|
||||
@ -62,11 +62,11 @@ XtMapHalMemory(IN PXTBL_PAGE_MAPPING PageMap)
|
||||
else
|
||||
{
|
||||
/* Set PPE base address based on existing PXE */
|
||||
PpeBase = (PHARDWARE_PTE)((PxeBase[(MM_HAL_VA_START >> MM_PXI_SHIFT) & 0x1FF].PageFrameNumber) << EFI_PAGE_SHIFT);
|
||||
PpeBase = (PHARDWARE_PTE)((PxeBase[(MM_HARDWARE_VA_START >> MM_PXI_SHIFT) & 0x1FF].PageFrameNumber) << EFI_PAGE_SHIFT);
|
||||
}
|
||||
|
||||
/* Check if PPE entry already exists */
|
||||
if(!PpeBase[(MM_HAL_VA_START >> MM_PPI_SHIFT) & 0x1FF].Valid)
|
||||
if(!PpeBase[(MM_HARDWARE_VA_START >> MM_PPI_SHIFT) & 0x1FF].Valid)
|
||||
{
|
||||
/* No valid PPE, allocate memory */
|
||||
Status = XtLdrProtocol->Memory.AllocatePages(1, &Address);
|
||||
@ -80,9 +80,9 @@ XtMapHalMemory(IN PXTBL_PAGE_MAPPING PageMap)
|
||||
RtlZeroMemory((PVOID)Address, EFI_PAGE_SIZE);
|
||||
|
||||
/* Make PPE valid */
|
||||
PpeBase[(MM_HAL_VA_START >> MM_PPI_SHIFT) & 0x1FF].Valid = 1;
|
||||
PpeBase[(MM_HAL_VA_START >> MM_PPI_SHIFT) & 0x1FF].PageFrameNumber = Address / EFI_PAGE_SIZE;
|
||||
PpeBase[(MM_HAL_VA_START >> MM_PPI_SHIFT) & 0x1FF].Writable = 1;
|
||||
PpeBase[(MM_HARDWARE_VA_START >> MM_PPI_SHIFT) & 0x1FF].Valid = 1;
|
||||
PpeBase[(MM_HARDWARE_VA_START >> MM_PPI_SHIFT) & 0x1FF].PageFrameNumber = Address / EFI_PAGE_SIZE;
|
||||
PpeBase[(MM_HARDWARE_VA_START >> MM_PPI_SHIFT) & 0x1FF].Writable = 1;
|
||||
|
||||
/* Set PDE base address */
|
||||
PdeBase = (PHARDWARE_PTE)Address;
|
||||
@ -90,14 +90,14 @@ XtMapHalMemory(IN PXTBL_PAGE_MAPPING PageMap)
|
||||
else
|
||||
{
|
||||
/* Set PDE base address, based on existing PPE */
|
||||
PdeBase = (PHARDWARE_PTE)((PpeBase[(MM_HAL_VA_START >> MM_PPI_SHIFT) & 0x1FF].PageFrameNumber) << EFI_PAGE_SHIFT);
|
||||
PdeBase = (PHARDWARE_PTE)((PpeBase[(MM_HARDWARE_VA_START >> MM_PPI_SHIFT) & 0x1FF].PageFrameNumber) << EFI_PAGE_SHIFT);
|
||||
}
|
||||
|
||||
/* Loop through 2 PDE entries */
|
||||
for(UINT Index = 0 ; Index < 2 ; Index++)
|
||||
{
|
||||
/* Check if PDE entry already exists */
|
||||
if(!PdeBase[((MM_HAL_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].Valid)
|
||||
if(!PdeBase[((MM_HARDWARE_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].Valid)
|
||||
{
|
||||
/* No valid PDE, allocate memory */
|
||||
Status = XtLdrProtocol->Memory.AllocatePages(1, &Address);
|
||||
@ -111,9 +111,9 @@ XtMapHalMemory(IN PXTBL_PAGE_MAPPING PageMap)
|
||||
RtlZeroMemory((PVOID)Address, EFI_PAGE_SIZE);
|
||||
|
||||
/* Make PDE valid */
|
||||
PdeBase[((MM_HAL_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].Valid = 1;
|
||||
PdeBase[((MM_HAL_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].PageFrameNumber = Address / EFI_PAGE_SIZE;
|
||||
PdeBase[((MM_HAL_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].Writable = 1;
|
||||
PdeBase[((MM_HARDWARE_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].Valid = 1;
|
||||
PdeBase[((MM_HARDWARE_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].PageFrameNumber = Address / EFI_PAGE_SIZE;
|
||||
PdeBase[((MM_HARDWARE_VA_START >> MM_PDI_SHIFT) & 0x1FF) + Index].Writable = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,16 +69,16 @@ EXTERN ULONG MmPageMapLevel;
|
||||
/* Processor structures data (THIS IS A TEMPORARY HACK) */
|
||||
EXTERN UCHAR MmProcessorStructuresData[MAXIMUM_PROCESSORS][KPROCESSOR_STRUCTURES_SIZE];
|
||||
|
||||
/* Allocation descriptors dedicated for HAL */
|
||||
EXTERN LOADER_MEMORY_DESCRIPTOR MmpHalAllocationDescriptors[MM_HAL_ALLOCATION_DESCRIPTORS];
|
||||
/* Allocation descriptors dedicated for hardware layer */
|
||||
EXTERN LOADER_MEMORY_DESCRIPTOR MmpHardwareAllocationDescriptors[MM_HARDWARE_ALLOCATION_DESCRIPTORS];
|
||||
|
||||
/* Live address of kernel HAL heap */
|
||||
EXTERN PVOID MmpHalHeapStart;
|
||||
/* Live address of kernel's hardware heap */
|
||||
EXTERN PVOID MmpHardwareHeapStart;
|
||||
|
||||
/* Architecture-specific memory extension */
|
||||
EXTERN BOOLEAN MmpMemoryExtension;
|
||||
|
||||
/* Number of used HAL allocation descriptors */
|
||||
EXTERN ULONG MmpUsedHalAllocationDescriptors;
|
||||
/* Number of used hardware allocation descriptors */
|
||||
EXTERN ULONG MmpUsedHardwareAllocationDescriptors;
|
||||
|
||||
#endif /* __XTOSKRNL_GLOBALS_H */
|
||||
|
@ -30,14 +30,14 @@ ULONG MmPageMapLevel;
|
||||
/* Processor structures data (THIS IS A TEMPORARY HACK) */
|
||||
UCHAR MmProcessorStructuresData[MAXIMUM_PROCESSORS][KPROCESSOR_STRUCTURES_SIZE] = {0};
|
||||
|
||||
/* Allocation descriptors dedicated for HAL */
|
||||
LOADER_MEMORY_DESCRIPTOR MmpHalAllocationDescriptors[MM_HAL_ALLOCATION_DESCRIPTORS];
|
||||
/* Allocation descriptors dedicated for hardware layer */
|
||||
LOADER_MEMORY_DESCRIPTOR MmpHardwareAllocationDescriptors[MM_HARDWARE_ALLOCATION_DESCRIPTORS];
|
||||
|
||||
/* Live address of kernel HAL heap */
|
||||
PVOID MmpHalHeapStart = MM_HAL_HEAP_START_ADDRESS;
|
||||
/* Live address of kernel's hardware heap */
|
||||
PVOID MmpHardwareHeapStart = MM_HARDWARE_HEAP_START_ADDRESS;
|
||||
|
||||
/* Architecture-specific memory extension */
|
||||
BOOLEAN MmpMemoryExtension;
|
||||
|
||||
/* Number of used HAL allocation descriptors */
|
||||
ULONG MmpUsedHalAllocationDescriptors = 0;
|
||||
/* Number of used hardware allocation descriptors */
|
||||
ULONG MmpUsedHardwareAllocationDescriptors = 0;
|
||||
|
@ -31,7 +31,7 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
IN BOOLEAN Aligned,
|
||||
OUT PULONG_PTR Buffer)
|
||||
{
|
||||
PLOADER_MEMORY_DESCRIPTOR Descriptor, ExtraDescriptor, HalDescriptor;
|
||||
PLOADER_MEMORY_DESCRIPTOR Descriptor, ExtraDescriptor, HardwareDescriptor;
|
||||
PFN_NUMBER Alignment, MaxPage;
|
||||
ULONGLONG PhysicalAddress;
|
||||
PLIST_ENTRY ListEntry;
|
||||
@ -43,7 +43,7 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
MaxPage = MM_MAXIMUM_PHYSICAL_ADDRESS >> MM_PAGE_SHIFT;
|
||||
|
||||
/* Make sure there are at least 2 descriptors available */
|
||||
if((MmpUsedHalAllocationDescriptors + 2) > MM_HAL_ALLOCATION_DESCRIPTORS)
|
||||
if((MmpUsedHardwareAllocationDescriptors + 2) > MM_HARDWARE_ALLOCATION_DESCRIPTORS)
|
||||
{
|
||||
/* Not enough descriptors, return error */
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
@ -84,13 +84,13 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
}
|
||||
|
||||
/* Allocate new descriptor */
|
||||
HalDescriptor = &MmpHalAllocationDescriptors[MmpUsedHalAllocationDescriptors];
|
||||
HalDescriptor->BasePage = Descriptor->BasePage + Alignment;
|
||||
HalDescriptor->MemoryType = LoaderHALCachedMemory;
|
||||
HalDescriptor->PageCount = PageCount;
|
||||
HardwareDescriptor = &MmpHardwareAllocationDescriptors[MmpUsedHardwareAllocationDescriptors];
|
||||
HardwareDescriptor->BasePage = Descriptor->BasePage + Alignment;
|
||||
HardwareDescriptor->MemoryType = LoaderHardwareCachedMemory;
|
||||
HardwareDescriptor->PageCount = PageCount;
|
||||
|
||||
/* Update HAL allocation descriptors count */
|
||||
MmpUsedHalAllocationDescriptors++;
|
||||
/* Update hardware allocation descriptors count */
|
||||
MmpUsedHardwareAllocationDescriptors++;
|
||||
|
||||
/* Check if alignment was done */
|
||||
if(Alignment)
|
||||
@ -99,13 +99,13 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
if(Descriptor->PageCount > (PageCount + Alignment))
|
||||
{
|
||||
/* Initialize extra descriptor */
|
||||
ExtraDescriptor = &MmpHalAllocationDescriptors[MmpUsedHalAllocationDescriptors];
|
||||
ExtraDescriptor = &MmpHardwareAllocationDescriptors[MmpUsedHardwareAllocationDescriptors];
|
||||
ExtraDescriptor->BasePage = Descriptor->BasePage + Alignment + (ULONG)PageCount;
|
||||
ExtraDescriptor->MemoryType = LoaderFree;
|
||||
ExtraDescriptor->PageCount = Descriptor->PageCount - (Alignment + (ULONG)PageCount);
|
||||
|
||||
/* Update HAL allocation descriptors count */
|
||||
MmpUsedHalAllocationDescriptors++;
|
||||
/* Update hardware allocation descriptors count */
|
||||
MmpUsedHardwareAllocationDescriptors++;
|
||||
|
||||
/* Insert extra descriptor in the list */
|
||||
RtlInsertHeadList(&Descriptor->ListEntry, &ExtraDescriptor->ListEntry);
|
||||
@ -115,7 +115,7 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
Descriptor->PageCount = Alignment;
|
||||
|
||||
/* Insert new descriptor in the list */
|
||||
RtlInsertHeadList(&Descriptor->ListEntry, &HalDescriptor->ListEntry);
|
||||
RtlInsertHeadList(&Descriptor->ListEntry, &HardwareDescriptor->ListEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -124,7 +124,7 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
Descriptor->PageCount -= (ULONG)PageCount;
|
||||
|
||||
/* Insert new descriptor in the list */
|
||||
RtlInsertTailList(&Descriptor->ListEntry, &HalDescriptor->ListEntry);
|
||||
RtlInsertTailList(&Descriptor->ListEntry, &HardwareDescriptor->ListEntry);
|
||||
|
||||
/* Check if source descriptor is fully consumed */
|
||||
if(Descriptor->PageCount == 0)
|
||||
@ -140,7 +140,7 @@ MmAllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps physical address to the virtual memory area used by kernel hardware layer (HAL).
|
||||
* Maps physical address to the virtual memory area used by kernel hardware layer.
|
||||
*
|
||||
* @param PhysicalAddress
|
||||
* Supplies the physical address to map.
|
||||
@ -170,7 +170,7 @@ MmMapHardwareMemory(IN PHYSICAL_ADDRESS PhysicalAddress,
|
||||
PHARDWARE_PTE PtePointer;
|
||||
|
||||
/* Initialize variables */
|
||||
BaseAddress = MmpHalHeapStart;
|
||||
BaseAddress = MmpHardwareHeapStart;
|
||||
MappedPages = 0;
|
||||
ReturnAddress = BaseAddress;
|
||||
*VirtualAddress = NULL;
|
||||
@ -206,10 +206,10 @@ MmMapHardwareMemory(IN PHYSICAL_ADDRESS PhysicalAddress,
|
||||
ReturnAddress = (PVOID)(ULONG_PTR)(BaseAddress + PAGE_OFFSET(PhysicalAddress.LowPart));
|
||||
|
||||
/* Check if base address starts at the beginning of the heap */
|
||||
if(BaseAddress == MmpHalHeapStart)
|
||||
if(BaseAddress == MmpHardwareHeapStart)
|
||||
{
|
||||
/* Move heap beyond base address */
|
||||
MmpHalHeapStart = (PVOID)((ULONG_PTR)BaseAddress + ((ULONG_PTR)PageCount << MM_PAGE_SHIFT));
|
||||
MmpHardwareHeapStart = (PVOID)((ULONG_PTR)BaseAddress + ((ULONG_PTR)PageCount << MM_PAGE_SHIFT));
|
||||
}
|
||||
|
||||
/* Iterate through mapped pages */
|
||||
@ -339,8 +339,8 @@ MmUnmapHardwareMemory(IN PVOID VirtualAddress,
|
||||
PHARDWARE_PTE PtePointer;
|
||||
PFN_NUMBER Page;
|
||||
|
||||
/* Check if address is valid HAL memory */
|
||||
if(VirtualAddress < (PVOID)MM_HAL_VA_START)
|
||||
/* Check if address is valid hardware memory */
|
||||
if(VirtualAddress < (PVOID)MM_HARDWARE_VA_START)
|
||||
{
|
||||
/* Invalid address, return error */
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
@ -372,10 +372,10 @@ MmUnmapHardwareMemory(IN PVOID VirtualAddress,
|
||||
}
|
||||
|
||||
/* Check if heap can be reused */
|
||||
if(MmpHalHeapStart > VirtualAddress)
|
||||
if(MmpHardwareHeapStart > VirtualAddress)
|
||||
{
|
||||
/* Free VA space */
|
||||
MmpHalHeapStart = VirtualAddress;
|
||||
MmpHardwareHeapStart = VirtualAddress;
|
||||
}
|
||||
|
||||
/* Return success */
|
||||
|
@ -65,7 +65,7 @@ MmpScanMemoryDescriptors(VOID)
|
||||
|
||||
/* Check if memory type is invisible or cached */
|
||||
if(MmpVerifyMemoryTypeInvisible(MemoryDescriptor->MemoryType) ||
|
||||
(MemoryDescriptor->MemoryType == LoaderHALCachedMemory))
|
||||
(MemoryDescriptor->MemoryType == LoaderHardwareCachedMemory))
|
||||
{
|
||||
/* Skip this mapping */
|
||||
MemoryMappings = MemoryMappings->Flink;
|
||||
|
Loading…
Reference in New Issue
Block a user