]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/MemoryAllocationLib.h
MdePkg/ProcessorBind: add defines for page allocation granularity
[mirror_edk2.git] / MdePkg / Include / Library / MemoryAllocationLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides services to allocate and free memory buffers of various memory types and alignments.\r
8789c5e0 3 \r
4 The Memory Allocation Library abstracts various common memory allocation operations. This library \r
5 allows code to be written in a phase-independent manner because the allocation of memory in PEI, DXE, \r
6 and SMM (for example) is done via a different mechanism. Using a common library interface makes it \r
7 much easier to port algorithms from phase to phase. \r
8 \r
1346352d 9Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
9df063a0 10This program and the accompanying materials\r
50a64e5b 11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
fb3df220 14\r
50a64e5b 15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
fb3df220 17\r
fb3df220 18**/\r
19\r
20#ifndef __MEMORY_ALLOCATION_LIB_H__\r
21#define __MEMORY_ALLOCATION_LIB_H__\r
22\r
23/**\r
24 Allocates one or more 4KB pages of type EfiBootServicesData.\r
25\r
26 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the\r
27 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
28 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
29 returned.\r
30\r
31 @param Pages The number of 4 KB pages to allocate.\r
32\r
33 @return A pointer to the allocated buffer or NULL if allocation fails.\r
34\r
35**/\r
36VOID *\r
37EFIAPI\r
38AllocatePages (\r
39 IN UINTN Pages\r
40 );\r
41\r
42/**\r
43 Allocates one or more 4KB pages of type EfiRuntimeServicesData.\r
44\r
45 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
46 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
47 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
48 returned.\r
49\r
50 @param Pages The number of 4 KB pages to allocate.\r
51\r
52 @return A pointer to the allocated buffer or NULL if allocation fails.\r
53\r
54**/\r
55VOID *\r
56EFIAPI\r
57AllocateRuntimePages (\r
58 IN UINTN Pages\r
59 );\r
60\r
61/**\r
62 Allocates one or more 4KB pages of type EfiReservedMemoryType.\r
63\r
64 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the\r
65 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
66 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
67 returned.\r
68\r
69 @param Pages The number of 4 KB pages to allocate.\r
70\r
71 @return A pointer to the allocated buffer or NULL if allocation fails.\r
72\r
73**/\r
74VOID *\r
75EFIAPI\r
76AllocateReservedPages (\r
77 IN UINTN Pages\r
78 );\r
79\r
80/**\r
81 Frees one or more 4KB pages that were previously allocated with one of the page allocation\r
82 functions in the Memory Allocation Library.\r
83\r
84 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
85 must have been allocated on a previous call to the page allocation services of the Memory\r
6e10b70a 86 Allocation Library. If it is not possible to free allocated pages, then this function will\r
446b94b0 87 perform no actions.\r
8789c5e0 88 \r
fb3df220 89 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
90 then ASSERT().\r
91 If Pages is zero, then ASSERT().\r
92 \r
93 @param Buffer Pointer to the buffer of pages to free.\r
94 @param Pages The number of 4 KB pages to free.\r
95\r
96**/\r
97VOID\r
98EFIAPI\r
99FreePages (\r
100 IN VOID *Buffer,\r
101 IN UINTN Pages\r
102 );\r
103\r
104/**\r
105 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
106\r
107 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
108 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
109 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
110 request, then NULL is returned.\r
8789c5e0 111 \r
fb3df220 112 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
1346352d 113 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().\r
fb3df220 114\r
115 @param Pages The number of 4 KB pages to allocate.\r
116 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
117 If Alignment is zero, then byte alignment is used.\r
118\r
119 @return A pointer to the allocated buffer or NULL if allocation fails.\r
120\r
121**/\r
122VOID *\r
123EFIAPI\r
124AllocateAlignedPages (\r
125 IN UINTN Pages,\r
126 IN UINTN Alignment\r
127 );\r
128\r
129/**\r
130 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r
131\r
132 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r
133 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
134 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
135 request, then NULL is returned.\r
8789c5e0 136 \r
fb3df220 137 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
1346352d 138 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().\r
fb3df220 139\r
140 @param Pages The number of 4 KB pages to allocate.\r
141 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
142 If Alignment is zero, then byte alignment is used.\r
143\r
144 @return A pointer to the allocated buffer or NULL if allocation fails.\r
145\r
146**/\r
147VOID *\r
148EFIAPI\r
149AllocateAlignedRuntimePages (\r
150 IN UINTN Pages,\r
151 IN UINTN Alignment\r
152 );\r
153\r
154/**\r
155 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
156\r
157 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r
158 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
159 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
160 request, then NULL is returned.\r
8789c5e0 161 \r
fb3df220 162 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
1346352d 163 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().\r
fb3df220 164\r
165 @param Pages The number of 4 KB pages to allocate.\r
166 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
167 If Alignment is zero, then byte alignment is used.\r
168\r
169 @return A pointer to the allocated buffer or NULL if allocation fails.\r
170\r
171**/\r
172VOID *\r
173EFIAPI\r
174AllocateAlignedReservedPages (\r
175 IN UINTN Pages,\r
176 IN UINTN Alignment\r
177 );\r
178\r
179/**\r
180 Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
181 allocation functions in the Memory Allocation Library.\r
182\r
183 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
184 must have been allocated on a previous call to the aligned page allocation services of the Memory\r
6e10b70a 185 Allocation Library. If it is not possible to free allocated pages, then this function will \r
446b94b0 186 perform no actions.\r
8789c5e0 187 \r
fb3df220 188 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
189 Library, then ASSERT().\r
190 If Pages is zero, then ASSERT().\r
191 \r
192 @param Buffer Pointer to the buffer of pages to free.\r
193 @param Pages The number of 4 KB pages to free.\r
194\r
195**/\r
196VOID\r
197EFIAPI\r
198FreeAlignedPages (\r
199 IN VOID *Buffer,\r
200 IN UINTN Pages\r
201 );\r
202\r
203/**\r
204 Allocates a buffer of type EfiBootServicesData.\r
205\r
206 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
207 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
208 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
209\r
210 @param AllocationSize The number of bytes to allocate.\r
211\r
212 @return A pointer to the allocated buffer or NULL if allocation fails.\r
213\r
214**/\r
215VOID *\r
216EFIAPI\r
217AllocatePool (\r
218 IN UINTN AllocationSize\r
219 );\r
220\r
221/**\r
222 Allocates a buffer of type EfiRuntimeServicesData.\r
223\r
224 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
225 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
226 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
227\r
228 @param AllocationSize The number of bytes to allocate.\r
229\r
230 @return A pointer to the allocated buffer or NULL if allocation fails.\r
231\r
232**/\r
233VOID *\r
234EFIAPI\r
235AllocateRuntimePool (\r
236 IN UINTN AllocationSize\r
237 );\r
238\r
239/**\r
8789c5e0 240 Allocates a buffer of type EfiReservedMemoryType.\r
fb3df220 241\r
8789c5e0 242 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns\r
fb3df220 243 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
244 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
245\r
246 @param AllocationSize The number of bytes to allocate.\r
247\r
248 @return A pointer to the allocated buffer or NULL if allocation fails.\r
249\r
250**/\r
251VOID *\r
252EFIAPI\r
253AllocateReservedPool (\r
254 IN UINTN AllocationSize\r
255 );\r
256\r
257/**\r
258 Allocates and zeros a buffer of type EfiBootServicesData.\r
259\r
260 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
261 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
262 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
263 request, then NULL is returned.\r
264\r
265 @param AllocationSize The number of bytes to allocate and zero.\r
266\r
267 @return A pointer to the allocated buffer or NULL if allocation fails.\r
268\r
269**/\r
270VOID *\r
271EFIAPI\r
272AllocateZeroPool (\r
273 IN UINTN AllocationSize\r
274 );\r
275\r
276/**\r
277 Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
278\r
279 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
280 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
281 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
282 request, then NULL is returned.\r
283\r
284 @param AllocationSize The number of bytes to allocate and zero.\r
285\r
286 @return A pointer to the allocated buffer or NULL if allocation fails.\r
287\r
288**/\r
289VOID *\r
290EFIAPI\r
291AllocateRuntimeZeroPool (\r
292 IN UINTN AllocationSize\r
293 );\r
294\r
295/**\r
296 Allocates and zeros a buffer of type EfiReservedMemoryType.\r
297\r
298 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
299 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
300 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
301 request, then NULL is returned.\r
302\r
303 @param AllocationSize The number of bytes to allocate and zero.\r
304\r
305 @return A pointer to the allocated buffer or NULL if allocation fails.\r
306\r
307**/\r
308VOID *\r
309EFIAPI\r
310AllocateReservedZeroPool (\r
311 IN UINTN AllocationSize\r
312 );\r
313\r
314/**\r
315 Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
316\r
317 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
318 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
319 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
320 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 321 \r
fb3df220 322 If Buffer is NULL, then ASSERT().\r
cc4e0485 323 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 324\r
325 @param AllocationSize The number of bytes to allocate and zero.\r
326 @param Buffer The buffer to copy to the allocated buffer.\r
327\r
328 @return A pointer to the allocated buffer or NULL if allocation fails.\r
329\r
330**/\r
331VOID *\r
332EFIAPI\r
333AllocateCopyPool (\r
334 IN UINTN AllocationSize,\r
335 IN CONST VOID *Buffer\r
336 );\r
337\r
338/**\r
339 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
340\r
341 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
342 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
343 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
344 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 345 \r
fb3df220 346 If Buffer is NULL, then ASSERT().\r
cc4e0485 347 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 348\r
349 @param AllocationSize The number of bytes to allocate and zero.\r
350 @param Buffer The buffer to copy to the allocated buffer.\r
351\r
352 @return A pointer to the allocated buffer or NULL if allocation fails.\r
353\r
354**/\r
355VOID *\r
356EFIAPI\r
357AllocateRuntimeCopyPool (\r
358 IN UINTN AllocationSize,\r
359 IN CONST VOID *Buffer\r
360 );\r
361\r
362/**\r
363 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
364\r
365 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
366 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
367 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
368 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 369 \r
fb3df220 370 If Buffer is NULL, then ASSERT().\r
cc4e0485 371 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 372\r
373 @param AllocationSize The number of bytes to allocate and zero.\r
374 @param Buffer The buffer to copy to the allocated buffer.\r
375\r
376 @return A pointer to the allocated buffer or NULL if allocation fails.\r
377\r
378**/\r
379VOID *\r
380EFIAPI\r
381AllocateReservedCopyPool (\r
382 IN UINTN AllocationSize,\r
383 IN CONST VOID *Buffer\r
384 );\r
385\r
c2390431 386/**\r
387 Reallocates a buffer of type EfiBootServicesData.\r
388\r
ab95d5f2 389 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 390 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and \r
391 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
392 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
393 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
394 enough memory remaining to satisfy the request, then NULL is returned.\r
395 \r
56304569 396 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r
397 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r
c2390431 398\r
399 @param OldSize The size, in bytes, of OldBuffer.\r
400 @param NewSize The size, in bytes, of the buffer to reallocate.\r
401 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
402 parameter that may be NULL.\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
409ReallocatePool (\r
410 IN UINTN OldSize,\r
411 IN UINTN NewSize,\r
412 IN VOID *OldBuffer OPTIONAL\r
413 );\r
414\r
415/**\r
416 Reallocates a buffer of type EfiRuntimeServicesData.\r
417\r
ab95d5f2 418 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 419 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and \r
420 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
421 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
422 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
423 enough memory remaining to satisfy the request, then NULL is returned.\r
2297186d 424\r
56304569 425 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r
426 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r
c2390431 427\r
428 @param OldSize The size, in bytes, of OldBuffer.\r
429 @param NewSize The size, in bytes, of the buffer to reallocate.\r
430 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
431 parameter that may be NULL.\r
432\r
433 @return A pointer to the allocated buffer or NULL if allocation fails.\r
434\r
435**/\r
436VOID *\r
437EFIAPI\r
438ReallocateRuntimePool (\r
439 IN UINTN OldSize,\r
440 IN UINTN NewSize,\r
441 IN VOID *OldBuffer OPTIONAL\r
442 );\r
443\r
444/**\r
445 Reallocates a buffer of type EfiReservedMemoryType.\r
446\r
ab95d5f2 447 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 448 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and \r
449 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
450 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
451 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
452 enough memory remaining to satisfy the request, then NULL is returned.\r
2297186d 453\r
56304569 454 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r
455 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r
c2390431 456\r
457 @param OldSize The size, in bytes, of OldBuffer.\r
458 @param NewSize The size, in bytes, of the buffer to reallocate.\r
459 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
460 parameter that may be NULL.\r
461\r
462 @return A pointer to the allocated buffer or NULL if allocation fails.\r
463\r
464**/\r
465VOID *\r
466EFIAPI\r
467ReallocateReservedPool (\r
468 IN UINTN OldSize,\r
469 IN UINTN NewSize,\r
470 IN VOID *OldBuffer OPTIONAL\r
471 );\r
472\r
fb3df220 473/**\r
474 Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
475 Memory Allocation Library.\r
476\r
477 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the\r
6e10b70a 478 pool allocation services of the Memory Allocation Library. If it is not possible to free pool\r
446b94b0 479 resources, then this function will perform no actions.\r
8789c5e0 480 \r
fb3df220 481 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
482 then ASSERT().\r
483\r
484 @param Buffer Pointer to the buffer to free.\r
485\r
486**/\r
487VOID\r
488EFIAPI\r
489FreePool (\r
490 IN VOID *Buffer\r
491 );\r
492\r
fb3df220 493#endif\r