]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Adjust the function layout to remove the prototype of internal functions to reduce...
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 17 Sep 2008 14:20:29 +0000 (14:20 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 17 Sep 2008 14:20:29 +0000 (14:20 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5921 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Mem/Page.c

index aeaa48da80f4357bec5b1b9cf99fd5856518fb53..179376dc31c6bc50a07845a5d80a3aafc259bc55 100644 (file)
@@ -87,17 +87,57 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
   { EfiMaxMemoryType,           0 }\r
 };\r
 \r
-//\r
-// Internal prototypes\r
-//\r
+\r
 /**\r
-  Find untested but initialized memory regions in GCD map and convert them to be DXE allocatable.\r
+  Enter critical section by gaining lock on gMemoryLock.\r
 \r
 **/\r
 VOID\r
-PromoteMemoryResource (\r
+CoreAcquireMemoryLock (\r
+  VOID\r
+  )\r
+{\r
+  CoreAcquireLock (&gMemoryLock);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Exit critical section by releasing lock on gMemoryLock.\r
+\r
+**/\r
+VOID\r
+CoreReleaseMemoryLock (\r
   VOID\r
-  );\r
+  )\r
+{\r
+  CoreReleaseLock (&gMemoryLock);\r
+}\r
+\r
+\r
+\r
+\r
+/**\r
+  Internal function.  Removes a descriptor entry.\r
+\r
+  @param  Entry                  The entry to remove\r
+\r
+**/\r
+VOID\r
+RemoveMemoryMapEntry (\r
+  IN OUT MEMORY_MAP      *Entry\r
+  )\r
+{\r
+  RemoveEntryList (&Entry->Link);\r
+  Entry->Link.ForwardLink = NULL;\r
+\r
+  if (Entry->FromPages) {\r
+    //\r
+    // Insert the free memory map descriptor to the end of mFreeMemoryMapEntryList\r
+    //\r
+    InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link);\r
+  }\r
+}\r
 \r
 /**\r
   Internal function.  Adds a ranges to the memory map.\r
@@ -117,51 +157,85 @@ CoreAddRange (
   IN EFI_PHYSICAL_ADDRESS     Start,\r
   IN EFI_PHYSICAL_ADDRESS     End,\r
   IN UINT64                   Attribute\r
-  );\r
+  )\r
+{\r
+  LIST_ENTRY        *Link;\r
+  MEMORY_MAP        *Entry;\r
 \r
-/**\r
-  Internal function.  Moves any memory descriptors that are on the\r
-  temporary descriptor stack to heap.\r
+  ASSERT ((Start & EFI_PAGE_MASK) == 0);\r
+  ASSERT (End > Start) ;\r
 \r
-**/\r
-VOID\r
-CoreFreeMemoryMapStack (\r
-  VOID\r
-  );\r
+  ASSERT_LOCKED (&gMemoryLock);\r
 \r
-/**\r
-  Internal function.  Converts a memory range to the specified type.\r
-  The range must exist in the memory map.\r
+  DEBUG ((DEBUG_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type));\r
 \r
-  @param  Start                  The first address of the range Must be page\r
-                                 aligned\r
-  @param  NumberOfPages          The number of pages to convert\r
-  @param  NewType                The new type for the memory range\r
+  //\r
+  // Memory map being altered so updated key\r
+  //\r
+  mMemoryMapKey += 1;\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
-  @retval EFI_NOT_FOUND          Could not find a descriptor cover the specified\r
-                                 range  or convertion not allowed.\r
-  @retval EFI_SUCCESS            Successfully converts the memory range to the\r
-                                 specified type.\r
+  //\r
+  // UEFI 2.0 added an event group for notificaiton on memory map changes.\r
+  // So we need to signal this Event Group every time the memory map changes.\r
+  // If we are in EFI 1.10 compatability mode no event groups will be\r
+  // found and nothing will happen we we call this function. These events\r
+  // will get signaled but since a lock is held around the call to this\r
+  // function the notificaiton events will only be called after this funciton\r
+  // returns and the lock is released.\r
+  //\r
+  CoreNotifySignalList (&gEfiEventMemoryMapChangeGuid);\r
 \r
-**/\r
-EFI_STATUS\r
-CoreConvertPages (\r
-  IN UINT64           Start,\r
-  IN UINT64           NumberOfPages,\r
-  IN EFI_MEMORY_TYPE  NewType\r
-  );\r
+  //\r
+  // Look for adjoining memory descriptor\r
+  //\r
 \r
-/**\r
-  Internal function.  Removes a descriptor entry.\r
+  // Two memory descriptors can only be merged if they have the same Type\r
+  // and the same Attribute\r
+  //\r
 \r
-  @param  Entry                  The entry to remove\r
+  Link = gMemoryMap.ForwardLink;\r
+  while (Link != &gMemoryMap) {\r
+    Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
+    Link  = Link->ForwardLink;\r
 \r
-**/\r
-VOID\r
-RemoveMemoryMapEntry (\r
-  IN OUT MEMORY_MAP      *Entry\r
-  );\r
+    if (Entry->Type != Type) {\r
+      continue;\r
+    }\r
+\r
+    if (Entry->Attribute != Attribute) {\r
+      continue;\r
+    }\r
+\r
+    if (Entry->End + 1 == Start) {\r
+\r
+      Start = Entry->Start;\r
+      RemoveMemoryMapEntry (Entry);\r
+\r
+    } else if (Entry->Start == End + 1) {\r
+\r
+      End = Entry->End;\r
+      RemoveMemoryMapEntry (Entry);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Add descriptor\r
+  //\r
+\r
+  mMapStack[mMapDepth].Signature     = MEMORY_MAP_SIGNATURE;\r
+  mMapStack[mMapDepth].FromPages      = FALSE;\r
+  mMapStack[mMapDepth].Type          = Type;\r
+  mMapStack[mMapDepth].Start         = Start;\r
+  mMapStack[mMapDepth].End           = End;\r
+  mMapStack[mMapDepth].VirtualStart  = 0;\r
+  mMapStack[mMapDepth].Attribute     = Attribute;\r
+  InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link);\r
+\r
+  mMapDepth += 1;\r
+  ASSERT (mMapDepth < MAX_MAP_DEPTH);\r
+\r
+  return ;\r
+}\r
 \r
 /**\r
   Internal function.  Deque a descriptor entry from the mFreeMemoryMapEntryList.\r
@@ -179,35 +253,114 @@ RemoveMemoryMapEntry (
 MEMORY_MAP *\r
 AllocateMemoryMapEntry (\r
   VOID\r
-  );\r
+  )\r
+{\r
+  MEMORY_MAP*            FreeDescriptorEntries;\r
+  MEMORY_MAP*            Entry;\r
+  UINTN                  Index;\r
+\r
+  if (IsListEmpty (&mFreeMemoryMapEntryList)) {\r
+    //\r
+    // The list is empty, to allocate one page to refuel the list\r
+    //\r
+    FreeDescriptorEntries = CoreAllocatePoolPages (EfiBootServicesData, EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION), DEFAULT_PAGE_ALLOCATION);\r
+    if(FreeDescriptorEntries != NULL) {\r
+      //\r
+      // Enque the free memmory map entries into the list\r
+      //\r
+      for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) {\r
+        FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;\r
+        InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);\r
+      }\r
+    } else {\r
+      return NULL;\r
+    }\r
+  }\r
+  //\r
+  // dequeue the first descriptor from the list\r
+  //\r
+  Entry = CR (mFreeMemoryMapEntryList.ForwardLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
+  RemoveEntryList (&Entry->Link);\r
+\r
+  return Entry;\r
+}\r
 \r
 \r
 /**\r
-  Enter critical section by gaining lock on gMemoryLock.\r
+  Internal function.  Moves any memory descriptors that are on the\r
+  temporary descriptor stack to heap.\r
 \r
 **/\r
 VOID\r
