]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c
EmbeddedPkg: Rectify file modes
[mirror_edk2.git] / EmbeddedPkg / Library / NullDmaLib / NullDmaLib.c
CommitLineData
aaeef063 1/** @file\r
2 Generic ARM implementation of DmaLib.h\r
3\r
4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
3402aac7 5\r
aaeef063 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Uefi.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/DmaLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20\r
21\r
22\r
3402aac7 23/**\r
aaeef063 24 Provides the DMA controller-specific addresses needed to access system memory.\r
3402aac7 25\r
aaeef063 26 Operation is relative to the DMA bus master.\r
3402aac7 27\r
aaeef063 28 @param Operation Indicates if the bus master is going to read or write to system memory.\r
29 @param HostAddress The system memory address to map to the DMA controller.\r
30 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r
3402aac7 31 that were mapped.\r
aaeef063 32 @param DeviceAddress The resulting map address for the bus master controller to use to\r
3402aac7 33 access the hosts HostAddress.\r
aaeef063 34 @param Mapping A resulting value to pass to Unmap().\r
3402aac7 35\r
aaeef063 36 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
3402aac7 37 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
aaeef063 38 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
40 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
3402aac7 41\r
aaeef063 42**/\r
43EFI_STATUS\r
44EFIAPI\r
45DmaMap (\r
46 IN DMA_MAP_OPERATION Operation,\r
47 IN VOID *HostAddress,\r
48 IN OUT UINTN *NumberOfBytes,\r
49 OUT PHYSICAL_ADDRESS *DeviceAddress,\r
50 OUT VOID **Mapping\r
51 )\r
52{\r
6be6c2e0 53 *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress;\r
54 *Mapping = NULL;\r
aaeef063 55 return EFI_SUCCESS;\r
56}\r
57\r
58\r
3402aac7 59/**\r
aaeef063 60 Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r
61 operation and releases any corresponding resources.\r
3402aac7 62\r
aaeef063 63 @param Mapping The mapping value returned from DmaMap*().\r
3402aac7 64\r
aaeef063 65 @retval EFI_SUCCESS The range was unmapped.\r
66 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
3402aac7 67\r
aaeef063 68**/\r
69EFI_STATUS\r
70EFIAPI\r
71DmaUnmap (\r
72 IN VOID *Mapping\r
73 )\r
74{\r
75 return EFI_SUCCESS;\r
76}\r
77\r
3402aac7 78/**\r
aaeef063 79 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
3402aac7
RC
80 mapping.\r
81\r
aaeef063 82 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
3402aac7
RC
83 EfiRuntimeServicesData.\r
84 @param Pages The number of pages to allocate.\r
aaeef063 85 @param HostAddress A pointer to store the base system memory address of the\r
3402aac7 86 allocated range.\r
aaeef063 87\r
88 @retval EFI_SUCCESS The requested memory pages were allocated.\r
89 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
3402aac7 90 MEMORY_WRITE_COMBINE and MEMORY_CACHED.\r
aaeef063 91 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
3402aac7
RC
92 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
93\r
aaeef063 94**/\r
95EFI_STATUS\r
96EFIAPI\r
97DmaAllocateBuffer (\r
98 IN EFI_MEMORY_TYPE MemoryType,\r
99 IN UINTN Pages,\r
100 OUT VOID **HostAddress\r
101 )\r
102{\r
103 if (HostAddress == NULL) {\r
104 return EFI_INVALID_PARAMETER;\r
105 }\r
106\r
107 //\r
108 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
109 //\r
110 // We used uncached memory to keep coherency\r
111 //\r
112 if (MemoryType == EfiBootServicesData) {\r
113 *HostAddress = AllocatePages (Pages);\r
114 } else if (MemoryType != EfiRuntimeServicesData) {\r
115 *HostAddress = AllocateRuntimePages (Pages);\r
116 } else {\r
117 return EFI_INVALID_PARAMETER;\r
118 }\r
119\r
120 return EFI_SUCCESS;\r
121}\r
122\r
123\r
3402aac7 124/**\r
aaeef063 125 Frees memory that was allocated with DmaAllocateBuffer().\r
3402aac7
RC
126\r
127 @param Pages The number of pages to free.\r
128 @param HostAddress The base system memory address of the allocated range.\r
129\r
aaeef063 130 @retval EFI_SUCCESS The requested memory pages were freed.\r
131 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
132 was not allocated with DmaAllocateBuffer().\r
3402aac7 133\r
aaeef063 134**/\r
135EFI_STATUS\r
136EFIAPI\r
137DmaFreeBuffer (\r
138 IN UINTN Pages,\r
139 IN VOID *HostAddress\r
140 )\r
141{\r
142 if (HostAddress == NULL) {\r
143 return EFI_INVALID_PARAMETER;\r
3402aac7
RC
144 }\r
145\r
aaeef063 146 FreePages (HostAddress, Pages);\r
147 return EFI_SUCCESS;\r
148}\r
149\r