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