]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
Make the EdkMoudlePkg build by allocate mCallbackFnTable at runtime as PCD_TOTAL_TOKE...
[mirror_edk2.git] / MdePkg / Library / PeiMemoryAllocationLib / MemoryAllocationLib.c
CommitLineData
878ddf1f 1/** @file\r
2 Support routines for memory allocation routines for use with drivers.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13 Module Name: MemoryAllocationLib.c\r
14\r
15**/\r
16\r
17\r
18\r
19/**\r
20 Allocates the number of 4KB pages specified by Pages of a certain memory type.\r
21\r
22 @param MemoryType The type of memory to allocate.\r
23 @param Pages The number of 4 KB pages to allocate.\r
24\r
25 @return A pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary.\r
26 If Pages is 0, then NULL is returned.\r
27 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
28\r
29**/\r
30VOID *\r
31InternalAllocatePages (\r
32 IN EFI_MEMORY_TYPE MemoryType, \r
33 IN UINTN Pages\r
34 )\r
35{\r
36 EFI_STATUS Status;\r
37 EFI_PHYSICAL_ADDRESS Memory; \r
38 EFI_PEI_SERVICES **PeiServices;\r
39\r
40 if (Pages == 0) {\r
41 return NULL;\r
42 }\r
43\r
44 PeiServices = GetPeiServicesTablePointer ();\r
45 Status = (*PeiServices)->AllocatePages (PeiServices, MemoryType, Pages, &Memory);\r
46 if (EFI_ERROR (Status)) {\r
47 Memory = 0;\r
48 }\r
49 return (VOID *) (UINTN) Memory;\r
50}\r
51\r
52/**\r
53 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData.\r
54\r
55 @param Pages The number of 4 KB pages to allocate.\r
56\r
57 @return A pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary.\r
58 If Pages is 0, then NULL is returned.\r
59 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
60\r
61**/\r
62VOID *\r
63EFIAPI\r
64AllocatePages (\r
65 IN UINTN Pages\r
66 )\r
67{\r
68 return InternalAllocatePages (EfiBootServicesData, Pages);\r
69}\r
70\r
71/**\r
72 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData. \r
73\r
74 @param Pages The number of 4 KB pages to allocate.\r
75\r
76 @return A pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary.\r
77 If Pages is 0, then NULL is returned.\r
78 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
79\r
80**/\r
81VOID *\r
82EFIAPI\r
83AllocateRuntimePages (\r
84 IN UINTN Pages\r
85 )\r
86{\r
87 return InternalAllocatePages (EfiRuntimeServicesData, Pages);\r
88}\r
89\r
90/**\r
91 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType. \r
92\r
93 @param Pages The number of 4 KB pages to allocate.\r
94\r
95 @return A pointer to the allocated buffer. The buffer returned is aligned on a 4KB boundary.\r
96 If Pages is 0, then NULL is returned.\r
97 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
98\r
99**/\r
100VOID *\r
101EFIAPI\r
102AllocateReservedPages (\r
103 IN UINTN Pages\r
104 )\r
105{\r
106 return InternalAllocatePages (EfiReservedMemoryType, Pages);\r
107}\r
108\r
109/**\r
110 Frees one or more 4KB pages that were previously allocated with \r
111 one of the page allocation functions in the Memory Allocation Library.\r
112\r
113 @param Buffer Pointer to the buffer of pages to free.\r
114 @param Pages The number of 4 KB pages to free.\r
115\r
116**/\r
117VOID\r
118EFIAPI\r
119FreePages (\r
120 IN VOID *Buffer,\r
121 IN UINTN Pages\r
122 )\r
123{\r
124 //\r
125 // PEI phase does not support to free pages, so leave it as NOP.\r
126 //\r
127}\r
128\r
129/**\r
130 Allocates the number of 4KB pages specified by Pages of a certian memory type \r
131 with an alignment specified by Alignment. \r
132\r
133 @param MemoryType The type of memory to allocate.\r
134 @param Pages The number of 4 KB pages to allocate.\r
135 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
136 If Alignment is zero, then byte alignment is used.\r
137\r
138 @return The allocated buffer is returned. If Pages is 0, then NULL is returned.\r
139 If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
140\r
141**/\r
142VOID *\r
143InternalAllocateAlignedPages (\r
144 IN EFI_MEMORY_TYPE MemoryType, \r
145 IN UINTN Pages,\r
146 IN UINTN Alignment\r
147 )\r
148{\r
149 VOID *Memory;\r
150 UINTN AlignmentMask;\r
151\r
152 //\r
153 // Alignment must be a power of two or zero.\r
154 //\r
155 ASSERT ((Alignment & (Alignment - 1)) == 0);\r
156\r
157 if (Pages == 0) {\r
158 return NULL;\r
159 }\r
160 //\r
a3657e3e 161 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
162 //\r
163 ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment)));\r
164 //\r
878ddf1f 165 // We would rather waste some memory to save PEI code size.\r
166 //\r
167 Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));\r
168 if (Alignment == 0) {\r
169 AlignmentMask = Alignment;\r
170 } else {\r
171 AlignmentMask = Alignment - 1; \r
172 }\r
173 return (VOID *) (UINTN) (((UINTN) Memory + AlignmentMask) & ~AlignmentMask);\r
174}\r
175\r
176/**\r
177 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData\r
178 with an alignment specified by Alignment. \r
179\r
180 @param Pages The number of 4 KB pages to allocate.\r
181 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
182 If Alignment is zero, then byte alignment is used.\r
183\r
184 @return The allocated buffer is returned. If Pages is 0, then NULL is returned.\r
185 If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
186\r
187**/\r
188VOID *\r
189EFIAPI\r
190AllocateAlignedPages (\r
191 IN UINTN Pages,\r
192 IN UINTN Alignment\r
193 )\r
194{\r
195 return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);\r
196}\r
197\r
198/**\r
199 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData\r
200 with an alignment specified by Alignment. \r
201\r
202 @param Pages The number of 4 KB pages to allocate.\r
203 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
204 If Alignment is zero, then byte alignment is used.\r
205\r
206 @return The allocated buffer is returned. If Pages is 0, then NULL is returned.\r
207 If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
208\r
209**/\r
210VOID *\r
211EFIAPI\r
212AllocateAlignedRuntimePages (\r
213 IN UINTN Pages,\r
214 IN UINTN Alignment\r
215 )\r
216{\r
217 return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);\r
218}\r
219\r
220/**\r
221 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
222\r
223 @param Pages The number of 4 KB pages to allocate.\r
224 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
225 If Alignment is zero, then byte alignment is used.\r
226\r
227 @return The allocated buffer is returned. If Pages is 0, then NULL is returned.\r
228 If there is not enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.\r
229\r
230**/\r
231VOID *\r
232EFIAPI\r
233AllocateAlignedReservedPages (\r
234 IN UINTN Pages,\r
235 IN UINTN Alignment\r
236 )\r
237{\r
238 return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);\r
239}\r
240\r
241/**\r
242 Frees one or more 4KB pages that were previously allocated with \r
243 one of the aligned page allocation functions in the Memory Allocation Library.\r
244\r
245 @param Buffer Pointer to the buffer of pages to free.\r
246 @param Pages The number of 4 KB pages to free.\r
247\r
248**/\r
249VOID\r
250EFIAPI\r
251FreeAlignedPages (\r
252 IN VOID *Buffer,\r
253 IN UINTN Pages\r
254 )\r
255{\r
256 //\r
257 // PEI phase does not support to free pages, so leave it as NOP.\r
258 //\r
259}\r
260\r
261/**\r
262 Allocates a buffer of a certain memory type.\r
263\r
264 @param MemoryType The type of memory to allocate.\r
265 @param AllocationSize The number of bytes to allocate.\r
266\r
267 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
268 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
269\r
270**/\r
271VOID *\r
272InternalAllocatePool (\r
273 IN EFI_MEMORY_TYPE MemoryType, \r
274 IN UINTN AllocationSize\r
275 )\r
276{\r
277 //\r
278 // If we need lots of small runtime/reserved memory type from PEI in the future, \r
279 // we can consider providing a more complex algorithm that allocates runtime pages and \r
280 // provide pool allocations from those pages. \r
281 //\r
282 return InternalAllocatePages (MemoryType, EFI_SIZE_TO_PAGES (AllocationSize));\r
283}\r
284\r
285/**\r
286 Allocates a buffer of type EfiBootServicesData.\r
287\r
288 @param AllocationSize The number of bytes to allocate.\r
289\r
290 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
291 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
292\r
293**/\r
294VOID *\r
295EFIAPI\r
296AllocatePool (\r
297 IN UINTN AllocationSize\r
298 )\r
299{\r
300 EFI_STATUS Status;\r
301 EFI_PEI_SERVICES **PeiServices;\r
302 VOID *Buffer;\r
303 \r
304 PeiServices = GetPeiServicesTablePointer ();\r
305\r
306 Status = (*PeiServices)->AllocatePool (PeiServices, AllocationSize, &Buffer);\r
307 if (EFI_ERROR (Status)) {\r
308 Buffer = NULL;\r
309 }\r
310 return Buffer;\r
311}\r
312\r
313/**\r
314 Allocates a buffer of type EfiRuntimeServicesData.\r
315\r
316 @param AllocationSize The number of bytes to allocate.\r
317\r
318 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
319 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
320\r
321**/\r
322VOID *\r
323EFIAPI\r
324AllocateRuntimePool (\r
325 IN UINTN AllocationSize\r
326 )\r
327{\r
328 return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
329}\r
330\r
331/**\r
332 Allocates a buffer of type EfiReservedMemoryType.\r
333\r
334 @param AllocationSize The number of bytes to allocate.\r
335\r
336 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
337 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
338\r
339**/\r
340VOID *\r
341EFIAPI\r
342AllocateReservedPool (\r
343 IN UINTN AllocationSize\r
344 )\r
345{\r
346 return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
347}\r
348\r
349/**\r
350 Allocates and zeros a buffer of a certian pool type.\r
351\r
352 @param PoolType The type of memory to allocate.\r
353 @param AllocationSize The number of bytes to allocate and zero.\r
354\r
355 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
356 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
357\r
358**/\r
359VOID *\r
360InternalAllocateZeroPool (\r
361 IN EFI_MEMORY_TYPE PoolType, \r
362 IN UINTN AllocationSize\r
363 ) \r
364{\r
365 VOID *Memory;\r
366\r
367 Memory = InternalAllocatePool (PoolType, AllocationSize);\r
368 if (Memory != NULL) {\r
369 Memory = ZeroMem (Memory, AllocationSize);\r
370 }\r
371 return Memory;\r
372}\r
373\r
374/**\r
375 Allocates and zeros a buffer of type EfiBootServicesData.\r
376\r
377 @param AllocationSize The number of bytes to allocate and zero.\r
378\r
379 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
380 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
381\r
382**/\r
383VOID *\r
384EFIAPI\r
385AllocateZeroPool (\r
386 IN UINTN AllocationSize\r
387 )\r
388{\r
389 VOID *Memory;\r
390\r
391 Memory = AllocatePool (AllocationSize);\r
392 if (Memory != NULL) {\r
393 Memory = ZeroMem (Memory, AllocationSize);\r
394 }\r
395 return Memory;\r
396}\r
397\r
398/**\r
399 Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
400\r
401 @param AllocationSize The number of bytes to allocate and zero.\r
402\r
403 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
404 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
405\r
406**/\r
407VOID *\r
408EFIAPI\r
409AllocateRuntimeZeroPool (\r
410 IN UINTN AllocationSize\r
411 )\r
412{\r
413 return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
414}\r
415\r
416/**\r
417 Allocates and zeros a buffer of type EfiReservedMemoryType.\r
418\r
419 @param AllocationSize The number of bytes to allocate and zero.\r
420\r
421 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
422 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
423\r
424**/\r
425VOID *\r
426EFIAPI\r
427AllocateReservedZeroPool (\r
428 IN UINTN AllocationSize\r
429 )\r
430{\r
431 return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
432}\r
433\r
434/**\r
435 Copies a buffer to an allocated buffer of a certian memory type. \r
436\r
437 @param MemoryType The type of pool to allocate.\r
438 @param AllocationSize The number of bytes to allocate and zero.\r
439 @param Buffer The buffer to copy to the allocated buffer.\r
440\r
441 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
442 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
443\r
444**/\r
445VOID *\r
446InternalAllocateCopyPool (\r
447 IN EFI_MEMORY_TYPE PoolType, \r
448 IN UINTN AllocationSize,\r
449 IN CONST VOID *Buffer\r
450 ) \r
451{\r
452 VOID *Memory;\r
453\r
454 Memory = InternalAllocatePool (PoolType, AllocationSize);\r
455 if (Memory != NULL) {\r
456 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
457 }\r
458 return Memory;\r
459} \r
460\r
461/**\r
462 Copies a buffer to an allocated buffer of type EfiBootServicesData. \r
463\r
464 @param AllocationSize The number of bytes to allocate.\r
465 @param Buffer The buffer to copy to the allocated buffer.\r
466\r
467 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
468 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
469\r
470**/\r
471VOID *\r
472EFIAPI\r
473AllocateCopyPool (\r
474 IN UINTN AllocationSize,\r
475 IN CONST VOID *Buffer\r
476 )\r
477{\r
478 VOID *Memory;\r
479\r
480 Memory = AllocatePool (AllocationSize);\r
481 if (Memory != NULL) {\r
482 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
483 }\r
484 return Memory;\r
485}\r
486\r
487/**\r
488 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData. \r
489\r
490 @param AllocationSize The number of bytes to allocate.\r
491 @param Buffer The buffer to copy to the allocated buffer.\r
492\r
493 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
494 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
495\r
496**/\r
497VOID *\r
498EFIAPI\r
499AllocateRuntimeCopyPool (\r
500 IN UINTN AllocationSize,\r
501 IN CONST VOID *Buffer\r
502 )\r
503{\r
504 return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r
505}\r
506\r
507/**\r
508 Copies a buffer to an allocated buffer of type EfiReservedMemoryType. \r
509\r
510 @param AllocationSize The number of bytes to allocate.\r
511 @param Buffer The buffer to copy to the allocated buffer.\r
512\r
513 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
514 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
515\r
516**/\r
517VOID *\r
518EFIAPI\r
519AllocateReservedCopyPool (\r
520 IN UINTN AllocationSize,\r
521 IN CONST VOID *Buffer\r
522 )\r
523{\r
524 return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
525}\r
526\r
527/**\r
528 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.\r
529\r
530 @param Buffer Pointer to the buffer to free.\r
531\r
532**/\r
533VOID\r
534EFIAPI\r
535FreePool (\r
536 IN VOID *Buffer\r
537 )\r
538{\r
539 //\r
540 // PEI phase does not support to free pool, so leave it as NOP.\r
541 //\r
542}\r
543\r
544/**\r
545 Allocates a buffer of a certain pool type at a specified alignment.\r
546\r
547 @param PoolType The type of pool to allocate.\r
548 @param AllocationSize The number of bytes to allocate.\r
549 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.\r
550\r
551 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
552 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
553\r
554**/\r
555VOID *\r
556InternalAllocateAlignedPool (\r
557 IN EFI_MEMORY_TYPE PoolType,\r
558 IN UINTN AllocationSize,\r
559 IN UINTN Alignment\r
560 )\r
561{\r
562 VOID *RawAddress;\r
563 UINTN AlignedAddress;\r
564 UINTN AlignmentMask;\r
565\r
566 //\r
567 // Alignment must be a power of two or zero.\r
568 //\r
569 ASSERT ((Alignment & (Alignment - 1)) == 0);\r
570 \r
571 if (Alignment == 0) {\r
572 AlignmentMask = Alignment;\r
573 } else {\r
574 AlignmentMask = Alignment - 1;\r
575 }\r
a3657e3e 576 //\r
577 // Make sure that AllocationSize plus AlignmentMask does not overflow.\r
578 //\r
579 ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));\r
878ddf1f 580\r
581 RawAddress = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask);\r
582 \r
583 AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;\r
584 \r
585 return (VOID *) AlignedAddress;\r
586}\r
587\r
588/**\r
589 Allocates a buffer of type EfiBootServicesData at a specified alignment.\r
590\r
591 @param AllocationSize The number of bytes to allocate.\r
592 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.\r
593\r
594 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
595 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
596\r
597**/\r
598VOID *\r
599EFIAPI\r
600AllocateAlignedPool (\r
601 IN UINTN AllocationSize,\r
602 IN UINTN Alignment\r
603 )\r
604{\r
605 VOID *RawAddress;\r
606 UINTN AlignedAddress;\r
607 UINTN AlignmentMask;\r
608\r
609 //\r
610 // Alignment must be a power of two or zero.\r
611 //\r
612 ASSERT ((Alignment & (Alignment - 1)) == 0);\r
613\r
614 if (Alignment == 0) {\r
615 AlignmentMask = Alignment;\r
616 } else {\r
617 AlignmentMask = Alignment - 1;\r
618 }\r
619\r
a3657e3e 620 //\r
621 // Make sure that AllocationSize plus AlignmentMask does not overflow.\r
622 //\r
623 ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));\r
624\r
878ddf1f 625 RawAddress = AllocatePool (AllocationSize + AlignmentMask);\r
626 \r
627 AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;\r
628 \r
629 return (VOID *) AlignedAddress;\r
630}\r
631\r
632/**\r
633 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.\r
634\r
635 @param AllocationSize The number of bytes to allocate.\r
636 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
637 If Alignment is zero, then byte alignment is used.\r
638\r
639 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
640 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
641\r
642**/\r
643VOID *\r
644EFIAPI\r
645AllocateAlignedRuntimePool (\r
646 IN UINTN AllocationSize,\r
647 IN UINTN Alignment\r
648 )\r
649{\r
650 return InternalAllocateAlignedPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
651}\r
652\r
653/**\r
654 Allocates a buffer of type EfiReservedMemoryType at a specified alignment.\r
655\r
656 @param AllocationSize The number of bytes to allocate.\r
657 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
658 If Alignment is zero, then byte alignment is used.\r
659\r
660 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
661 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
662\r
663**/\r
664VOID *\r
665EFIAPI\r
666AllocateAlignedReservedPool (\r
667 IN UINTN AllocationSize,\r
668 IN UINTN Alignment\r
669 )\r
670{\r
671 return InternalAllocateAlignedPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
672}\r
673\r
674/**\r
675 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.\r
676\r
677 @param PoolType The type of pool to allocate.\r
678 @param AllocationSize The number of bytes to allocate.\r
679 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
680 If Alignment is zero, then byte alignment is used.\r
681\r
682 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
683 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
684\r
685**/\r
686VOID *\r
687InternalAllocateAlignedZeroPool (\r
688 IN EFI_MEMORY_TYPE PoolType,\r
689 IN UINTN AllocationSize,\r
690 IN UINTN Alignment\r
691 )\r
692{\r
693 VOID *Memory;\r
694\r
695 Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
696 if (Memory != NULL) {\r
697 Memory = ZeroMem (Memory, AllocationSize);\r
698 }\r
699 return Memory;\r
700}\r
701\r
702/**\r
703 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.\r
704\r
705 @param AllocationSize The number of bytes to allocate.\r
706 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
707 If Alignment is zero, then byte alignment is used.\r
708\r
709 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
710 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
711\r
712**/\r
713VOID *\r
714EFIAPI\r
715AllocateAlignedZeroPool (\r
716 IN UINTN AllocationSize,\r
717 IN UINTN Alignment\r
718 )\r
719{\r
720 VOID *Memory;\r
721\r
722 Memory = AllocateAlignedPool (AllocationSize, Alignment);\r
723 if (Memory != NULL) {\r
724 Memory = ZeroMem (Memory, AllocationSize);\r
725 }\r
726 return Memory;\r
727}\r
728\r
729/**\r
730 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.\r
731\r
732 @param AllocationSize The number of bytes to allocate.\r
733 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
734 If Alignment is zero, then byte alignment is used.\r
735\r
736 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
737 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
738\r
739**/\r
740VOID *\r
741EFIAPI\r
742AllocateAlignedRuntimeZeroPool (\r
743 IN UINTN AllocationSize,\r
744 IN UINTN Alignment\r
745 )\r
746{\r
747 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
748}\r
749\r
750/**\r
751 Allocates and zeros a buffer of type EfiReservedMemoryType at a specified alignment.\r
752\r
753 @param AllocationSize The number of bytes to allocate.\r
754 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
755 If Alignment is zero, then byte alignment is used.\r
756\r
757 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
758 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
759\r
760**/\r
761VOID *\r
762EFIAPI\r
763AllocateAlignedReservedZeroPool (\r
764 IN UINTN AllocationSize,\r
765 IN UINTN Alignment\r
766 )\r
767{\r
768 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
769}\r
770\r
771/**\r
772 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.\r
773\r
774 @param PoolType The type of pool to allocate.\r
775 @param AllocationSize The number of bytes to allocate.\r
776 @param Buffer The buffer to copy to the allocated buffer.\r
777 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
778 If Alignment is zero, then byte alignment is used.\r
779\r
780 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
781 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
782\r
783**/\r
784VOID *\r
785InternalAllocateAlignedCopyPool (\r
786 IN EFI_MEMORY_TYPE PoolType,\r
787 IN UINTN AllocationSize,\r
788 IN CONST VOID *Buffer,\r
789 IN UINTN Alignment\r
790 )\r
791{\r
792 VOID *Memory;\r
793 \r
794 Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
795 if (Memory != NULL) {\r
796 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
797 }\r
798 return Memory;\r
799}\r
800\r
801/**\r
802 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.\r
803\r
804 @param AllocationSize The number of bytes to allocate.\r
805 @param Buffer The buffer to copy to the allocated buffer.\r
806 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
807 If Alignment is zero, then byte alignment is used.\r
808\r
809 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
810 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
811\r
812**/\r
813VOID *\r
814EFIAPI\r
815AllocateAlignedCopyPool (\r
816 IN UINTN AllocationSize,\r
817 IN CONST VOID *Buffer,\r
818 IN UINTN Alignment\r
819 )\r
820{\r
821 VOID *Memory;\r
822 \r
823 Memory = AllocateAlignedPool (AllocationSize, Alignment);\r
824 if (Memory != NULL) {\r
825 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
826 }\r
827 return Memory;\r
828}\r
829\r
830/**\r
831 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.\r
832\r
833 @param AllocationSize The number of bytes to allocate.\r
834 @param Buffer The buffer to copy to the allocated buffer.\r
835 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
836 If Alignment is zero, then byte alignment is used.\r
837\r
838 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
839 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
840\r
841**/\r
842VOID *\r
843EFIAPI\r
844AllocateAlignedRuntimeCopyPool (\r
845 IN UINTN AllocationSize,\r
846 IN CONST VOID *Buffer,\r
847 IN UINTN Alignment\r
848 )\r
849{\r
850 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer, Alignment);\r
851}\r
852\r
853/**\r
854 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.\r
855\r
856 @param AllocationSize The number of bytes to allocate.\r
857 @param Buffer The buffer to copy to the allocated buffer.\r
858 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
859 If Alignment is zero, then byte alignment is used.\r
860\r
861 @return A pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned.\r
862 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
863\r
864**/\r
865VOID *\r
866EFIAPI\r
867AllocateAlignedReservedCopyPool (\r
868 IN UINTN AllocationSize,\r
869 IN CONST VOID *Buffer,\r
870 IN UINTN Alignment\r
871 )\r
872{\r
873 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType, AllocationSize, Buffer, Alignment);\r
874}\r
875\r
876/**\r
877 Frees a buffer that was previously allocated with one of the aligned pool allocation functions \r
878 in the Memory Allocation Library.\r
879\r
880 @param Buffer Pointer to the buffer to free.\r
881\r
882**/\r
883VOID\r
884EFIAPI\r
885FreeAlignedPool (\r
886 IN VOID *Buffer\r
887 )\r
888{\r
889 //\r
890 // PEI phase does not support to free pool, so leave it as NOP.\r
891 //\r
892}\r