TianoCore EDK2 master
Loading...
Searching...
No Matches
CoherentDmaLib.c
Go to the documentation of this file.
1
10#include <Uefi.h>
11#include <Library/DebugLib.h>
12#include <Library/DmaLib.h>
14
16PHYSICAL_ADDRESS
17HostToDeviceAddress (
18 IN VOID *Address
19 )
20{
21 return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset);
22}
23
45EFIAPI
47 IN DMA_MAP_OPERATION Operation,
48 IN VOID *HostAddress,
49 IN OUT UINTN *NumberOfBytes,
50 OUT PHYSICAL_ADDRESS *DeviceAddress,
51 OUT VOID **Mapping
52 )
53{
54 if ((HostAddress == NULL) ||
55 (NumberOfBytes == NULL) ||
56 (DeviceAddress == NULL) ||
57 (Mapping == NULL))
58 {
59 return EFI_INVALID_PARAMETER;
60 }
61
62 *DeviceAddress = HostToDeviceAddress (HostAddress);
63 *Mapping = NULL;
64 return EFI_SUCCESS;
65}
66
78EFIAPI
80 IN VOID *Mapping
81 )
82{
83 return EFI_SUCCESS;
84}
85
104EFIAPI
106 IN EFI_MEMORY_TYPE MemoryType,
107 IN UINTN Pages,
108 OUT VOID **HostAddress
109 )
110{
111 return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);
112}
113
134EFIAPI
136 IN EFI_MEMORY_TYPE MemoryType,
137 IN UINTN Pages,
138 IN UINTN Alignment,
139 OUT VOID **HostAddress
140 )
141{
142 if (Alignment == 0) {
143 Alignment = EFI_PAGE_SIZE;
144 }
145
146 if ((HostAddress == NULL) ||
147 ((Alignment & (Alignment - 1)) != 0))
148 {
149 return EFI_INVALID_PARAMETER;
150 }
151
152 //
153 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData
154 //
155 if (MemoryType == EfiBootServicesData) {
156 *HostAddress = AllocateAlignedPages (Pages, Alignment);
157 } else if (MemoryType == EfiRuntimeServicesData) {
158 *HostAddress = AllocateAlignedRuntimePages (Pages, Alignment);
159 } else {
160 return EFI_INVALID_PARAMETER;
161 }
162
163 if (*HostAddress == NULL) {
164 return EFI_OUT_OF_RESOURCES;
165 }
166
167 return EFI_SUCCESS;
168}
169
182EFIAPI
184 IN UINTN Pages,
185 IN VOID *HostAddress
186 )
187{
188 if (HostAddress == NULL) {
189 return EFI_INVALID_PARAMETER;
190 }
191
192 FreePages (HostAddress, Pages);
193 return EFI_SUCCESS;
194}
UINT64 UINTN
EFI_STATUS EFIAPI DmaAllocateAlignedBuffer(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, IN UINTN Alignment, OUT VOID **HostAddress)
EFI_STATUS EFIAPI DmaUnmap(IN VOID *Mapping)
EFI_STATUS EFIAPI DmaMap(IN DMA_MAP_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
EFI_STATUS EFIAPI DmaAllocateBuffer(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, OUT VOID **HostAddress)
EFI_STATUS EFIAPI DmaFreeBuffer(IN UINTN Pages, IN VOID *HostAddress)
DMA_MAP_OPERATION
Definition: DmaLib.h:37
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
VOID *EFIAPI AllocateAlignedRuntimePages(IN UINTN Pages, IN UINTN Alignment)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
VOID *EFIAPI AllocateAlignedPages(IN UINTN Pages, IN UINTN Alignment)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_MEMORY_TYPE
@ EfiBootServicesData
@ EfiRuntimeServicesData