7f814ffd |
1 | /** @file |
2 | |
3 | Abstractions for simple OMAP DMA. The DMA functions are modeled on |
4 | the PCI IO protocol and follow the same rules as outlined in the UEFI specification. |
5 | OMAP_DMA4 structure elements are described in the OMAP35xx TRM. Currently |
6 | there is no PCI'less DMA protocol, if one existed it could be used to |
7 | replace this library. |
8 | |
9 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> |
10 | |
11 | This program and the accompanying materials |
12 | are licensed and made available under the terms and conditions of the BSD License |
13 | which accompanies this distribution. The full text of the license may be found at |
14 | http://opensource.org/licenses/bsd-license.php |
15 | |
16 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, |
17 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. |
18 | |
19 | **/ |
20 | |
21 | #ifndef __OMAP_DMA_LIB_H__ |
22 | #define __OMAP_DMA_LIB_H__ |
23 | |
24 | typedef enum {\r |
25 | ///\r |
26 | /// A read operation from system memory by a bus master.\r |
27 | ///\r |
28 | MapOperationBusMasterRead,\r |
29 | ///\r |
30 | /// A write operation from system memory by a bus master.\r |
31 | ///\r |
32 | MapOperationBusMasterWrite,\r |
33 | ///\r |
34 | /// Provides both read and write access to system memory by both the processor and a\r |
35 | /// bus master. The buffer is coherent from both the processor's and the bus master's point of view.\r |
36 | ///\r |
37 | MapOperationBusMasterCommonBuffer,\r |
38 | MapOperationMaximum\r |
39 | } DMA_MAP_OPERATION;\r |
40 | |
41 | |
42 | // Example from DMA chapter of the OMAP35xx spec |
43 | typedef struct {\r |
44 | UINT8 DataType; // DMA4_CSDPi[1:0]\r |
45 | UINT8 ReadPortAccessType; // DMA4_CSDPi[8:7]\r |
46 | UINT8 WritePortAccessType; // DMA4_CSDPi[15:14]\r |
47 | UINT8 SourceEndiansim; // DMA4_CSDPi[21]\r |
48 | UINT8 DestinationEndianism; // DMA4_CSDPi[19]\r |
49 | UINT8 WriteMode; // DMA4_CSDPi[17:16]\r |
50 | UINT8 SourcePacked; // DMA4_CSDPi[6]\r |
51 | UINT8 DestinationPacked; // DMA4_CSDPi[13]\r |
52 | UINT32 NumberOfElementPerFrame; // DMA4_CENi\r |
53 | UINT32 NumberOfFramePerTransferBlock; // DMA4_CFNi\r |
54 | UINT32 SourceStartAddress; // DMA4_CSSAi\r |
55 | UINT32 DestinationStartAddress; // DMA4_CDSAi\r |
56 | UINT32 SourceElementIndex; // DMA4_CSEi\r |
57 | UINT32 SourceFrameIndex; // DMA4_CSFi\r |
58 | UINT32 DestinationElementIndex; // DMA4_CDEi\r |
59 | UINT32 DestinationFrameIndex; // DMA4_CDFi\r |
60 | UINT8 ReadPortAccessMode; // DMA4_CCRi[13:12]\r |
61 | UINT8 WritePortAccessMode; // DMA4_CCRi[15:14]\r |
62 | UINT8 ReadPriority; // DMA4_CCRi[6]\r |
63 | UINT8 WritePriority; // DMA4_CCRi[23]\r |
64 | UINT8 ReadRequestNumber; // DMA4_CCRi[4:0]\r |
65 | UINT8 WriteRequestNumber; // DMA4_CCRi[20:19] |
66 | } OMAP_DMA4; |
67 | |
68 | |
69 | /** \r |
70 | Configure OMAP DMA Channel\r |
71 | \r |
72 | @param Channel DMA Channel to configure\r |
73 | @param Dma4 Pointer to structure used to initialize DMA registers for the Channel \r |
74 | \r |
75 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r |
76 | @retval EFI_INVALID_PARAMETER Channel is not valid\r |
77 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested information.\r |
78 | \r |
79 | **/ |
80 | EFI_STATUS |
81 | EFIAPI |
82 | EnableDmaChannel ( |
83 | IN UINTN Channel, |
84 | IN OMAP_DMA4 *Dma4 |
85 | ); |
86 | |
87 | /** \r |
88 | Turn of DMA channel configured by EnableDma().\r |
89 | \r |
90 | @param Channel DMA Channel to configure\r |
91 | \r |
92 | @retval EFI_SUCCESS DMA hardware disabled\r |
93 | @retval EFI_INVALID_PARAMETER Channel is not valid\r |
94 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested information.\r |
95 | \r |
96 | **/ |
97 | EFI_STATUS |
98 | EFIAPI |
99 | DisableDmaChannel ( |
100 | IN UINTN Channel |
101 | ); |
102 | |
103 | |
104 | /** \r |
105 | Provides the DMA controller-specific addresses needed to access system memory.\r |
106 | \r |
107 | Operation is relative to the DMA bus master.\r |
108 | \r |
109 | @param Operation Indicates if the bus master is going to read or write to system memory.\r |
110 | @param HostAddress The system memory address to map to the DMA controller.\r |
111 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r |
112 | that were mapped. \r |
113 | @param DeviceAddress The resulting map address for the bus master controller to use to\r |
114 | access the hosts HostAddress. \r |
115 | @param Mapping A resulting value to pass to Unmap().\r |
116 | \r |
117 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r |
118 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. \r |
119 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
120 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r |
121 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r |
122 | \r |
123 | **/ |
124 | EFI_STATUS |
125 | EFIAPI |
126 | DmaMap ( |
127 | IN DMA_MAP_OPERATION Operation, |
128 | IN VOID *HostAddress,\r |
129 | IN OUT UINTN *NumberOfBytes,\r |
130 | OUT PHYSICAL_ADDRESS *DeviceAddress,\r |
131 | OUT VOID **Mapping\r |
132 | ); |
133 | |
134 | |
135 | |
136 | |
137 | /** \r |
138 | Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r |
139 | operation and releases any corresponding resources.\r |
140 | \r |
141 | @param Mapping The mapping value returned from DmaMap*().\r |
142 | \r |
143 | @retval EFI_SUCCESS The range was unmapped.\r |
144 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r |
145 | \r |
146 | **/ |
147 | EFI_STATUS |
148 | EFIAPI |
149 | DmaUnmap ( |
150 | IN VOID *Mapping\r |
151 | ); |
152 | |
153 | |
154 | /** \r |
155 | Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r |
156 | mapping. \r |
157 | \r |
158 | @param MemoryType The type of memory to allocate, EfiBootServicesData or\r |
159 | EfiRuntimeServicesData. \r |
160 | @param Pages The number of pages to allocate. \r |
161 | @param HostAddress A pointer to store the base system memory address of the\r |
162 | allocated range. \r |
163 | \r |
164 | @retval EFI_SUCCESS The requested memory pages were allocated.\r |
165 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r |
166 | MEMORY_WRITE_COMBINE and MEMORY_CACHED. \r |
167 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
168 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. \r |
169 | \r |
170 | **/ |
171 | EFI_STATUS |
172 | EFIAPI |
173 | DmaAllocateBuffer ( |
174 | IN EFI_MEMORY_TYPE MemoryType, |
175 | IN UINTN Pages,\r |
176 | OUT VOID **HostAddress\r |
177 | );\r |
178 | |
179 | |
180 | /** \r |
181 | Frees memory that was allocated with DmaAllocateBuffer().\r |
182 | \r |
183 | @param Pages The number of pages to free. \r |
184 | @param HostAddress The base system memory address of the allocated range. \r |
185 | \r |
186 | @retval EFI_SUCCESS The requested memory pages were freed.\r |
187 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r |
188 | was not allocated with DmaAllocateBuffer().\r |
189 | \r |
190 | **/\r |
191 | EFI_STATUS |
192 | EFIAPI |
193 | DmaFreeBuffer ( |
194 | IN UINTN Pages,\r |
195 | IN VOID *HostAddress\r |
196 | );\r |
197 | |
198 | |
199 | #endif |
200 | |