]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Include/Library/DmaLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / Include / Library / DmaLib.h
CommitLineData
1e57a462 1/** @file\r
2 DMA abstraction library APIs. Based on UEFI PCI IO protocol DMA abstractions.\r
3402aac7 3 At some point these functions will probably end up in a non PCI protocol\r
1e57a462 4 for embedded systems.\r
5\r
aaeef063 6 DMA Bus Master Read Operation:\r
3402aac7
RC
7 Call DmaMap() for MapOperationBusMasterRead.\r
8 Program the DMA Bus Master with the DeviceAddress returned by DmaMap().\r
9 Start the DMA Bus Master.\r
10 Wait for DMA Bus Master to complete the read operation.\r
1e57a462 11 Call DmaUnmap().\r
12\r
13 DMA Bus Master Write Operation:\r
aaeef063 14 Call DmaMap() for MapOperationBusMasterWrite.\r
15 Program the DMA Bus Master with the DeviceAddress returned by DmaMap().\r
16 Start the DMA Bus Master.\r
17 Wait for DMA Bus Master to complete the write operation.\r
1e57a462 18 Call DmaUnmap().\r
19\r
20 DMA Bus Master Common Buffer Operation:\r
3402aac7
RC
21 Call DmaAllocateBuffer() to allocate a common buffer.\r
22 Call DmaMap() for MapOperationBusMasterCommonBuffer.\r
23 Program the DMA Bus Master with the DeviceAddress returned by DmaMap().\r
24 The common buffer can now be accessed equally by the processor and the DMA bus master.\r
25 Call DmaUnmap().\r
1e57a462 26 Call DmaFreeBuffer().\r
27\r
28 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
29\r
878b807a 30 SPDX-License-Identifier: BSD-2-Clause-Patent\r
1e57a462 31\r
32**/\r
33\r
34#ifndef __DMA_LIB_H__\r
35#define __DMA_LIB_H__\r
36\r
aaeef063 37typedef enum {\r
38 ///\r
39 /// A read operation from system memory by a bus master.\r
40 ///\r
41 MapOperationBusMasterRead,\r
42 ///\r
43 /// A write operation from system memory by a bus master.\r
44 ///\r
45 MapOperationBusMasterWrite,\r
46 ///\r
47 /// Provides both read and write access to system memory by both the processor and a\r
48 /// bus master. The buffer is coherent from both the processor's and the bus master's point of view.\r
49 ///\r
50 MapOperationBusMasterCommonBuffer,\r
51 MapOperationMaximum\r
52} DMA_MAP_OPERATION;\r
1e57a462 53\r
3402aac7 54/**\r
aaeef063 55 Provides the DMA controller-specific addresses needed to access system memory.\r
3402aac7 56\r
aaeef063 57 Operation is relative to the DMA bus master.\r
3402aac7 58\r
aaeef063 59 @param Operation Indicates if the bus master is going to read or write to system memory.\r
60 @param HostAddress The system memory address to map to the DMA controller.\r
61 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r
3402aac7 62 that were mapped.\r
aaeef063 63 @param DeviceAddress The resulting map address for the bus master controller to use to\r
3402aac7 64 access the hosts HostAddress.\r
aaeef063 65 @param Mapping A resulting value to pass to DmaUnmap().\r
3402aac7 66\r
aaeef063 67 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
3402aac7 68 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
aaeef063 69 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
70 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
71 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
3402aac7 72\r
1e57a462 73**/\r
74EFI_STATUS\r
75EFIAPI\r
76DmaMap (\r
e7108d0e
MK
77 IN DMA_MAP_OPERATION Operation,\r
78 IN VOID *HostAddress,\r
79 IN OUT UINTN *NumberOfBytes,\r
80 OUT PHYSICAL_ADDRESS *DeviceAddress,\r
81 OUT VOID **Mapping\r
1e57a462 82 );\r
83\r
3402aac7 84/**\r
aaeef063 85 Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer\r
86 operation and releases any corresponding resources.\r
3402aac7 87\r
aaeef063 88 @param Mapping The mapping value returned from DmaMap().\r
3402aac7 89\r
aaeef063 90 @retval EFI_SUCCESS The range was unmapped.\r
91 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
3402aac7 92\r
1e57a462 93**/\r
94EFI_STATUS\r
95EFIAPI\r
96DmaUnmap (\r
e7108d0e 97 IN VOID *Mapping\r
1e57a462 98 );\r
99\r
3402aac7 100/**\r
aaeef063 101 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
3402aac7
RC
102 mapping.\r
103\r
aaeef063 104 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
3402aac7
RC
105 EfiRuntimeServicesData.\r
106 @param Pages The number of pages to allocate.\r
aaeef063 107 @param HostAddress A pointer to store the base system memory address of the\r
3402aac7 108 allocated range.\r
aaeef063 109\r
110 @retval EFI_SUCCESS The requested memory pages were allocated.\r
111 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
3402aac7 112 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
aaeef063 113 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
3402aac7
RC
114 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
115\r
1e57a462 116**/\r
117EFI_STATUS\r
118EFIAPI\r
119DmaAllocateBuffer (\r
e7108d0e
MK
120 IN EFI_MEMORY_TYPE MemoryType,\r
121 IN UINTN Pages,\r
122 OUT VOID **HostAddress\r
aaeef063 123 );\r
1e57a462 124\r
3402aac7 125/**\r
aaeef063 126 Frees memory that was allocated with DmaAllocateBuffer().\r
3402aac7
RC
127\r
128 @param Pages The number of pages to free.\r
129 @param HostAddress The base system memory address of the allocated range.\r
130\r
aaeef063 131 @retval EFI_SUCCESS The requested memory pages were freed.\r
132 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
133 was not allocated with DmaAllocateBuffer().\r
3402aac7 134\r
aaeef063 135**/\r
1e57a462 136EFI_STATUS\r
137EFIAPI\r
138DmaFreeBuffer (\r
e7108d0e
MK
139 IN UINTN Pages,\r
140 IN VOID *HostAddress\r
aaeef063 141 );\r
1e57a462 142\r
deef290f
AB
143/**\r
144 Allocates pages that are suitable for an DmaMap() of type\r
145 MapOperationBusMasterCommonBuffer mapping, at the requested alignment.\r
146\r
147 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
148 EfiRuntimeServicesData.\r
149 @param Pages The number of pages to allocate.\r
150 @param Alignment Alignment in bytes of the base of the returned\r
151 buffer (must be a power of 2)\r
152 @param HostAddress A pointer to store the base system memory address of the\r
153 allocated range.\r
1e57a462 154\r
deef290f
AB
155 @retval EFI_SUCCESS The requested memory pages were allocated.\r
156 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
157 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
158 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
159 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
160\r
161**/\r
162EFI_STATUS\r
163EFIAPI\r
164DmaAllocateAlignedBuffer (\r
e7108d0e
MK
165 IN EFI_MEMORY_TYPE MemoryType,\r
166 IN UINTN Pages,\r
167 IN UINTN Alignment,\r
168 OUT VOID **HostAddress\r
deef290f
AB
169 );\r
170\r
deef290f 171#endif\r