]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c
EmbeddedPkg/CoherentDmaLib: Fix typo in DmaAlignedBuffer
[mirror_edk2.git] / EmbeddedPkg / Library / CoherentDmaLib / CoherentDmaLib.c
CommitLineData
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
0bcb8010
AB
22STATIC\r
23PHYSICAL_ADDRESS\r
24HostToDeviceAddress (\r
25 IN VOID *Address\r
26 )\r
27{\r
28 return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset);\r
29}\r
aaeef063 30\r
3402aac7 31/**\r
aaeef063 32 Provides the DMA controller-specific addresses needed to access system memory.\r
3402aac7 33\r
aaeef063 34 Operation is relative to the DMA bus master.\r
3402aac7 35\r
aaeef063 36 @param Operation Indicates if the bus master is going to read or write to system memory.\r
37 @param HostAddress The system memory address to map to the DMA controller.\r
38 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r
3402aac7 39 that were mapped.\r
aaeef063 40 @param DeviceAddress The resulting map address for the bus master controller to use to\r
3402aac7 41 access the hosts HostAddress.\r
aaeef063 42 @param Mapping A resulting value to pass to Unmap().\r
3402aac7 43\r
aaeef063 44 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
3402aac7 45 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
aaeef063 46 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
47 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
48 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
3402aac7 49\r
aaeef063 50**/\r
51EFI_STATUS\r
52EFIAPI\r
53DmaMap (\r
54 IN DMA_MAP_OPERATION Operation,\r
55 IN VOID *HostAddress,\r
56 IN OUT UINTN *NumberOfBytes,\r
57 OUT PHYSICAL_ADDRESS *DeviceAddress,\r
58 OUT VOID **Mapping\r
59 )\r
60{\r
0bcb8010 61 *DeviceAddress = HostToDeviceAddress (HostAddress);\r
6be6c2e0 62 *Mapping = NULL;\r
aaeef063 63 return EFI_SUCCESS;\r
64}\r
65\r
66\r
3402aac7 67/**\r
aaeef063 68 Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r
69 operation and releases any corresponding resources.\r
3402aac7 70\r
aaeef063 71 @param Mapping The mapping value returned from DmaMap*().\r
3402aac7 72\r
aaeef063 73 @retval EFI_SUCCESS The range was unmapped.\r
74 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
3402aac7 75\r
aaeef063 76**/\r
77EFI_STATUS\r
78EFIAPI\r
79DmaUnmap (\r
80 IN VOID *Mapping\r
81 )\r
82{\r
83 return EFI_SUCCESS;\r
84}\r
85\r
3402aac7 86/**\r
aaeef063 87 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
3402aac7
RC
88 mapping.\r
89\r
aaeef063 90 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
3402aac7
RC
91 EfiRuntimeServicesData.\r
92 @param Pages The number of pages to allocate.\r
aaeef063 93 @param HostAddress A pointer to store the base system memory address of the\r
3402aac7 94 allocated range.\r
aaeef063 95\r
96 @retval EFI_SUCCESS The requested memory pages were allocated.\r
97 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
3402aac7 98 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
aaeef063 99 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
3402aac7
RC
100 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
101\r
aaeef063 102**/\r
103EFI_STATUS\r
104EFIAPI\r
105DmaAllocateBuffer (\r
106 IN EFI_MEMORY_TYPE MemoryType,\r
107 IN UINTN Pages,\r
108 OUT VOID **HostAddress\r
109 )\r
110{\r
deef290f
AB
111 return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);\r
112}\r
113\r
114\r
115/**\r
116 Allocates pages that are suitable for an DmaMap() of type\r
117 MapOperationBusMasterCommonBuffer mapping, at the requested alignment.\r
118\r
119 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
120 EfiRuntimeServicesData.\r
121 @param Pages The number of pages to allocate.\r
122 @param Alignment Alignment in bytes of the base of the returned\r
123 buffer (must be a power of 2)\r
124 @param HostAddress A pointer to store the base system memory address of the\r
125 allocated range.\r
126\r
127 @retval EFI_SUCCESS The requested memory pages were allocated.\r
128 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
129 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
130 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
131 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
132\r
133**/\r
134EFI_STATUS\r
135EFIAPI\r
136DmaAllocateAlignedBuffer (\r
137 IN EFI_MEMORY_TYPE MemoryType,\r
138 IN UINTN Pages,\r
139 IN UINTN Alignment,\r
140 OUT VOID **HostAddress\r
141 )\r
142{\r
143 if (Alignment == 0) {\r
144 Alignment = EFI_PAGE_SIZE;\r
145 }\r
146\r
147 if (HostAddress == NULL ||\r
148 (Alignment & (Alignment - 1)) != 0) {\r
aaeef063 149 return EFI_INVALID_PARAMETER;\r
150 }\r
151\r
152 //\r
153 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
154 //\r
aaeef063 155 if (MemoryType == EfiBootServicesData) {\r
deef290f 156 *HostAddress = AllocateAlignedPages (Pages, Alignment);\r
c783da65 157 } else if (MemoryType == EfiRuntimeServicesData) {\r
deef290f 158 *HostAddress = AllocateAlignedRuntimePages (Pages, Alignment);\r
aaeef063 159 } else {\r
160 return EFI_INVALID_PARAMETER;\r
161 }\r
162\r
deef290f
AB
163 if (*HostAddress == NULL) {\r
164 return EFI_OUT_OF_RESOURCES;\r
165 }\r
aaeef063 166 return EFI_SUCCESS;\r
167}\r
168\r
169\r
3402aac7 170/**\r
aaeef063 171 Frees memory that was allocated with DmaAllocateBuffer().\r
3402aac7
RC
172\r
173 @param Pages The number of pages to free.\r
174 @param HostAddress The base system memory address of the allocated range.\r
175\r
aaeef063 176 @retval EFI_SUCCESS The requested memory pages were freed.\r
177 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
178 was not allocated with DmaAllocateBuffer().\r
3402aac7 179\r
aaeef063 180**/\r
181EFI_STATUS\r
182EFIAPI\r
183DmaFreeBuffer (\r
184 IN UINTN Pages,\r
185 IN VOID *HostAddress\r
186 )\r
187{\r
188 if (HostAddress == NULL) {\r
189 return EFI_INVALID_PARAMETER;\r
3402aac7
RC
190 }\r
191\r
aaeef063 192 FreePages (HostAddress, Pages);\r
193 return EFI_SUCCESS;\r
194}\r
195\r