]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmDmaLib: implement DmaAllocateAlignedBuffer()
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 24 Aug 2017 19:13:10 +0000 (20:13 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 29 Aug 2017 16:54:54 +0000 (17:54 +0100)
Implement the new DmaLib routine that returns DMA'able buffers
at a specified minimum alignment.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

index e12bda4c2d33f29b96c325b33b8c4b9d42af5d5a..2a8cf0fe21a48b21fdfab0d4f4e389343cf52304 100644 (file)
@@ -284,6 +284,37 @@ DmaAllocateBuffer (
   IN  UINTN                        Pages,\r
   OUT VOID                         **HostAddress\r
   )\r
+{\r
+  return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);\r
+}\r
+\r
+/**\r
+  Allocates pages that are suitable for an DmaMap() of type\r
+  MapOperationBusMasterCommonBuffer mapping, at the requested alignment.\r
+\r
+  @param  MemoryType            The type of memory to allocate, EfiBootServicesData or\r
+                                EfiRuntimeServicesData.\r
+  @param  Pages                 The number of pages to allocate.\r
+  @param  Alignment             Alignment in bytes of the base of the returned\r
+                                buffer (must be a power of 2)\r
+  @param  HostAddress           A pointer to store the base system memory address of the\r
+                                allocated range.\r
+\r
+  @retval EFI_SUCCESS           The requested memory pages were allocated.\r
+  @retval EFI_UNSUPPORTED       Attributes is unsupported. The only legal attribute bits are\r
+                                MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
+  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
+  @retval EFI_OUT_OF_RESOURCES  The memory pages could not be allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DmaAllocateAlignedBuffer (\r
+  IN  EFI_MEMORY_TYPE              MemoryType,\r
+  IN  UINTN                        Pages,\r
+  IN  UINTN                        Alignment,\r
+  OUT VOID                         **HostAddress\r
+  )\r
 {\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR   GcdDescriptor;\r
   VOID                              *Allocation;\r
@@ -291,14 +322,19 @@ DmaAllocateBuffer (
   UNCACHED_ALLOCATION               *Alloc;\r
   EFI_STATUS                        Status;\r
 \r
-  if (HostAddress == NULL) {\r
+  if (Alignment == 0) {\r
+    Alignment = EFI_PAGE_SIZE;\r
+  }\r
+\r
+  if (HostAddress == NULL ||\r
+      (Alignment & (Alignment - 1)) != 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   if (MemoryType == EfiBootServicesData) {\r
-    Allocation = AllocatePages (Pages);\r
+    Allocation = AllocateAlignedPages (Pages, Alignment);\r
   } else if (MemoryType == EfiRuntimeServicesData) {\r
-    Allocation = AllocateRuntimePages (Pages);\r
+    Allocation = AllocateAlignedRuntimePages (Pages, Alignment);\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r
   }\r