Fix system memory map issue.
authorgikidy <gikidy@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 30 Jun 2009 05:47:12 +0000 (05:47 +0000)
committergikidy <gikidy@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 30 Jun 2009 05:47:12 +0000 (05:47 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8685 6f19259b-4bc3-4df7-8a09-765794883524

DuetPkg/DxeIpl/DxeInit.c
DuetPkg/DxeIpl/HobGeneration.c
DuetPkg/DxeIpl/HobGeneration.h
DuetPkg/Library/DuetBdsLib/BdsPlatform.c

index dff64b48563f1cc5fa12686c9b0d3459266e7394..bee7f1130760b78ccf8f3a43beadd320b6324980 100644 (file)
@@ -78,14 +78,16 @@ MemoryAbove1MB.PhysicalStart <--------------------------------------------------
                         <------------------------------+           |               |\r
         Permament Stack (0x20 Pages = 128K)                        |               |\r
                         <- Phit.EfiMemoryTop ----------+-----------+---------------+\r
-        DxeCore                                                                    |\r
-                                                                                DxeCore\r
-        DxeIpl                                                                     |\r
-                        <----------------------------------------------------------+\r
-        NvFV + FtwFV                                                               |\r
+        NvFV (64K)                                                                 |\r
                                                                                  MMIO\r
-        BFV                                                                        |\r
-                        <- Top of Free Memory reported by E820 --------------------+\r
+        FtwFV (128K)                                                               |  \r
+                        <----------------------------------------------------------+<---------+\r
+        DxeCore                                                                    |          |\r
+                                                                                DxeCore       |\r
+        DxeIpl                                                                     |   Allocated in EfiLdr\r
+                        <----------------------------------------------------------+          |\r
+        BFV                                                                      MMIO         |\r
+                        <- Top of Free Memory reported by E820 --------------------+<---------+\r
         ACPINVS        or\r
         ACPIReclaim    or\r
         Reserved\r
@@ -267,11 +269,44 @@ Returns:
   PrintString(" Length = ");\r
   PrintValue64(gHob->NvFtwFvb.FvbInfo.Entries[0].Length);\r
   PrintString("\n");\r
+  PrintString("BfvResource = ");\r
+  PrintValue64(gHob->BfvResource.PhysicalStart);\r
+  PrintString(" Length = ");\r
+  PrintValue64(gHob->BfvResource.ResourceLength);\r
+  PrintString("\n");\r
+  PrintString("NvStorageFvResource = ");\r
+  PrintValue64(gHob->NvStorageFvResource.PhysicalStart);\r
+  PrintString(" Length = ");\r
+  PrintValue64(gHob->NvStorageFvResource.ResourceLength);\r
+  PrintString("\n");\r
+  PrintString("NvStorage = ");\r
+  PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Base);\r
+  PrintString(" Length = ");\r
+  PrintValue64(gHob->NvStorage.FvbInfo.Entries[0].Length);\r
+  PrintString("\n");\r
+  PrintString("NvFtwFvResource = ");\r
+  PrintValue64(gHob->NvFtwFvResource.PhysicalStart);\r
+  PrintString(" Length = ");\r
+  PrintValue64(gHob->NvFtwFvResource.ResourceLength);\r
+  PrintString("\n");\r
+  PrintString("NvFtwWorking = ");\r
+  PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Base);\r
+  PrintString(" Length = ");\r
+  PrintValue64(gHob->NvFtwWorking.FvbInfo.Entries[0].Length);\r
+  PrintString("\n");\r
+  PrintString("NvFtwSpare = ");\r
+  PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Base);\r
+  PrintString(" Length = ");\r
+  PrintValue64(gHob->NvFtwSpare.FvbInfo.Entries[0].Length);\r
+  PrintString("\n");\r
   PrintString("Stack = ");   \r
   PrintValue64(gHob->Stack.AllocDescriptor.MemoryBaseAddress);\r
   PrintString(" StackLength = ");   \r
   PrintValue64(gHob->Stack.AllocDescriptor.MemoryLength);\r
   PrintString("\n");   \r
+  PrintString("PageTable = ");   \r
+  PrintValue64((UINTN)PageTableBase);\r
+  PrintString("\n");     \r
   PrintString("MemoryFreeUnder1MB = ");   \r
   PrintValue64(gHob->MemoryFreeUnder1MB.PhysicalStart);\r
   PrintString(" MemoryFreeUnder1MBLength = ");   \r
index ebe6788877db5f083d769316f14e8b34c375a6f7..224d6a710e9a2fae3f18b266a8a9c56c6cf91965 100644 (file)
@@ -190,6 +190,26 @@ HOB_TEMPLATE  gHobTemplate = {
     EFI_DXE_FILE_GUID,\r
     0x0                                             //  EFI_PHYSICAL_ADDRESS of EntryPoint;\r
   },\r
