]>
Commit | Line | Data |
---|---|---|
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 | |
43 | EFI_STATUS\r | |
44 | EFIAPI\r | |
45 | DmaMap (\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 | |
59 | /** \r | |
60 | Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()\r | |
61 | operation and releases any corresponding resources.\r | |
62 | \r | |
63 | @param Mapping The mapping value returned from DmaMap*().\r | |
64 | \r | |
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 | |
67 | \r | |
68 | **/\r | |
69 | EFI_STATUS\r | |
70 | EFIAPI\r | |
71 | DmaUnmap (\r | |
72 | IN VOID *Mapping\r | |
73 | )\r | |
74 | {\r | |
75 | return EFI_SUCCESS;\r | |
76 | }\r | |
77 | \r | |
78 | /** \r | |
79 | Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.\r | |
80 | mapping. \r | |
81 | \r | |
82 | @param MemoryType The type of memory to allocate, EfiBootServicesData or\r | |
83 | EfiRuntimeServicesData. \r | |
84 | @param Pages The number of pages to allocate. \r | |
85 | @param HostAddress A pointer to store the base system memory address of the\r | |
86 | allocated range. \r | |
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 | |
90 | MEMORY_WRITE_COMBINE and MEMORY_CACHED. \r | |
91 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
92 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. \r | |
93 | \r | |
94 | **/\r | |
95 | EFI_STATUS\r | |
96 | EFIAPI\r | |
97 | DmaAllocateBuffer (\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 | |
124 | /** \r | |
125 | Frees memory that was allocated with DmaAllocateBuffer().\r | |
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 | |
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 | |
133 | \r | |
134 | **/\r | |
135 | EFI_STATUS\r | |
136 | EFIAPI\r | |
137 | DmaFreeBuffer (\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 | |
144 | } \r | |
145 | \r | |
146 | FreePages (HostAddress, Pages);\r | |
147 | return EFI_SUCCESS;\r | |
148 | }\r | |
149 | \r |