/** @file\r
*\r
-* Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
+* Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
\r
#include "BdsInternal.h"\r
\r
-#include <Library/HobLib.h>\r
-#include <Library/TimerLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/SerialPortLib.h>\r
-\r
-STATIC CHAR8 *mTokenList[] = {\r
- /*"SEC",*/\r
- "PEI",\r
- "DXE",\r
- "BDS",\r
- NULL\r
-};\r
-\r
EFI_STATUS\r
ShutdownUefiBootServices (\r
VOID\r
return EFI_SUCCESS;\r
}\r
\r
-STATIC\r
-EFI_STATUS\r
-InsertSystemMemoryResources (\r
- LIST_ENTRY *ResourceList,\r
- EFI_HOB_RESOURCE_DESCRIPTOR *ResHob\r
- )\r
-{\r
- BDS_SYSTEM_MEMORY_RESOURCE *NewResource;\r
- LIST_ENTRY *Link;\r
- LIST_ENTRY *NextLink;\r
- LIST_ENTRY AttachedResources;\r
- BDS_SYSTEM_MEMORY_RESOURCE *Resource;\r
- EFI_PHYSICAL_ADDRESS NewResourceEnd;\r
-\r
- if (IsListEmpty (ResourceList)) {\r
- NewResource = AllocateZeroPool (sizeof(BDS_SYSTEM_MEMORY_RESOURCE));\r
- NewResource->PhysicalStart = ResHob->PhysicalStart;\r
- NewResource->ResourceLength = ResHob->ResourceLength;\r
- InsertTailList (ResourceList, &NewResource->Link);\r
- return EFI_SUCCESS;\r
- }\r
-\r
- InitializeListHead (&AttachedResources);\r
-\r
- Link = ResourceList->ForwardLink;\r
- ASSERT (Link != NULL);\r
- while (Link != ResourceList) {\r
- Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;\r
-\r
- // Sanity Check. The resources should not overlapped.\r
- ASSERT(!((ResHob->PhysicalStart >= Resource->PhysicalStart) && (ResHob->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))));\r
- ASSERT(!((ResHob->PhysicalStart + ResHob->ResourceLength - 1 >= Resource->PhysicalStart) &&\r
- ((ResHob->PhysicalStart + ResHob->ResourceLength - 1) < (Resource->PhysicalStart + Resource->ResourceLength))));\r
-\r
- // The new resource is attached after this resource descriptor\r
- if (ResHob->PhysicalStart == Resource->PhysicalStart + Resource->ResourceLength) {\r
- Resource->ResourceLength = Resource->ResourceLength + ResHob->ResourceLength;\r
-\r
- NextLink = RemoveEntryList (&Resource->Link);\r
- InsertTailList (&AttachedResources, &Resource->Link);\r
- Link = NextLink;\r
- }\r
- // The new resource is attached before this resource descriptor\r
- else if (ResHob->PhysicalStart + ResHob->ResourceLength == Resource->PhysicalStart) {\r
- Resource->PhysicalStart = ResHob->PhysicalStart;\r
- Resource->ResourceLength = Resource->ResourceLength + ResHob->ResourceLength;\r
-\r
- NextLink = RemoveEntryList (&Resource->Link);\r
- InsertTailList (&AttachedResources, &Resource->Link);\r
- Link = NextLink;\r
- } else {\r
- Link = Link->ForwardLink;\r
- }\r
- }\r
-\r
- if (!IsListEmpty (&AttachedResources)) {\r
- // See if we can merge the attached resource with other resources\r
-\r
- NewResource = (BDS_SYSTEM_MEMORY_RESOURCE*)GetFirstNode (&AttachedResources);\r
- Link = RemoveEntryList (&NewResource->Link);\r
- while (!IsListEmpty (&AttachedResources)) {\r
- // Merge resources\r
- Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)Link;\r
-\r
- // Ensure they overlap each other\r
- ASSERT(\r
- ((NewResource->PhysicalStart >= Resource->PhysicalStart) && (NewResource->PhysicalStart < (Resource->PhysicalStart + Resource->ResourceLength))) ||\r
- (((NewResource->PhysicalStart + NewResource->ResourceLength) >= Resource->PhysicalStart) && ((NewResource->PhysicalStart + NewResource->ResourceLength) < (Resource->PhysicalStart + Resource->ResourceLength)))\r
- );\r
-\r
- NewResourceEnd = MAX (NewResource->PhysicalStart + NewResource->ResourceLength, Resource->PhysicalStart + Resource->ResourceLength);\r
- NewResource->PhysicalStart = MIN (NewResource->PhysicalStart, Resource->PhysicalStart);\r
- NewResource->ResourceLength = NewResourceEnd - NewResource->PhysicalStart;\r
-\r
- Link = RemoveEntryList (Link);\r
- }\r
- } else {\r
- // None of the Resource of the list is attached to this ResHob. Create a new entry for it\r
- NewResource = AllocateZeroPool (sizeof(BDS_SYSTEM_MEMORY_RESOURCE));\r
- NewResource->PhysicalStart = ResHob->PhysicalStart;\r
- NewResource->ResourceLength = ResHob->ResourceLength;\r
- }\r
- InsertTailList (ResourceList, &NewResource->Link);\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetSystemMemoryResources (\r
- IN LIST_ENTRY *ResourceList\r
- )\r
-{\r
- EFI_HOB_RESOURCE_DESCRIPTOR *ResHob;\r
-\r
- InitializeListHead (ResourceList);\r
-\r
- // Find the first System Memory Resource Descriptor\r
- ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);\r
- while ((ResHob != NULL) && (ResHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY)) {\r
- ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
- }\r
-\r
- // Did not find any\r
- if (ResHob == NULL) {\r
- return EFI_NOT_FOUND;\r
- } else {\r
- InsertSystemMemoryResources (ResourceList, ResHob);\r
- }\r
-\r
- ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
- while (ResHob != NULL) {\r
- if (ResHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
- InsertSystemMemoryResources (ResourceList, ResHob);\r
- }\r
- ResHob = (EFI_HOB_RESOURCE_DESCRIPTOR *)GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,(VOID *)((UINTN)ResHob + ResHob->Header.HobLength));\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-PrintPerformance (\r
- VOID\r
- )\r
-{\r
- UINTN Key;\r
- CONST VOID *Handle;\r
- CONST CHAR8 *Token, *Module;\r
- UINT64 Start, Stop, TimeStamp;\r
- UINT64 Delta, TicksPerSecond, Milliseconds;\r
- UINTN Index;\r
- CHAR8 Buffer[100];\r
- UINTN CharCount;\r
- BOOLEAN CountUp;\r
-\r
- TicksPerSecond = GetPerformanceCounterProperties (&Start, &Stop);\r
- if (Start < Stop) {\r
- CountUp = TRUE;\r
- } else {\r
- CountUp = FALSE;\r
- }\r
-\r
- TimeStamp = 0;\r
- Key = 0;\r
- do {\r
- Key = GetPerformanceMeasurement (Key, (CONST VOID **)&Handle, &Token, &Module, &Start, &Stop);\r
- if (Key != 0) {\r
- for (Index = 0; mTokenList[Index] != NULL; Index++) {\r
- if (AsciiStriCmp (mTokenList[Index], Token) == 0) {\r
- Delta = CountUp?(Stop - Start):(Start - Stop);\r
- TimeStamp += Delta;\r
- Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);\r
- CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"%6a %6ld ms\n", Token, Milliseconds);\r
- SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
- break;\r
- }\r
- }\r
- }\r
- } while (Key != 0);\r
-\r
- CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Total Time = %ld ms\n\n", DivU64x64Remainder (MultU64x32 (TimeStamp, 1000), TicksPerSecond, NULL));\r
- SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
-}\r
-\r
EFI_STATUS\r
GetGlobalEnvironmentVariable (\r
IN CONST CHAR16* VariableName,\r