2 Generic ARM implementation of DmaLib.h
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
18 #include <Library/DmaLib.h>
19 #include <Library/MemoryAllocationLib.h>
28 return (PHYSICAL_ADDRESS
)(UINTN
)Address
+ PcdGet64 (PcdDmaDeviceOffset
);
32 Provides the DMA controller-specific addresses needed to access system memory.
34 Operation is relative to the DMA bus master.
36 @param Operation Indicates if the bus master is going to read or write to system memory.
37 @param HostAddress The system memory address to map to the DMA controller.
38 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
40 @param DeviceAddress The resulting map address for the bus master controller to use to
41 access the hosts HostAddress.
42 @param Mapping A resulting value to pass to Unmap().
44 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
45 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
46 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
47 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
48 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
54 IN DMA_MAP_OPERATION Operation
,
56 IN OUT UINTN
*NumberOfBytes
,
57 OUT PHYSICAL_ADDRESS
*DeviceAddress
,
61 *DeviceAddress
= HostToDeviceAddress (HostAddress
);
68 Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()
69 operation and releases any corresponding resources.
71 @param Mapping The mapping value returned from DmaMap*().
73 @retval EFI_SUCCESS The range was unmapped.
74 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
87 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
90 @param MemoryType The type of memory to allocate, EfiBootServicesData or
91 EfiRuntimeServicesData.
92 @param Pages The number of pages to allocate.
93 @param HostAddress A pointer to store the base system memory address of the
96 @retval EFI_SUCCESS The requested memory pages were allocated.
97 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
98 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
99 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
100 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
106 IN EFI_MEMORY_TYPE MemoryType
,
108 OUT VOID
**HostAddress
111 return DmaAllocateAlignedBuffer (MemoryType
, Pages
, 0, HostAddress
);
116 Allocates pages that are suitable for an DmaMap() of type
117 MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
119 @param MemoryType The type of memory to allocate, EfiBootServicesData or
120 EfiRuntimeServicesData.
121 @param Pages The number of pages to allocate.
122 @param Alignment Alignment in bytes of the base of the returned
123 buffer (must be a power of 2)
124 @param HostAddress A pointer to store the base system memory address of the
127 @retval EFI_SUCCESS The requested memory pages were allocated.
128 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
129 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
130 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
131 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
136 DmaAllocateAlignedBuffer (
137 IN EFI_MEMORY_TYPE MemoryType
,
140 OUT VOID
**HostAddress
143 if (Alignment
== 0) {
144 Alignment
= EFI_PAGE_SIZE
;
147 if (HostAddress
== NULL
||
148 (Alignment
& (Alignment
- 1)) != 0) {
149 return EFI_INVALID_PARAMETER
;
153 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData
155 if (MemoryType
== EfiBootServicesData
) {
156 *HostAddress
= AllocateAlignedPages (Pages
, Alignment
);
157 } else if (MemoryType
!= EfiRuntimeServicesData
) {
158 *HostAddress
= AllocateAlignedRuntimePages (Pages
, Alignment
);
160 return EFI_INVALID_PARAMETER
;
163 if (*HostAddress
== NULL
) {
164 return EFI_OUT_OF_RESOURCES
;
171 Frees memory that was allocated with DmaAllocateBuffer().
173 @param Pages The number of pages to free.
174 @param HostAddress The base system memory address of the allocated range.
176 @retval EFI_SUCCESS The requested memory pages were freed.
177 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
178 was not allocated with DmaAllocateBuffer().
188 if (HostAddress
== NULL
) {
189 return EFI_INVALID_PARAMETER
;
192 FreePages (HostAddress
, Pages
);