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) | |
<- Phit.EfiMemoryTop ----------+-----------+---------------+
DxeCore |
DxeCore
DxeIpl |
<----------------------------------------------------------+
NvFV + FtwFV |
NvFV (64K) |
MMIO
BFV |
<- Top of Free Memory reported by E820 --------------------+
FtwFV (128K) |
<----------------------------------------------------------+<---------+
DxeCore | |
DxeCore |
DxeIpl | Allocated in EfiLdr
<----------------------------------------------------------+ |
BFV MMIO |
<- Top of Free Memory reported by E820 --------------------+<---------+
ACPINVS or
ACPIReclaim or
Reserved
@ -267,11 +269,44 @@ Returns:
PrintString(" Length = ");
PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);
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 = ");
PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);
PrintString(" StackLength = ");
PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);
PrintString("\n");
PrintString("PageTable = ");
PrintValue64((UINTN)PageTableBase);
PrintString("\n");
PrintString("MemoryFreeUnder1MB = ");
PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);
PrintString(" MemoryFreeUnder1MBLength = ");

View File

@ -190,6 +190,26 @@ HOB_TEMPLATE gHobTemplate = {
EFI_DXE_FILE_GUID,
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
{
{
@ -453,6 +473,23 @@ HOB_TEMPLATE gHobTemplate = {
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
{
{
@ -703,9 +740,13 @@ PrepareHobDxeCore (
UINT64 DxeCoreLength
)
{
gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreImageBase;
gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress = DxeCoreImageBase;
gHob->DxeCore.MemoryAllocationHeader.MemoryLength = DxeCoreLength;
gHob->DxeCore.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreEntryPoint;
gHob->MemoryDxeCore.PhysicalStart = DxeCoreImageBase;
gHob->MemoryDxeCore.ResourceLength = DxeCoreLength;
}
VOID *
@ -878,7 +919,8 @@ PrepareHobNvStorage (
// Create the FVB holding FTW spaces
//
FtwFvbBase = (EFI_PHYSICAL_ADDRESS)((UINTN) StorageFvbBase + NV_STORAGE_FVB_SIZE);
gHob->NvFtwFvb.FvbInfo.Entries[0].Base = FtwFvbBase;
gHob->NvFtwFvResource.PhysicalStart =
gHob->NvFtwFvb.FvbInfo.Entries[0].Base = FtwFvbBase;
//
// Put FTW Working in front
//

View File

@ -1,6 +1,6 @@
/** @file
Copyright (c) 2006 - 2007, Intel Corporation
Copyright (c) 2006 - 2009, Intel Corporation
All rights reserved. This program and the accompanying materials
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
@ -84,6 +84,7 @@ typedef struct {
EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove1MB;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryAbove4GB;
EFI_HOB_MEMORY_ALLOCATION_MODULE DxeCore;
EFI_HOB_RESOURCE_DESCRIPTOR MemoryDxeCore;
MEMORY_TYPE_INFORMATION_HOB MemoryTypeInfo;
TABLE_HOB Acpi;
TABLE_HOB Acpi20;
@ -105,7 +106,8 @@ typedef struct {
FVB_HOB NvStorageFvb;
FVB_HOB NvStorage;
EFI_HOB_RESOURCE_DESCRIPTOR NvFtwFvResource;
FVB_HOB NvFtwFvb;
FVB_HOB NvFtwWorking;
FVB_HOB NvFtwSpare;

View File

@ -147,13 +147,13 @@ UpdateMemoryMap (
VOID
)
{
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS GuidHob;
VOID *Table;
MEMORY_DESC_HOB MemoryDescHob;
UINTN Index;
EFI_PHYSICAL_ADDRESS Memory;
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS GuidHob;
VOID *Table;
MEMORY_DESC_HOB MemoryDescHob;
UINTN Index;
EFI_PHYSICAL_ADDRESS Memory;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
//
// Get Hob List
//
@ -187,16 +187,62 @@ UpdateMemoryMap (
(MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode) ||
(MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||
(MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {
DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%x, ", MemoryDescHob.MemDesc[Index].PhysicalStart));
DEBUG ((EFI_D_ERROR, "PageNumber - 0x%x, ", MemoryDescHob.MemDesc[Index].NumberOfPages));
DEBUG ((EFI_D_ERROR, "Type - 0x%x\n", MemoryDescHob.MemDesc[Index].Type));
DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%016lx, ", MemoryDescHob.MemDesc[Index].PhysicalStart));
DEBUG ((EFI_D_ERROR, "PageNumber - 0x%016lx, ", MemoryDescHob.MemDesc[Index].NumberOfPages));
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) ||
(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;
}
//
// 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.
//
continue;
}
//
// ACPI or reserved memory
//
Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeSystemMemory,
MemoryDescHob.MemDesc[Index].PhysicalStart,
@ -204,7 +250,7 @@ UpdateMemoryMap (
MemoryDescHob.MemDesc[Index].Attribute
);
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) ||
(MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {
//
@ -224,7 +270,7 @@ UpdateMemoryMap (
&Memory
);
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.
//