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 |
|
---|
56 |
|
---|
57 | /**
|
---|
58 | Provides the DMA controller-specific addresses needed to access system memory.
|
---|
59 |
|
---|
60 | Operation is relative to the DMA bus master.
|
---|
61 |
|
---|
62 | @param Operation Indicates if the bus master is going to read or write to system memory.
|
---|
63 | @param HostAddress The system memory address to map to the DMA controller.
|
---|
64 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
|
---|
65 | that were mapped.
|
---|
66 | @param DeviceAddress The resulting map address for the bus master controller to use to
|
---|
67 | access the hosts HostAddress.
|
---|
68 | @param Mapping A resulting value to pass to DmaUnmap().
|
---|
69 |
|
---|
70 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
|
---|
71 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
|
---|
72 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
---|
73 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
|
---|
74 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
|
---|
75 |
|
---|
76 | **/
|
---|
77 | EFI_STATUS
|
---|
78 | EFIAPI
|
---|
79 | DmaMap (
|
---|
80 | IN DMA_MAP_OPERATION Operation,
|
---|
81 | IN VOID *HostAddress,
|
---|
82 | IN OUT UINTN *NumberOfBytes,
|
---|
83 | OUT PHYSICAL_ADDRESS *DeviceAddress,
|
---|
84 | OUT VOID **Mapping
|
---|
85 | );
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | /**
|
---|
91 | Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer
|
---|
92 | operation and releases any corresponding resources.
|
---|
93 |
|
---|
94 | @param Mapping The mapping value returned from DmaMap().
|
---|
95 |
|
---|
96 | @retval EFI_SUCCESS The range was unmapped.
|
---|
97 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
|
---|
98 |
|
---|
99 | **/
|
---|
100 | EFI_STATUS
|
---|
101 | EFIAPI
|
---|
102 | DmaUnmap (
|
---|
103 | IN VOID *Mapping
|
---|
104 | );
|
---|
105 |
|
---|
106 |
|
---|
107 | /**
|
---|
108 | Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
|
---|
109 | mapping.
|
---|
110 |
|
---|
111 | @param MemoryType The type of memory to allocate, EfiBootServicesData or
|
---|
112 | EfiRuntimeServicesData.
|
---|
113 | @param Pages The number of pages to allocate.
|
---|
114 | @param HostAddress A pointer to store the base system memory address of the
|
---|
115 | allocated range.
|
---|
116 |
|
---|
117 | @retval EFI_SUCCESS The requested memory pages were allocated.
|
---|
118 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
|
---|
119 | MEMORY_WRITE_COMBINE and MEMORY_CACHED.
|
---|
120 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
---|
121 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
|
---|
122 |
|
---|
123 | **/
|
---|
124 | EFI_STATUS
|
---|
125 | EFIAPI
|
---|
126 | DmaAllocateBuffer (
|
---|
127 | IN EFI_MEMORY_TYPE MemoryType,
|
---|
128 | IN UINTN Pages,
|
---|
129 | OUT VOID **HostAddress
|
---|
130 | );
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | Frees memory that was allocated with DmaAllocateBuffer().
|
---|
135 |
|
---|
136 | @param Pages The number of pages to free.
|
---|
137 | @param HostAddress The base system memory address of the allocated range.
|
---|
138 |
|
---|
139 | @retval EFI_SUCCESS The requested memory pages were freed.
|
---|
140 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
|
---|
141 | was not allocated with DmaAllocateBuffer().
|
---|
142 |
|
---|
143 | **/
|
---|
144 | EFI_STATUS
|
---|
145 | EFIAPI
|
---|
146 | DmaFreeBuffer (
|
---|
147 | IN UINTN Pages,
|
---|
148 | IN VOID *HostAddress
|
---|
149 | );
|
---|
150 |
|
---|
151 |
|
---|
152 | /**
|
---|
153 | Allocates pages that are suitable for an DmaMap() of type
|
---|
154 | MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
|
---|
155 |
|
---|
156 | @param MemoryType The type of memory to allocate, EfiBootServicesData or
|
---|
157 | EfiRuntimeServicesData.
|
---|
158 | @param Pages The number of pages to allocate.
|
---|
159 | @param Alignment Alignment in bytes of the base of the returned
|
---|
160 | buffer (must be a power of 2)
|
---|
161 | @param HostAddress A pointer to store the base system memory address of the
|
---|
162 | allocated range.
|
---|
163 |
|
---|
164 | @retval EFI_SUCCESS The requested memory pages were allocated.
|
---|
165 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
|
---|
166 | MEMORY_WRITE_COMBINE and MEMORY_CACHED.
|
---|
167 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
---|
168 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
|
---|
169 |
|
---|
170 | **/
|
---|
171 | EFI_STATUS
|
---|
172 | EFIAPI
|
---|
173 | DmaAllocateAlignedBuffer (
|
---|
174 | IN EFI_MEMORY_TYPE MemoryType,
|
---|
175 | IN UINTN Pages,
|
---|
176 | IN UINTN Alignment,
|
---|
177 | OUT VOID **HostAddress
|
---|
178 | );
|
---|
179 |
|
---|
180 |
|
---|
181 | #endif
|
---|