Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamictables: Add SMBIOS dispatcher and generators #510

Open
wants to merge 11 commits into
base: dynamictables-reorg
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ 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[MAX_SMBIOS_HANDLES];
} 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 < MAX_SMBIOS_HANDLES; 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 @@ -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,71 @@

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, if the value SMBIOS_HANDLE_PI_RESERVED

Choose a reason for hiding this comment

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

I think the documentation for the SmbiosHandle parameter is out of sync with the code. Also, do we need a pointer to the SMBIOS handle?

If the intention is that we might need to extend the functionality to generate the handle in this function and return, then please add a comment to that effect. Then again the order of invocation of the table installation and handle generation would need to change in BuildXXX functions.
Which brings us back to should we support the handle generation in this function in the first place?

is passed then a new SmbiosHandle is assigned.
@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.
**/
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 < MAX_SMBIOS_HANDLES; 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 < MAX_SMBIOS_HANDLES; 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 +295,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.
**/
UINT16
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",
__FUNCTION__,
GeneratorId,
HandleMap->SmbiosGeneratorId
));
ASSERT (FALSE);
return SMBIOS_HANDLE_INVALID;
}

return HandleMap->SmbiosTblHandle;
}
Loading