]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c
EmbeddedPkg/CoherentDmaLib: Add missing checks to DmaMap
[mirror_edk2.git] / EmbeddedPkg / Library / CoherentDmaLib / CoherentDmaLib.c
index 4cbe349190a99c534ed124203cb5d4f2634706dd..eb88fa288a99b649f004dc9d95c09ef67a83c4fd 100644 (file)
 #include <Library/MemoryAllocationLib.h>\r
 \r
 \r
+STATIC\r
+PHYSICAL_ADDRESS\r
+HostToDeviceAddress (\r
+  IN  VOID      *Address\r
+  )\r
+{\r
+  return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset);\r
+}\r
 \r
 /**\r
   Provides the DMA controller-specific addresses needed to access system memory.\r
@@ -50,7 +58,13 @@ DmaMap (
   OUT    VOID                           **Mapping\r
   )\r
 {\r
-  *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress;\r
+  if (HostAddress == NULL ||\r
+      NumberOfBytes == NULL ||\r
+      DeviceAddress == NULL ||\r
+      Mapping == NULL ) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  *DeviceAddress = HostToDeviceAddress (HostAddress);\r
   *Mapping = NULL;\r
   return EFI_SUCCESS;\r
 }\r
@@ -146,7 +160,7 @@ DmaAllocateAlignedBuffer (
   //\r
   if (MemoryType == EfiBootServicesData) {\r
     *HostAddress = AllocateAlignedPages (Pages, Alignment);\r
-  } else if (MemoryType != EfiRuntimeServicesData) {\r
+  } else if (MemoryType == EfiRuntimeServicesData) {\r
     *HostAddress = AllocateAlignedRuntimePages (Pages, Alignment);\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r