-CoreAcquireMemoryLock (\r
+CoreFreeMemoryMapStack (\r
   VOID\r
   )\r
 {\r
-  CoreAcquireLock (&gMemoryLock);\r
-}\r
+  MEMORY_MAP      *Entry;\r
+  MEMORY_MAP      *Entry2;\r
+  LIST_ENTRY      *Link2;\r
 \r
+  ASSERT_LOCKED (&gMemoryLock);\r
 \r
+  //\r
+  // If already freeing the map stack, then return\r
+  //\r
+  if (mFreeMapStack != 0) {\r
+    return ;\r
+  }\r
 \r
-/**\r
-  Exit critical section by releasing lock on gMemoryLock.\r
+  //\r
+  // Move the temporary memory descriptor stack into pool\r
+  //\r
+  mFreeMapStack += 1;\r
 \r
-**/\r
-VOID\r
-CoreReleaseMemoryLock (\r
-  VOID\r
-  )\r
-{\r
-  CoreReleaseLock (&gMemoryLock);\r
-}\r
+  while (mMapDepth != 0) {\r
+    //\r
+    // Deque an memory map entry from mFreeMemoryMapEntryList\r
+    //\r
+    Entry = AllocateMemoryMapEntry ();\r
 \r
+    ASSERT (Entry);\r
+\r
+    //\r
+    // Update to proper entry\r
+    //\r
+    mMapDepth -= 1;\r
+\r
+    if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {\r
+\r
+      //\r
+      // Move this entry to general memory\r
+      //\r
+      RemoveEntryList (&mMapStack[mMapDepth].Link);\r
+      mMapStack[mMapDepth].Link.ForwardLink = NULL;\r
+\r
+      CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));\r
+      Entry->FromPages = TRUE;\r
+\r
+      //\r
+      // Find insertion location\r
+      //\r
+      for (Link2 = gMemoryMap.ForwardLink; Link2 != &gMemoryMap; Link2 = Link2->ForwardLink) {\r
+        Entry2 = CR (Link2, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
+        if (Entry2->FromPages && Entry2->Start > Entry->Start) {\r
+          break;\r
+        }\r
+      }\r
+\r
+      InsertTailList (Link2, &Entry->Link);\r
+\r
+    } else {\r
+      //\r
+      // This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list,\r
+      // so here no need to move it to memory.\r
+      //\r
+      InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link);\r
+    }\r
+  }\r
+\r
+  mFreeMapStack -= 1;\r
+}\r
 \r
 /**\r
   Find untested but initialized memory regions in GCD map and convert them to be DXE allocatable.\r
@@ -424,255 +577,6 @@ CoreAddMemoryDescriptor (
 }\r
 \r
 \r
-\r
-/**\r
-  Internal function.  Adds a ranges to the memory map.\r
-  The range must not already exist in the map.\r
-\r
-  @param  Type                   The type of memory range to add\r
-  @param  Start                  The starting address in the memory range Must be\r
-                                 paged aligned\r
-  @param  End                    The last address in the range Must be the last\r
-                                 byte of a page\r
-  @param  Attribute              The attributes of the memory range to add\r
-\r
-**/\r
-VOID\r
-CoreAddRange (\r
-  IN EFI_MEMORY_TYPE          Type,\r
-  IN EFI_PHYSICAL_ADDRESS     Start,\r
-  IN EFI_PHYSICAL_ADDRESS     End,\r
-  IN UINT64                   Attribute\r
-  )\r
-{\r
-  LIST_ENTRY        *Link;\r
-  MEMORY_MAP        *Entry;\r
-\r
-  ASSERT ((Start & EFI_PAGE_MASK) == 0);\r
-  ASSERT (End > Start) ;\r
-\r
-  ASSERT_LOCKED (&gMemoryLock);\r
-\r
-  DEBUG ((DEBUG_PAGE, "AddRange: %lx-%lx to %d\n", Start, End, Type));\r
-\r
-  //\r
-  // Memory map being altered so updated key\r
-  //\r
-  mMemoryMapKey += 1;\r
-\r
-  //\r
-  // UEFI 2.0 added an event group for notificaiton on memory map changes.\r
-  // So we need to signal this Event Group every time the memory map changes.\r
-  // If we are in EFI 1.10 compatability mode no event groups will be\r
-  // found and nothing will happen we we call this function. These events\r
-  // will get signaled but since a lock is held around the call to this\r
-  // function the notificaiton events will only be called after this funciton\r
-  // returns and the lock is released.\r
-  //\r
-  CoreNotifySignalList (&gEfiEventMemoryMapChangeGuid);\r
-\r
-  //\r
-  // Look for adjoining memory descriptor\r
-  //\r
-\r
-  // Two memory descriptors can only be merged if they have the same Type\r
-  // and the same Attribute\r
-  //\r
-\r
-  Link = gMemoryMap.ForwardLink;\r
-  while (Link != &gMemoryMap) {\r
-    Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
-    Link  = Link->ForwardLink;\r
-\r
-    if (Entry->Type != Type) {\r
-      continue;\r
-    }\r
-\r
-    if (Entry->Attribute != Attribute) {\r
-      continue;\r
-    }\r
-\r
-    if (Entry->End + 1 == Start) {\r
-\r
-      Start = Entry->Start;\r
-      RemoveMemoryMapEntry (Entry);\r
-\r
-    } else if (Entry->Start == End + 1) {\r
-\r
-      End = Entry->End;\r
-      RemoveMemoryMapEntry (Entry);\r
-    }\r
-  }\r
-\r
-  //\r
-  // Add descriptor\r
-  //\r
-\r
-  mMapStack[mMapDepth].Signature     = MEMORY_MAP_SIGNATURE;\r
-  mMapStack[mMapDepth].FromPages      = FALSE;\r
-  mMapStack[mMapDepth].Type          = Type;\r
-  mMapStack[mMapDepth].Start         = Start;\r
-  mMapStack[mMapDepth].End           = End;\r
-  mMapStack[mMapDepth].VirtualStart  = 0;\r
-  mMapStack[mMapDepth].Attribute     = Attribute;\r
-  InsertTailList (&gMemoryMap, &mMapStack[mMapDepth].Link);\r
-\r
-  mMapDepth += 1;\r
-  ASSERT (mMapDepth < MAX_MAP_DEPTH);\r
-\r
-  return ;\r
-}\r
-\r
-\r
-/**\r
-  Internal function.  Moves any memory descriptors that are on the\r
-  temporary descriptor stack to heap.\r
-\r
-**/\r
-VOID\r
-CoreFreeMemoryMapStack (\r
-  VOID\r
-  )\r
-{\r
-  MEMORY_MAP      *Entry;\r
-  MEMORY_MAP      *Entry2;\r
-  LIST_ENTRY      *Link2;\r
-\r
-  ASSERT_LOCKED (&gMemoryLock);\r
-\r
-  //\r
-  // If already freeing the map stack, then return\r
-  //\r
-  if (mFreeMapStack != 0) {\r
-    return ;\r
-  }\r
-\r
-  //\r
-  // Move the temporary memory descriptor stack into pool\r
-  //\r
-  mFreeMapStack += 1;\r
-\r
-  while (mMapDepth != 0) {\r
-    //\r
-    // Deque an memory map entry from mFreeMemoryMapEntryList\r
-    //\r
-    Entry = AllocateMemoryMapEntry ();\r
-\r
-    ASSERT (Entry);\r
-\r
-    //\r
-    // Update to proper entry\r
-    //\r
-    mMapDepth -= 1;\r
-\r
-    if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {\r
-\r
-      //\r
-      // Move this entry to general memory\r
-      //\r
-      RemoveEntryList (&mMapStack[mMapDepth].Link);\r
-      mMapStack[mMapDepth].Link.ForwardLink = NULL;\r
-\r
-      CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));\r
-      Entry->FromPages = TRUE;\r
-\r
-      //\r
-      // Find insertion location\r
-      //\r
-      for (Link2 = gMemoryMap.ForwardLink; Link2 != &gMemoryMap; Link2 = Link2->ForwardLink) {\r
-        Entry2 = CR (Link2, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
-        if (Entry2->FromPages && Entry2->Start > Entry->Start) {\r
-          break;\r
-        }\r
-      }\r
-\r
-      InsertTailList (Link2, &Entry->Link);\r
-\r
-    } else {\r
-      //\r
-      // This item of mMapStack[mMapDepth] has already been dequeued from gMemoryMap list,\r
-      // so here no need to move it to memory.\r
-      //\r
-      InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link);\r
-    }\r
-  }\r
-\r
-  mFreeMapStack -= 1;\r
-}\r
-\r
-\r
-/**\r
-  Internal function.  Removes a descriptor entry.\r
-\r
-  @param  Entry                  The entry to remove\r
-\r
-**/\r
-VOID\r
-RemoveMemoryMapEntry (\r
-  IN OUT MEMORY_MAP      *Entry\r
-  )\r
-{\r
-  RemoveEntryList (&Entry->Link);\r
-  Entry->Link.ForwardLink = NULL;\r
-\r
-  if (Entry->FromPages) {\r
-    //\r
-    // Insert the free memory map descriptor to the end of mFreeMemoryMapEntryList\r
-    //\r
-    InsertTailList (&mFreeMemoryMapEntryList, &Entry->Link);\r
-  }\r
-}\r
-\r
-\r
-/**\r
-  Internal function.  Deque a descriptor entry from the mFreeMemoryMapEntryList.\r
-  If the list is emtry, then allocate a new page to refuel the list.\r
-  Please Note this algorithm to allocate the memory map descriptor has a property\r
-  that the memory allocated for memory entries always grows, and will never really be freed\r
-  For example, if the current boot uses 2000 memory map entries at the maximum point, but\r
-  ends up with only 50 at the time the OS is booted, then the memory associated with the 1950\r
-  memory map entries is still allocated from EfiBootServicesMemory.\r
-\r
-\r
-  @return The Memory map descriptor dequed from the mFreeMemoryMapEntryList\r
-\r
-**/\r
-MEMORY_MAP *\r
-AllocateMemoryMapEntry (\r
-  VOID\r
-  )\r
-{\r
-  MEMORY_MAP*            FreeDescriptorEntries;\r
-  MEMORY_MAP*            Entry;\r
-  UINTN                  Index;\r
-\r
-  if (IsListEmpty (&mFreeMemoryMapEntryList)) {\r
-    //\r
-    // The list is empty, to allocate one page to refuel the list\r
-    //\r
-    FreeDescriptorEntries = CoreAllocatePoolPages (EfiBootServicesData, EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION), DEFAULT_PAGE_ALLOCATION);\r
-    if(FreeDescriptorEntries != NULL) {\r
-      //\r
-      // Enque the free memmory map entries into the list\r
-      //\r
-      for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) {\r
-        FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;\r
-        InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);\r
-      }\r
-    } else {\r
-      return NULL;\r
-    }\r
-  }\r
-  //\r
-  // dequeue the first descriptor from the list\r
-  //\r
-  Entry = CR (mFreeMemoryMapEntryList.ForwardLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);\r
-  RemoveEntryList (&Entry->Link);\r
-\r
-  return Entry;\r
-}\r
-\r
-\r
 /**\r
   Internal function.  Converts a memory range to the specified type.\r
   The range must exist in the memory map.\r