|
12 | 12 | #include <IndustryStandard/SmBios.h>
|
13 | 13 | #include <Library/BaseLib.h>
|
14 | 14 | #include <Library/BaseMemoryLib.h>
|
| 15 | +#include <Library/MemoryAllocationLib.h> |
15 | 16 | #include <Library/DebugLib.h>
|
16 | 17 |
|
17 | 18 | // Module specific include files.
|
|
24 | 25 |
|
25 | 26 | extern EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo;
|
26 | 27 |
|
| 28 | +/** Add a new entry to the SMBIOS table Map. |
| 29 | +
|
| 30 | + @param [in] Smbios SMBIOS Protocol pointer. |
| 31 | + @param [in] SmbiosHandle SMBIOS Handle to be added. |
| 32 | + @param [in] CmObjectToken CmObjectToken of the CM_OBJECT used to build the SMBIOS Table |
| 33 | + @param [in] GeneratorId Smbios Table Generator Id. |
| 34 | +
|
| 35 | + @retval EFI_SUCCESS Successfully added/generated the handle. |
| 36 | + @retval EFI_OUT_OF_RESOURCESNULL Failure to add/generate the handle. |
| 37 | +**/ |
| 38 | +EFI_STATUS |
| 39 | +EFIAPI |
| 40 | +AddSmbiosHandle ( |
| 41 | + IN EFI_SMBIOS_PROTOCOL *Smbios, |
| 42 | + IN SMBIOS_HANDLE *SmbiosHandle, |
| 43 | + IN CM_OBJECT_TOKEN CmObjectToken, |
| 44 | + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId |
| 45 | + ) |
| 46 | +{ |
| 47 | + EFI_STATUS Status; |
| 48 | + UINTN Index; |
| 49 | + |
| 50 | + Status = EFI_OUT_OF_RESOURCES; |
| 51 | + |
| 52 | + for (Index = 0; Index < FixedPcdGet16(PcdMaxSmbiosHandleMapEntries); Index++) { |
| 53 | + if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle == SMBIOS_HANDLE_PI_RESERVED) { |
| 54 | + TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle = *SmbiosHandle; |
| 55 | + TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken = CmObjectToken; |
| 56 | + TableFactoryInfo.SmbiosHandleMap[Index].SmbiosGeneratorId = GeneratorId; |
| 57 | + Status = EFI_SUCCESS; |
| 58 | + break; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return Status; |
| 63 | +} |
| 64 | + |
| 65 | +/** Return a pointer to the SMBIOS table Map. |
| 66 | +
|
| 67 | + @param [in] GeneratorId The CmObjectToken to look up an SMBIOS Handle. |
| 68 | +
|
| 69 | + @retval SMBIOS_HANDLE_MAP if the CmObjectToken is found. |
| 70 | + @retval NULL if not found. |
| 71 | +**/ |
| 72 | +SMBIOS_HANDLE_MAP * |
| 73 | +EFIAPI |
| 74 | +FindSmbiosHandle ( |
| 75 | + CM_OBJECT_TOKEN CmObjectToken |
| 76 | + ) |
| 77 | +{ |
| 78 | + UINTN Index; |
| 79 | + SMBIOS_HANDLE_MAP *SmbiosHandleMap; |
| 80 | + |
| 81 | + SmbiosHandleMap = NULL; |
| 82 | + for (Index = 0; Index < FixedPcdGet16(PcdMaxSmbiosHandleMapEntries); Index++) { |
| 83 | + if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken == CmObjectToken) { |
| 84 | + SmbiosHandleMap = &TableFactoryInfo.SmbiosHandleMap[Index]; |
| 85 | + break; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + return SmbiosHandleMap; |
| 90 | +} |
| 91 | + |
27 | 92 | /** Return a pointer to the SMBIOS table generator.
|
28 | 93 |
|
29 | 94 | @param [in] This Pointer to the Dynamic Table Factory Protocol.
|
@@ -229,3 +294,44 @@ DeregisterSmbiosTableGenerator (
|
229 | 294 | DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
|
230 | 295 | return EFI_SUCCESS;
|
231 | 296 | }
|
| 297 | + |
| 298 | +/** Find and return SMBIOS handle based on associated CM object token. |
| 299 | +
|
| 300 | + @param [in] GeneratorId SMBIOS generator ID used to build the SMBIOS Table. |
| 301 | + @param [in] CmObjectToken Token of the CM_OBJECT used to build the SMBIOS Table. |
| 302 | +
|
| 303 | + @return SMBIOS handle of the table associated with SmbiosGeneratorId and |
| 304 | + CmObjectToken if found. Otherwise, returns 0xFFFF. |
| 305 | +**/ |
| 306 | +SMBIOS_HANDLE |
| 307 | +EFIAPI |
| 308 | +FindSmbiosHandleEx ( |
| 309 | + IN SMBIOS_TABLE_GENERATOR_ID GeneratorId, |
| 310 | + IN CM_OBJECT_TOKEN CmObjToken |
| 311 | + ) |
| 312 | +{ |
| 313 | + SMBIOS_HANDLE_MAP *HandleMap; |
| 314 | + |
| 315 | + if (CmObjToken == CM_NULL_TOKEN) { |
| 316 | + return SMBIOS_HANDLE_INVALID; |
| 317 | + } |
| 318 | + |
| 319 | + HandleMap = FindSmbiosHandle (CmObjToken); |
| 320 | + if (HandleMap == NULL) { |
| 321 | + return SMBIOS_HANDLE_INVALID; |
| 322 | + } |
| 323 | + |
| 324 | + if (HandleMap->SmbiosGeneratorId != GeneratorId) { |
| 325 | + DEBUG (( |
| 326 | + DEBUG_ERROR, |
| 327 | + "%a: Expect ID %d but get %d\n", |
| 328 | + __func__, |
| 329 | + GeneratorId, |
| 330 | + HandleMap->SmbiosGeneratorId |
| 331 | + )); |
| 332 | + ASSERT (FALSE); |
| 333 | + return SMBIOS_HANDLE_INVALID; |
| 334 | + } |
| 335 | + |
| 336 | + return HandleMap->SmbiosTblHandle; |
| 337 | +} |
0 commit comments