]>
Commit | Line | Data |
---|---|---|
aaeef063 | 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:\r | |
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.\r | |
15 | Program the DMA Bus Master with the DeviceAddress returned by DmaMap().\r | |
16 | Start the DMA Bus Master.\r | |
17 | Wait for DMA Bus Master to complete the write operation.\r | |
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 | This program and the accompanying materials | |
31 | are licensed and made available under the terms and conditions of the BSD License | |
32 | which accompanies this distribution. The full text of the license may be found at | |
33 | http://opensource.org/licenses/bsd-license.php | |
34 | ||
35 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
36 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
37 | ||
38 | **/ | |
39 | ||
40 | #ifndef __DMA_LIB_H__ | |
41 | #define __DMA_LIB_H__ | |
42 | ||
43 | typedef enum {\r | |
44 | ///\r | |
45 | /// A read operation from system memory by a bus master.\r | |
46 | ///\r | |
47 | MapOperationBusMasterRead,\r | |
48 | ///\r | |
49 | /// A write operation from system memory by a bus master.\r | |
50 | ///\r | |
51 | MapOperationBusMasterWrite,\r | |
52 | ///\r | |
53 | /// Provides both read and write access to system memory by both the processor and a\r | |
54 | /// bus master. The buffer is coherent from both the processor's and the bus master's point of view.\r | |
55 | ///\r | |
56 | MapOperationBusMasterCommonBuffer,\r | |
57 | MapOperationMaximum\r | |
58 | } DMA_MAP_OPERATION;\r | |
59 | ||
60 | ||
61 | ||
62 | ||
63 | /** \r | |
64 | Provides the DMA controller-specific addresses needed to access system memory.\r | |
65 | \r | |
66 | Operation is relative to the DMA bus master.\r | |
67 | \r | |
68 | @param Operation Indicates if the bus master is going to read or write to system memory.\r | |
69 | @param HostAddress The system memory address to map to the DMA controller.\r | |
70 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r | |
71 | that were mapped. \r | |
72 | @param DeviceAddress The resulting map address for the bus master controller to use to\r | |
73 | access the hosts HostAddress. \r | |
74 | @param Mapping A resulting value to pass to DmaUnmap().\r | |
75 | \r | |
76 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r | |
77 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. \r | |
78 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
79 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
80 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r | |
81 | \r | |
82 | **/ | |
83 | EFI_STATUS | |
84 | EFIAPI | |
85 | DmaMap ( | |
86 | IN DMA_MAP_OPERATION Operation, | |
87 | IN VOID *HostAddress,\r | |
88 | IN OUT UINTN *NumberOfBytes,\r | |
89 | OUT PHYSICAL_ADDRESS *DeviceAddress,\r | |
90 | OUT VOID **Mapping\r | |
91 | ); | |
92 | ||
93 | ||
94 | ||
95 | ||
96 | /** \r | |
97 | Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer\r | |
98 | operation and releases any corresponding resources.\r | |
99 | \r | |
100 | @param Mapping The mapping value returned from DmaMap().\r | |
101 | \r | |
102 | @retval EFI_SUCCESS The range was unmapped.\r | |
103 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r | |
104 | \r | |
105 | **/ | |
106 | EFI_STATUS | |
107 | EFIAPI | |
108 | DmaUnmap ( | |
109 | IN VOID *Mapping\r | |
110 | ); | |
111 | ||
112 | ||
113 | /** \r | |
114 | Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r | |
115 | mapping. \r | |
116 | \r | |
117 | @param MemoryType The type of memory to allocate, EfiBootServicesData or\r | |
118 | EfiRuntimeServicesData. \r | |
119 | @param Pages The number of pages to allocate. \r | |
120 | @param HostAddress A pointer to store the base system memory address of the\r | |
121 | allocated range. \r | |
122 | \r | |
123 | @retval EFI_SUCCESS The requested memory pages were allocated.\r | |
124 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r | |
125 | MEMORY_WRITE_COMBINE and MEMORY_CACHED. \r | |
126 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
127 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. \r | |
128 | \r | |
129 | **/ | |
130 | EFI_STATUS | |
131 | EFIAPI | |
132 | DmaAllocateBuffer ( | |
133 | IN EFI_MEMORY_TYPE MemoryType, | |
134 | IN UINTN Pages,\r | |
135 | OUT VOID **HostAddress\r | |
136 | );\r | |
137 | ||
138 | ||
139 | /** \r | |
140 | Frees memory that was allocated with DmaAllocateBuffer().\r | |
141 | \r | |
142 | @param Pages The number of pages to free. \r | |
143 | @param HostAddress The base system memory address of the allocated range. \r | |
144 | \r | |
145 | @retval EFI_SUCCESS The requested memory pages were freed.\r | |
146 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r | |
147 | was not allocated with DmaAllocateBuffer().\r | |
148 | \r | |
149 | **/\r | |
150 | EFI_STATUS | |
151 | EFIAPI | |
152 | DmaFreeBuffer ( | |
153 | IN UINTN Pages,\r | |
154 | IN VOID *HostAddress\r | |
155 | );\r | |
156 | ||
157 | ||
158 | #endif | |
159 |