@@ -391,26 +391,20 @@ CoreFreeMemoryMapStack (
391391
392392EFI_STATUS
393393AcceptMemoryResource (
394- IN UINTN Type ,
394+ IN EFI_ALLOCATE_TYPE Type ,
395395 IN UINTN AcceptSize ,
396396 IN OUT EFI_PHYSICAL_ADDRESS * Memory
397397 )
398398{
399399 LIST_ENTRY * Link ;
400400 EFI_GCD_MAP_ENTRY * GcdEntry ;
401- EFI_PHYSICAL_ADDRESS UnacceptedEntryBase ;
402- UINTN UnacceptedEntryEnd ;
403- UINTN UnacceptedEntryLength ;
404- UINTN UnacceptedEntryCapability ;
401+ EFI_GCD_MAP_ENTRY UnacceptedEntry ;
405402 MEMORY_ACCEPT_PROTOCOL * MemoryAcceptProtocol ;
406403 UINTN Start ;
407404 UINTN End ;
408405 EFI_STATUS Status ;
409406
410- Status = EFI_OUT_OF_RESOURCES ;
411- UnacceptedEntryBase = 0 ;
412- UnacceptedEntryEnd = 0 ;
413- AcceptSize = (AcceptSize + SIZE_32MB - 1 ) & ~(SIZE_32MB - 1 );
407+ AcceptSize = (AcceptSize + SIZE_32MB - 1 ) & ~(SIZE_32MB - 1 );
414408
415409 if (AcceptSize == 0 ) {
416410 return EFI_INVALID_PARAMETER ;
@@ -427,6 +421,7 @@ AcceptMemoryResource (
427421 }
428422
429423 if (Type == AllocateMaxAddress ) {
424+
430425 if (* Memory < EFI_PAGE_MASK ) {
431426 return EFI_INVALID_PARAMETER ;
432427 }
@@ -458,6 +453,7 @@ AcceptMemoryResource (
458453 GcdEntry = CR (Link , EFI_GCD_MAP_ENTRY , Link , EFI_GCD_MAP_SIGNATURE );
459454
460455 if (GcdEntry -> GcdMemoryType == EfiGcdMemoryTypeUnaccepted ) {
456+
461457 if (Type == AllocateMaxAddress ) {
462458 if (GcdEntry -> BaseAddress + AcceptSize - 1 > * Memory ) {
463459 continue ;
@@ -468,15 +464,13 @@ AcceptMemoryResource (
468464 }
469465 }
470466
471- UnacceptedEntryBase = GcdEntry -> BaseAddress ;
472- UnacceptedEntryEnd = GcdEntry -> EndAddress ;
473- UnacceptedEntryLength = GcdEntry -> EndAddress - GcdEntry -> BaseAddress + 1 ;
474- UnacceptedEntryCapability = GcdEntry -> Capabilities ;
467+ UnacceptedEntry = * GcdEntry ;
468+
475469 //
476470 // Remove the target memory space from GCD.
477471 //
478- if (AcceptSize <= UnacceptedEntryLength ) {
479- CoreRemoveMemorySpace (GcdEntry -> BaseAddress , UnacceptedEntryLength );
472+ if (AcceptSize <= UnacceptedEntry . EndAddress - UnacceptedEntry . BaseAddress + 1 ) {
473+ CoreRemoveMemorySpace (GcdEntry -> BaseAddress , UnacceptedEntry . EndAddress - UnacceptedEntry . BaseAddress + 1 );
480474
481475 if (Type != AllocateAddress ) {
482476 Start = GcdEntry -> BaseAddress ;
@@ -500,16 +494,21 @@ AcceptMemoryResource (
500494 return EFI_OUT_OF_RESOURCES ;
501495 }
502496
497+ //
498+ // Fix me! CoreAddMemorySpace() should not be called in the allocation process
499+ // because it will allocate memory for GCD map entry.
500+ //
501+
503502 //
504503 // Add the remain lower part of unaccepted memory to the
505504 // Gcd memory space and memory map.
506505 //
507- if (Start > UnacceptedEntryBase ) {
506+ if (Start > UnacceptedEntry . BaseAddress ) {
508507 CoreAddMemorySpace (
509508 EfiGcdMemoryTypeUnaccepted ,
510- UnacceptedEntryBase ,
511- Start - UnacceptedEntryBase ,
512- UnacceptedEntryCapability
509+ UnacceptedEntry . BaseAddress ,
510+ Start - UnacceptedEntry . BaseAddress ,
511+ UnacceptedEntry . Capabilities
513512 );
514513 }
515514
@@ -528,12 +527,12 @@ AcceptMemoryResource (
528527 // Add the remain higher part of unaccepted memory to the
529528 // Gcd memory space and memory map.
530529 //
531- if (UnacceptedEntryEnd > End ) {
530+ if (UnacceptedEntry . EndAddress > End ) {
532531 CoreAddMemorySpace (
533532 EfiGcdMemoryTypeUnaccepted ,
534533 End + 1 ,
535- UnacceptedEntryEnd - End ,
536- UnacceptedEntryCapability
534+ UnacceptedEntry . EndAddress - End ,
535+ UnacceptedEntry . Capabilities
537536 );
538537 }
539538
@@ -2193,7 +2192,6 @@ CoreAllocatePoolPages (
21932192 )
21942193{
21952194 UINT64 Start ;
2196-
21972195 //
21982196 // Find the pages to convert
21992197 //
0 commit comments