Clean up OMAP DMA lib and split into generic DMA lib based on PCI_IO DMA abstractions...
authorandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 29 May 2010 00:21:30 +0000 (00:21 +0000)
committerandrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 29 May 2010 00:21:30 +0000 (00:21 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10555 6f19259b-4bc3-4df7-8a09-765794883524

ArmEbPkg/ArmEbPkg.dsc
ArmPkg/ArmPkg.dsc
BeagleBoardPkg/BeagleBoardPkg.dsc
Omap35xxPkg/Include/Library/OmapDmaLib.h
Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.c
Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf
Omap35xxPkg/MMCHSDxe/MMCHS.h
Omap35xxPkg/MMCHSDxe/MMCHS.inf
Omap35xxPkg/Omap35xxPkg.dsc
Omap35xxPkg/PciEmulation/PciEmulation.h
Omap35xxPkg/PciEmulation/PciEmulation.inf

index b035273..8a02235 100644 (file)
   TimerLib|ArmEbPkg/Library/TimerLib/TimerLib.inf  
   SerialPortLib|ArmEbPkg/Library/SerialPortLib/SerialPortLib.inf
   GdbSerialLib|ArmEbPkg/Library/GdbSerialLib/GdbSerialLib.inf
-
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
 
 
 [LibraryClasses.common.SEC]
index 819ee5c..4185a11 100644 (file)
@@ -66,6 +66,7 @@
   ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7Lib.inf
   CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
   ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
 
 [LibraryClasses.ARM]
   NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
index 65f0106..bc88620 100644 (file)
   GdbSerialLib|Omap35xxPkg/Library/GdbSerialLib/GdbSerialLib.inf
   ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
   DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
 
 [LibraryClasses.common.SEC]
   ArmLib|ArmPkg/Library/ArmLib/ArmV7/ArmV7LibPrePi.inf
index d4daf6d..0dc4468 100755 (executable)
@@ -1,10 +1,7 @@
 /** @file
 
-  Abstractions for simple OMAP DMA. The DMA functions are modeled on 
-  the PCI IO protocol and follow the same rules as outlined in the UEFI specification.
-  OMAP_DMA4 structure elements are described in the OMAP35xx TRM. Currently 
-  there is no PCI'less DMA protocol, if one existed it could be used to
-  replace this library.
+  Abstractions for simple OMAP DMA. 
+  OMAP_DMA4 structure elements are described in the OMAP35xx TRM. 
 
   Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
 
 #ifndef __OMAP_DMA_LIB_H__
 #define __OMAP_DMA_LIB_H__
 
-typedef enum {\r
-  ///\r
-  /// A read operation from system memory by a bus master.\r
-  ///\r
-  MapOperationBusMasterRead,\r
-  ///\r
-  /// A write operation from system memory by a bus master.\r
-  ///\r
-  MapOperationBusMasterWrite,\r
-  ///\r
-  /// Provides both read and write access to system memory by both the processor and a\r
-  /// bus master. The buffer is coherent from both the processor's and the bus master's point of view.\r
-  ///\r
-  MapOperationBusMasterCommonBuffer,\r
-  MapOperationMaximum\r
-} DMA_MAP_OPERATION;\r
-
 
 // Example from DMA chapter of the OMAP35xx spec
 typedef struct {\r
@@ -105,100 +85,6 @@ DisableDmaChannel (
   );
 
 
-/**                                                                 \r
-  Provides the DMA controller-specific addresses needed to access system memory.\r
-  \r
-  Operation is relative to the DMA bus master.\r
-            \r
-  @param  Operation             Indicates if the bus master is going to read or write to system memory.\r
-  @param  HostAddress           The system memory address to map to the DMA controller.\r
-  @param  NumberOfBytes         On input the number of bytes to map. On output the number of bytes\r
-                                that were mapped.                                                 \r
-  @param  DeviceAddress         The resulting map address for the bus master controller to use to\r
-                                access the hosts HostAddress.                                        \r
-  @param  Mapping               A resulting value to pass to Unmap().\r
-                                  \r
-  @retval EFI_SUCCESS           The range was mapped for the returned NumberOfBytes.\r
-  @retval EFI_UNSUPPORTED       The HostAddress cannot be mapped as a common buffer.                                \r
-  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
-  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
-  @retval EFI_DEVICE_ERROR      The system hardware could not map the requested address.\r
-                                   \r
-**/
-EFI_STATUS
-EFIAPI
-DmaMap (
-  IN     DMA_MAP_OPERATION              Operation,
-  IN     VOID                           *HostAddress,\r
-  IN OUT UINTN                          *NumberOfBytes,\r
-  OUT    PHYSICAL_ADDRESS               *DeviceAddress,\r
-  OUT    VOID                           **Mapping\r
-  );
-
-
-
-
-/**                                                                 \r
-  Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r
-  operation and releases any corresponding resources.\r
-            \r
-  @param  Mapping               The mapping value returned from DmaMap*().\r
-                                  \r
-  @retval EFI_SUCCESS           The range was unmapped.\r
-  @retval EFI_DEVICE_ERROR      The data was not committed to the target system memory.\r
-                                   \r
-**/
-EFI_STATUS
-EFIAPI
-DmaUnmap (
-  IN  VOID                         *Mapping\r
-  );
-
-
-/**                                                                 \r
-  Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
-  mapping.                                                                       \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  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
-**/
-EFI_STATUS
-EFIAPI
-DmaAllocateBuffer (
-  IN  EFI_MEMORY_TYPE              MemoryType,
-  IN  UINTN                        Pages,\r
-  OUT VOID                         **HostAddress\r
-  );\r
-
-
-/**                                                                 \r
-  Frees memory that was allocated with DmaAllocateBuffer().\r
-            \r
-  @param  Pages                 The number of pages to free.                                \r
-  @param  HostAddress           The base system memory address of the allocated range.                                    \r
-                                  \r
-  @retval EFI_SUCCESS           The requested memory pages were freed.\r
-  @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
-                                was not allocated with DmaAllocateBuffer().\r
-                                     \r
-**/\r
-EFI_STATUS
-EFIAPI
-DmaFreeBuffer (
-  IN  UINTN                        Pages,\r
-  IN  VOID                         *HostAddress\r
-  );\r
-
 
 #endif 
 
index 27617fa..d118312 100755 (executable)
@@ -1,6 +1,6 @@
 /** @file\r
-  OMAP35xx DMA abstractions modeled on PCI IO protocol. EnableDma()/DisableDma()\r
-  are from OMAP35xx TRM. \r
+  Abstractions for simple OMAP DMA channel.\r
+  \r
 \r
   Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
   \r
 #include <Base.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/OmapDmaLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UncachedMemoryAllocationLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
-#include <Library/ArmLib.h>\r
 #include <Omap3530/Omap3530.h>\r
 \r
-#include <Protocol/Cpu.h>\r
-\r
-typedef struct {\r
-  EFI_PHYSICAL_ADDRESS      HostAddress;\r
-  EFI_PHYSICAL_ADDRESS      DeviceAddress;\r
-  UINTN                     NumberOfBytes;\r
-  DMA_MAP_OPERATION         Operation;\r
-  BOOLEAN                   DoubleBuffer;\r
-} MAP_INFO_INSTANCE;\r
-\r
-\r
-\r
-EFI_CPU_ARCH_PROTOCOL      *gCpu;\r
-UINTN                      gCacheAlignment = 0;\r
 \r
 /**                                                                 \r
   Configure OMAP DMA Channel\r
@@ -192,229 +174,3 @@ DisableDmaChannel (
 \r
 \r
 \r
-/**                                                                 \r
-  Provides the DMA controller-specific addresses needed to access system memory.\r
-  \r
-  Operation is relative to the DMA bus master.\r
-            \r
-  @param  Operation             Indicates if the bus master is going to read or write to system memory.\r
-  @param  HostAddress           The system memory address to map to the DMA controller.\r
-  @param  NumberOfBytes         On input the number of bytes to map. On output the number of bytes\r
-                                that were mapped.                                                 \r
-  @param  DeviceAddress         The resulting map address for the bus master controller to use to\r
-                                access the hosts HostAddress.                                        \r
-  @param  Mapping               A resulting value to pass to Unmap().\r
-                                  \r
-  @retval EFI_SUCCESS           The range was mapped for the returned NumberOfBytes.\r
-  @retval EFI_UNSUPPORTED       The HostAddress cannot be mapped as a common buffer.                                \r
-  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
-  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
-  @retval EFI_DEVICE_ERROR      The system hardware could not map the requested address.\r
-                                   \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DmaMap (\r
-  IN     DMA_MAP_OPERATION              Operation,\r
-  IN     VOID                           *HostAddress,\r
-  IN OUT UINTN                          *NumberOfBytes,\r
-  OUT    PHYSICAL_ADDRESS               *DeviceAddress,\r
-  OUT    VOID                           **Mapping\r
-  )\r
-{\r
-  EFI_STATUS            Status;\r
-  MAP_INFO_INSTANCE     *Map;\r
-  VOID                  *Buffer;\r
-\r
-  if ( HostAddress == NULL || NumberOfBytes == NULL || \r
-       DeviceAddress == NULL || Mapping == NULL ) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-\r
-  if (Operation >= MapOperationMaximum) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  *DeviceAddress = ConvertToPhysicalAddress (HostAddress);\r
-\r
-  // Remember range so we can flush on the other side\r
-  Map = AllocatePool (sizeof (MAP_INFO_INSTANCE));\r
-  if (Map == NULL) {\r
-    return  EFI_OUT_OF_RESOURCES;\r
-  }\r
-  \r
-  *Mapping = Map;\r
-\r
-  if (((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) {\r
-    Map->DoubleBuffer  = TRUE;\r
-    Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-    \r
-    *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)Buffer;\r
-    \r
-  } else {\r
-    Map->DoubleBuffer  = FALSE;\r
-  }\r
-\r
-  *NumberOfBytes &= *NumberOfBytes & ~(gCacheAlignment - 1); // Only do it on full cache lines\r
-  \r
-  Map->HostAddress   = (UINTN)HostAddress;\r
-  Map->DeviceAddress = *DeviceAddress;\r
-  Map->NumberOfBytes = *NumberOfBytes;\r
-  Map->Operation     = Operation;\r
-\r
-  if (Map->DoubleBuffer) {\r
-    if (Map->Operation == MapOperationBusMasterWrite) {\r
-      CopyMem ((VOID *)(UINTN)Map->DeviceAddress, (VOID *)(UINTN)Map->HostAddress, Map->NumberOfBytes);\r
-    }\r
-  } else {\r
-    // EfiCpuFlushTypeWriteBack, EfiCpuFlushTypeInvalidate\r
-    if (Map->Operation == MapOperationBusMasterWrite || Map->Operation == MapOperationBusMasterRead) {\r
-      gCpu->FlushDataCache (gCpu, (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress,  Map->NumberOfBytes, EfiCpuFlushTypeWriteBackInvalidate);\r
-    }\r
-  }\r
-  \r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**                                                                 \r
-  Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r
-  operation and releases any corresponding resources.\r
-            \r
-  @param  Mapping               The mapping value returned from DmaMap*().\r
-                                  \r
-  @retval EFI_SUCCESS           The range was unmapped.\r
-  @retval EFI_DEVICE_ERROR      The data was not committed to the target system memory.\r
-                                   \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DmaUnmap (\r
-  IN  VOID                         *Mapping\r
-  )\r
-{\r
-  MAP_INFO_INSTANCE *Map;\r
-  \r
-  if (Mapping == NULL) {\r
-    ASSERT (FALSE);\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  Map = (MAP_INFO_INSTANCE *)Mapping;\r
-  \r
-  if (Map->DoubleBuffer) {\r
-    if (Map->Operation == MapOperationBusMasterRead) {\r
-      CopyMem ((VOID *)(UINTN)Map->HostAddress, (VOID *)(UINTN)Map->DeviceAddress, Map->NumberOfBytes);\r
-    }\r
-    \r
-    DmaFreeBuffer (EFI_SIZE_TO_PAGES (Map->NumberOfBytes), (VOID *)(UINTN)Map->DeviceAddress);\r
-  \r
-  } else {\r
-    if (Map->Operation == MapOperationBusMasterWrite) {\r
-      //\r
-      // Make sure we read buffer from uncached memory and not the cache\r
-      //\r
-      gCpu->FlushDataCache (gCpu, Map->HostAddress, Map->NumberOfBytes, EfiCpuFlushTypeInvalidate);\r
-    }\r
-  }\r
-  \r
-  FreePool (Map);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**                                                                 \r
-  Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
-  mapping.                                                                       \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  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
-DmaAllocateBuffer (\r
-  IN  EFI_MEMORY_TYPE              MemoryType,\r
-  IN  UINTN                        Pages,\r
-  OUT VOID                         **HostAddress\r
-  )\r
-{\r
-  if (HostAddress == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
-  //\r
-  // We used uncached memory to keep coherency\r
-  //\r
-  if (MemoryType == EfiBootServicesData) {\r
-    *HostAddress = UncachedAllocatePages (Pages);\r
-  } else if (MemoryType != EfiRuntimeServicesData) {\r
-    *HostAddress = UncachedAllocateRuntimePages (Pages);\r
-  } else {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**                                                                 \r
-  Frees memory that was allocated with DmaAllocateBuffer().\r
-            \r
-  @param  Pages                 The number of pages to free.                                \r
-  @param  HostAddress           The base system memory address of the allocated range.                                    \r
-                                  \r
-  @retval EFI_SUCCESS           The requested memory pages were freed.\r
-  @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
-                                was not allocated with DmaAllocateBuffer().\r
-                                     \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DmaFreeBuffer (\r
-  IN  UINTN                        Pages,\r
-  IN  VOID                         *HostAddress\r
-  )\r
-{\r
-  if (HostAddress == NULL) {\r
-     return EFI_INVALID_PARAMETER;\r
-  } \r
-  \r
-  UncachedFreePages (HostAddress, Pages);\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-OmapDmaLibConstructor (\r
-  IN EFI_HANDLE       ImageHandle,\r
-  IN EFI_SYSTEM_TABLE *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS              Status;\r
-\r
-  // Get the Cpu protocol for later use\r
-  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu);\r
-  ASSERT_EFI_ERROR(Status);\r
-\r
-  gCacheAlignment = ArmDataCacheLineLength ();\r
-  \r
-  return Status;\r
-}\r
-\r
index 04be6e0..4356853 100755 (executable)
@@ -18,7 +18,7 @@
   MODULE_TYPE                    = UEFI_DRIVER\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = OmapDmaLib \r
-  CONSTRUCTOR                    = OmapDmaLibConstructor\r
+\r
 \r
 [Sources.common]\r
   OmapDmaLib.c\r
index e7d8b7e..2cda567 100644 (file)
@@ -26,6 +26,7 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/OmapLib.h>
 #include <Library/OmapDmaLib.h>
+#include <Library/DmaLib.h>
 
 #include <Protocol/EmbeddedExternalDevice.h>\r
 #include <Protocol/BlockIo.h>
index 3313ddd..0931112 100644 (file)
@@ -36,6 +36,7 @@
   MemoryAllocationLib
   IoLib
   OmapDmaLib
+  DmaLib
 
 [Guids]
   
index 5e4fa30..fda0b7b 100644 (file)
@@ -60,6 +60,7 @@
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
   UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+  DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
 
 #
 # Assume everything is fixed at build
 [Components.common]
   Omap35xxPkg/Library/Omap35xxTimerLib/Omap35xxTimerLib.inf  
   Omap35xxPkg/Library/OmapLib/OmapLib.inf
-  Omap35xxPkg/Library/OmapLib/OmapDmaLib.inf
+  Omap35xxPkg/Library/OmapDmaLib/OmapDmaLib.inf
   
   Omap35xxPkg/Flash/Flash.inf
   Omap35xxPkg/MMCHSDxe/MMCHS.inf
index 066a553..7db4f33 100644 (file)
@@ -29,6 +29,7 @@
 #include <Library/UefiLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/OmapDmaLib.h>\r
+#include <Library/DmaLib.h>\r
 \r
 #include <Protocol/EmbeddedExternalDevice.h>\r
 #include <Protocol/DevicePath.h>\r
index e9da1fb..8567b69 100644 (file)
@@ -42,6 +42,7 @@
   UefiRuntimeServicesTableLib\r
   IoLib\r
   OmapDmaLib\r
+  DmaLib\r
 \r
 [Protocols]\r
   gEfiPciRootBridgeIoProtocolGuid\r