]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add new PCD gEfiMdeModulePkgTokenSpaceGuid.PcdMaxEfiSystemTablePointerAddress for...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 9 Nov 2010 07:54:53 +0000 (07:54 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 9 Nov 2010 07:54:53 +0000 (07:54 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11018 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/DxeMain.inf
MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
MdeModulePkg/MdeModulePkg.dec

index 52a47f9f8c9d950208203de891a8c6a97aea744f..8b99908df0b482dfb50d156a022d10be8b623c3a 100644 (file)
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressBootTimeCodePageNumber    ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber     ## SOMETIMES_CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable            ## CONSUMES
\ No newline at end of file
+  gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable            ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxEfiSystemTablePointerAddress         ## CONSUMES\r
+  
\ No newline at end of file
index 2bff6e8dc7bf0f33caa39aa777279589ec723794..47660729ba79fff8906e413d81ab5a3d47ccbcbf 100644 (file)
@@ -2,7 +2,7 @@
   Support functions for managing debug image info table when loading and unloading\r
   images.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -24,9 +24,7 @@ EFI_DEBUG_IMAGE_INFO_TABLE_HEADER  mDebugInfoTableHeader = {
 \r
 UINTN mMaxTableEntries = 0;\r
 \r
-EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;\r
-\r
-#define FOUR_MEG_ALIGNMENT   0x400000\r
+EFI_SYSTEM_TABLE_POINTER  *mDebugTable = NULL;\r
 \r
 #define EFI_DEBUG_TABLE_ENTRY_SIZE       (sizeof (VOID *))\r
 \r
@@ -40,18 +38,98 @@ CoreInitializeDebugImageInfoTable (
   VOID\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
+  EFI_STATUS            Status;\r
+  UINTN                 Pages;\r
+  EFI_PHYSICAL_ADDRESS  Memory;\r
+  UINTN                 AlignedMemory;\r
+  UINTN                 AlignmentMask;\r
+  UINTN                 UnalignedPages;\r
+  UINTN                 RealPages;\r
 \r
   //\r
   // Allocate 4M aligned page for the structure and fill in the data.\r
   // Ideally we would update the CRC now as well, but the service may not yet be available.\r
   // See comments in the CoreUpdateDebugTableCrc32() function below for details.\r
   //\r
-  mDebugTable = AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER)), FOUR_MEG_ALIGNMENT); \r
+  Pages          = EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER));\r
+  AlignmentMask  = SIZE_4MB - 1;\r
+  RealPages      = Pages + EFI_SIZE_TO_PAGES (SIZE_4MB);\r
+\r
+  //\r
+  // Attempt to allocate memory below PcdMaxEfiSystemTablePointerAddress\r
+  // If PcdMaxEfiSystemTablePointerAddress is 0, then allocate memory below\r
+  // MAX_ADDRESS\r
+  //\r
+  Memory = PcdGet64 (PcdMaxEfiSystemTablePointerAddress);\r
+  if (Memory == 0) {\r
+    Memory = MAX_ADDRESS;\r
+  }\r
+  Status = CoreAllocatePages (\r
+             AllocateMaxAddress, \r
+             EfiBootServicesData,\r
+             RealPages, \r
+             &Memory\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    if (PcdGet64 (PcdMaxEfiSystemTablePointerAddress) != 0) {\r
+      DEBUG ((EFI_D_INFO, "Allocate memory for EFI_SYSTEM_TABLE_POINTER below PcdMaxEfiSystemTablePointerAddress failed. \\r
+                          Retry to allocate memroy as close to the top of memory as feasible.\n"));\r
+    }\r
+    //\r
+    // If the initial memory allocation fails, then reattempt allocation\r
+    // as close to the top of memory as feasible.\r
+    //\r
+    Status = CoreAllocatePages (\r
+               AllocateAnyPages, \r
+               EfiBootServicesData,\r
+               RealPages, \r
+               &Memory\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+    if (EFI_ERROR (Status)) {\r
+      return;\r
+    }\r
+  }  \r
+\r
+  //\r
+  // Free overallocated pages\r
+  //\r
+  AlignedMemory  = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;\r
+  UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);\r
+  if (UnalignedPages > 0) {\r
+    //\r
+    // Free first unaligned page(s).\r
+    //\r
+    Status = CoreFreePages (Memory, UnalignedPages);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+  Memory         = (EFI_PHYSICAL_ADDRESS)(AlignedMemory + EFI_PAGES_TO_SIZE (Pages));\r
+  UnalignedPages = RealPages - Pages - UnalignedPages;\r
+  if (UnalignedPages > 0) {\r
+    //\r
+    // Free last unaligned page(s).\r
+    //\r
+    Status = CoreFreePages (Memory, UnalignedPages);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  //\r
+  // Set mDebugTable to the 4MB aligned allocated pages\r
+  //\r
+  mDebugTable = (EFI_SYSTEM_TABLE_POINTER  *)(AlignedMemory);\r
   ASSERT (mDebugTable != NULL);\r
-  mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;\r
+\r
+  //\r
+  // Initialize EFI_SYSTEM_TABLE_POINTER structure\r
+  //  \r
+  mDebugTable->Signature          = EFI_SYSTEM_TABLE_SIGNATURE;\r
   mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;\r
-  mDebugTable->Crc32 = 0;\r
+  mDebugTable->Crc32              = 0;\r
+  \r
+  //\r
+  // Install the EFI_SYSTEM_TABLE_POINTER structure in the EFI System \r
+  // Configuration Table\r
+  //\r
   Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
index aa805630c3159f427ace99ae724f0e10b91983f6..83b09ec201911adcc20c03451cc5f27a5822a77b 100644 (file)
@@ -77,6 +77,7 @@
   ##  @libraryclass  Debug Agent is used to provide soft debug capability.\r
   #\r
   DebugAgentLib|Include/Library/DebugAgentLib.h\r
+\r
 [Guids]\r
   ## MdeModule package token space guid\r
   # Include/Guid/MdeModulePkgTokenSpace.h\r
   ## RTC Update Timeout Value\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdRealTimeClockUpdateTimeout|100000|UINT32|0x00010034\r
 \r
+  ## Maximum address that the DXE Core will allocate the EFI_SYSTEM_TABLE_POINTER\r
+  #  structure.  The default value for this PCD is 0, which means that the DXE Core\r
+  #  will allocate the buffer from the EFI_SYSTEM_TABLE_POINTER structure on a 4MB\r
+  #  boundary as close to the top of memory as feasible.  If this PCD is set to a \r
+  #  value other than 0, then the DXE Core will first attempt to allocate the \r
+  #  EFI_SYSTEM_TABLE_POINTER structure on a 4MB boundary below the address specified\r
+  #  by this PCD, and if that allocation fails, retry the allocation on a 4MB\r
+  #  boundary as close to the top of memory as feasible.\r
+  #\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxEfiSystemTablePointerAddress|0x0|UINT64|0x30001027\r
+  \r
 [PcdsPatchableInModule,PcdsDynamic]\r
   ## This PCD defines the Console output column and the default value is 25 according to UEFI spec\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow|25|UINT32|0x40000006\r