]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c
EmbeddedPkg/EmbeddedPkg.dsc: fix build for non-ARM architectures
[mirror_edk2.git] / EmbeddedPkg / Library / NullDmaLib / NullDmaLib.c
1 /** @file
2 Generic ARM implementation of DmaLib.h
3
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
5
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
10
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.
13
14 **/
15
16 #include <Uefi.h>
17 #include <Library/DebugLib.h>
18 #include <Library/DmaLib.h>
19 #include <Library/MemoryAllocationLib.h>
20
21
22
23 /**
24 Provides the DMA controller-specific addresses needed to access system memory.
25
26 Operation is relative to the DMA bus master.
27
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
31 that were mapped.
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().
35
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.
41
42 **/
43 EFI_STATUS
44 EFIAPI
45 DmaMap (
46 IN DMA_MAP_OPERATION Operation,
47 IN VOID *HostAddress,
48 IN OUT UINTN *NumberOfBytes,
49 OUT PHYSICAL_ADDRESS *DeviceAddress,
50 OUT VOID **Mapping
51 )
52 {
53 *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress;
54 *Mapping = NULL;
55 return EFI_SUCCESS;
56 }
57
58
59 /**
60 Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()
61 operation and releases any corresponding resources.
62
63 @param Mapping The mapping value returned from DmaMap*().
64
65 @retval EFI_SUCCESS The range was unmapped.
66 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
67
68 **/
69 EFI_STATUS
70 EFIAPI
71 DmaUnmap (
72 IN VOID *Mapping
73 )
74 {
75 return EFI_SUCCESS;
76 }
77
78 /**
79 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
80 mapping.
81
82 @param MemoryType The type of memory to allocate, EfiBootServicesData or
83 EfiRuntimeServicesData.
84 @param Pages The number of pages to allocate.
85 @param HostAddress A pointer to store the base system memory address of the
86 allocated range.
87
88 @retval EFI_SUCCESS The requested memory pages were allocated.
89 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
90 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
91 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
92 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
93
94 **/
95 EFI_STATUS
96 EFIAPI
97 DmaAllocateBuffer (
98 IN EFI_MEMORY_TYPE MemoryType,
99 IN UINTN Pages,
100 OUT VOID **HostAddress
101 )
102 {
103 return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);
104 }
105
106
107 /**
108 Allocates pages that are suitable for an DmaMap() of type
109 MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
110
111 @param MemoryType The type of memory to allocate, EfiBootServicesData or
112 EfiRuntimeServicesData.
113 @param Pages The number of pages to allocate.
114 @param Alignment Alignment in bytes of the base of the returned
115 buffer (must be a power of 2)
116 @param HostAddress A pointer to store the base system memory address of the
117 allocated range.
118
119 @retval EFI_SUCCESS The requested memory pages were allocated.
120 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
121 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
122 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
123 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
124
125 **/
126 EFI_STATUS
127 EFIAPI
128 DmaAllocateAlignedBuffer (
129 IN EFI_MEMORY_TYPE MemoryType,
130 IN UINTN Pages,
131 IN UINTN Alignment,
132 OUT VOID **HostAddress
133 )
134 {
135 if (Alignment == 0) {
136 Alignment = EFI_PAGE_SIZE;
137 }
138
139 if (HostAddress == NULL ||
140 (Alignment & (Alignment - 1)) != 0) {
141 return EFI_INVALID_PARAMETER;
142 }
143
144 //
145 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData
146 //
147 if (MemoryType == EfiBootServicesData) {
148 *HostAddress = AllocateAlignedPages (Pages, Alignment);
149 } else if (MemoryType != EfiRuntimeServicesData) {
150 *HostAddress = AllocateAlignedRuntimePages (Pages, Alignment);
151 } else {
152 return EFI_INVALID_PARAMETER;
153 }
154
155 if (*HostAddress == NULL) {
156 return EFI_OUT_OF_RESOURCES;
157 }
158 return EFI_SUCCESS;
159 }
160
161
162 /**
163 Frees memory that was allocated with DmaAllocateBuffer().
164
165 @param Pages The number of pages to free.
166 @param HostAddress The base system memory address of the allocated range.
167
168 @retval EFI_SUCCESS The requested memory pages were freed.
169 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
170 was not allocated with DmaAllocateBuffer().
171
172 **/
173 EFI_STATUS
174 EFIAPI
175 DmaFreeBuffer (
176 IN UINTN Pages,
177 IN VOID *HostAddress
178 )
179 {
180 if (HostAddress == NULL) {
181 return EFI_INVALID_PARAMETER;
182 }
183
184 FreePages (HostAddress, Pages);
185 return EFI_SUCCESS;
186 }
187