]>
Commit | Line | Data |
---|---|---|
aaeef063 | 1 | /** @file\r |
2 | Generic ARM implementation of DmaLib.h\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r | |
3402aac7 | 5 | \r |
aaeef063 | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <Uefi.h>\r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/DmaLib.h>\r | |
19 | #include <Library/MemoryAllocationLib.h>\r | |
20 | \r | |
21 | \r | |
22 | \r | |
3402aac7 | 23 | /**\r |
aaeef063 | 24 | Provides the DMA controller-specific addresses needed to access system memory.\r |
3402aac7 | 25 | \r |
aaeef063 | 26 | Operation is relative to the DMA bus master.\r |
3402aac7 | 27 | \r |
aaeef063 | 28 | @param Operation Indicates if the bus master is going to read or write to system memory.\r |
29 | @param HostAddress The system memory address to map to the DMA controller.\r | |
30 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r | |
3402aac7 | 31 | that were mapped.\r |
aaeef063 | 32 | @param DeviceAddress The resulting map address for the bus master controller to use to\r |
3402aac7 | 33 | access the hosts HostAddress.\r |
aaeef063 | 34 | @param Mapping A resulting value to pass to Unmap().\r |
3402aac7 | 35 | \r |
aaeef063 | 36 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r |
3402aac7 | 37 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r |
aaeef063 | 38 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
39 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
40 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r | |
3402aac7 | 41 | \r |
aaeef063 | 42 | **/\r |
43 | EFI_STATUS\r | |
44 | EFIAPI\r | |
45 | DmaMap (\r | |
46 | IN DMA_MAP_OPERATION Operation,\r | |
47 | IN VOID *HostAddress,\r | |
48 | IN OUT UINTN *NumberOfBytes,\r | |
49 | OUT PHYSICAL_ADDRESS *DeviceAddress,\r | |
50 | OUT VOID **Mapping\r | |
51 | )\r | |
52 | {\r | |
6be6c2e0 | 53 | *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress;\r |
54 | *Mapping = NULL;\r | |
aaeef063 | 55 | return EFI_SUCCESS;\r |
56 | }\r | |
57 | \r | |
58 | \r | |
3402aac7 | 59 | /**\r |
aaeef063 | 60 | Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r |
61 | operation and releases any corresponding resources.\r | |
3402aac7 | 62 | \r |
aaeef063 | 63 | @param Mapping The mapping value returned from DmaMap*().\r |
3402aac7 | 64 | \r |
aaeef063 | 65 | @retval EFI_SUCCESS The range was unmapped.\r |
66 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r | |
3402aac7 | 67 | \r |
aaeef063 | 68 | **/\r |
69 | EFI_STATUS\r | |
70 | EFIAPI\r | |
71 | DmaUnmap (\r | |
72 | IN VOID *Mapping\r | |
73 | )\r | |
74 | {\r | |
75 | return EFI_SUCCESS;\r | |
76 | }\r | |
77 | \r | |
3402aac7 | 78 | /**\r |
aaeef063 | 79 | Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r |
3402aac7 RC |
80 | mapping.\r |
81 | \r | |
aaeef063 | 82 | @param MemoryType The type of memory to allocate, EfiBootServicesData or\r |
3402aac7 RC |
83 | EfiRuntimeServicesData.\r |
84 | @param Pages The number of pages to allocate.\r | |
aaeef063 | 85 | @param HostAddress A pointer to store the base system memory address of the\r |
3402aac7 | 86 | allocated range.\r |
aaeef063 | 87 | \r |
88 | @retval EFI_SUCCESS The requested memory pages were allocated.\r | |
89 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r | |
3402aac7 | 90 | MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r |
aaeef063 | 91 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r |
3402aac7 RC |
92 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r |
93 | \r | |
aaeef063 | 94 | **/\r |
95 | EFI_STATUS\r | |
96 | EFIAPI\r | |
97 | DmaAllocateBuffer (\r | |
98 | IN EFI_MEMORY_TYPE MemoryType,\r | |
99 | IN UINTN Pages,\r | |
100 | OUT VOID **HostAddress\r | |
101 | )\r | |
102 | {\r | |
deef290f AB |
103 | return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);\r |
104 | }\r | |
105 | \r | |
106 | \r | |
107 | /**\r | |
108 | Allocates pages that are suitable for an DmaMap() of type\r | |
109 | MapOperationBusMasterCommonBuffer mapping, at the requested alignment.\r | |
110 | \r | |
111 | @param MemoryType The type of memory to allocate, EfiBootServicesData or\r | |
112 | EfiRuntimeServicesData.\r | |
113 | @param Pages The number of pages to allocate.\r | |
114 | @param Alignment Alignment in bytes of the base of the returned\r | |
115 | buffer (must be a power of 2)\r | |
116 | @param HostAddress A pointer to store the base system memory address of the\r | |
117 | allocated range.\r | |
118 | \r | |
119 | @retval EFI_SUCCESS The requested memory pages were allocated.\r | |
120 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r | |
121 | MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r | |
122 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
123 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r | |
124 | \r | |
125 | **/\r | |
126 | EFI_STATUS\r | |
127 | EFIAPI\r | |
128 | DmaAllocateAlignedBuffer (\r | |
129 | IN EFI_MEMORY_TYPE MemoryType,\r | |
130 | IN UINTN Pages,\r | |
131 | IN UINTN Alignment,\r | |
132 | OUT VOID **HostAddress\r | |
133 | )\r | |
134 | {\r | |
135 | if (Alignment == 0) {\r | |
136 | Alignment = EFI_PAGE_SIZE;\r | |
137 | }\r | |
138 | \r | |
139 | if (HostAddress == NULL ||\r | |
140 | (Alignment & (Alignment - 1)) != 0) {\r | |
aaeef063 | 141 | return EFI_INVALID_PARAMETER;\r |
142 | }\r | |
143 | \r | |
144 | //\r | |
145 | // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r | |
146 | //\r | |
aaeef063 | 147 | if (MemoryType == EfiBootServicesData) {\r |
deef290f | 148 | *HostAddress = AllocateAlignedPages (Pages, Alignment);\r |
aaeef063 | 149 | } else if (MemoryType != EfiRuntimeServicesData) {\r |
deef290f | 150 | *HostAddress = AllocateAlignedRuntimePages (Pages, Alignment);\r |
aaeef063 | 151 | } else {\r |
152 | return EFI_INVALID_PARAMETER;\r | |
153 | }\r | |
154 | \r | |
deef290f AB |
155 | if (*HostAddress == NULL) {\r |
156 | return EFI_OUT_OF_RESOURCES;\r | |
157 | }\r | |
aaeef063 | 158 | return EFI_SUCCESS;\r |
159 | }\r | |
160 | \r | |
161 | \r | |
3402aac7 | 162 | /**\r |
aaeef063 | 163 | Frees memory that was allocated with DmaAllocateBuffer().\r |
3402aac7 RC |
164 | \r |
165 | @param Pages The number of pages to free.\r | |
166 | @param HostAddress The base system memory address of the allocated range.\r | |
167 | \r | |
aaeef063 | 168 | @retval EFI_SUCCESS The requested memory pages were freed.\r |
169 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r | |
170 | was not allocated with DmaAllocateBuffer().\r | |
3402aac7 | 171 | \r |
aaeef063 | 172 | **/\r |
173 | EFI_STATUS\r | |
174 | EFIAPI\r | |
175 | DmaFreeBuffer (\r | |
176 | IN UINTN Pages,\r | |
177 | IN VOID *HostAddress\r | |
178 | )\r | |
179 | {\r | |
180 | if (HostAddress == NULL) {\r | |
181 | return EFI_INVALID_PARAMETER;\r | |
3402aac7 RC |
182 | }\r |
183 | \r | |
aaeef063 | 184 | FreePages (HostAddress, Pages);\r |
185 | return EFI_SUCCESS;\r | |
186 | }\r | |
187 | \r |