-/*++\r
+/** @file \r
+\r
+ The file contains the GCD related services in the EFI Boot Services Table.\r
+ The GCD services are used to manage the memory and I/O regions that \r
+ are accessible to the CPU that is executing the DXE core.\r
\r
-Copyright (c) 2006, Intel Corporation \r
+Copyright (c) 2006 - 2008, Intel Corporation \r
All rights reserved. This program and the accompanying materials \r
are licensed and made available under the terms and conditions of the BSD License \r
which accompanies this distribution. The full text of the license may be found at \r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
\r
-Module Name:\r
-\r
- gcd.c\r
-\r
-Abstract:\r
- The file contains the GCD related services in the EFI Boot Services Table.\r
- The GCD services are used to manage the memory and I/O regions that \r
- are accessible to the CPU that is executing the DXE core.\r
-\r
---*/\r
+**/\r
\r
#include <DxeMain.h>\r
\r
\r
EFI_STATUS\r
CoreInitializeGcdServices (\r
- IN VOID **HobStart,\r
+ IN OUT VOID **HobStart,\r
IN EFI_PHYSICAL_ADDRESS MemoryBaseAddress,\r
IN UINT64 MemoryLength\r
)\r
memory map, so memory allocations and resource allocations can be made. The first\r
part of this function can not depend on any memory services until at least one\r
memory descriptor is provided to the memory services. Then the memory services\r
- can be used to intialize the GCD map.\r
+ can be used to intialize the GCD map. The HobStart will be relocated to a pool \r
+ buffer.\r
\r
Arguments:\r
\r
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
MemoryHob = Hob.MemoryAllocation;\r
BaseAddress = MemoryHob->AllocDescriptor.MemoryBaseAddress;\r
- Status = CoreAllocateMemorySpace (\r
- EfiGcdAllocateAddress,\r
- EfiGcdMemoryTypeSystemMemory, \r
- 0,\r
- MemoryHob->AllocDescriptor.MemoryLength,\r
- &BaseAddress,\r
- gDxeCoreImageHandle,\r
- NULL\r
- );\r
+ Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);\r
if (!EFI_ERROR (Status)) {\r
- Status = CoreGetMemorySpaceDescriptor (MemoryHob->AllocDescriptor.MemoryBaseAddress, &Descriptor);\r
- if (!EFI_ERROR (Status)) {\r
+ Status = CoreAllocateMemorySpace (\r
+ EfiGcdAllocateAddress,\r
+ Descriptor.GcdMemoryType, \r
+ 0,\r
+ MemoryHob->AllocDescriptor.MemoryLength,\r
+ &BaseAddress,\r
+ gDxeCoreImageHandle,\r
+ NULL\r
+ );\r
+ if (!EFI_ERROR (Status) && Descriptor.GcdMemoryType == EfiGcdMemoryTypeSystemMemory) {\r
CoreAddMemoryDescriptor (\r
MemoryHob->AllocDescriptor.MemoryType,\r
MemoryHob->AllocDescriptor.MemoryBaseAddress,\r
ASSERT (NewHobList != NULL);\r
\r
*HobStart = NewHobList;\r
+ gHobList = NewHobList;\r
\r
//\r
// Add and allocate the remaining unallocated system memory to the memory services.\r
if (MemorySpaceMap[Index].ImageHandle == NULL) {\r
BaseAddress = PageAlignAddress (MemorySpaceMap[Index].BaseAddress);\r
Length = PageAlignLength (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - BaseAddress);\r
+ if (Length == 0 || MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress) {\r
+ continue;\r
+ }\r
CoreAddMemoryDescriptor (\r
EfiConventionalMemory,\r
BaseAddress,\r