Commit | Line | Data |
---|---|---|
2ef2b01e | 1 | /** @file\r |
a7463b30 | 2 | UncachedMemoryAllocation lib that uses DXE Service to change cachability for\r |
883b666e | 3 | a buffer.\r |
2ef2b01e | 4 | \r |
d6ebcab7 | 5 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r |
1a70a690 | 6 | Copyright (c) 2014, AMR Ltd. All rights reserved.<BR>\r |
3402aac7 | 7 | \r |
d6ebcab7 | 8 | This program and the accompanying materials\r |
2ef2b01e A |
9 | are licensed and made available under the terms and conditions of the BSD License\r |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
44c01161 | 18 | #include <Base.h>\r |
883b666e | 19 | #include <Library/BaseLib.h>\r |
2ef2b01e | 20 | #include <Library/BaseMemoryLib.h>\r |
883b666e | 21 | #include <Library/MemoryAllocationLib.h>\r |
2ef2b01e A |
22 | #include <Library/DebugLib.h>\r |
23 | #include <Library/UefiBootServicesTableLib.h>\r | |
24 | #include <Library/UncachedMemoryAllocationLib.h>\r | |
25 | #include <Library/PcdLib.h>\r | |
26 | #include <Library/ArmLib.h>\r | |
883b666e | 27 | #include <Library/DxeServicesTableLib.h>\r |
28 | \r | |
883b666e | 29 | VOID *\r |
30 | UncachedInternalAllocatePages (\r | |
3402aac7 | 31 | IN EFI_MEMORY_TYPE MemoryType,\r |
883b666e | 32 | IN UINTN Pages\r |
33 | );\r | |
34 | \r | |
35 | VOID *\r | |
36 | UncachedInternalAllocateAlignedPages (\r | |
3402aac7 | 37 | IN EFI_MEMORY_TYPE MemoryType,\r |
883b666e | 38 | IN UINTN Pages,\r |
39 | IN UINTN Alignment\r | |
40 | );\r | |
3402aac7 RC |
41 | \r |
42 | \r | |
2ef2b01e | 43 | \r |
883b666e | 44 | //\r |
45 | // Assume all of memory has the same cache attributes, unless we do our magic\r | |
46 | //\r | |
47 | UINT64 gAttributes;\r | |
48 | \r | |
49 | typedef struct {\r | |
1a70a690 OM |
50 | EFI_PHYSICAL_ADDRESS Base;\r |
51 | VOID *Allocation;\r | |
52 | UINTN Pages;\r | |
53 | EFI_MEMORY_TYPE MemoryType;\r | |
54 | BOOLEAN Allocated;\r | |
55 | LIST_ENTRY Link;\r | |
883b666e | 56 | } FREE_PAGE_NODE;\r |
57 | \r | |
1a70a690 OM |
58 | STATIC LIST_ENTRY mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);\r |
59 | // Track the size of the non-allocated buffer in the linked-list\r | |
60 | STATIC UINTN mFreedBufferSize = 0;\r | |
883b666e | 61 | \r |
1a70a690 OM |
62 | /**\r |
63 | * This function firstly checks if the requested allocation can fit into one\r | |
64 | * of the previously allocated buffer.\r | |
65 | * If the requested allocation does not fit in the existing pool then\r | |
66 | * the function makes a new allocation.\r | |
67 | *\r | |
68 | * @param MemoryType Type of memory requested for the new allocation\r | |
69 | * @param Pages Number of requested page\r | |
70 | * @param Alignment Required alignment\r | |
71 | * @param Allocation Address of the newly allocated buffer\r | |
72 | *\r | |
73 | * @return EFI_SUCCESS If the function manage to allocate a buffer\r | |
74 | * @return !EFI_SUCCESS If the function did not manage to allocate a buffer\r | |
75 | */\r | |
76 | STATIC\r | |
77 | EFI_STATUS\r | |
78 | AllocatePagesFromList (\r | |
79 | IN EFI_MEMORY_TYPE MemoryType,\r | |
80 | IN UINTN Pages,\r | |
81 | IN UINTN Alignment,\r | |
82 | OUT VOID **Allocation\r | |
2ef2b01e A |
83 | )\r |
84 | {\r | |
1a70a690 OM |
85 | EFI_STATUS Status;\r |
86 | LIST_ENTRY *Link;\r | |
87 | FREE_PAGE_NODE *Node;\r | |
883b666e | 88 | FREE_PAGE_NODE *NewNode;\r |
1a70a690 OM |
89 | UINTN AlignmentMask;\r |
90 | EFI_PHYSICAL_ADDRESS Memory;\r | |
91 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r | |
92 | \r | |
93 | // Alignment must be a power of two or zero.\r | |
94 | ASSERT ((Alignment & (Alignment - 1)) == 0);\r | |
95 | \r | |
96 | //\r | |
97 | // Look in our list for the smallest page that could satisfy the new allocation\r | |
98 | //\r | |
99 | NewNode = NULL;\r | |
100 | for (Link = mPageList.ForwardLink; Link != &mPageList; Link = Link->ForwardLink) {\r | |
101 | Node = BASE_CR (Link, FREE_PAGE_NODE, Link);\r | |
102 | if ((Node->Allocated == FALSE) && (Node->MemoryType == MemoryType)) {\r | |
103 | // We have a node that fits our requirements\r | |
104 | if (((UINTN)Node->Base & (Alignment - 1)) == 0) {\r | |
105 | // We found a page that matches the page size\r | |
106 | if (Node->Pages == Pages) {\r | |
107 | Node->Allocated = TRUE;\r | |
108 | Node->Allocation = (VOID*)(UINTN)Node->Base;\r | |
109 | *Allocation = Node->Allocation;\r | |
110 | \r | |
111 | // Update the size of the freed buffer\r | |
112 | mFreedBufferSize -= Pages * EFI_PAGE_SIZE;\r | |
113 | return EFI_SUCCESS;\r | |
114 | } else if (Node->Pages > Pages) {\r | |
115 | if (NewNode == NULL) {\r | |
116 | // It is the first node that could contain our new allocation\r | |
117 | NewNode = Node;\r | |
118 | } else if (NewNode->Pages > Node->Pages) {\r | |
119 | // This node offers a smaller number of page.\r | |
120 | NewNode = Node;\r | |
121 | }\r | |
122 | }\r | |
123 | }\r | |
124 | }\r | |
125 | }\r | |
126 | // Check if we have found a node that could contain our new allocation\r | |
127 | if (NewNode != NULL) {\r | |
128 | NewNode->Allocated = TRUE;\r | |
129 | Node->Allocation = (VOID*)(UINTN)Node->Base;\r | |
130 | *Allocation = Node->Allocation;\r | |
131 | return EFI_SUCCESS;\r | |
132 | }\r | |
3402aac7 | 133 | \r |
1a70a690 OM |
134 | //\r |
135 | // Otherwise, we need to allocate a new buffer\r | |
136 | //\r | |
137 | \r | |
138 | // We do not want to over-allocate in case the alignment requirement does not\r | |
139 | // require extra pages\r | |
140 | if (Alignment > EFI_PAGE_SIZE) {\r | |
141 | AlignmentMask = Alignment - 1;\r | |
142 | Pages += EFI_SIZE_TO_PAGES (Alignment);\r | |
143 | } else {\r | |
144 | AlignmentMask = 0;\r | |
145 | }\r | |
146 | \r | |
147 | Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r | |
148 | if (EFI_ERROR (Status)) {\r | |
149 | return Status;\r | |
150 | }\r | |
151 | \r | |
152 | Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);\r | |
153 | if (!EFI_ERROR (Status)) {\r | |
154 | // We are making an assumption that all of memory has the same default attributes\r | |
155 | gAttributes = Descriptor.Attributes;\r | |
156 | } else {\r | |
157 | gBS->FreePages (Memory, Pages);\r | |
158 | return Status;\r | |
159 | }\r | |
160 | \r | |
161 | Status = gDS->SetMemorySpaceAttributes (Memory, EFI_PAGES_TO_SIZE (Pages), EFI_MEMORY_WC);\r | |
162 | if (EFI_ERROR (Status)) {\r | |
163 | gBS->FreePages (Memory, Pages);\r | |
164 | return Status;\r | |
165 | }\r | |
166 | \r | |
167 | NewNode = AllocatePool (sizeof (FREE_PAGE_NODE));\r | |
883b666e | 168 | if (NewNode == NULL) {\r |
169 | ASSERT (FALSE);\r | |
1a70a690 OM |
170 | gBS->FreePages (Memory, Pages);\r |
171 | return EFI_OUT_OF_RESOURCES;\r | |
883b666e | 172 | }\r |
3402aac7 | 173 | \r |
1a70a690 OM |
174 | NewNode->Base = Memory;\r |
175 | NewNode->Allocation = (VOID*)(((UINTN)Memory + AlignmentMask) & ~AlignmentMask);\r | |
883b666e | 176 | NewNode->Pages = Pages;\r |
1a70a690 OM |
177 | NewNode->Allocated = TRUE;\r |
178 | NewNode->MemoryType = MemoryType;\r | |
3402aac7 | 179 | \r |
883b666e | 180 | InsertTailList (&mPageList, &NewNode->Link);\r |
1a70a690 OM |
181 | \r |
182 | *Allocation = NewNode->Allocation;\r | |
183 | return EFI_SUCCESS;\r | |
2ef2b01e A |
184 | }\r |
185 | \r | |
1a70a690 OM |
186 | /**\r |
187 | * Free the memory allocation\r | |
188 | *\r | |
189 | * This function will actually try to find the allocation in the linked list.\r | |
190 | * And it will then mark the entry as freed.\r | |
191 | *\r | |
192 | * @param Allocation Base address of the buffer to free\r | |
193 | *\r | |
194 | * @return EFI_SUCCESS The allocation has been freed\r | |
195 | * @return EFI_NOT_FOUND The allocation was not found in the pool.\r | |
196 | * @return EFI_INVALID_PARAMETER If Allocation is NULL\r | |
197 | *\r | |
198 | */\r | |
199 | STATIC\r | |
200 | EFI_STATUS\r | |
201 | FreePagesFromList (\r | |
202 | IN VOID *Allocation\r | |
203 | )\r | |
204 | {\r | |
205 | LIST_ENTRY *Link;\r | |
206 | FREE_PAGE_NODE *Node;\r | |
207 | \r | |
208 | if (Allocation == NULL) {\r | |
209 | return EFI_INVALID_PARAMETER;\r | |
210 | }\r | |
883b666e | 211 | \r |
1a70a690 OM |
212 | for (Link = mPageList.ForwardLink; Link != &mPageList; Link = Link->ForwardLink) {\r |
213 | Node = BASE_CR (Link, FREE_PAGE_NODE, Link);\r | |
214 | if ((UINTN)Node->Allocation == (UINTN)Allocation) {\r | |
215 | Node->Allocated = FALSE;\r | |
216 | \r | |
217 | // Update the size of the freed buffer\r | |
218 | mFreedBufferSize += Node->Pages * EFI_PAGE_SIZE;\r | |
219 | \r | |
220 | // If the size of the non-allocated reaches the threshold we raise a warning.\r | |
221 | // It might be an expected behaviour in some cases.\r | |
222 | // We might device to free some of these buffers later on.\r | |
223 | if (mFreedBufferSize > PcdGet64 (PcdArmFreeUncachedMemorySizeThreshold)) {\r | |
224 | DEBUG ((EFI_D_WARN, "Warning: The list of non-allocated buffer has reach the threshold.\n"));\r | |
225 | }\r | |
226 | return EFI_SUCCESS;\r | |
227 | }\r | |
228 | }\r | |
229 | \r | |
230 | return EFI_NOT_FOUND;\r | |
231 | }\r | |
232 | \r | |
233 | /**\r | |
234 | * This function is automatically invoked when the driver exits\r | |
235 | * It frees all the non-allocated memory buffer.\r | |
236 | * This function is not responsible to free allocated buffer (eg: case of memory leak,\r | |
237 | * runtime allocation).\r | |
238 | */\r | |
239 | EFI_STATUS\r | |
240 | EFIAPI\r | |
241 | UncachedMemoryAllocationLibDestructor (\r | |
242 | IN EFI_HANDLE ImageHandle,\r | |
243 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
2ef2b01e A |
244 | )\r |
245 | {\r | |
883b666e | 246 | LIST_ENTRY *Link;\r |
247 | FREE_PAGE_NODE *OldNode;\r | |
248 | \r | |
1a70a690 OM |
249 | // Test if the list is empty\r |
250 | Link = mPageList.ForwardLink;\r | |
251 | if (Link == &mPageList) {\r | |
252 | return EFI_SUCCESS;\r | |
253 | }\r | |
3402aac7 | 254 | \r |
1a70a690 OM |
255 | // Free all the pages and nodes\r |
256 | do {\r | |
883b666e | 257 | OldNode = BASE_CR (Link, FREE_PAGE_NODE, Link);\r |
1a70a690 OM |
258 | // Point to the next entry\r |
259 | Link = Link->ForwardLink;\r | |
3402aac7 | 260 | \r |
1a70a690 OM |
261 | // We only free the non-allocated buffer\r |
262 | if (OldNode->Allocated == FALSE) {\r | |
263 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);\r | |
883b666e | 264 | RemoveEntryList (&OldNode->Link);\r |
265 | FreePool (OldNode);\r | |
883b666e | 266 | }\r |
1a70a690 | 267 | } while (Link != &mPageList);\r |
883b666e | 268 | \r |
1a70a690 | 269 | return EFI_SUCCESS;\r |
2ef2b01e A |
270 | }\r |
271 | \r | |
883b666e | 272 | /**\r |
273 | Converts a cached or uncached address to a physical address suitable for use in SoC registers.\r | |
274 | \r | |
275 | @param VirtualAddress The pointer to convert.\r | |
276 | \r | |
277 | @return The physical address of the supplied virtual pointer.\r | |
278 | \r | |
279 | **/\r | |
280 | EFI_PHYSICAL_ADDRESS\r | |
281 | ConvertToPhysicalAddress (\r | |
282 | IN VOID *VirtualAddress\r | |
283 | )\r | |
284 | {\r | |
285 | return (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAddress;\r | |
286 | }\r | |
287 | \r | |
288 | \r | |
2ef2b01e A |
289 | VOID *\r |
290 | UncachedInternalAllocatePages (\r | |
3402aac7 | 291 | IN EFI_MEMORY_TYPE MemoryType,\r |
2ef2b01e A |
292 | IN UINTN Pages\r |
293 | )\r | |
294 | {\r | |
883b666e | 295 | return UncachedInternalAllocateAlignedPages (MemoryType, Pages, EFI_PAGE_SIZE);\r |
2ef2b01e A |
296 | }\r |
297 | \r | |
883b666e | 298 | \r |
2ef2b01e A |
299 | VOID *\r |
300 | EFIAPI\r | |
301 | UncachedAllocatePages (\r | |
302 | IN UINTN Pages\r | |
303 | )\r | |
304 | {\r | |
305 | return UncachedInternalAllocatePages (EfiBootServicesData, Pages);\r | |
306 | }\r | |
307 | \r | |
308 | VOID *\r | |
309 | EFIAPI\r | |
310 | UncachedAllocateRuntimePages (\r | |
311 | IN UINTN Pages\r | |
312 | )\r | |
313 | {\r | |
314 | return UncachedInternalAllocatePages (EfiRuntimeServicesData, Pages);\r | |
315 | }\r | |
316 | \r | |
317 | VOID *\r | |
318 | EFIAPI\r | |
319 | UncachedAllocateReservedPages (\r | |
320 | IN UINTN Pages\r | |
321 | )\r | |
322 | {\r | |
323 | return UncachedInternalAllocatePages (EfiReservedMemoryType, Pages);\r | |
324 | }\r | |
325 | \r | |
883b666e | 326 | \r |
327 | \r | |
2ef2b01e A |
328 | VOID\r |
329 | EFIAPI\r | |
330 | UncachedFreePages (\r | |
331 | IN VOID *Buffer,\r | |
332 | IN UINTN Pages\r | |
333 | )\r | |
334 | {\r | |
883b666e | 335 | UncachedFreeAlignedPages (Buffer, Pages);\r |
336 | return;\r | |
2ef2b01e A |
337 | }\r |
338 | \r | |
883b666e | 339 | \r |
2ef2b01e A |
340 | VOID *\r |
341 | UncachedInternalAllocateAlignedPages (\r | |
3402aac7 | 342 | IN EFI_MEMORY_TYPE MemoryType,\r |
2ef2b01e A |
343 | IN UINTN Pages,\r |
344 | IN UINTN Alignment\r | |
345 | )\r | |
346 | {\r | |
1a70a690 OM |
347 | EFI_STATUS Status;\r |
348 | VOID *Allocation;\r | |
3402aac7 | 349 | \r |
2ef2b01e A |
350 | if (Pages == 0) {\r |
351 | return NULL;\r | |
352 | }\r | |
3402aac7 | 353 | \r |
1a70a690 OM |
354 | Allocation = NULL;\r |
355 | Status = AllocatePagesFromList (MemoryType, Pages, Alignment, &Allocation);\r | |
356 | if (EFI_ERROR (Status)) {\r | |
357 | ASSERT_EFI_ERROR (Status);\r | |
358 | return NULL;\r | |
359 | } else {\r | |
360 | return Allocation;\r | |
2ef2b01e | 361 | }\r |
2ef2b01e A |
362 | }\r |
363 | \r | |
2ef2b01e A |
364 | \r |
365 | VOID\r | |
366 | EFIAPI\r | |
367 | UncachedFreeAlignedPages (\r | |
368 | IN VOID *Buffer,\r | |
369 | IN UINTN Pages\r | |
370 | )\r | |
371 | {\r | |
1a70a690 | 372 | FreePagesFromList (Buffer);\r |
2ef2b01e A |
373 | }\r |
374 | \r | |
883b666e | 375 | \r |
2ef2b01e A |
376 | VOID *\r |
377 | UncachedInternalAllocateAlignedPool (\r | |
378 | IN EFI_MEMORY_TYPE PoolType,\r | |
379 | IN UINTN AllocationSize,\r | |
380 | IN UINTN Alignment\r | |
381 | )\r | |
382 | {\r | |
883b666e | 383 | VOID *AlignedAddress;\r |
3402aac7 | 384 | \r |
2ef2b01e A |
385 | //\r |
386 | // Alignment must be a power of two or zero.\r | |
387 | //\r | |
388 | ASSERT ((Alignment & (Alignment - 1)) == 0);\r | |
389 | \r | |
883b666e | 390 | if (Alignment < EFI_PAGE_SIZE) {\r |
391 | Alignment = EFI_PAGE_SIZE;\r | |
2ef2b01e | 392 | }\r |
3402aac7 | 393 | \r |
883b666e | 394 | AlignedAddress = UncachedInternalAllocateAlignedPages (PoolType, EFI_SIZE_TO_PAGES (AllocationSize), Alignment);\r |
395 | if (AlignedAddress == NULL) {\r | |
2ef2b01e A |
396 | return NULL;\r |
397 | }\r | |
398 | \r | |
2ef2b01e A |
399 | return (VOID *) AlignedAddress;\r |
400 | }\r | |
401 | \r | |
402 | VOID *\r | |
403 | EFIAPI\r | |
404 | UncachedAllocateAlignedPool (\r | |
405 | IN UINTN AllocationSize,\r | |
406 | IN UINTN Alignment\r | |
407 | )\r | |
408 | {\r | |
409 | return UncachedInternalAllocateAlignedPool (EfiBootServicesData, AllocationSize, Alignment);\r | |
410 | }\r | |
411 | \r | |
412 | VOID *\r | |
413 | EFIAPI\r | |
414 | UncachedAllocateAlignedRuntimePool (\r | |
415 | IN UINTN AllocationSize,\r | |
416 | IN UINTN Alignment\r | |
417 | )\r | |
418 | {\r | |
419 | return UncachedInternalAllocateAlignedPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r | |
420 | }\r | |
421 | \r | |
422 | VOID *\r | |
423 | EFIAPI\r | |
424 | UncachedAllocateAlignedReservedPool (\r | |
425 | IN UINTN AllocationSize,\r | |
426 | IN UINTN Alignment\r | |
427 | )\r | |
428 | {\r | |
429 | return UncachedInternalAllocateAlignedPool (EfiReservedMemoryType, AllocationSize, Alignment);\r | |
430 | }\r | |
431 | \r | |
432 | VOID *\r | |
433 | UncachedInternalAllocateAlignedZeroPool (\r | |
434 | IN EFI_MEMORY_TYPE PoolType,\r | |
435 | IN UINTN AllocationSize,\r | |
436 | IN UINTN Alignment\r | |
437 | )\r | |
438 | {\r | |
439 | VOID *Memory;\r | |
440 | Memory = UncachedInternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r | |
441 | if (Memory != NULL) {\r | |
442 | Memory = ZeroMem (Memory, AllocationSize);\r | |
443 | }\r | |
444 | return Memory;\r | |
445 | }\r | |
446 | \r | |
447 | VOID *\r | |
448 | EFIAPI\r | |
449 | UncachedAllocateAlignedZeroPool (\r | |
450 | IN UINTN AllocationSize,\r | |
451 | IN UINTN Alignment\r | |
452 | )\r | |
453 | {\r | |
454 | return UncachedInternalAllocateAlignedZeroPool (EfiBootServicesData, AllocationSize, Alignment);\r | |
455 | }\r | |
456 | \r | |
457 | VOID *\r | |
458 | EFIAPI\r | |
459 | UncachedAllocateAlignedRuntimeZeroPool (\r | |
460 | IN UINTN AllocationSize,\r | |
461 | IN UINTN Alignment\r | |
462 | )\r | |
463 | {\r | |
464 | return UncachedInternalAllocateAlignedZeroPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r | |
465 | }\r | |
466 | \r | |
467 | VOID *\r | |
468 | EFIAPI\r | |
469 | UncachedAllocateAlignedReservedZeroPool (\r | |
470 | IN UINTN AllocationSize,\r | |
471 | IN UINTN Alignment\r | |
472 | )\r | |
473 | {\r | |
474 | return UncachedInternalAllocateAlignedZeroPool (EfiReservedMemoryType, AllocationSize, Alignment);\r | |
475 | }\r | |
476 | \r | |
477 | VOID *\r | |
478 | UncachedInternalAllocateAlignedCopyPool (\r | |
479 | IN EFI_MEMORY_TYPE PoolType,\r | |
480 | IN UINTN AllocationSize,\r | |
481 | IN CONST VOID *Buffer,\r | |
482 | IN UINTN Alignment\r | |
483 | )\r | |
484 | {\r | |
485 | VOID *Memory;\r | |
3402aac7 | 486 | \r |
2ef2b01e A |
487 | ASSERT (Buffer != NULL);\r |
488 | ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r | |
489 | \r | |
490 | Memory = UncachedInternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r | |
491 | if (Memory != NULL) {\r | |
492 | Memory = CopyMem (Memory, Buffer, AllocationSize);\r | |
493 | }\r | |
494 | return Memory;\r | |
495 | }\r | |
496 | \r | |
497 | VOID *\r | |
498 | EFIAPI\r | |
499 | UncachedAllocateAlignedCopyPool (\r | |
500 | IN UINTN AllocationSize,\r | |
501 | IN CONST VOID *Buffer,\r | |
502 | IN UINTN Alignment\r | |
503 | )\r | |
504 | {\r | |
505 | return UncachedInternalAllocateAlignedCopyPool (EfiBootServicesData, AllocationSize, Buffer, Alignment);\r | |
506 | }\r | |
507 | \r | |
508 | VOID *\r | |
509 | EFIAPI\r | |
510 | UncachedAllocateAlignedRuntimeCopyPool (\r | |
511 | IN UINTN AllocationSize,\r | |
512 | IN CONST VOID *Buffer,\r | |
513 | IN UINTN Alignment\r | |
514 | )\r | |
515 | {\r | |
516 | return UncachedInternalAllocateAlignedCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer, Alignment);\r | |
517 | }\r | |
518 | \r | |
519 | VOID *\r | |
520 | EFIAPI\r | |
521 | UncachedAllocateAlignedReservedCopyPool (\r | |
522 | IN UINTN AllocationSize,\r | |
523 | IN CONST VOID *Buffer,\r | |
524 | IN UINTN Alignment\r | |
525 | )\r | |
526 | {\r | |
527 | return UncachedInternalAllocateAlignedCopyPool (EfiReservedMemoryType, AllocationSize, Buffer, Alignment);\r | |
528 | }\r | |
529 | \r | |
530 | VOID\r | |
531 | EFIAPI\r | |
532 | UncachedFreeAlignedPool (\r | |
883b666e | 533 | IN VOID *Allocation\r |
2ef2b01e A |
534 | )\r |
535 | {\r | |
1a70a690 | 536 | UncachedFreePages (Allocation, 0);\r |
2ef2b01e A |
537 | }\r |
538 | \r | |
539 | VOID *\r | |
540 | UncachedInternalAllocatePool (\r | |
3402aac7 | 541 | IN EFI_MEMORY_TYPE MemoryType,\r |
2ef2b01e A |
542 | IN UINTN AllocationSize\r |
543 | )\r | |
544 | {\r | |
883b666e | 545 | UINTN CacheLineLength = ArmDataCacheLineLength ();\r |
546 | return UncachedInternalAllocateAlignedPool (MemoryType, AllocationSize, CacheLineLength);\r | |
2ef2b01e A |
547 | }\r |
548 | \r | |
549 | VOID *\r | |
550 | EFIAPI\r | |
551 | UncachedAllocatePool (\r | |
552 | IN UINTN AllocationSize\r | |
553 | )\r | |
554 | {\r | |
555 | return UncachedInternalAllocatePool (EfiBootServicesData, AllocationSize);\r | |
556 | }\r | |
557 | \r | |
558 | VOID *\r | |
559 | EFIAPI\r | |
560 | UncachedAllocateRuntimePool (\r | |
561 | IN UINTN AllocationSize\r | |
562 | )\r | |
563 | {\r | |
564 | return UncachedInternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r | |
565 | }\r | |
566 | \r | |
567 | VOID *\r | |
568 | EFIAPI\r | |
569 | UncachedAllocateReservedPool (\r | |
570 | IN UINTN AllocationSize\r | |
571 | )\r | |
572 | {\r | |
573 | return UncachedInternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r | |
574 | }\r | |
575 | \r | |
576 | VOID *\r | |
577 | UncachedInternalAllocateZeroPool (\r | |
3402aac7 | 578 | IN EFI_MEMORY_TYPE PoolType,\r |
2ef2b01e | 579 | IN UINTN AllocationSize\r |
3402aac7 | 580 | )\r |
2ef2b01e A |
581 | {\r |
582 | VOID *Memory;\r | |
583 | \r | |
584 | Memory = UncachedInternalAllocatePool (PoolType, AllocationSize);\r | |
585 | if (Memory != NULL) {\r | |
586 | Memory = ZeroMem (Memory, AllocationSize);\r | |
587 | }\r | |
588 | return Memory;\r | |
589 | }\r | |
590 | \r | |
591 | VOID *\r | |
592 | EFIAPI\r | |
593 | UncachedAllocateZeroPool (\r | |
594 | IN UINTN AllocationSize\r | |
595 | )\r | |
596 | {\r | |
597 | return UncachedInternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r | |
598 | }\r | |
599 | \r | |
600 | VOID *\r | |
601 | EFIAPI\r | |
602 | UncachedAllocateRuntimeZeroPool (\r | |
603 | IN UINTN AllocationSize\r | |
604 | )\r | |
605 | {\r | |
606 | return UncachedInternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r | |
607 | }\r | |
608 | \r | |
609 | VOID *\r | |
610 | EFIAPI\r | |
611 | UncachedAllocateReservedZeroPool (\r | |
612 | IN UINTN AllocationSize\r | |
613 | )\r | |
614 | {\r | |
615 | return UncachedInternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r | |
616 | }\r | |
617 | \r | |
618 | VOID *\r | |
619 | UncachedInternalAllocateCopyPool (\r | |
3402aac7 | 620 | IN EFI_MEMORY_TYPE PoolType,\r |
2ef2b01e A |
621 | IN UINTN AllocationSize,\r |
622 | IN CONST VOID *Buffer\r | |
3402aac7 | 623 | )\r |
2ef2b01e A |
624 | {\r |
625 | VOID *Memory;\r | |
626 | \r | |
627 | ASSERT (Buffer != NULL);\r | |
628 | ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r | |
629 | \r | |
630 | Memory = UncachedInternalAllocatePool (PoolType, AllocationSize);\r | |
631 | if (Memory != NULL) {\r | |
632 | Memory = CopyMem (Memory, Buffer, AllocationSize);\r | |
633 | }\r | |
634 | return Memory;\r | |
3402aac7 | 635 | }\r |
2ef2b01e A |
636 | \r |
637 | VOID *\r | |
638 | EFIAPI\r | |
639 | UncachedAllocateCopyPool (\r | |
640 | IN UINTN AllocationSize,\r | |
641 | IN CONST VOID *Buffer\r | |
642 | )\r | |
643 | {\r | |
644 | return UncachedInternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);\r | |
645 | }\r | |
646 | \r | |
647 | VOID *\r | |
648 | EFIAPI\r | |
649 | UncachedAllocateRuntimeCopyPool (\r | |
650 | IN UINTN AllocationSize,\r | |
651 | IN CONST VOID *Buffer\r | |
652 | )\r | |
653 | {\r | |
654 | return UncachedInternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r | |
655 | }\r | |
656 | \r | |
657 | VOID *\r | |
658 | EFIAPI\r | |
659 | UncachedAllocateReservedCopyPool (\r | |
660 | IN UINTN AllocationSize,\r | |
661 | IN CONST VOID *Buffer\r | |
662 | )\r | |
663 | {\r | |
664 | return UncachedInternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r | |
665 | }\r | |
666 | \r | |
667 | VOID\r | |
668 | EFIAPI\r | |
669 | UncachedFreePool (\r | |
670 | IN VOID *Buffer\r | |
671 | )\r | |
672 | {\r | |
883b666e | 673 | UncachedFreeAlignedPool (Buffer);\r |
2ef2b01e A |
674 | }\r |
675 | \r | |
676 | VOID\r | |
677 | EFIAPI\r | |
678 | UncachedSafeFreePool (\r | |
679 | IN VOID *Buffer\r | |
680 | )\r | |
681 | {\r | |
682 | if (Buffer != NULL) {\r | |
683 | UncachedFreePool (Buffer);\r | |
684 | Buffer = NULL;\r | |
685 | }\r | |
686 | }\r | |
687 | \r |