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