]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c
Add a DMA lib that works like PCI_IO protocl. Add a NULL version that would work...
[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
5 \r
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
23/** \r
24 Provides the DMA controller-specific addresses needed to access system memory.\r
25 \r
26 Operation is relative to the DMA bus master.\r
27 \r
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
31 that were mapped. \r
32 @param DeviceAddress The resulting map address for the bus master controller to use to\r
33 access the hosts HostAddress. \r
34 @param Mapping A resulting value to pass to Unmap().\r
35 \r
36 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
37 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. \r
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
41 \r
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
53 return EFI_SUCCESS;\r
54}\r
55\r
56\r
57/** \r
58 Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r
59 operation and releases any corresponding resources.\r
60 \r
61 @param Mapping The mapping value returned from DmaMap*().\r
62 \r
63 @retval EFI_SUCCESS The range was unmapped.\r
64 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
65 \r
66**/\r
67EFI_STATUS\r
68EFIAPI\r
69DmaUnmap (\r
70 IN VOID *Mapping\r
71 )\r
72{\r
73 return EFI_SUCCESS;\r
74}\r
75\r
76/** \r
77 Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r
78 mapping. \r
79 \r
80 @param MemoryType The type of memory to allocate, EfiBootServicesData or\r
81 EfiRuntimeServicesData. \r
82 @param Pages The number of pages to allocate. \r
83 @param HostAddress A pointer to store the base system memory address of the\r
84 allocated range. \r
85\r
86 @retval EFI_SUCCESS The requested memory pages were allocated.\r
87 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
88 MEMORY_WRITE_COMBINE and MEMORY_CACHED. \r
89 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r
90 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. \r
91 \r
92**/\r
93EFI_STATUS\r
94EFIAPI\r
95DmaAllocateBuffer (\r
96 IN EFI_MEMORY_TYPE MemoryType,\r
97 IN UINTN Pages,\r
98 OUT VOID **HostAddress\r
99 )\r
100{\r
101 if (HostAddress == NULL) {\r
102 return EFI_INVALID_PARAMETER;\r
103 }\r
104\r
105 //\r
106 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
107 //\r
108 // We used uncached memory to keep coherency\r
109 //\r
110 if (MemoryType == EfiBootServicesData) {\r
111 *HostAddress = AllocatePages (Pages);\r
112 } else if (MemoryType != EfiRuntimeServicesData) {\r
113 *HostAddress = AllocateRuntimePages (Pages);\r
114 } else {\r
115 return EFI_INVALID_PARAMETER;\r
116 }\r
117\r
118 return EFI_SUCCESS;\r
119}\r
120\r
121\r
122/** \r
123 Frees memory that was allocated with DmaAllocateBuffer().\r
124 \r
125 @param Pages The number of pages to free. \r
126 @param HostAddress The base system memory address of the allocated range. \r
127 \r
128 @retval EFI_SUCCESS The requested memory pages were freed.\r
129 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
130 was not allocated with DmaAllocateBuffer().\r
131 \r
132**/\r
133EFI_STATUS\r
134EFIAPI\r
135DmaFreeBuffer (\r
136 IN UINTN Pages,\r
137 IN VOID *HostAddress\r
138 )\r
139{\r
140 if (HostAddress == NULL) {\r
141 return EFI_INVALID_PARAMETER;\r
142 } \r
143 \r
144 FreePages (HostAddress, Pages);\r
145 return EFI_SUCCESS;\r
146}\r
147\r