Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ typedef struct DynamicTableFactoryInfo {
CustomDtTableGeneratorList[FixedPcdGet16 (
PcdMaxCustomDTGenerators
)];

/// An array for holding a map of SMBIOS handles and the CM Object
/// token used to build the SMBIOS record.
SMBIOS_HANDLE_MAP
SmbiosHandleMap[FixedPcdGet16 (
PcdMaxSmbiosHandleMapEntries
)];
} EDKII_DYNAMIC_TABLE_FACTORY_INFO;

/** Return a pointer to the ACPI table generator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL DynamicTableFactoryProtocol = {
GetDtTableGenerator,
RegisterDtTableGenerator,
DeregisterDtTableGenerator,
AddSmbiosHandle,
FindSmbiosHandle,
FindSmbiosHandleEx,
&TableFactoryInfo
};

Expand All @@ -65,6 +68,12 @@ DynamicTableFactoryDxeInitialize (
)
{
EFI_STATUS Status;
UINTN Idx;

for (Idx = 0; Idx < FixedPcdGet16(PcdMaxSmbiosHandleMapEntries); Idx++) {
TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosTblHandle = SMBIOS_HANDLE_PI_RESERVED;
TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosCmToken = 0;
}

Status = gBS->InstallProtocolInterface (
&ImageHandle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdMaxCustomACPIGenerators
gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdMaxCustomSMBIOSGenerators
gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdMaxCustomDTGenerators
gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdMaxSmbiosHandleMapEntries

[Protocols]
gEdkiiDynamicTableFactoryProtocolGuid # PRODUCES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <IndustryStandard/SmBios.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>

// Module specific include files.
Expand All @@ -24,6 +25,70 @@

extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo;

/** Add a new entry to the SMBIOS table Map.

@param [in] Smbios SMBIOS Protocol pointer.
@param [in] SmbiosHandle SMBIOS Handle to be added.
@param [in] CmObjectToken CmObjectToken of the CM_OBJECT used to build the SMBIOS Table
@param [in] GeneratorId Smbios Table Generator Id.

@retval EFI_SUCCESS Successfully added/generated the handle.
@retval EFI_OUT_OF_RESOURCESNULL Failure to add/generate the handle.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "EFI_OUT_OF_RESOURCESNULL".

**/
EFI_STATUS
EFIAPI
AddSmbiosHandle (
IN EFI_SMBIOS_PROTOCOL *Smbios,
IN SMBIOS_HANDLE *SmbiosHandle,
IN CM_OBJECT_TOKEN CmObjectToken,
IN SMBIOS_TABLE_GENERATOR_ID GeneratorId
)
{
EFI_STATUS Status;
UINTN Index;

Status = EFI_OUT_OF_RESOURCES;

for (Index = 0; Index < FixedPcdGet16(PcdMaxSmbiosHandleMapEntries); Index++) {
if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle == SMBIOS_HANDLE_PI_RESERVED) {
TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle = *SmbiosHandle;
TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken = CmObjectToken;
TableFactoryInfo.SmbiosHandleMap[Index].SmbiosGeneratorId = GeneratorId;
Status = EFI_SUCCESS;
break;
}
}

return Status;
}

/** Return a pointer to the SMBIOS table Map.

@param [in] GeneratorId The CmObjectToken to look up an SMBIOS Handle.

@retval SMBIOS_HANDLE_MAP if the CmObjectToken is found.
@retval NULL if not found.
**/
SMBIOS_HANDLE_MAP *
EFIAPI
FindSmbiosHandle (
CM_OBJECT_TOKEN CmObjectToken
)
{
UINTN Index;
SMBIOS_HANDLE_MAP *SmbiosHandleMap;

SmbiosHandleMap = NULL;
for (Index = 0; Index < FixedPcdGet16(PcdMaxSmbiosHandleMapEntries); Index++) {
if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken == CmObjectToken) {
SmbiosHandleMap = &TableFactoryInfo.SmbiosHandleMap[Index];
break;
}
}

return SmbiosHandleMap;
}

/** Return a pointer to the SMBIOS table generator.

@param [in] This Pointer to the Dynamic Table Factory Protocol.
Expand Down Expand Up @@ -229,3 +294,44 @@ DeregisterSmbiosTableGenerator (
DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
return EFI_SUCCESS;
}

/** Find and return SMBIOS handle based on associated CM object token.

@param [in] GeneratorId SMBIOS generator ID used to build the SMBIOS Table.
@param [in] CmObjectToken Token of the CM_OBJECT used to build the SMBIOS Table.

@return SMBIOS handle of the table associated with SmbiosGeneratorId and
CmObjectToken if found. Otherwise, returns 0xFFFF.
**/
SMBIOS_HANDLE
EFIAPI
FindSmbiosHandleEx (
IN SMBIOS_TABLE_GENERATOR_ID GeneratorId,
IN CM_OBJECT_TOKEN CmObjToken
)
{
SMBIOS_HANDLE_MAP *HandleMap;

if (CmObjToken == CM_NULL_TOKEN) {
return SMBIOS_HANDLE_INVALID;
}

HandleMap = FindSmbiosHandle (CmObjToken);
if (HandleMap == NULL) {
return SMBIOS_HANDLE_INVALID;
}

if (HandleMap->SmbiosGeneratorId != GeneratorId) {
DEBUG ((
DEBUG_ERROR,
"%a: Expect ID %d but get %d\n",
__func__,
GeneratorId,
HandleMap->SmbiosGeneratorId
));
ASSERT (FALSE);
return SMBIOS_HANDLE_INVALID;
}

return HandleMap->SmbiosTblHandle;
}
Loading