Several changes to EFI memory mapping
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
* Move EFI memory type conversion to separate routine * Never map VRAM * Map only pages not exceeding the lowest physical page
This commit is contained in:
parent
6871291c9a
commit
7bcdd8562d
@ -57,6 +57,9 @@ BlConsoleInitialize();
|
|||||||
VOID
|
VOID
|
||||||
BlConsolePutChar(IN USHORT Character);
|
BlConsolePutChar(IN USHORT Character);
|
||||||
|
|
||||||
|
LOADER_MEMORY_TYPE
|
||||||
|
BlConvertEfiMemoryType(IN EFI_MEMORY_TYPE EfiMemoryType);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
BlCreateStack(IN PVOID *StackPtr,
|
BlCreateStack(IN PVOID *StackPtr,
|
||||||
IN ULONG StackSize,
|
IN ULONG StackSize,
|
||||||
|
@ -178,6 +178,51 @@ BlAddVirtualMemoryMapping(IN PLIST_ENTRY MemoryMappings,
|
|||||||
return STATUS_EFI_SUCCESS;
|
return STATUS_EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an EFI memory type into an XTOS memory type.
|
||||||
|
*
|
||||||
|
* @param EfiMemoryType
|
||||||
|
* Supplies the EFI memory type.
|
||||||
|
*
|
||||||
|
* @return Returns a conversion of the memory type.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
LOADER_MEMORY_TYPE
|
||||||
|
BlConvertEfiMemoryType(IN EFI_MEMORY_TYPE EfiMemoryType)
|
||||||
|
{
|
||||||
|
LOADER_MEMORY_TYPE MemoryType;
|
||||||
|
|
||||||
|
/* Check EFI memory type and convert to XTOS memory type */
|
||||||
|
switch(EfiMemoryType)
|
||||||
|
{
|
||||||
|
case EfiACPIMemoryNVS:
|
||||||
|
case EfiACPIReclaimMemory:
|
||||||
|
case EfiPalCode:
|
||||||
|
case EfiReservedMemoryType:
|
||||||
|
MemoryType = LoaderSpecialMemory;
|
||||||
|
break;
|
||||||
|
case EfiRuntimeServicesCode:
|
||||||
|
case EfiRuntimeServicesData:
|
||||||
|
case EfiMemoryMappedIO:
|
||||||
|
case EfiMemoryMappedIOPortSpace:
|
||||||
|
MemoryType = LoaderFirmwarePermanent;
|
||||||
|
break;
|
||||||
|
case EfiLoaderCode:
|
||||||
|
MemoryType = LoaderFirmwareTemporary;
|
||||||
|
break;
|
||||||
|
case EfiUnusableMemory:
|
||||||
|
MemoryType = LoaderBad;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
MemoryType = LoaderFree;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return XTOS memory type */
|
||||||
|
return MemoryType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine allocates one or more 4KB pages.
|
* This routine allocates one or more 4KB pages.
|
||||||
*
|
*
|
||||||
@ -353,12 +398,10 @@ BlInitializeVirtualMemory(IN OUT PLIST_ENTRY MemoryMappings,
|
|||||||
LOADER_MEMORY_TYPE MemoryType;
|
LOADER_MEMORY_TYPE MemoryType;
|
||||||
PUCHAR VirtualAddress;
|
PUCHAR VirtualAddress;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
BOOLEAN MapVRam;
|
|
||||||
SIZE_T Index;
|
SIZE_T Index;
|
||||||
|
|
||||||
/* Set initial VA and assume VRAM will be mapped */
|
/* Set initial virtual address */
|
||||||
VirtualAddress = *MemoryMapAddress;
|
VirtualAddress = *MemoryMapAddress;
|
||||||
MapVRam = TRUE;
|
|
||||||
|
|
||||||
/* Get memory map */
|
/* Get memory map */
|
||||||
Status = BlGetMemoryMap(&MemoryMap, &MapKey, &DescriptorSize, &DescriptorCount);
|
Status = BlGetMemoryMap(&MemoryMap, &MapKey, &DescriptorSize, &DescriptorCount);
|
||||||
@ -370,27 +413,14 @@ BlInitializeVirtualMemory(IN OUT PLIST_ENTRY MemoryMappings,
|
|||||||
/* Iterate through all descriptors from memory map */
|
/* Iterate through all descriptors from memory map */
|
||||||
for(Index = 0; Index < DescriptorCount; Index++)
|
for(Index = 0; Index < DescriptorCount; Index++)
|
||||||
{
|
{
|
||||||
/* Check memory type */
|
|
||||||
switch(MemoryMap->Type)
|
|
||||||
{
|
|
||||||
case EfiACPIMemoryNVS:
|
|
||||||
case EfiACPIReclaimMemory:
|
|
||||||
case EfiPalCode:
|
|
||||||
case EfiReservedMemoryType:
|
|
||||||
MemoryType = LoaderSpecialMemory;
|
|
||||||
break;
|
|
||||||
case EfiLoaderCode:
|
|
||||||
MemoryType = LoaderFirmwareTemporary;
|
|
||||||
break;
|
|
||||||
case EfiUnusableMemory:
|
|
||||||
MemoryType = LoaderBad;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
MemoryType = LoaderFree;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do initial memory mappings */
|
/* Make sure descriptor does not go beyond lowest physical page */
|
||||||
|
if((MemoryMap->PhysicalStart + (MemoryMap->NumberOfPages * EFI_PAGE_SIZE)) <= (UINT_PTR)-1)
|
||||||
|
{
|
||||||
|
/* Convert EFI memory type into XTOS memory type */
|
||||||
|
MemoryType = BlConvertEfiMemoryType(MemoryMap->Type);
|
||||||
|
|
||||||
|
/* Do memory mappings depending on memory type */
|
||||||
if(MemoryType == LoaderFirmwareTemporary)
|
if(MemoryType == LoaderFirmwareTemporary)
|
||||||
{
|
{
|
||||||
/* Map EFI firmware code */
|
/* Map EFI firmware code */
|
||||||
@ -399,20 +429,13 @@ BlInitializeVirtualMemory(IN OUT PLIST_ENTRY MemoryMappings,
|
|||||||
}
|
}
|
||||||
else if(MemoryType != LoaderFree)
|
else if(MemoryType != LoaderFree)
|
||||||
{
|
{
|
||||||
/* Add non-free memory mapping */
|
/* Add any non-free memory mapping */
|
||||||
Status = BlAddVirtualMemoryMapping(MemoryMappings, VirtualAddress,
|
Status = BlAddVirtualMemoryMapping(MemoryMappings, VirtualAddress,
|
||||||
(PVOID)MemoryMap->PhysicalStart, MemoryMap->NumberOfPages, MemoryType);
|
(PVOID)MemoryMap->PhysicalStart, MemoryMap->NumberOfPages, MemoryType);
|
||||||
|
|
||||||
/* Calculate next valid virtual address */
|
/* Calculate next valid virtual address */
|
||||||
VirtualAddress += MemoryMap->NumberOfPages * EFI_PAGE_SIZE;
|
VirtualAddress += MemoryMap->NumberOfPages * EFI_PAGE_SIZE;
|
||||||
|
|
||||||
/* Check if VRAM should be as well mapped */
|
|
||||||
if((MemoryMap->PhysicalStart + (MemoryMap->NumberOfPages << EFI_PAGE_SHIFT) > 0xA0000) &&
|
|
||||||
(MemoryMap->PhysicalStart <= 0xA0000))
|
|
||||||
{
|
|
||||||
/* No need to map VRAM */
|
|
||||||
MapVRam = FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -431,17 +454,6 @@ BlInitializeVirtualMemory(IN OUT PLIST_ENTRY MemoryMappings,
|
|||||||
/* Grab next descriptor */
|
/* Grab next descriptor */
|
||||||
MemoryMap = (PEFI_MEMORY_DESCRIPTOR)((PUCHAR)MemoryMap + DescriptorSize);
|
MemoryMap = (PEFI_MEMORY_DESCRIPTOR)((PUCHAR)MemoryMap + DescriptorSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if VRAM should mapped */
|
|
||||||
if(MapVRam)
|
|
||||||
{
|
|
||||||
/* Add VRAM mapping */
|
|
||||||
Status = BlAddVirtualMemoryMapping(MemoryMappings, NULL, (PVOID)0xA0000, 0x60, LoaderFirmwarePermanent);
|
|
||||||
if(Status != STATUS_EFI_SUCCESS)
|
|
||||||
{
|
|
||||||
/* VRAM mapping failed */
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store next valid virtual address and return success */
|
/* Store next valid virtual address and return success */
|
||||||
|
Loading…
Reference in New Issue
Block a user