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>
24 Provides the DMA controller-specific addresses needed to access system memory.
26 Operation is relative to the DMA bus master.
28 @param Operation Indicates if the bus master is going to read or write to system memory.
29 @param HostAddress The system memory address to map to the DMA controller.
30 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
32 @param DeviceAddress The resulting map address for the bus master controller to use to
33 access the hosts HostAddress.
34 @param Mapping A resulting value to pass to Unmap().
36 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
37 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
38 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
40 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
46 IN DMA_MAP_OPERATION Operation
,
48 IN OUT UINTN
*NumberOfBytes
,
49 OUT PHYSICAL_ADDRESS
*DeviceAddress
,
58 Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()
59 operation and releases any corresponding resources.
61 @param Mapping The mapping value returned from DmaMap*().
63 @retval EFI_SUCCESS The range was unmapped.
64 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
77 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
80 @param MemoryType The type of memory to allocate, EfiBootServicesData or
81 EfiRuntimeServicesData.
82 @param Pages The number of pages to allocate.
83 @param HostAddress A pointer to store the base system memory address of the
86 @retval EFI_SUCCESS The requested memory pages were allocated.
87 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
88 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
89 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
90 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
96 IN EFI_MEMORY_TYPE MemoryType
,
98 OUT VOID
**HostAddress
101 if (HostAddress
== NULL
) {
102 return EFI_INVALID_PARAMETER
;
106 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData
108 // We used uncached memory to keep coherency
110 if (MemoryType
== EfiBootServicesData
) {
111 *HostAddress
= AllocatePages (Pages
);
112 } else if (MemoryType
!= EfiRuntimeServicesData
) {
113 *HostAddress
= AllocateRuntimePages (Pages
);
115 return EFI_INVALID_PARAMETER
;
123 Frees memory that was allocated with DmaAllocateBuffer().
125 @param Pages The number of pages to free.
126 @param HostAddress The base system memory address of the allocated range.
128 @retval EFI_SUCCESS The requested memory pages were freed.
129 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
130 was not allocated with DmaAllocateBuffer().
140 if (HostAddress
== NULL
) {
141 return EFI_INVALID_PARAMETER
;
144 FreePages (HostAddress
, Pages
);