3 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
4 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
6 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HiiLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/PrintLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
19 #include "SmbiosMisc.h"
23 CONST CHAR8
* MonthStr
;
28 MONTH_DESCRIPTION mMonthDescription
[] = {
41 { "???", 1 }, // Use 1 as default month
45 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
48 @param Value Pointer to Base2_Data
54 Base2ToByteWith64KUnit (
60 Size
= ((Value
+ (SIZE_64KB
- 1)) >> 16);
66 Returns the date and time this file (and firmware) was built.
68 @param[out] *Time Pointer to the EFI_TIME structure to fill in.
75 CONST CHAR8
*ReleaseDate
= __DATE__
;
76 CONST CHAR8
*ReleaseTime
= __TIME__
;
79 for (i
= 0; i
< 12; i
++) {
80 if (AsciiStrnCmp (ReleaseDate
, mMonthDescription
[i
].MonthStr
, 3) == 0) {
85 Time
->Month
= mMonthDescription
[i
].MonthInt
;
86 Time
->Day
= AsciiStrDecimalToUintn (ReleaseDate
+ 4);
87 Time
->Year
= AsciiStrDecimalToUintn (ReleaseDate
+ 7);
88 Time
->Hour
= AsciiStrDecimalToUintn (ReleaseTime
);
89 Time
->Minute
= AsciiStrDecimalToUintn (ReleaseTime
+ 3);
90 Time
->Second
= AsciiStrDecimalToUintn (ReleaseTime
+ 6);
94 Fetches the firmware ('BIOS') release date from the
95 FirmwareVersionInfo HOB.
97 @return The release date as a UTF-16 string
107 ReleaseDate
= AllocateZeroPool ((sizeof (CHAR16
)) * SMBIOS_STRING_MAX_LENGTH
);
108 if (ReleaseDate
== NULL
) {
112 GetReleaseTime (&BuildTime
);
114 (VOID
)UnicodeSPrintAsciiFormat (ReleaseDate
,
115 (sizeof (CHAR16
)) * SMBIOS_STRING_MAX_LENGTH
,
126 Fetches the firmware ('BIOS') version from the
127 FirmwareVersionInfo HOB.
129 @return The version as a UTF-16 string
136 CHAR16
*ReleaseString
;
138 ReleaseString
= (CHAR16
*)FixedPcdGetPtr (PcdFirmwareVersionString
);
140 return ReleaseString
;
145 This function makes boot time changes to the contents of the
146 MiscBiosVendor (Type 0) record.
148 @param RecordData Pointer to SMBIOS table with default values.
149 @param Smbios SMBIOS protocol.
151 @retval EFI_SUCCESS The SMBIOS table was successfully added.
152 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
153 @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory.
156 SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor
)
158 CHAR8
*OptionalStrStart
;
163 UINTN BiosPhysicalSize
;
167 CHAR16
*Char16String
;
169 EFI_STRING_ID TokenToUpdate
;
170 EFI_STRING_ID TokenToGet
;
171 SMBIOS_TABLE_TYPE0
*SmbiosRecord
;
172 SMBIOS_TABLE_TYPE0
*InputData
;
175 // First check for invalid parameters.
177 if (RecordData
== NULL
) {
178 return EFI_INVALID_PARAMETER
;
181 InputData
= (SMBIOS_TABLE_TYPE0
*)RecordData
;
183 Vendor
= (CHAR16
*) PcdGetPtr (PcdFirmwareVendor
);
185 if (StrLen (Vendor
) > 0) {
186 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
187 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Vendor
, NULL
);
190 Version
= GetBiosVersion();
192 if (StrLen (Version
) > 0) {
193 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
194 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Version
, NULL
);
196 Version
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
197 if (StrLen (Version
) > 0) {
198 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
199 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Version
, NULL
);
203 Char16String
= GetBiosReleaseDate ();
204 if (StrLen(Char16String
) > 0) {
205 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
206 HiiSetString (mSmbiosMiscHiiHandle
, TokenToUpdate
, Char16String
, NULL
);
209 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
210 Vendor
= HiiGetPackageString (&gEfiCallerIdGuid
, TokenToGet
, NULL
);
211 VendorStrLen
= StrLen (Vendor
);
213 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
214 Version
= HiiGetPackageString (&gEfiCallerIdGuid
, TokenToGet
, NULL
);
215 VerStrLen
= StrLen (Version
);
217 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
218 ReleaseDate
= HiiGetPackageString (&gEfiCallerIdGuid
, TokenToGet
, NULL
);
219 DateStrLen
= StrLen (ReleaseDate
);
222 // Now update the BiosPhysicalSize
224 BiosPhysicalSize
= FixedPcdGet32 (PcdFdSize
);
227 // Two zeros following the last string.
229 SmbiosRecord
= AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 +
232 if (SmbiosRecord
== NULL
) {
233 Status
= EFI_OUT_OF_RESOURCES
;
237 (VOID
)CopyMem (SmbiosRecord
, InputData
, sizeof (SMBIOS_TABLE_TYPE0
));
239 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE0
);
240 SmbiosRecord
->BiosSegment
= (UINT16
)(FixedPcdGet32 (PcdFdBaseAddress
) / SIZE_64KB
);
241 if (BiosPhysicalSize
< SIZE_16MB
) {
242 SmbiosRecord
->BiosSize
= Base2ToByteWith64KUnit (BiosPhysicalSize
) - 1;
244 SmbiosRecord
->BiosSize
= 0xFF;
245 if (BiosPhysicalSize
< SIZE_16GB
) {
246 SmbiosRecord
->ExtendedBiosSize
.Size
= BiosPhysicalSize
/ SIZE_1MB
;
247 SmbiosRecord
->ExtendedBiosSize
.Unit
= 0; // Size is in MB
249 SmbiosRecord
->ExtendedBiosSize
.Size
= BiosPhysicalSize
/ SIZE_1GB
;
250 SmbiosRecord
->ExtendedBiosSize
.Unit
= 1; // Size is in GB
254 SmbiosRecord
->SystemBiosMajorRelease
= (UINT8
) (PcdGet16 (PcdSystemBiosRelease
) >> 8);
255 SmbiosRecord
->SystemBiosMinorRelease
= (UINT8
) (PcdGet16 (PcdSystemBiosRelease
) & 0xFF);
257 SmbiosRecord
->EmbeddedControllerFirmwareMajorRelease
= (UINT16
)
258 (PcdGet16 (PcdEmbeddedControllerFirmwareRelease
) >> 8);
259 SmbiosRecord
->EmbeddedControllerFirmwareMinorRelease
= (UINT16
)
260 (PcdGet16 (PcdEmbeddedControllerFirmwareRelease
) & 0xFF);
262 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
263 UnicodeStrToAsciiStrS (Vendor
, OptionalStrStart
, VendorStrLen
+ 1);
264 StrStart
= OptionalStrStart
+ VendorStrLen
+ 1;
265 UnicodeStrToAsciiStrS (Version
, StrStart
, VerStrLen
+ 1);
266 StrStart
+= VerStrLen
+ 1;
267 UnicodeStrToAsciiStrS (ReleaseDate
, StrStart
, DateStrLen
+ 1);
269 // Now we have got the full smbios record, call smbios protocol to add this record.
271 Status
= SmbiosMiscAddRecord ((UINT8
*)SmbiosRecord
, NULL
);
272 if (EFI_ERROR (Status
)) {
273 DEBUG ((DEBUG_ERROR
, "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",
274 __FUNCTION__
, DEBUG_LINE_NUMBER
, Status
));
277 FreePool (SmbiosRecord
);
280 if (Vendor
!= NULL
) {
284 if (Version
!= NULL
) {
288 if (ReleaseDate
!= NULL
) {
289 FreePool (ReleaseDate
);
292 if (Char16String
!= NULL
) {
293 FreePool (Char16String
);