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