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