Fix system memory map issue.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8685 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
gikidy 2009-06-30 05:47:12 +00:00
parent 5540f4aa18
commit d569cbb0d1
4 changed files with 150 additions and 25 deletions

View File

@ -78,14 +78,16 @@ MemoryAbove1MB.PhysicalStart <--------------------------------------------------
<------------------------------+ | | <------------------------------+ | |
Permament Stack (0x20 Pages = 128K) | | Permament Stack (0x20 Pages = 128K) | |
<- Phit.EfiMemoryTop ----------+-----------+---------------+ <- Phit.EfiMemoryTop ----------+-----------+---------------+
DxeCore | NvFV (64K) |
DxeCore
DxeIpl |
<----------------------------------------------------------+
NvFV + FtwFV |
MMIO MMIO
BFV | FtwFV (128K) |
<- Top of Free Memory reported by E820 --------------------+ <----------------------------------------------------------+<---------+
DxeCore | |
DxeCore |
DxeIpl | Allocated in EfiLdr
<----------------------------------------------------------+ |
BFV MMIO |
<- Top of Free Memory reported by E820 --------------------+<---------+
ACPINVS or ACPINVS or
ACPIReclaim or ACPIReclaim or
Reserved Reserved
@ -267,11 +269,44 @@ Returns:
PrintString(" Length = "); PrintString(" Length = ");
PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length); PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);
PrintString("\n"); PrintString("\n");
PrintString("BfvResource = ");
PrintValue64(gHob->BfvResource.PhysicalStart);
PrintString(" Length = ");
PrintValue64(gHob->BfvResource.ResourceLength);
PrintString("\n");
PrintString("NvStorageFvResource = ");
PrintValue64(gHob->NvStorageFvResource.PhysicalStart);
PrintString(" Length = ");
PrintValue64(gHob->NvStorageFvResource.ResourceLength);
PrintString("\n");
PrintString("NvStorage = ");
PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Base);
PrintString(" Length = ");
PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Length);
PrintString("\n");
PrintString("NvFtwFvResource = ");
PrintValue64(gHob->NvFtwFvResource.PhysicalStart);
PrintString(" Length = ");
PrintValue64(gHob->NvFtwFvResource.ResourceLength);
PrintString("\n");
PrintString("NvFtwWorking = ");
PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Base);
PrintString(" Length = ");
PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Length);
PrintString("\n");
PrintString("NvFtwSpare = ");
PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Base);
PrintString(" Length = ");
PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Length);
PrintString("\n");
PrintString("Stack = "); PrintString("Stack = ");
PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress); PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);
PrintString(" StackLength = "); PrintString(" StackLength = ");
PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength); PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);
PrintString("\n"); PrintString("\n");
PrintString("PageTable = ");
PrintValue64((UINTN)PageTableBase);
PrintString("\n");
PrintString("MemoryFreeUnder1MB = "); PrintString("MemoryFreeUnder1MB = ");
PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart); PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);
PrintString(" MemoryFreeUnder1MBLength = "); PrintString(" MemoryFreeUnder1MBLength = ");

View File

