/** @file\r
Support routines for SMRAM profile.\r
\r
- Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
- 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
- http://opensource.org/licenses/bsd-license.php.\r
-\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
+ Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
};\r
GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mSmramProfileContextPtr = NULL;\r
\r
-BOOLEAN mSmramReadyToLock;\r
-BOOLEAN mSmramProfileGettingStatus = FALSE;\r
-BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;\r
-EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath;\r
-UINTN mSmramProfileDriverPathSize;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramReadyToLock;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileGettingStatus = FALSE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mSmramProfileDriverPath;\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmramProfileDriverPathSize;\r
\r
/**\r
- Dump SMRAM infromation.\r
+ Dump SMRAM information.\r
\r
**/\r
VOID\r
@param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer.\r
On return, points to the size of the data returned in ProfileBuffer.\r
@param[out] ProfileBuffer Profile buffer.\r
- \r
+\r
@return EFI_SUCCESS Get the memory profile data successfully.\r
@return EFI_UNSUPPORTED Memory profile is unsupported.\r
- @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. \r
+ @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data.\r
ProfileSize is updated with the size required.\r
\r
**/\r
IN CHAR8 *ActionString OPTIONAL\r
);\r
\r
-EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_SMM_MEMORY_PROFILE_PROTOCOL mSmmProfileProtocol = {\r
SmramProfileProtocolGetData,\r
SmramProfileProtocolRegisterImage,\r
SmramProfileProtocolUnregisterImage,\r
return mSmramProfileContextPtr;\r
}\r
\r
-/**\r
- Retrieves the magic value from the PE/COFF header.\r
-\r
- @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
-\r
- @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32\r
- @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+\r
-\r
-**/\r
-UINT16\r
-InternalPeCoffGetPeHeaderMagicValue (\r
- IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
- )\r
-{\r
- //\r
- // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value\r
- // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the\r
- // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
- // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
- //\r
- if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
- return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
- }\r
- //\r
- // Return the magic value from the PC/COFF Optional Header\r
- //\r
- return Hdr.Pe32->OptionalHeader.Magic;\r
-}\r
-\r
/**\r
Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory.\r
If Pe32Data is NULL, then ASSERT().\r
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
return Hdr.Te->Subsystem;\r
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
- Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr);\r
+ Magic = Hdr.Pe32->OptionalHeader.Magic;\r
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
return Hdr.Pe32->OptionalHeader.Subsystem;\r
} else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
if (EFI_ERROR (Status)) {\r
return NULL;\r
}\r
+ ASSERT (DriverInfoData != NULL);\r
\r
ZeroMem (DriverInfoData, sizeof (*DriverInfoData));\r
\r
//\r
return TRUE;\r
}\r
- \r
+\r
//\r
// Record FilePath without end node.\r
//\r
FREE_POOL_HEADER *Pool;\r
UINTN PoolListIndex;\r
UINTN Index;\r
+ UINTN SmmPoolTypeIndex;\r
\r
ContextData = GetSmramProfileContext ();\r
if (ContextData == NULL) {\r
Node = Node->BackLink) {\r
Index++;\r
}\r
- for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
- FreePoolList = &mSmmPoolLists[PoolListIndex];\r
- for (Node = FreePoolList->BackLink;\r
- Node != FreePoolList;\r
- Node = Node->BackLink) {\r
- Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
- if (Pool->Header.Available) {\r
- Index++;\r
+ for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+ for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+ FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];\r
+ for (Node = FreePoolList->BackLink;\r
+ Node != FreePoolList;\r
+ Node = Node->BackLink) {\r
+ Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+ if (Pool->Header.Available) {\r
+ Index++;\r
+ }\r
}\r
}\r
}\r
\r
-\r
TotalSize += (sizeof (MEMORY_PROFILE_FREE_MEMORY) + Index * sizeof (MEMORY_PROFILE_DESCRIPTOR));\r
TotalSize += (sizeof (MEMORY_PROFILE_MEMORY_RANGE) + mFullSmramRangeCount * sizeof (MEMORY_PROFILE_DESCRIPTOR));\r
\r
UINT64 RemainingSize;\r
UINTN PdbSize;\r
UINTN ActionStringSize;\r
+ UINTN SmmPoolTypeIndex;\r
\r
ContextData = GetSmramProfileContext ();\r
if (ContextData == NULL) {\r
Node = Node->BackLink) {\r
Index++;\r
}\r
- for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
- FreePoolList = &mSmmPoolLists[MAX_POOL_INDEX - PoolListIndex - 1];\r
- for (Node = FreePoolList->BackLink;\r
- Node != FreePoolList;\r
- Node = Node->BackLink) {\r
- Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
- if (Pool->Header.Available) {\r
- Index++;\r
+ for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+ for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+ FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];\r
+ for (Node = FreePoolList->BackLink;\r
+ Node != FreePoolList;\r
+ Node = Node->BackLink) {\r
+ Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+ if (Pool->Header.Available) {\r
+ Index++;\r
+ }\r
}\r
}\r
}\r
}\r
Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
}\r
- for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
- FreePoolList = &mSmmPoolLists[MAX_POOL_INDEX - PoolListIndex - 1];\r
- for (Node = FreePoolList->BackLink;\r
- Node != FreePoolList;\r
- Node = Node->BackLink) {\r
- Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
- if (Pool->Header.Available) {\r
- if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {\r
- if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {\r
- MemoryProfileDescriptor = ProfileBuffer;\r
- MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;\r
- MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
- MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;\r
- MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS) (UINTN) Pool;\r
- MemoryProfileDescriptor->Size = Pool->Header.Size;\r
-\r
- RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
- ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
- } else {\r
- goto Done;\r
+ for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+ for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+ FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];\r
+ for (Node = FreePoolList->BackLink;\r
+ Node != FreePoolList;\r
+ Node = Node->BackLink) {\r
+ Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+ if (Pool->Header.Available) {\r
+ if (*ProfileOffset < (Offset + sizeof (MEMORY_PROFILE_DESCRIPTOR))) {\r
+ if (RemainingSize >= sizeof (MEMORY_PROFILE_DESCRIPTOR)) {\r
+ MemoryProfileDescriptor = ProfileBuffer;\r
+ MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;\r
+ MemoryProfileDescriptor->Header.Length = sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
+ MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;\r
+ MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS) (UINTN) Pool;\r
+ MemoryProfileDescriptor->Size = Pool->Header.Size;\r
+\r
+ RemainingSize -= sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
+ ProfileBuffer = (UINT8 *) ProfileBuffer + sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
+ } else {\r
+ goto Done;\r
+ }\r
}\r
+ Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
}\r
- Offset += sizeof (MEMORY_PROFILE_DESCRIPTOR);\r
}\r
}\r
}\r
@param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer.\r
On return, points to the size of the data returned in ProfileBuffer.\r
@param[out] ProfileBuffer Profile buffer.\r
- \r
+\r
@return EFI_SUCCESS Get the memory profile data successfully.\r
@return EFI_UNSUPPORTED Memory profile is unsupported.\r
- @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. \r
+ @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data.\r
ProfileSize is updated with the size required.\r
\r
**/\r
EFI_SMM_DRIVER_ENTRY DriverEntry;\r
VOID *EntryPointInImage;\r
EFI_GUID *Name;\r
- \r
+\r
ZeroMem (&DriverEntry, sizeof (DriverEntry));\r
Name = GetFileNameFromFilePath (FilePath);\r
if (Name != NULL) {\r
UINTN PoolListIndex;\r
MEMORY_PROFILE_CONTEXT_DATA *ContextData;\r
BOOLEAN SmramProfileGettingStatus;\r
+ UINTN SmmPoolTypeIndex;\r
\r
ContextData = GetSmramProfileContext ();\r
if (ContextData == NULL) {\r
SmramProfileGettingStatus = mSmramProfileGettingStatus;\r
mSmramProfileGettingStatus = TRUE;\r
\r
- DEBUG ((EFI_D_INFO, "======= SmramProfile begin =======\n"));\r
-\r
- for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
- DEBUG ((EFI_D_INFO, "FreePoolList (%d):\n", PoolListIndex));\r
- FreePoolList = &mSmmPoolLists[PoolListIndex];\r
- for (Node = FreePoolList->BackLink, Index = 0;\r
- Node != FreePoolList;\r
- Node = Node->BackLink, Index++) {\r
- Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
- DEBUG ((EFI_D_INFO, " Index - 0x%x\n", Index));\r
- DEBUG ((EFI_D_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pool));\r
- DEBUG ((EFI_D_INFO, " Size - 0x%08x\n", Pool->Header.Size));\r
- DEBUG ((EFI_D_INFO, " Available - 0x%02x\n", Pool->Header.Available));\r
+ DEBUG ((DEBUG_INFO, "======= SmramProfile begin =======\n"));\r
+\r
+ for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {\r
+ for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {\r
+ DEBUG ((DEBUG_INFO, "FreePoolList(%d)(%d):\n", SmmPoolTypeIndex, PoolListIndex));\r
+ FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];\r
+ for (Node = FreePoolList->BackLink, Index = 0;\r
+ Node != FreePoolList;\r
+ Node = Node->BackLink, Index++) {\r
+ Pool = BASE_CR (Node, FREE_POOL_HEADER, Link);\r
+ DEBUG ((DEBUG_INFO, " Index - 0x%x\n", Index));\r
+ DEBUG ((DEBUG_INFO, " PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS) (UINTN) Pool));\r
+ DEBUG ((DEBUG_INFO, " Size - 0x%08x\n", Pool->Header.Size));\r
+ DEBUG ((DEBUG_INFO, " Available - 0x%02x\n", Pool->Header.Available));\r
+ }\r
}\r
}\r
\r
- DEBUG ((EFI_D_INFO, "======= SmramProfile end =======\n"));\r
+ DEBUG ((DEBUG_INFO, "======= SmramProfile end =======\n"));\r
\r
mSmramProfileGettingStatus = SmramProfileGettingStatus;\r
}\r
CHAR8 *String;\r
} ACTION_STRING;\r
\r
-ACTION_STRING mExtActionString[] = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED ACTION_STRING mExtActionString[] = {\r
{MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES, "Lib:AllocatePages"},\r
{MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES, "Lib:AllocateRuntimePages"},\r
{MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES, "Lib:AllocateReservedPages"},\r
{MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL, "Lib:ReallocateReservedPool"},\r
};\r
\r
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mUserDefinedActionString[] = {"UserDefined-0x80000000"};\r
-\r
typedef struct {\r
EFI_MEMORY_TYPE MemoryType;\r
CHAR8 *MemoryTypeStr;\r
)\r
{\r
UINTN Index;\r
- for (Index = 0; Index < sizeof (mMemoryTypeString) / sizeof (mMemoryTypeString[0]); Index++) {\r
+ for (Index = 0; Index < ARRAY_SIZE (mMemoryTypeString); Index++) {\r
if (mMemoryTypeString[Index].MemoryType == MemoryType) {\r
return mMemoryTypeString[Index].MemoryTypeStr;\r
}\r
CHAR8 **ActionString;\r
\r
ActionString = mSmmActionString;\r
- ActionStringCount = sizeof (mSmmActionString) / sizeof (mSmmActionString[0]);\r
+ ActionStringCount = ARRAY_SIZE (mSmmActionString);\r
\r
if ((UINTN) (UINT32) Action < ActionStringCount) {\r
return ActionString[Action];\r
}\r
- for (Index = 0; Index < sizeof (mExtActionString) / sizeof (mExtActionString[0]); Index++) {\r
+ for (Index = 0; Index < ARRAY_SIZE (mExtActionString); Index++) {\r
if (mExtActionString[Index].Action == Action) {\r
return mExtActionString[Index].String;\r
}\r
}\r
\r
/**\r
- Dump SMRAM infromation.\r
+ Dump SMRAM information.\r
\r
**/\r
VOID\r