|
| 1 | +/** @file |
| 2 | + SMBIOS Type0 Table Generator. |
| 3 | +
|
| 4 | + Copyright (c) 2024 - 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 5 | + Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR> |
| 6 | +
|
| 7 | + SPDX-License-Identifier: BSD-2-Clause-Patent |
| 8 | +**/ |
| 9 | + |
| 10 | +#include <Library/BaseLib.h> |
| 11 | +#include <Library/BaseMemoryLib.h> |
| 12 | +#include <Library/DebugLib.h> |
| 13 | +#include <Library/MemoryAllocationLib.h> |
| 14 | +#include <Library/SmbiosStringTableLib.h> |
| 15 | + |
| 16 | +// Module specific include files. |
| 17 | +#include <ConfigurationManagerObject.h> |
| 18 | +#include <ConfigurationManagerHelper.h> |
| 19 | +#include <Protocol/ConfigurationManagerProtocol.h> |
| 20 | +#include <Protocol/DynamicTableFactoryProtocol.h> |
| 21 | +#include <Protocol/Smbios.h> |
| 22 | +#include <IndustryStandard/SmBios.h> |
| 23 | + |
| 24 | +/** This macro expands to a function that retrieves the BIOS Information |
| 25 | + from the Configuration Manager. |
| 26 | +*/ |
| 27 | +GET_OBJECT_LIST ( |
| 28 | + EObjNameSpaceArchCommon, |
| 29 | + EArchCommonObjBiosInfo, |
| 30 | + CM_ARCH_COMMON_BIOS_INFO |
| 31 | + ) |
| 32 | + |
| 33 | +/** |
| 34 | + Free any resources allocated when installing SMBIOS Type0 table. |
| 35 | +
|
| 36 | + @param [in] This Pointer to the SMBIOS table generator. |
| 37 | + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory |
| 38 | + Protocol interface. |
| 39 | + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. |
| 40 | + @param [in] CfgMgrProtocol Pointer to the Configuration Manager |
| 41 | + Protocol interface. |
| 42 | + @param [in] Table Pointer to the SMBIOS table. |
| 43 | +
|
| 44 | + @retval EFI_SUCCESS Table freed successfully. |
| 45 | +**/ |
| 46 | +STATIC |
| 47 | +EFI_STATUS |
| 48 | +FreeSmbiosType0Table ( |
| 49 | + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, |
| 50 | + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, |
| 51 | + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, |
| 52 | + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, |
| 53 | + IN SMBIOS_STRUCTURE **CONST Table |
| 54 | + ) |
| 55 | +{ |
| 56 | + if (*Table != NULL) { |
| 57 | + FreePool (*Table); |
| 58 | + } |
| 59 | + |
| 60 | + return EFI_SUCCESS; |
| 61 | +} |
| 62 | + |
| 63 | +/** Construct SMBIOS Type0 Table describing BIOS information. |
| 64 | +
|
| 65 | + If this function allocates any resources then they must be freed |
| 66 | + in the FreeSmbiosType0Table function. |
| 67 | +
|
| 68 | + @param [in] This Pointer to the SMBIOS table generator. |
| 69 | + @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory |
| 70 | + Protocol interface. |
| 71 | + @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. |
| 72 | + @param [in] CfgMgrProtocol Pointer to the Configuration Manager |
| 73 | + Protocol interface. |
| 74 | + @param [out] Table Pointer to the SMBIOS table. |
| 75 | + @param [out] CmObjectToken Pointer to the CM Object Token. |
| 76 | +
|
| 77 | + @retval EFI_SUCCESS Table generated successfully. |
| 78 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 79 | + @retval EFI_NOT_FOUND Could not find information. |
| 80 | + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. |
| 81 | +**/ |
| 82 | +STATIC |
| 83 | +EFI_STATUS |
| 84 | +BuildSmbiosType0Table ( |
| 85 | + IN CONST SMBIOS_TABLE_GENERATOR *This, |
| 86 | + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, |
| 87 | + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, |
| 88 | + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, |
| 89 | + OUT SMBIOS_STRUCTURE **Table, |
| 90 | + OUT CM_OBJECT_TOKEN *CmObjectToken |
| 91 | + ) |
| 92 | +{ |
| 93 | + EFI_STATUS Status; |
| 94 | + CM_OBJECT_TOKEN CmObject; |
| 95 | + UINT8 VendorRef; |
| 96 | + UINT8 VersionRef; |
| 97 | + UINT8 ReleaseDateRef; |
| 98 | + SMBIOS_TABLE_TYPE0 *SmbiosRecord; |
| 99 | + UINTN SmbiosRecordSize; |
| 100 | + STRING_TABLE StrTable; |
| 101 | + CHAR8 *OptionalStrings; |
| 102 | + CM_ARCH_COMMON_BIOS_INFO *BiosInfo; |
| 103 | + |
| 104 | + ASSERT (This != NULL); |
| 105 | + ASSERT (SmbiosTableInfo != NULL); |
| 106 | + ASSERT (CfgMgrProtocol != NULL); |
| 107 | + ASSERT (Table != NULL); |
| 108 | + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); |
| 109 | + |
| 110 | + // |
| 111 | + // Retrieve BIOS info from CM object |
| 112 | + // |
| 113 | + *Table = NULL; |
| 114 | + Status = GetEArchCommonObjBiosInfo ( |
| 115 | + CfgMgrProtocol, |
| 116 | + CM_NULL_TOKEN, |
| 117 | + &BiosInfo, |
| 118 | + NULL |
| 119 | + ); |
| 120 | + if (EFI_ERROR (Status)) { |
| 121 | + DEBUG (( |
| 122 | + DEBUG_ERROR, |
| 123 | + "%a: Failed to get Bios Info CM Object %r\n", |
| 124 | + __func__, |
| 125 | + Status |
| 126 | + )); |
| 127 | + return Status; |
| 128 | + } |
| 129 | + |
| 130 | + // |
| 131 | + // Copy strings to SMBIOS table |
| 132 | + // |
| 133 | + Status = StringTableInitialize (&StrTable, 3); |
| 134 | + if (EFI_ERROR (Status)) { |
| 135 | + DEBUG (( |
| 136 | + DEBUG_ERROR, |
| 137 | + "%a: Failed to allocate string table for CM Object, %r\n", |
| 138 | + __func__, |
| 139 | + Status |
| 140 | + )); |
| 141 | + goto exit; |
| 142 | + } |
| 143 | + |
| 144 | + VendorRef = 0; |
| 145 | + VersionRef = 0; |
| 146 | + ReleaseDateRef = 0; |
| 147 | + |
| 148 | + if ((BiosInfo->BiosVendor != NULL) && (BiosInfo->BiosVendor[0] != '\0')) { |
| 149 | + Status = StringTableAddString (&StrTable, BiosInfo->BiosVendor, &VendorRef); |
| 150 | + if (EFI_ERROR (Status)) { |
| 151 | + DEBUG ((DEBUG_ERROR, "%a: Failed to add BiosVendor string %r\n", __func__, Status)); |
| 152 | + goto exit; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + if ((BiosInfo->BiosVersion != NULL) && (BiosInfo->BiosVersion[0] != '\0')) { |
| 157 | + Status = StringTableAddString (&StrTable, BiosInfo->BiosVersion, &VersionRef); |
| 158 | + if (EFI_ERROR (Status)) { |
| 159 | + DEBUG ((DEBUG_ERROR, "%a: Failed to add BiosVersion string %r\n", __func__, Status)); |
| 160 | + goto exit; |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + if ((BiosInfo->BiosReleaseDate != NULL) && (BiosInfo->BiosReleaseDate[0] != '\0')) { |
| 165 | + Status = StringTableAddString (&StrTable, BiosInfo->BiosReleaseDate, &ReleaseDateRef); |
| 166 | + if (EFI_ERROR (Status)) { |
| 167 | + DEBUG ((DEBUG_ERROR, "%a: Failed to add BiosReleaseDate string %r\n", __func__, Status)); |
| 168 | + goto exit; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE0) + |
| 173 | + StringTableGetStringSetSize (&StrTable); |
| 174 | + SmbiosRecord = (SMBIOS_TABLE_TYPE0 *)AllocateZeroPool (SmbiosRecordSize); |
| 175 | + if (SmbiosRecord == NULL) { |
| 176 | + DEBUG ((DEBUG_ERROR, "%a: memory allocation failed for smbios type0 record\n", __func__)); |
| 177 | + Status = EFI_OUT_OF_RESOURCES; |
| 178 | + goto exit; |
| 179 | + } |
| 180 | + |
| 181 | + SmbiosRecord->BiosSegment = BiosInfo->BiosSegment; |
| 182 | + SmbiosRecord->BiosSize = BiosInfo->BiosSize; |
| 183 | + |
| 184 | + SmbiosRecord->BiosCharacteristics = BiosInfo->BiosCharacteristics; |
| 185 | + |
| 186 | + SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = BiosInfo->BIOSCharacteristicsExtensionBytes[0]; |
| 187 | + SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = BiosInfo->BIOSCharacteristicsExtensionBytes[1]; |
| 188 | + |
| 189 | + SmbiosRecord->SystemBiosMajorRelease = BiosInfo->SystemBiosMajorRelease; |
| 190 | + SmbiosRecord->SystemBiosMinorRelease = BiosInfo->SystemBiosMinorRelease; |
| 191 | + |
| 192 | + SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = BiosInfo->ECFirmwareMajorRelease; |
| 193 | + SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = BiosInfo->ECFirmwareMinorRelease; |
| 194 | + |
| 195 | + SmbiosRecord->ExtendedBiosSize = BiosInfo->ExtendedBiosSize; |
| 196 | + |
| 197 | + SmbiosRecord->Vendor = VendorRef; |
| 198 | + SmbiosRecord->BiosVersion = VersionRef; |
| 199 | + SmbiosRecord->BiosReleaseDate = ReleaseDateRef; |
| 200 | + |
| 201 | + OptionalStrings = (CHAR8 *)(SmbiosRecord + 1); |
| 202 | + // publish the string set |
| 203 | + StringTablePublishStringSet ( |
| 204 | + &StrTable, |
| 205 | + OptionalStrings, |
| 206 | + (SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE0)) |
| 207 | + ); |
| 208 | + // setup the header |
| 209 | + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION; |
| 210 | + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0); |
| 211 | + CmObject = BiosInfo->BiosInfoToken; |
| 212 | + |
| 213 | + *Table = (SMBIOS_STRUCTURE *)SmbiosRecord; |
| 214 | + *CmObjectToken = CmObject; |
| 215 | + |
| 216 | +exit: |
| 217 | + // free string table |
| 218 | + StringTableFree (&StrTable); |
| 219 | + return Status; |
| 220 | +} |
| 221 | + |
| 222 | +/** The interface for the SMBIOS Type0 Table Generator. |
| 223 | +*/ |
| 224 | +STATIC |
| 225 | +CONST |
| 226 | +SMBIOS_TABLE_GENERATOR SmbiosType0Generator = { |
| 227 | + // Generator ID |
| 228 | + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType00), |
| 229 | + // Generator Description |
| 230 | + L"SMBIOS.TYPE0.GENERATOR", |
| 231 | + // SMBIOS Table Type |
| 232 | + EFI_SMBIOS_TYPE_BIOS_INFORMATION, |
| 233 | + // Build table function |
| 234 | + BuildSmbiosType0Table, |
| 235 | + // Free function |
| 236 | + FreeSmbiosType0Table, |
| 237 | + NULL, |
| 238 | + NULL |
| 239 | +}; |
| 240 | + |
| 241 | +/** Register the Generator with the SMBIOS Table Factory. |
| 242 | +
|
| 243 | + @param [in] ImageHandle The handle to the image. |
| 244 | + @param [in] SystemTable Pointer to the System Table. |
| 245 | +
|
| 246 | + @retval EFI_SUCCESS The Generator is registered. |
| 247 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 248 | + @retval EFI_ALREADY_STARTED The Generator for the Table ID |
| 249 | + is already registered. |
| 250 | +**/ |
| 251 | +EFI_STATUS |
| 252 | +EFIAPI |
| 253 | +SmbiosType0LibConstructor ( |
| 254 | + IN EFI_HANDLE ImageHandle, |
| 255 | + IN EFI_SYSTEM_TABLE *SystemTable |
| 256 | + ) |
| 257 | +{ |
| 258 | + EFI_STATUS Status; |
| 259 | + |
| 260 | + Status = RegisterSmbiosTableGenerator (&SmbiosType0Generator); |
| 261 | + DEBUG (( |
| 262 | + DEBUG_INFO, |
| 263 | + "SMBIOS Type 0: Register Generator. Status = %r\n", |
| 264 | + Status |
| 265 | + )); |
| 266 | + ASSERT_EFI_ERROR (Status); |
| 267 | + |
| 268 | + return Status; |
| 269 | +} |
| 270 | + |
| 271 | +/** Deregister the Generator from the SMBIOS Table Factory. |
| 272 | +
|
| 273 | + @param [in] ImageHandle The handle to the image. |
| 274 | + @param [in] SystemTable Pointer to the System Table. |
| 275 | +
|
| 276 | + @retval EFI_SUCCESS The Generator is deregistered. |
| 277 | + @retval EFI_INVALID_PARAMETER A parameter is invalid. |
| 278 | + @retval EFI_NOT_FOUND The Generator is not registered. |
| 279 | +**/ |
| 280 | +EFI_STATUS |
| 281 | +EFIAPI |
| 282 | +SmbiosType0LibDestructor ( |
| 283 | + IN EFI_HANDLE ImageHandle, |
| 284 | + IN EFI_SYSTEM_TABLE *SystemTable |
| 285 | + ) |
| 286 | +{ |
| 287 | + EFI_STATUS Status; |
| 288 | + |
| 289 | + Status = DeregisterSmbiosTableGenerator (&SmbiosType0Generator); |
| 290 | + DEBUG (( |
| 291 | + DEBUG_INFO, |
| 292 | + "SMBIOS Type0: Deregister Generator. Status = %r\n", |
| 293 | + Status |
| 294 | + )); |
| 295 | + ASSERT_EFI_ERROR (Status); |
| 296 | + return Status; |
| 297 | +} |
0 commit comments