@ -190,6 +190,26 @@ HOB_TEMPLATE gHobTemplate = {
EFI_DXE_FILE_GUID, EFI_DXE_FILE_GUID,
0x0 // EFI_PHYSICAL_ADDRESS of EntryPoint; 0x0 // EFI_PHYSICAL_ADDRESS of EntryPoint;
}, },
{ // MemoryDxeCore
{
EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, // HobType
sizeof (EFI_HOB_RESOURCE_DESCRIPTOR), // HobLength
0 // Reserved
},
{
0 // Owner Guid
},
EFI_RESOURCE_SYSTEM_MEMORY, // ResourceType
(EFI_RESOURCE_ATTRIBUTE_PRESENT |
// EFI_RESOURCE_ATTRIBUTE_TESTED | // Do not mark as TESTED, or DxeCore will find it and use it before check Allocation
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE),
0x0, // PhysicalStart
0 // ResourceLength
},
{ // Memory Map Hints to reduce fragmentation in the memory map { // Memory Map Hints to reduce fragmentation in the memory map
{ {
{ {
@ -453,6 +473,23 @@ HOB_TEMPLATE gHobTemplate = {
0 0
} }
}, },
{ // NV Ftw FV Resource
{
EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, // HobType
sizeof (EFI_HOB_RESOURCE_DESCRIPTOR), // HobLength
0 // Reserved
},
{
0 // Owner Guid
},
EFI_RESOURCE_FIRMWARE_DEVICE, // ResourceType
(EFI_RESOURCE_ATTRIBUTE_PRESENT |
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_TESTED |
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE), // ResourceAttribute
0, // PhysicalStart (Fixed later)
NV_FTW_FVB_SIZE // ResourceLength
},
{ // FVB holding FTW spaces including Working & Spare space { // FVB holding FTW spaces including Working & Spare space
{ {
{ {
@ -703,9 +740,13 @@ PrepareHobDxeCore (
UINT64 DxeCoreLength UINT64 DxeCoreLength
) )
{ {
gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreImageBase; gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress = DxeCoreImageBase;
gHob->DxeCore.MemoryAllocationHeader.MemoryLength = DxeCoreLength; gHob->DxeCore.MemoryAllocationHeader.MemoryLength = DxeCoreLength;
gHob->DxeCore.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreEntryPoint; gHob->DxeCore.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreEntryPoint;
gHob->MemoryDxeCore.PhysicalStart = DxeCoreImageBase;
gHob->MemoryDxeCore.ResourceLength = DxeCoreLength;
} }
VOID * VOID *
@ -878,6 +919,7 @@ PrepareHobNvStorage (
// Create the FVB holding FTW spaces // Create the FVB holding FTW spaces
// //
FtwFvbBase = (EFI_PHYSICAL_ADDRESS)((UINTN) StorageFvbBase + NV_STORAGE_FVB_SIZE); FtwFvbBase = (EFI_PHYSICAL_ADDRESS)((UINTN) StorageFvbBase + NV_STORAGE_FVB_SIZE);
gHob->NvFtwFvResource.PhysicalStart =
gHob->NvFtwFvb.FvbInfo.Entries[0].Base = FtwFvbBase; gHob->NvFtwFvb.FvbInfo.Entries[0].Base = FtwFvbBase;
// //
// Put FTW Working in front // Put FTW Working in front

View File

@ -1,6 +1,6 @@
/** @file /** @file
Copyright (c) 2006 - 2007, Intel Corporation Copyright (c) 2006 - 2009, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -84,6 +84,7 @@ typedef struct {
EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove1MB; EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove1MB;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove4GB; EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove4GB;
EFI_HOB_MEMORY_ALLOCATION_MODULE DxeCore; EFI_HOB_MEMORY_ALLOCATION_MODULE DxeCore;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryDxeCore;
MEMORY_TYPE_INFORMATION_HOB MemoryTypeInfo; MEMORY_TYPE_INFORMATION_HOB MemoryTypeInfo;
TABLE_HOB Acpi; TABLE_HOB Acpi;
TABLE_HOB Acpi20; TABLE_HOB Acpi20;
@ -106,6 +107,7 @@ typedef struct {
FVB_HOB NvStorageFvb; FVB_HOB NvStorageFvb;
FVB_HOB NvStorage; FVB_HOB NvStorage;
EFI_HOB_RESOURCE_DESCRIPTOR NvFtwFvResource;
FVB_HOB NvFtwFvb; FVB_HOB NvFtwFvb;
FVB_HOB NvFtwWorking; FVB_HOB NvFtwWorking;
FVB_HOB NvFtwSpare; FVB_HOB NvFtwSpare;

View File

@ -153,7 +153,7 @@ UpdateMemoryMap (
MEMORY_DESC_HOB MemoryDescHob; MEMORY_DESC_HOB MemoryDescHob;
UINTN Index; UINTN Index;
EFI_PHYSICAL_ADDRESS Memory; EFI_PHYSICAL_ADDRESS Memory;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
// //
// Get Hob List // Get Hob List
// //
@ -187,16 +187,62 @@ UpdateMemoryMap (
(MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode) || (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode) ||
(MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) || (MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||
(MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) { (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {
DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%x, ", MemoryDescHob.MemDesc[Index].PhysicalStart)); DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%016lx, ", MemoryDescHob.MemDesc[Index].PhysicalStart));
DEBUG ((EFI_D_ERROR, "PageNumber - 0x%x, ", MemoryDescHob.MemDesc[Index].NumberOfPages)); DEBUG ((EFI_D_ERROR, "PageNumber - 0x%016lx, ", MemoryDescHob.MemDesc[Index].NumberOfPages));
DEBUG ((EFI_D_ERROR, "Type - 0x%x\n", MemoryDescHob.MemDesc[Index].Type)); DEBUG ((EFI_D_ERROR, "Attribute - 0x%016lx, ", MemoryDescHob.MemDesc[Index].Attribute));
DEBUG ((EFI_D_ERROR, "Type - 0x%08x\n", MemoryDescHob.MemDesc[Index].Type));
if ((MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) || if ((MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) ||
(MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode)) { (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode)) {
// //
// Skip RuntimeSevicesData and RuntimeServicesCode, they are BFV // For RuntimeSevicesData and RuntimeServicesCode, they are BFV or DxeCore.
// The memory type is assigned in EfiLdr
//
Status = gDS->GetMemorySpaceDescriptor (MemoryDescHob.MemDesc[Index].PhysicalStart, &Descriptor);
if (EFI_ERROR (Status)) {
continue;
}
if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeReserved) {
//
// BFV or tested DXE core
// //
continue; continue;
} }
//
// Untested DXE Core region, free and remove
//
Status = gDS->FreeMemorySpace (
MemoryDescHob.MemDesc[Index].PhysicalStart,
LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "FreeMemorySpace fail - %r!\n", Status));
continue;
}
Status = gDS->RemoveMemorySpace (
MemoryDescHob.MemDesc[Index].PhysicalStart,
LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "RemoveMemorySpace fail - %r!\n", Status));
continue;
}
//
// Convert Runtime type to BootTime type
//
if (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) {
MemoryDescHob.MemDesc[Index].Type = EfiBootServicesData;
} else {
MemoryDescHob.MemDesc[Index].Type = EfiBootServicesCode;
}
//
// PassThrough, let below code add and alloate.
//
}
//
// ACPI or reserved memory
//
Status = gDS->AddMemorySpace ( Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeSystemMemory, EfiGcdMemoryTypeSystemMemory,
MemoryDescHob.MemDesc[Index].PhysicalStart, MemoryDescHob.MemDesc[Index].PhysicalStart,
@ -204,7 +250,7 @@ UpdateMemoryMap (
MemoryDescHob.MemDesc[Index].Attribute MemoryDescHob.MemDesc[Index].Attribute
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "AddMemorySpace fail!\n")); DEBUG ((EFI_D_ERROR, "AddMemorySpace fail - %r!\n", Status));
if ((MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) || if ((MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||
(MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) { (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {
// //
@ -224,7 +270,7 @@ UpdateMemoryMap (
&Memory &Memory
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "AllocatePages fail!\n")); DEBUG ((EFI_D_ERROR, "AllocatePages fail - %r!\n", Status));
// //
// For the page added, it must be allocated. // For the page added, it must be allocated.
// //