]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
ArmPkg/UncachedMemoryAllocationLib: use CWG value to align pool allocations
[mirror_edk2.git] / ArmPkg / Library / UncachedMemoryAllocationLib / UncachedMemoryAllocationLib.c
index b859f63c2b5a0256b01f650a4f29bce4ecf893de..0d8abad2343379d24533ee6552ed1705fc3cba0e 100644 (file)
@@ -25,6 +25,7 @@
 #include <Library/PcdLib.h>\r
 #include <Library/ArmLib.h>\r
 #include <Library/DxeServicesTableLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
 \r
 VOID *\r
 UncachedInternalAllocatePages (\r
@@ -41,11 +42,6 @@ UncachedInternalAllocateAlignedPages (
 \r
 \r
 \r
-//\r
-// Assume all of memory has the same cache attributes, unless we do our magic\r
-//\r
-UINT64  gAttributes;\r
-\r
 typedef struct {\r
   EFI_PHYSICAL_ADDRESS  Base;\r
   VOID                  *Allocation;\r
@@ -53,6 +49,7 @@ typedef struct {
   EFI_MEMORY_TYPE       MemoryType;\r
   BOOLEAN               Allocated;\r
   LIST_ENTRY            Link;\r
+  UINT64                Attributes;\r
 } FREE_PAGE_NODE;\r
 \r
 STATIC LIST_ENTRY  mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);\r
@@ -96,6 +93,7 @@ AllocatePagesFromList (
   //\r
   // Look in our list for the smallest page that could satisfy the new allocation\r
   //\r
+  Node = NULL;\r
   NewNode = NULL;\r
   for (Link = mPageList.ForwardLink; Link != &mPageList; Link = Link->ForwardLink) {\r
     Node = BASE_CR (Link, FREE_PAGE_NODE, Link);\r
@@ -151,10 +149,7 @@ AllocatePagesFromList (
   }\r
 \r
   Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);\r
-  if (!EFI_ERROR (Status)) {\r
-    // We are making an assumption that all of memory has the same default attributes\r
-    gAttributes = Descriptor.Attributes;\r
-  } else {\r
+  if (EFI_ERROR (Status)) {\r
     gBS->FreePages (Memory, Pages);\r
     return Status;\r
   }\r
@@ -165,6 +160,8 @@ AllocatePagesFromList (
     return Status;\r
   }\r
 \r
+  InvalidateDataCacheRange ((VOID *)(UINTN)Memory, EFI_PAGES_TO_SIZE (Pages));\r
+\r
   NewNode = AllocatePool (sizeof (FREE_PAGE_NODE));\r
   if (NewNode == NULL) {\r
     ASSERT (FALSE);\r
@@ -177,6 +174,7 @@ AllocatePagesFromList (
   NewNode->Pages      = Pages;\r
   NewNode->Allocated  = TRUE;\r
   NewNode->MemoryType = MemoryType;\r
+  NewNode->Attributes = Descriptor.Attributes;\r
 \r
   InsertTailList (&mPageList, &NewNode->Link);\r
 \r
@@ -262,6 +260,10 @@ UncachedMemoryAllocationLibDestructor (
     // We only free the non-allocated buffer\r
     if (OldNode->Allocated == FALSE) {\r
       gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);\r
+\r
+      gDS->SetMemorySpaceAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base,\r
+             EFI_PAGES_TO_SIZE (OldNode->Pages), OldNode->Attributes);\r
+\r
       RemoveEntryList (&OldNode->Link);\r
       FreePool (OldNode);\r
     }\r
@@ -543,7 +545,7 @@ UncachedInternalAllocatePool (
   IN UINTN            AllocationSize\r
   )\r
 {\r
-  UINTN CacheLineLength = ArmDataCacheLineLength ();\r
+  UINTN CacheLineLength = ArmCacheWritebackGranule ();\r
   return UncachedInternalAllocateAlignedPool (MemoryType, AllocationSize, CacheLineLength);\r
 }\r
 \r