DmaLib.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /** @file
  2. DMA abstraction library APIs. Based on UEFI PCI IO protocol DMA abstractions.
  3. At some point these functions will probably end up in a non PCI protocol
  4. for embedded systems.
  5. DMA Bus Master Read Operation:
  6. Call DmaMap() for MapOperationBusMasterRead.
  7. Program the DMA Bus Master with the DeviceAddress returned by DmaMap().
  8. Start the DMA Bus Master.
  9. Wait for DMA Bus Master to complete the read operation.
  10. Call DmaUnmap().
  11. DMA Bus Master Write Operation:
  12. Call DmaMap() for MapOperationBusMasterWrite.
  13. Program the DMA Bus Master with the DeviceAddress returned by DmaMap().
  14. Start the DMA Bus Master.
  15. Wait for DMA Bus Master to complete the write operation.
  16. Call DmaUnmap().
  17. DMA Bus Master Common Buffer Operation:
  18. Call DmaAllocateBuffer() to allocate a common buffer.
  19. Call DmaMap() for MapOperationBusMasterCommonBuffer.
  20. Program the DMA Bus Master with the DeviceAddress returned by DmaMap().
  21. The common buffer can now be accessed equally by the processor and the DMA bus master.
  22. Call DmaUnmap().
  23. Call DmaFreeBuffer().
  24. Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
  25. SPDX-License-Identifier: BSD-2-Clause-Patent
  26. **/
  27. #ifndef __DMA_LIB_H__
  28. #define __DMA_LIB_H__
  29. typedef enum {
  30. ///
  31. /// A read operation from system memory by a bus master.
  32. ///
  33. MapOperationBusMasterRead,
  34. ///
  35. /// A write operation from system memory by a bus master.
  36. ///
  37. MapOperationBusMasterWrite,
  38. ///
  39. /// Provides both read and write access to system memory by both the processor and a
  40. /// bus master. The buffer is coherent from both the processor's and the bus master's point of view.
  41. ///
  42. MapOperationBusMasterCommonBuffer,
  43. MapOperationMaximum
  44. } DMA_MAP_OPERATION;
  45. /**
  46. Provides the DMA controller-specific addresses needed to access system memory.
  47. Operation is relative to the DMA bus master.
  48. @param Operation Indicates if the bus master is going to read or write to system memory.
  49. @param HostAddress The system memory address to map to the DMA controller.
  50. @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
  51. that were mapped.
  52. @param DeviceAddress The resulting map address for the bus master controller to use to
  53. access the hosts HostAddress.
  54. @param Mapping A resulting value to pass to DmaUnmap().
  55. @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
  56. @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
  57. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
  58. @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
  59. @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
  60. **/
  61. EFI_STATUS
  62. EFIAPI
  63. DmaMap (
  64. IN DMA_MAP_OPERATION Operation,
  65. IN VOID *HostAddress,
  66. IN OUT UINTN *NumberOfBytes,
  67. OUT PHYSICAL_ADDRESS *DeviceAddress,
  68. OUT VOID **Mapping
  69. );
  70. /**
  71. Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer
  72. operation and releases any corresponding resources.
  73. @param Mapping The mapping value returned from DmaMap().
  74. @retval EFI_SUCCESS The range was unmapped.
  75. @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
  76. **/
  77. EFI_STATUS
  78. EFIAPI
  79. DmaUnmap (
  80. IN VOID *Mapping
  81. );
  82. /**
  83. Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
  84. mapping.
  85. @param MemoryType The type of memory to allocate, EfiBootServicesData or
  86. EfiRuntimeServicesData.
  87. @param Pages The number of pages to allocate.
  88. @param HostAddress A pointer to store the base system memory address of the
  89. allocated range.
  90. @retval EFI_SUCCESS The requested memory pages were allocated.
  91. @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
  92. MEMORY_WRITE_COMBINE and MEMORY_CACHED.
  93. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
  94. @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
  95. **/
  96. EFI_STATUS
  97. EFIAPI
  98. DmaAllocateBuffer (
  99. IN EFI_MEMORY_TYPE MemoryType,
  100. IN UINTN Pages,
  101. OUT VOID **HostAddress
  102. );
  103. /**
  104. Frees memory that was allocated with DmaAllocateBuffer().
  105. @param Pages The number of pages to free.
  106. @param HostAddress The base system memory address of the allocated range.
  107. @retval EFI_SUCCESS The requested memory pages were freed.
  108. @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
  109. was not allocated with DmaAllocateBuffer().
  110. **/
  111. EFI_STATUS
  112. EFIAPI
  113. DmaFreeBuffer (
  114. IN UINTN Pages,
  115. IN VOID *HostAddress
  116. );
  117. /**
  118. Allocates pages that are suitable for an DmaMap() of type
  119. MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
  120. @param MemoryType The type of memory to allocate, EfiBootServicesData or
  121. EfiRuntimeServicesData.
  122. @param Pages The number of pages to allocate.
  123. @param Alignment Alignment in bytes of the base of the returned
  124. buffer (must be a power of 2)
  125. @param HostAddress A pointer to store the base system memory address of the
  126. allocated range.
  127. @retval EFI_SUCCESS The requested memory pages were allocated.
  128. @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
  129. MEMORY_WRITE_COMBINE and MEMORY_CACHED.
  130. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
  131. @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
  132. **/
  133. EFI_STATUS
  134. EFIAPI
  135. DmaAllocateAlignedBuffer (
  136. IN EFI_MEMORY_TYPE MemoryType,
  137. IN UINTN Pages,
  138. IN UINTN Alignment,
  139. OUT VOID **HostAddress
  140. );
  141. #endif