]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Support routines for memory allocation routines \r | |
3 | based on PeiService for PEI phase drivers.\r | |
4 | \r | |
5 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r | |
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 | |
14 | **/\r | |
15 | \r | |
16 | \r | |
17 | #include <PiPei.h>\r | |
18 | \r | |
19 | \r | |
20 | #include <Library/MemoryAllocationLib.h>\r | |
21 | #include <Library/PeiServicesLib.h>\r | |
22 | #include <Library/BaseMemoryLib.h>\r | |
23 | #include <Library/DebugLib.h>\r | |
24 | \r | |
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 | |
39 | VOID *\r | |
40 | InternalAllocatePages (\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 | |
47 | \r | |
48 | if (Pages == 0) {\r | |
49 | return NULL;\r | |
50 | }\r | |
51 | \r | |
52 | Status = PeiServicesAllocatePages (MemoryType, Pages, &Memory);\r | |
53 | if (EFI_ERROR (Status)) {\r | |
54 | return NULL;\r | |
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 | |
72 | VOID *\r | |
73 | EFIAPI\r | |
74 | AllocatePages (\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 | |
94 | VOID *\r | |
95 | EFIAPI\r | |
96 | AllocateRuntimePages (\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 | |
116 | VOID *\r | |
117 | EFIAPI\r | |
118 | AllocateReservedPages (\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 | |
132 | If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r | |
133 | then ASSERT().\r | |
134 | If Pages is zero, then ASSERT().\r | |
135 | \r | |
136 | @param Buffer Pointer to the buffer of pages to free.\r | |
137 | @param Pages The number of 4 KB pages to free.\r | |
138 | \r | |
139 | **/\r | |
140 | VOID\r | |
141 | EFIAPI\r | |
142 | FreePages (\r | |
143 | IN VOID *Buffer,\r | |
144 | IN UINTN Pages\r | |
145 | )\r | |
146 | {\r | |
147 | //\r | |
148 | // PEI phase does not support to free pages, so leave it as NOP.\r | |
149 | //\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | Allocates one or more 4KB pages of a certain memory type at a specified alignment.\r | |
154 | \r | |
155 | Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment\r | |
156 | specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.\r | |
157 | If there is not enough memory at the specified alignment remaining to satisfy the request, then\r | |
158 | NULL is returned.\r | |
159 | If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r | |
160 | \r | |
161 | @param MemoryType The type of memory to allocate.\r | |
162 | @param Pages The number of 4 KB pages to allocate.\r | |
163 | @param Alignment The requested alignment of the allocation. Must be a power of two.\r | |
164 | If Alignment is zero, then byte alignment is used.\r | |
165 | \r | |
166 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
167 | \r | |
168 | **/\r | |
169 | VOID *\r | |
170 | InternalAllocateAlignedPages (\r | |
171 | IN EFI_MEMORY_TYPE MemoryType, \r | |
172 | IN UINTN Pages,\r | |
173 | IN UINTN Alignment\r | |
174 | )\r | |
175 | {\r | |
176 | VOID *Memory;\r | |
177 | UINTN AlignmentMask;\r | |
178 | \r | |
179 | //\r | |
180 | // Alignment must be a power of two or zero.\r | |
181 | //\r | |
182 | ASSERT ((Alignment & (Alignment - 1)) == 0);\r | |
183 | \r | |
184 | if (Pages == 0) {\r | |
185 | return NULL;\r | |
186 | }\r | |
187 | //\r | |
188 | // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r | |
189 | //\r | |
190 | ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment)));\r | |
191 | //\r | |
192 | // We would rather waste some memory to save PEI code size.\r | |
193 | //\r | |
194 | Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));\r | |
195 | if (Alignment == 0) {\r | |
196 | AlignmentMask = Alignment;\r | |
197 | } else {\r | |
198 | AlignmentMask = Alignment - 1; \r | |
199 | }\r | |
200 | return (VOID *) (UINTN) (((UINTN) Memory + AlignmentMask) & ~AlignmentMask);\r | |
201 | }\r | |
202 | \r | |
203 | /**\r | |
204 | Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r | |
205 | \r | |
206 | Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r | |
207 | alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r | |
208 | returned. If there is not enough memory at the specified alignment remaining to satisfy the\r | |
209 | request, then NULL is returned.\r | |
210 | If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r | |
211 | \r | |
212 | @param Pages The number of 4 KB pages to allocate.\r | |
213 | @param Alignment The requested alignment of the allocation. Must be a power of two.\r | |
214 | If Alignment is zero, then byte alignment is used.\r | |
215 | \r | |
216 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
217 | \r | |
218 | **/\r | |
219 | VOID *\r | |
220 | EFIAPI\r | |
221 | AllocateAlignedPages (\r | |
222 | IN UINTN Pages,\r | |
223 | IN UINTN Alignment\r | |
224 | )\r | |
225 | {\r | |
226 | return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);\r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
230 | Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r | |
231 | \r | |
232 | Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r | |
233 | alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r | |
234 | returned. If there is not enough memory at the specified alignment remaining to satisfy the\r | |
235 | request, then NULL is returned.\r | |
236 | If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r | |
237 | \r | |
238 | @param Pages The number of 4 KB pages to allocate.\r | |
239 | @param Alignment The requested alignment of the allocation. Must be a power of two.\r | |
240 | If Alignment is zero, then byte alignment is used.\r | |
241 | \r | |
242 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
243 | \r | |
244 | **/\r | |
245 | VOID *\r | |
246 | EFIAPI\r | |
247 | AllocateAlignedRuntimePages (\r | |
248 | IN UINTN Pages,\r | |
249 | IN UINTN Alignment\r | |
250 | )\r | |
251 | {\r | |
252 | return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);\r | |
253 | }\r | |
254 | \r | |
255 | /**\r | |
256 | Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r | |
257 | \r | |
258 | Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r | |
259 | alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r | |
260 | returned. If there is not enough memory at the specified alignment remaining to satisfy the\r | |
261 | request, then NULL is returned.\r | |
262 | If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r | |
263 | \r | |
264 | @param Pages The number of 4 KB pages to allocate.\r | |
265 | @param Alignment The requested alignment of the allocation. Must be a power of two.\r | |
266 | If Alignment is zero, then byte alignment is used.\r | |
267 | \r | |
268 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
269 | \r | |
270 | **/\r | |
271 | VOID *\r | |
272 | EFIAPI\r | |
273 | AllocateAlignedReservedPages (\r | |
274 | IN UINTN Pages,\r | |
275 | IN UINTN Alignment\r | |
276 | )\r | |
277 | {\r | |
278 | return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);\r | |
279 | }\r | |
280 | \r | |
281 | /**\r | |
282 | Frees one or more 4KB pages that were previously allocated with one of the aligned page\r | |
283 | allocation functions in the Memory Allocation Library.\r | |
284 | \r | |
285 | Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r | |
286 | must have been allocated on a previous call to the aligned page allocation services of the Memory\r | |
287 | Allocation Library.\r | |
288 | If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r | |
289 | Library, then ASSERT().\r | |
290 | If Pages is zero, then ASSERT().\r | |
291 | \r | |
292 | @param Buffer Pointer to the buffer of pages to free.\r | |
293 | @param Pages The number of 4 KB pages to free.\r | |
294 | \r | |
295 | **/\r | |
296 | VOID\r | |
297 | EFIAPI\r | |
298 | FreeAlignedPages (\r | |
299 | IN VOID *Buffer,\r | |
300 | IN UINTN Pages\r | |
301 | )\r | |
302 | {\r | |
303 | //\r | |
304 | // PEI phase does not support to free pages, so leave it as NOP.\r | |
305 | //\r | |
306 | }\r | |
307 | \r | |
308 | /**\r | |
309 | Allocates a buffer of a certain pool type.\r | |
310 | \r | |
311 | Allocates the number bytes specified by AllocationSize of a certain pool type and returns a\r | |
312 | pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r | |
313 | returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
314 | \r | |
315 | @param MemoryType The type of memory to allocate.\r | |
316 | @param AllocationSize The number of bytes to allocate.\r | |
317 | \r | |
318 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
319 | \r | |
320 | **/\r | |
321 | VOID *\r | |
322 | InternalAllocatePool (\r | |
323 | IN EFI_MEMORY_TYPE MemoryType, \r | |
324 | IN UINTN AllocationSize\r | |
325 | )\r | |
326 | {\r | |
327 | //\r | |
328 | // If we need lots of small runtime/reserved memory type from PEI in the future, \r | |
329 | // we can consider providing a more complex algorithm that allocates runtime pages and \r | |
330 | // provide pool allocations from those pages. \r | |
331 | //\r | |
332 | return InternalAllocatePages (MemoryType, EFI_SIZE_TO_PAGES (AllocationSize));\r | |
333 | }\r | |
334 | \r | |
335 | /**\r | |
336 | Allocates a buffer of type EfiBootServicesData.\r | |
337 | \r | |
338 | Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r | |
339 | pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r | |
340 | returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
341 | \r | |
342 | @param AllocationSize The number of bytes to allocate.\r | |
343 | \r | |
344 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
345 | \r | |
346 | **/\r | |
347 | VOID *\r | |
348 | EFIAPI\r | |
349 | AllocatePool (\r | |
350 | IN UINTN AllocationSize\r | |
351 | )\r | |
352 | {\r | |
353 | EFI_STATUS Status;\r | |
354 | VOID *Buffer;\r | |
355 | \r | |
356 | Status = PeiServicesAllocatePool (AllocationSize, &Buffer);\r | |
357 | if (EFI_ERROR (Status)) {\r | |
358 | Buffer = NULL;\r | |
359 | }\r | |
360 | return Buffer;\r | |
361 | }\r | |
362 | \r | |
363 | /**\r | |
364 | Allocates a buffer of type EfiRuntimeServicesData.\r | |
365 | \r | |
366 | Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r | |
367 | a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r | |
368 | returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
369 | \r | |
370 | @param AllocationSize The number of bytes to allocate.\r | |
371 | \r | |
372 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
373 | \r | |
374 | **/\r | |
375 | VOID *\r | |
376 | EFIAPI\r | |
377 | AllocateRuntimePool (\r | |
378 | IN UINTN AllocationSize\r | |
379 | )\r | |
380 | {\r | |
381 | return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r | |
382 | }\r | |
383 | \r | |
384 | /**\r | |
385 | Allocates a buffer of type EfieservedMemoryType.\r | |
386 | \r | |
387 | Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns\r | |
388 | a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r | |
389 | returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
390 | \r | |
391 | @param AllocationSize The number of bytes to allocate.\r | |
392 | \r | |
393 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
394 | \r | |
395 | **/\r | |
396 | VOID *\r | |
397 | EFIAPI\r | |
398 | AllocateReservedPool (\r | |
399 | IN UINTN AllocationSize\r | |
400 | )\r | |
401 | {\r | |
402 | return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r | |
403 | }\r | |
404 | \r | |
405 | /**\r | |
406 | Allocates and zeros a buffer of a certian pool type.\r | |
407 | \r | |
408 | Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r | |
409 | with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid\r | |
410 | buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,\r | |
411 | then NULL is returned.\r | |
412 | \r | |
413 | @param PoolType The type of memory to allocate.\r | |
414 | @param AllocationSize The number of bytes to allocate and zero.\r | |
415 | \r | |
416 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
417 | \r | |
418 | **/\r | |
419 | VOID *\r | |
420 | InternalAllocateZeroPool (\r | |
421 | IN EFI_MEMORY_TYPE PoolType, \r | |
422 | IN UINTN AllocationSize\r | |
423 | ) \r | |
424 | {\r | |
425 | VOID *Memory;\r | |
426 | \r | |
427 | Memory = InternalAllocatePool (PoolType, AllocationSize);\r | |
428 | if (Memory != NULL) {\r | |
429 | Memory = ZeroMem (Memory, AllocationSize);\r | |
430 | }\r | |
431 | return Memory;\r | |
432 | }\r | |
433 | \r | |
434 | /**\r | |
435 | Allocates and zeros a buffer of type EfiBootServicesData.\r | |
436 | \r | |
437 | Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r | |
438 | buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r | |
439 | valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r | |
440 | request, then NULL is returned.\r | |
441 | \r | |
442 | @param AllocationSize The number of bytes to allocate and zero.\r | |
443 | \r | |
444 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
445 | \r | |
446 | **/\r | |
447 | VOID *\r | |
448 | EFIAPI\r | |
449 | AllocateZeroPool (\r | |
450 | IN UINTN AllocationSize\r | |
451 | )\r | |
452 | {\r | |
453 | VOID *Memory;\r | |
454 | \r | |
455 | Memory = AllocatePool (AllocationSize);\r | |
456 | if (Memory != NULL) {\r | |
457 | Memory = ZeroMem (Memory, AllocationSize);\r | |
458 | }\r | |
459 | return Memory;\r | |
460 | }\r | |
461 | \r | |
462 | /**\r | |
463 | Allocates and zeros a buffer of type EfiRuntimeServicesData.\r | |
464 | \r | |
465 | Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r | |
466 | buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r | |
467 | valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r | |
468 | request, then NULL is returned.\r | |
469 | \r | |
470 | @param AllocationSize The number of bytes to allocate and zero.\r | |
471 | \r | |
472 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
473 | \r | |
474 | **/\r | |
475 | VOID *\r | |
476 | EFIAPI\r | |
477 | AllocateRuntimeZeroPool (\r | |
478 | IN UINTN AllocationSize\r | |
479 | )\r | |
480 | {\r | |
481 | return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r | |
482 | }\r | |
483 | \r | |
484 | /**\r | |
485 | Allocates and zeros a buffer of type EfiReservedMemoryType.\r | |
486 | \r | |
487 | Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r | |
488 | buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r | |
489 | valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r | |
490 | request, then NULL is returned.\r | |
491 | \r | |
492 | @param AllocationSize The number of bytes to allocate and zero.\r | |
493 | \r | |
494 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
495 | \r | |
496 | **/\r | |
497 | VOID *\r | |
498 | EFIAPI\r | |
499 | AllocateReservedZeroPool (\r | |
500 | IN UINTN AllocationSize\r | |
501 | )\r | |
502 | {\r | |
503 | return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r | |
504 | }\r | |
505 | \r | |
506 | /**\r | |
507 | Copies a buffer to an allocated buffer of a certian pool type.\r | |
508 | \r | |
509 | Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r | |
510 | AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r | |
511 | allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r | |
512 | is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
513 | If Buffer is NULL, then ASSERT().\r | |
514 | If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r | |
515 | \r | |
516 | @param PoolType The type of pool to allocate.\r | |
517 | @param AllocationSize The number of bytes to allocate and zero.\r | |
518 | @param Buffer The buffer to copy to the allocated buffer.\r | |
519 | \r | |
520 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
521 | \r | |
522 | **/\r | |
523 | VOID *\r | |
524 | InternalAllocateCopyPool (\r | |
525 | IN EFI_MEMORY_TYPE PoolType, \r | |
526 | IN UINTN AllocationSize,\r | |
527 | IN CONST VOID *Buffer\r | |
528 | ) \r | |
529 | {\r | |
530 | VOID *Memory;\r | |
531 | \r | |
532 | ASSERT (Buffer != NULL);\r | |
533 | ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r | |
534 | \r | |
535 | Memory = InternalAllocatePool (PoolType, AllocationSize);\r | |
536 | if (Memory != NULL) {\r | |
537 | Memory = CopyMem (Memory, Buffer, AllocationSize);\r | |
538 | }\r | |
539 | return Memory;\r | |
540 | } \r | |
541 | \r | |
542 | /**\r | |
543 | Copies a buffer to an allocated buffer of type EfiBootServicesData.\r | |
544 | \r | |
545 | Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r | |
546 | AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r | |
547 | allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r | |
548 | is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
549 | If Buffer is NULL, then ASSERT().\r | |
550 | If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r | |
551 | \r | |
552 | @param AllocationSize The number of bytes to allocate and zero.\r | |
553 | @param Buffer The buffer to copy to the allocated buffer.\r | |
554 | \r | |
555 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
556 | \r | |
557 | **/\r | |
558 | VOID *\r | |
559 | EFIAPI\r | |
560 | AllocateCopyPool (\r | |
561 | IN UINTN AllocationSize,\r | |
562 | IN CONST VOID *Buffer\r | |
563 | )\r | |
564 | {\r | |
565 | VOID *Memory;\r | |
566 | \r | |
567 | ASSERT (Buffer != NULL);\r | |
568 | ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r | |
569 | \r | |
570 | Memory = AllocatePool (AllocationSize);\r | |
571 | if (Memory != NULL) {\r | |
572 | Memory = CopyMem (Memory, Buffer, AllocationSize);\r | |
573 | }\r | |
574 | return Memory;\r | |
575 | }\r | |
576 | \r | |
577 | /**\r | |
578 | Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r | |
579 | \r | |
580 | Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r | |
581 | AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r | |
582 | allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r | |
583 | is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
584 | If Buffer is NULL, then ASSERT().\r | |
585 | If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r | |
586 | \r | |
587 | @param AllocationSize The number of bytes to allocate and zero.\r | |
588 | @param Buffer The buffer to copy to the allocated buffer.\r | |
589 | \r | |
590 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
591 | \r | |
592 | **/\r | |
593 | VOID *\r | |
594 | EFIAPI\r | |
595 | AllocateRuntimeCopyPool (\r | |
596 | IN UINTN AllocationSize,\r | |
597 | IN CONST VOID *Buffer\r | |
598 | )\r | |
599 | {\r | |
600 | return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r | |
601 | }\r | |
602 | \r | |
603 | /**\r | |
604 | Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r | |
605 | \r | |
606 | Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r | |
607 | AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r | |
608 | allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r | |
609 | is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
610 | If Buffer is NULL, then ASSERT().\r | |
611 | If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r | |
612 | \r | |
613 | @param AllocationSize The number of bytes to allocate and zero.\r | |
614 | @param Buffer The buffer to copy to the allocated buffer.\r | |
615 | \r | |
616 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
617 | \r | |
618 | **/\r | |
619 | VOID *\r | |
620 | EFIAPI\r | |
621 | AllocateReservedCopyPool (\r | |
622 | IN UINTN AllocationSize,\r | |
623 | IN CONST VOID *Buffer\r | |
624 | )\r | |
625 | {\r | |
626 | return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r | |
627 | }\r | |
628 | \r | |
629 | /**\r | |
630 | Frees a buffer that was previously allocated with one of the pool allocation functions in the\r | |
631 | Memory Allocation Library.\r | |
632 | \r | |
633 | Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the\r | |
634 | pool allocation services of the Memory Allocation Library.\r | |
635 | If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r | |
636 | then ASSERT().\r | |
637 | \r | |
638 | @param Buffer Pointer to the buffer to free.\r | |
639 | \r | |
640 | **/\r | |
641 | VOID\r | |
642 | EFIAPI\r | |
643 | FreePool (\r | |
644 | IN VOID *Buffer\r | |
645 | )\r | |
646 | {\r | |
647 | //\r | |
648 | // PEI phase does not support to free pool, so leave it as NOP.\r | |
649 | //\r | |
650 | }\r | |
651 | \r | |
652 | \r |