]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Mem/Pool.c
MdeModulePkg/DxeCore: implement memory protection policy
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / Pool.c
1 /** @file
2 UEFI Memory pool management functions.
3
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DxeMain.h"
16 #include "Imem.h"
17
18 STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
19
20 #define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
21 typedef struct {
22 UINT32 Signature;
23 UINT32 Index;
24 LIST_ENTRY Link;
25 } POOL_FREE;
26
27
28 #define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
29 typedef struct {
30 UINT32 Signature;
31 UINT32 Reserved;
32 EFI_MEMORY_TYPE Type;
33 UINTN Size;
34 CHAR8 Data[1];
35 } POOL_HEAD;
36
37 #define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
38
39 #define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
40 typedef struct {
41 UINT32 Signature;
42 UINT32 Reserved;
43 UINTN Size;
44 } POOL_TAIL;
45
46 #define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
47
48 #define HEAD_TO_TAIL(a) \
49 ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
50
51 //
52 // Each element is the sum of the 2 previous ones: this allows us to migrate
53 // blocks between bins by splitting them up, while not wasting too much memory
54 // as we would in a strict power-of-2 sequence
55 //
56 STATIC CONST UINT16 mPoolSizeTable[] = {
57 128, 256, 384, 640, 1024, 1664, 2688, 4352, 7040, 11392, 18432, 29824
58 };
59
60 #define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
61 #define LIST_TO_SIZE(a) (mPoolSizeTable [a])
62
63 #define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
64
65 #define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
66
67 //
68 // Globals
69 //
70
71 #define POOL_SIGNATURE SIGNATURE_32('p','l','s','t')
72 typedef struct {
73 INTN Signature;
74 UINTN Used;
75 EFI_MEMORY_TYPE MemoryType;
76 LIST_ENTRY FreeList[MAX_POOL_LIST];
77 LIST_ENTRY Link;
78 } POOL;
79
80 //
81 // Pool header for each memory type.
82 //
83 POOL mPoolHead[EfiMaxMemoryType];
84
85 //
86 // List of pool header to search for the appropriate memory type.
87 //
88 LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
89
90 /**
91 Get pool size table index from the specified size.
92
93 @param Size The specified size to get index from pool table.
94
95 @return The index of pool size table.
96
97 **/
98 STATIC
99 UINTN
100 GetPoolIndexFromSize (
101 UINTN Size
102 )
103 {
104 UINTN Index;
105
106 for (Index = 0; Index < MAX_POOL_LIST; Index++) {
107 if (mPoolSizeTable [Index] >= Size) {
108 return Index;
109 }
110 }
111 return MAX_POOL_LIST;
112 }
113
114 /**
115 Called to initialize the pool.
116
117 **/
118 VOID
119 CoreInitializePool (
120 VOID
121 )
122 {
123 UINTN Type;
124 UINTN Index;
125
126 for (Type=0; Type < EfiMaxMemoryType; Type++) {
127 mPoolHead[Type].Signature = 0;
128 mPoolHead[Type].Used = 0;
129 mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE) Type;
130 for (Index=0; Index < MAX_POOL_LIST; Index++) {
131 InitializeListHead (&mPoolHead[Type].FreeList[Index]);
132 }
133 }
134 }
135
136
137 /**
138 Look up pool head for specified memory type.
139
140 @param MemoryType Memory type of which pool head is looked for
141
142 @return Pointer of Corresponding pool head.
143
144 **/
145 POOL *
146 LookupPoolHead (
147 IN EFI_MEMORY_TYPE MemoryType
148 )
149 {
150 LIST_ENTRY *Link;
151 POOL *Pool;
152 UINTN Index;
153
154 if ((UINT32)MemoryType < EfiMaxMemoryType) {
155 return &mPoolHead[MemoryType];
156 }
157
158 //
159 // MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI
160 // OS loaders that are provided by operating system vendors.
161 // MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.
162 //
163 if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
164
165 for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) {
166 Pool = CR(Link, POOL, Link, POOL_SIGNATURE);
167 if (Pool->MemoryType == MemoryType) {
168 return Pool;
169 }
170 }
171
172 Pool = CoreAllocatePoolI (EfiBootServicesData, sizeof (POOL));
173 if (Pool == NULL) {
174 return NULL;
175 }
176
177 Pool->Signature = POOL_SIGNATURE;
178 Pool->Used = 0;
179 Pool->MemoryType = MemoryType;
180 for (Index=0; Index < MAX_POOL_LIST; Index++) {
181 InitializeListHead (&Pool->FreeList[Index]);
182 }
183
184 InsertHeadList (&mPoolHeadList, &Pool->Link);
185
186 return Pool;
187 }
188
189 return NULL;
190 }
191
192
193
194 /**
195 Allocate pool of a particular type.
196
197 @param PoolType Type of pool to allocate
198 @param Size The amount of pool to allocate
199 @param Buffer The address to return a pointer to the allocated
200 pool
201
202 @retval EFI_INVALID_PARAMETER Buffer is NULL.
203 PoolType is in the range EfiMaxMemoryType..0x6FFFFFFF.
204 PoolType is EfiPersistentMemory.
205 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
206 @retval EFI_SUCCESS Pool successfully allocated.
207
208 **/
209 EFI_STATUS
210 EFIAPI
211 CoreInternalAllocatePool (
212 IN EFI_MEMORY_TYPE PoolType,
213 IN UINTN Size,
214 OUT VOID **Buffer
215 )
216 {
217 EFI_STATUS Status;
218
219 //
220 // If it's not a valid type, fail it
221 //
222 if ((PoolType >= EfiMaxMemoryType && PoolType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
223 (PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) {
224 return EFI_INVALID_PARAMETER;
225 }
226
227 if (Buffer == NULL) {
228 return EFI_INVALID_PARAMETER;
229 }
230
231 *Buffer = NULL;
232
233 //
234 // If size is too large, fail it
235 // Base on the EFI spec, return status of EFI_OUT_OF_RESOURCES
236 //
237 if (Size > MAX_POOL_SIZE) {
238 return EFI_OUT_OF_RESOURCES;
239 }
240
241 //
242 // Acquire the memory lock and make the allocation
243 //
244 Status = CoreAcquireLockOrFail (&mPoolMemoryLock);
245 if (EFI_ERROR (Status)) {
246 return EFI_OUT_OF_RESOURCES;
247 }
248
249 *Buffer = CoreAllocatePoolI (PoolType, Size);
250 CoreReleaseLock (&mPoolMemoryLock);
251 return (*Buffer != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
252 }
253
254 /**
255 Allocate pool of a particular type.
256
257 @param PoolType Type of pool to allocate
258 @param Size The amount of pool to allocate
259 @param Buffer The address to return a pointer to the allocated
260 pool
261
262 @retval EFI_INVALID_PARAMETER Buffer is NULL.
263 PoolType is in the range EfiMaxMemoryType..0x6FFFFFFF.
264 PoolType is EfiPersistentMemory.
265 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
266 @retval EFI_SUCCESS Pool successfully allocated.
267
268 **/
269 EFI_STATUS
270 EFIAPI
271 CoreAllocatePool (
272 IN EFI_MEMORY_TYPE PoolType,
273 IN UINTN Size,
274 OUT VOID **Buffer
275 )
276 {
277 EFI_STATUS Status;
278
279 Status = CoreInternalAllocatePool (PoolType, Size, Buffer);
280 if (!EFI_ERROR (Status)) {
281 CoreUpdateProfile (
282 (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
283 MemoryProfileActionAllocatePool,
284 PoolType,
285 Size,
286 *Buffer,
287 NULL
288 );
289 InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
290 }
291 return Status;
292 }
293
294 STATIC
295 VOID *
296 CoreAllocatePoolPagesI (
297 IN EFI_MEMORY_TYPE PoolType,
298 IN UINTN NoPages,
299 IN UINTN Granularity
300 )
301 {
302 VOID *Buffer;
303 EFI_STATUS Status;
304
305 Status = CoreAcquireLockOrFail (&gMemoryLock);
306 if (EFI_ERROR (Status)) {
307 return NULL;
308 }
309
310 Buffer = CoreAllocatePoolPages (PoolType, NoPages, Granularity);
311 CoreReleaseMemoryLock ();
312
313 if (Buffer != NULL) {
314 ApplyMemoryProtectionPolicy (EfiConventionalMemory, PoolType,
315 (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (NoPages));
316 }
317 return Buffer;
318 }
319
320 /**
321 Internal function to allocate pool of a particular type.
322 Caller must have the memory lock held
323
324 @param PoolType Type of pool to allocate
325 @param Size The amount of pool to allocate
326
327 @return The allocate pool, or NULL
328
329 **/
330 VOID *
331 CoreAllocatePoolI (
332 IN EFI_MEMORY_TYPE PoolType,
333 IN UINTN Size
334 )
335 {
336 POOL *Pool;
337 POOL_FREE *Free;
338 POOL_HEAD *Head;
339 POOL_TAIL *Tail;
340 CHAR8 *NewPage;
341 VOID *Buffer;
342 UINTN Index;
343 UINTN FSize;
344 UINTN Offset, MaxOffset;
345 UINTN NoPages;
346 UINTN Granularity;
347
348 ASSERT_LOCKED (&mPoolMemoryLock);
349
350 if (PoolType == EfiACPIReclaimMemory ||
351 PoolType == EfiACPIMemoryNVS ||
352 PoolType == EfiRuntimeServicesCode ||
353 PoolType == EfiRuntimeServicesData) {
354
355 Granularity = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
356 } else {
357 Granularity = DEFAULT_PAGE_ALLOCATION;
358 }
359
360 //
361 // Adjust the size by the pool header & tail overhead
362 //
363
364 //
365 // Adjusting the Size to be of proper alignment so that
366 // we don't get an unaligned access fault later when
367 // pool_Tail is being initialized
368 //
369 Size = ALIGN_VARIABLE (Size);
370
371 Size += POOL_OVERHEAD;
372 Index = SIZE_TO_LIST(Size);
373 Pool = LookupPoolHead (PoolType);
374 if (Pool== NULL) {
375 return NULL;
376 }
377 Head = NULL;
378
379 //
380 // If allocation is over max size, just allocate pages for the request
381 // (slow)
382 //
383 if (Index >= SIZE_TO_LIST (Granularity)) {
384 NoPages = EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
385 NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
386 Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity);
387 goto Done;
388 }
389
390 //
391 // If there's no free pool in the proper list size, go get some more pages
392 //
393 if (IsListEmpty (&Pool->FreeList[Index])) {
394
395 Offset = LIST_TO_SIZE (Index);
396 MaxOffset = Granularity;
397
398 //
399 // Check the bins holding larger blocks, and carve one up if needed
400 //
401 while (++Index < SIZE_TO_LIST (Granularity)) {
402 if (!IsListEmpty (&Pool->FreeList[Index])) {
403 Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
404 RemoveEntryList (&Free->Link);
405 NewPage = (VOID *) Free;
406 MaxOffset = LIST_TO_SIZE (Index);
407 goto Carve;
408 }
409 }
410
411 //
412 // Get another page
413 //
414 NewPage = CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES (Granularity), Granularity);
415 if (NewPage == NULL) {
416 goto Done;
417 }
418
419 //
420 // Serve the allocation request from the head of the allocated block
421 //
422 Carve:
423 Head = (POOL_HEAD *) NewPage;
424
425 //
426 // Carve up remaining space into free pool blocks
427 //
428 Index--;
429 while (Offset < MaxOffset) {
430 ASSERT (Index < MAX_POOL_LIST);
431 FSize = LIST_TO_SIZE(Index);
432
433 while (Offset + FSize <= MaxOffset) {
434 Free = (POOL_FREE *) &NewPage[Offset];
435 Free->Signature = POOL_FREE_SIGNATURE;
436 Free->Index = (UINT32)Index;
437 InsertHeadList (&Pool->FreeList[Index], &Free->Link);
438 Offset += FSize;
439 }
440 Index -= 1;
441 }
442
443 ASSERT (Offset == MaxOffset);
444 goto Done;
445 }
446
447 //
448 // Remove entry from free pool list
449 //
450 Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
451 RemoveEntryList (&Free->Link);
452
453 Head = (POOL_HEAD *) Free;
454
455 Done:
456 Buffer = NULL;
457
458 if (Head != NULL) {
459
460 //
461 // If we have a pool buffer, fill in the header & tail info
462 //
463 Head->Signature = POOL_HEAD_SIGNATURE;
464 Head->Size = Size;
465 Head->Type = (EFI_MEMORY_TYPE) PoolType;
466 Tail = HEAD_TO_TAIL (Head);
467 Tail->Signature = POOL_TAIL_SIGNATURE;
468 Tail->Size = Size;
469 Buffer = Head->Data;
470 DEBUG_CLEAR_MEMORY (Buffer, Size - POOL_OVERHEAD);
471
472 DEBUG ((
473 DEBUG_POOL,
474 "AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,
475 Buffer,
476 (UINT64)(Size - POOL_OVERHEAD),
477 (UINT64) Pool->Used
478 ));
479
480 //
481 // Account the allocation
482 //
483 Pool->Used += Size;
484
485 } else {
486 DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64) Size));
487 }
488
489 return Buffer;
490 }
491
492
493
494 /**
495 Frees pool.
496
497 @param Buffer The allocated pool entry to free
498 @param PoolType Pointer to pool type
499
500 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
501 @retval EFI_SUCCESS Pool successfully freed.
502
503 **/
504 EFI_STATUS
505 EFIAPI
506 CoreInternalFreePool (
507 IN VOID *Buffer,
508 OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
509 )
510 {
511 EFI_STATUS Status;
512
513 if (Buffer == NULL) {
514 return EFI_INVALID_PARAMETER;
515 }
516
517 CoreAcquireLock (&mPoolMemoryLock);
518 Status = CoreFreePoolI (Buffer, PoolType);
519 CoreReleaseLock (&mPoolMemoryLock);
520 return Status;
521 }
522
523 /**
524 Frees pool.
525
526 @param Buffer The allocated pool entry to free
527
528 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
529 @retval EFI_SUCCESS Pool successfully freed.
530
531 **/
532 EFI_STATUS
533 EFIAPI
534 CoreFreePool (
535 IN VOID *Buffer
536 )
537 {
538 EFI_STATUS Status;
539 EFI_MEMORY_TYPE PoolType;
540
541 Status = CoreInternalFreePool (Buffer, &PoolType);
542 if (!EFI_ERROR (Status)) {
543 CoreUpdateProfile (
544 (EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
545 MemoryProfileActionFreePool,
546 PoolType,
547 0,
548 Buffer,
549 NULL
550 );
551 InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
552 }
553 return Status;
554 }
555
556 STATIC
557 VOID
558 CoreFreePoolPagesI (
559 IN EFI_MEMORY_TYPE PoolType,
560 IN EFI_PHYSICAL_ADDRESS Memory,
561 IN UINTN NoPages
562 )
563 {
564 CoreAcquireMemoryLock ();
565 CoreFreePoolPages (Memory, NoPages);
566 CoreReleaseMemoryLock ();
567
568 ApplyMemoryProtectionPolicy (PoolType, EfiConventionalMemory,
569 (EFI_PHYSICAL_ADDRESS)(UINTN)Memory, EFI_PAGES_TO_SIZE (NoPages));
570 }
571
572 /**
573 Internal function to free a pool entry.
574 Caller must have the memory lock held
575
576 @param Buffer The allocated pool entry to free
577 @param PoolType Pointer to pool type
578
579 @retval EFI_INVALID_PARAMETER Buffer not valid
580 @retval EFI_SUCCESS Buffer successfully freed.
581
582 **/
583 EFI_STATUS
584 CoreFreePoolI (
585 IN VOID *Buffer,
586 OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
587 )
588 {
589 POOL *Pool;
590 POOL_HEAD *Head;
591 POOL_TAIL *Tail;
592 POOL_FREE *Free;
593 UINTN Index;
594 UINTN NoPages;
595 UINTN Size;
596 CHAR8 *NewPage;
597 UINTN Offset;
598 BOOLEAN AllFree;
599 UINTN Granularity;
600
601 ASSERT(Buffer != NULL);
602 //
603 // Get the head & tail of the pool entry
604 //
605 Head = CR (Buffer, POOL_HEAD, Data, POOL_HEAD_SIGNATURE);
606 ASSERT(Head != NULL);
607
608 if (Head->Signature != POOL_HEAD_SIGNATURE) {
609 return EFI_INVALID_PARAMETER;
610 }
611
612 Tail = HEAD_TO_TAIL (Head);
613 ASSERT(Tail != NULL);
614
615 //
616 // Debug
617 //
618 ASSERT (Tail->Signature == POOL_TAIL_SIGNATURE);
619 ASSERT (Head->Size == Tail->Size);
620 ASSERT_LOCKED (&mPoolMemoryLock);
621
622 if (Tail->Signature != POOL_TAIL_SIGNATURE) {
623 return EFI_INVALID_PARAMETER;
624 }
625
626 if (Head->Size != Tail->Size) {
627 return EFI_INVALID_PARAMETER;
628 }
629
630 //
631 // Determine the pool type and account for it
632 //
633 Size = Head->Size;
634 Pool = LookupPoolHead (Head->Type);
635 if (Pool == NULL) {
636 return EFI_INVALID_PARAMETER;
637 }
638 Pool->Used -= Size;
639 DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64) Pool->Used));
640
641 if (Head->Type == EfiACPIReclaimMemory ||
642 Head->Type == EfiACPIMemoryNVS ||
643 Head->Type == EfiRuntimeServicesCode ||
644 Head->Type == EfiRuntimeServicesData) {
645
646 Granularity = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
647 } else {
648 Granularity = DEFAULT_PAGE_ALLOCATION;
649 }
650
651 if (PoolType != NULL) {
652 *PoolType = Head->Type;
653 }
654
655 //
656 // Determine the pool list
657 //
658 Index = SIZE_TO_LIST(Size);
659 DEBUG_CLEAR_MEMORY (Head, Size);
660
661 //
662 // If it's not on the list, it must be pool pages
663 //
664 if (Index >= SIZE_TO_LIST (Granularity)) {
665
666 //
667 // Return the memory pages back to free memory
668 //
669 NoPages = EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
670 NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
671 CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) (UINTN) Head, NoPages);
672
673 } else {
674
675 //
676 // Put the pool entry onto the free pool list
677 //
678 Free = (POOL_FREE *) Head;
679 ASSERT(Free != NULL);
680 Free->Signature = POOL_FREE_SIGNATURE;
681 Free->Index = (UINT32)Index;
682 InsertHeadList (&Pool->FreeList[Index], &Free->Link);
683
684 //
685 // See if all the pool entries in the same page as Free are freed pool
686 // entries
687 //
688 NewPage = (CHAR8 *)((UINTN)Free & ~(Granularity - 1));
689 Free = (POOL_FREE *) &NewPage[0];
690 ASSERT(Free != NULL);
691
692 if (Free->Signature == POOL_FREE_SIGNATURE) {
693
694 AllFree = TRUE;
695 Offset = 0;
696
697 while ((Offset < Granularity) && (AllFree)) {
698 Free = (POOL_FREE *) &NewPage[Offset];
699 ASSERT(Free != NULL);
700 if (Free->Signature != POOL_FREE_SIGNATURE) {
701 AllFree = FALSE;
702 }
703 Offset += LIST_TO_SIZE(Free->Index);
704 }
705
706 if (AllFree) {
707
708 //
709 // All of the pool entries in the same page as Free are free pool
710 // entries
711 // Remove all of these pool entries from the free loop lists.
712 //
713 Free = (POOL_FREE *) &NewPage[0];
714 ASSERT(Free != NULL);
715 Offset = 0;
716
717 while (Offset < Granularity) {
718 Free = (POOL_FREE *) &NewPage[Offset];
719 ASSERT(Free != NULL);
720 RemoveEntryList (&Free->Link);
721 Offset += LIST_TO_SIZE(Free->Index);
722 }
723
724 //
725 // Free the page
726 //
727 CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) (UINTN)NewPage,
728 EFI_SIZE_TO_PAGES (Granularity));
729 }
730 }
731 }
732
733 //
734 // If this is an OS/OEM specific memory type, then check to see if the last
735 // portion of that memory type has been freed. If it has, then free the
736 // list entry for that memory type
737 //
738 if (((UINT32) Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && Pool->Used == 0) {
739 RemoveEntryList (&Pool->Link);
740 CoreFreePoolI (Pool, NULL);
741 }
742
743 return EFI_SUCCESS;
744 }
745