+  { // MemoryDxeCore\r
+    {\r
+      EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,             // HobType\r
+      sizeof (EFI_HOB_RESOURCE_DESCRIPTOR),         // HobLength\r
+      0                                             // Reserved\r
+    },\r
+    {\r
+      0                                             // Owner Guid\r
+    },\r
+    EFI_RESOURCE_SYSTEM_MEMORY,                     // ResourceType\r
+    (EFI_RESOURCE_ATTRIBUTE_PRESENT                 |\r
+//     EFI_RESOURCE_ATTRIBUTE_TESTED                  | // Do not mark as TESTED, or DxeCore will find it and use it before check Allocation\r
+     EFI_RESOURCE_ATTRIBUTE_INITIALIZED             |\r
+     EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE             | \r
+     EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE       | \r
+     EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | \r
+     EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE),     \r
+    0x0,                                            // PhysicalStart\r
+    0                                               // ResourceLength\r
+  },\r
   { // Memory Map Hints to reduce fragmentation in the memory map\r
     {\r
       {\r
@@ -453,6 +473,23 @@ HOB_TEMPLATE  gHobTemplate = {
       0\r
     }\r
   },\r
+  { // NV Ftw FV Resource\r
+    {\r
+      EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,     // HobType\r
+      sizeof (EFI_HOB_RESOURCE_DESCRIPTOR), // HobLength\r
+      0                                     // Reserved\r
+    },\r
+    {\r
+      0                                     // Owner Guid\r
+    },\r
+    EFI_RESOURCE_FIRMWARE_DEVICE,           // ResourceType\r
+    (EFI_RESOURCE_ATTRIBUTE_PRESENT    |\r
+     EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+     EFI_RESOURCE_ATTRIBUTE_TESTED |\r
+     EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE),  // ResourceAttribute\r
+    0,                                              // PhysicalStart (Fixed later)\r
+    NV_FTW_FVB_SIZE                                 // ResourceLength\r
+  },  \r
   { // FVB holding FTW spaces including Working & Spare space\r
     {\r
       {\r
@@ -703,9 +740,13 @@ PrepareHobDxeCore (
   UINT64                DxeCoreLength\r
   )\r
 {\r
-  gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreImageBase;\r
+  gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress = DxeCoreImageBase;\r
   gHob->DxeCore.MemoryAllocationHeader.MemoryLength = DxeCoreLength;\r
   gHob->DxeCore.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)DxeCoreEntryPoint;\r
+\r
+\r
+  gHob->MemoryDxeCore.PhysicalStart   = DxeCoreImageBase;\r
+  gHob->MemoryDxeCore.ResourceLength  = DxeCoreLength;  \r
 }\r
 \r
 VOID *\r
@@ -878,7 +919,8 @@ PrepareHobNvStorage (
   // Create the FVB holding FTW spaces\r
   //\r
   FtwFvbBase = (EFI_PHYSICAL_ADDRESS)((UINTN) StorageFvbBase + NV_STORAGE_FVB_SIZE);\r
-  gHob->NvFtwFvb.FvbInfo.Entries[0].Base = FtwFvbBase;\r
+  gHob->NvFtwFvResource.PhysicalStart =\r
+    gHob->NvFtwFvb.FvbInfo.Entries[0].Base = FtwFvbBase;\r
   //\r
   // Put FTW Working in front\r
   //\r
index 61d2e9966fd7189b072c08b646888fd9847c7745..021b3ed5019ab30ee9bdf0bd8fe79a4f968b5ccf 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2009, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -84,6 +84,7 @@ typedef struct {
   EFI_HOB_RESOURCE_DESCRIPTOR       MemoryAbove1MB;\r
   EFI_HOB_RESOURCE_DESCRIPTOR       MemoryAbove4GB;\r
   EFI_HOB_MEMORY_ALLOCATION_MODULE  DxeCore;\r
+  EFI_HOB_RESOURCE_DESCRIPTOR       MemoryDxeCore;\r
   MEMORY_TYPE_INFORMATION_HOB       MemoryTypeInfo;\r
   TABLE_HOB                         Acpi;\r
   TABLE_HOB                         Acpi20;\r
@@ -105,7 +106,8 @@ typedef struct {
 \r
   FVB_HOB                           NvStorageFvb;\r
   FVB_HOB                           NvStorage;\r
-\r
+  \r
+  EFI_HOB_RESOURCE_DESCRIPTOR       NvFtwFvResource;\r
   FVB_HOB                           NvFtwFvb;\r
   FVB_HOB                           NvFtwWorking;\r
   FVB_HOB                           NvFtwSpare;\r
index ba9cbf5e2af6767553e6e54ca3b435f49e2160fb..9f9283c99f720bc40a9ca8c62fd0f510cf6bc35a 100644 (file)
@@ -147,13 +147,13 @@ UpdateMemoryMap (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-  EFI_PEI_HOB_POINTERS        GuidHob;\r
-  VOID                        *Table;\r
-  MEMORY_DESC_HOB             MemoryDescHob;\r
-  UINTN                       Index;\r
-  EFI_PHYSICAL_ADDRESS        Memory;\r
-\r
+  EFI_STATUS                      Status;\r
+  EFI_PEI_HOB_POINTERS            GuidHob;\r
+  VOID                            *Table;\r
+  MEMORY_DESC_HOB                 MemoryDescHob;\r
+  UINTN                           Index;\r
+  EFI_PHYSICAL_ADDRESS            Memory;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r
   //\r
   // Get Hob List\r
   //\r
@@ -187,16 +187,62 @@ UpdateMemoryMap (
         (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode) ||\r
         (MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||\r
         (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {\r
-      DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%x, ", MemoryDescHob.MemDesc[Index].PhysicalStart));\r
-      DEBUG ((EFI_D_ERROR, "PageNumber    - 0x%x, ", MemoryDescHob.MemDesc[Index].NumberOfPages));\r
-      DEBUG ((EFI_D_ERROR, "Type          - 0x%x\n", MemoryDescHob.MemDesc[Index].Type));\r
+      DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%016lx, ", MemoryDescHob.MemDesc[Index].PhysicalStart));\r
+      DEBUG ((EFI_D_ERROR, "PageNumber    - 0x%016lx, ", MemoryDescHob.MemDesc[Index].NumberOfPages));\r
+      DEBUG ((EFI_D_ERROR, "Attribute     - 0x%016lx, ", MemoryDescHob.MemDesc[Index].Attribute));\r
+      DEBUG ((EFI_D_ERROR, "Type          - 0x%08x\n", MemoryDescHob.MemDesc[Index].Type));\r
       if ((MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) ||\r
           (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode)) {\r
         //\r
-        // Skip RuntimeSevicesData and RuntimeServicesCode, they are BFV\r
+        // For RuntimeSevicesData and RuntimeServicesCode, they are BFV or DxeCore.\r
+        // The memory type is assigned in EfiLdr\r
+        //\r
+        Status = gDS->GetMemorySpaceDescriptor (MemoryDescHob.MemDesc[Index].PhysicalStart, &Descriptor);\r
+        if (EFI_ERROR (Status)) {\r
+          continue;\r
+        }\r
+        if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeReserved) {\r
+          //\r
+          // BFV or tested DXE core\r
+          //\r
+          continue;\r
+        }\r
+        //\r
+        // Untested DXE Core region, free and remove\r
+        //\r
+        Status = gDS->FreeMemorySpace (\r
+                        MemoryDescHob.MemDesc[Index].PhysicalStart,\r
+                        LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)\r
+                        );\r
+        if (EFI_ERROR (Status)) {\r
+          DEBUG ((EFI_D_ERROR, "FreeMemorySpace fail - %r!\n", Status));\r
+          continue;\r
+        }\r
+        Status = gDS->RemoveMemorySpace (\r
+                        MemoryDescHob.MemDesc[Index].PhysicalStart,\r
+                        LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT)\r
+                        );\r
+        if (EFI_ERROR (Status)) {\r
+          DEBUG ((EFI_D_ERROR, "RemoveMemorySpace fail - %r!\n", Status));\r
+          continue;\r
+        }\r
+\r
+        //\r
+        // Convert Runtime type to BootTime type\r
+        //\r
+        if (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) {\r
+          MemoryDescHob.MemDesc[Index].Type = EfiBootServicesData;\r
+        } else {\r
+          MemoryDescHob.MemDesc[Index].Type = EfiBootServicesCode;\r
+        }\r
+\r
+        //\r
+        // PassThrough, let below code add and alloate.\r
         //\r
-        continue;\r
       }\r
+      //\r
+      // ACPI or reserved memory\r
+      //\r
       Status = gDS->AddMemorySpace (\r
                       EfiGcdMemoryTypeSystemMemory,\r
                       MemoryDescHob.MemDesc[Index].PhysicalStart,\r
@@ -204,7 +250,7 @@ UpdateMemoryMap (
                       MemoryDescHob.MemDesc[Index].Attribute\r
                       );\r
       if (EFI_ERROR (Status)) {\r
-        DEBUG ((EFI_D_ERROR, "AddMemorySpace fail!\n"));\r
+        DEBUG ((EFI_D_ERROR, "AddMemorySpace fail - %r!\n", Status));\r
         if ((MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||\r
             (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {\r
           //\r
@@ -224,7 +270,7 @@ UpdateMemoryMap (
                       &Memory\r
                       );\r
       if (EFI_ERROR (Status)) {\r
-        DEBUG ((EFI_D_ERROR, "AllocatePages fail!\n"));\r
+        DEBUG ((EFI_D_ERROR, "AllocatePages fail - %r!\n", Status));\r
         //\r
         // For the page added, it must be allocated.\r
         //\r