2 BIOS vendor information boot time changes.
6 Copyright (c) 2013-2015 Intel Corporation.
8 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include "CommonHeader.h"
16 #include "SmbiosMisc.h"
19 This function returns the value & exponent to Base2 for a given
20 Hex value. This is used to calculate the BiosPhysicalDeviceSize.
22 @param Value The hex value which is to be converted into value-exponent form
23 @param Exponent The exponent out of the conversion
25 @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.
26 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
30 GetValueExponentBase2(
35 if ((Value
== NULL
) || (Exponent
== NULL
)) {
36 return EFI_INVALID_PARAMETER
;
39 while ((*Value
% 2) == 0) {
48 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
51 @param Base2Data Pointer to Base2_Data
53 @retval EFI_SUCCESS Transform successfully.
54 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
58 Base2ToByteWith64KUnit (
59 IN EFI_EXP_BASE2_DATA
*Base2Data
65 Value
= Base2Data
->Value
;
66 Exponent
= Base2Data
->Exponent
;
75 This function makes boot time changes to the contents of the
76 MiscBiosVendor (Type 0).
78 @param RecordData Pointer to copy of RecordData from the Data Table.
80 @retval EFI_SUCCESS All parameters were valid.
81 @retval EFI_UNSUPPORTED Unexpected RecordType value.
82 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
85 MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor
)
87 CHAR8
*OptionalStrStart
;
91 UINTN BiosPhysicalSizeHexValue
;
92 UINTN BiosPhysicalSizeExponent
;
93 CHAR16 Version
[SMBIOS_STRING_MAX_LENGTH
];
94 CHAR16 Vendor
[SMBIOS_STRING_MAX_LENGTH
];
95 CHAR16 ReleaseDate
[SMBIOS_STRING_MAX_LENGTH
];
96 EFI_STRING VersionPtr
;
98 EFI_STRING ReleaseDatePtr
;
100 STRING_REF TokenToGet
;
101 STRING_REF TokenToUpdate
;
102 SMBIOS_TABLE_TYPE0
*SmbiosRecord
;
103 EFI_SMBIOS_HANDLE SmbiosHandle
;
104 EFI_MISC_BIOS_VENDOR
*ForType0InputData
;
106 BiosPhysicalSizeHexValue
= 0x0;
107 BiosPhysicalSizeExponent
= 0x0;
108 ForType0InputData
= (EFI_MISC_BIOS_VENDOR
*)RecordData
;
111 // First check for invalid parameters.
113 if (RecordData
== NULL
) {
114 return EFI_INVALID_PARAMETER
;
117 // Now update the BiosPhysicalSize
119 BiosPhysicalSizeHexValue
= PcdGet32 (PcdFlashAreaSize
);
120 Status
= GetValueExponentBase2 (
121 &BiosPhysicalSizeHexValue
,
122 &BiosPhysicalSizeExponent
124 if(Status
== EFI_SUCCESS
){
125 ForType0InputData
->BiosPhysicalDeviceSize
.Value
= (UINT16
)BiosPhysicalSizeHexValue
;
126 ForType0InputData
->BiosPhysicalDeviceSize
.Exponent
= (UINT16
)BiosPhysicalSizeExponent
;
129 // Update strings from PCD
131 AsciiStrToUnicodeStr ((CHAR8
*) PcdGetPtr (PcdSMBIOSBiosVendor
), Vendor
);
132 if (StrLen (Vendor
) > 0) {
133 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
134 HiiSetString (mHiiHandle
, TokenToUpdate
, Vendor
, NULL
);
136 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
137 VendorPtr
= HiiGetPackageString(&gEfiCallerIdGuid
, TokenToGet
, NULL
);
138 VendorStrLen
= StrLen(VendorPtr
);
139 if (VendorStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
140 return EFI_UNSUPPORTED
;
143 UnicodeSPrint (Version
, sizeof (Version
), L
"0x%08x", PcdGet32 (PcdFirmwareRevision
));
144 if (StrLen (Version
) > 0) {
145 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
146 HiiSetString (mHiiHandle
, TokenToUpdate
, Version
, NULL
);
148 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
149 VersionPtr
= HiiGetPackageString(&gEfiCallerIdGuid
, TokenToGet
, NULL
);
150 VerStrLen
= StrLen(VersionPtr
);
151 if (VerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
152 return EFI_UNSUPPORTED
;
155 AsciiStrToUnicodeStr ((CHAR8
*) PcdGetPtr (PcdSMBIOSBiosReleaseDate
), ReleaseDate
);
156 if (StrLen (ReleaseDate
) > 0) {
157 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
158 HiiSetString (mHiiHandle
, TokenToUpdate
, ReleaseDate
, NULL
);
160 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
161 ReleaseDatePtr
= HiiGetPackageString(&gEfiCallerIdGuid
, TokenToGet
, NULL
);
162 DateStrLen
= StrLen(ReleaseDatePtr
);
163 if (DateStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
164 return EFI_UNSUPPORTED
;
168 // Two zeros following the last string.
170 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 + VerStrLen
+ 1 + DateStrLen
+ 1 + 1);
171 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 + VerStrLen
+ 1 + DateStrLen
+ 1 + 1);
173 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_INFORMATION
;
174 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE0
);
176 // Make handle chosen by smbios protocol.add automatically.
178 SmbiosRecord
->Hdr
.Handle
= 0;
180 // Vendor will be the 1st optional string following the formatted structure.
182 SmbiosRecord
->Vendor
= 1;
184 // Version will be the 2nd optional string following the formatted structure.
186 SmbiosRecord
->BiosVersion
= 2;
187 SmbiosRecord
->BiosSegment
= PcdGet16 (PcdSMBIOSBiosStartAddress
);
189 // ReleaseDate will be the 3rd optional string following the formatted structure.
191 SmbiosRecord
->BiosReleaseDate
= 3;
192 SmbiosRecord
->BiosSize
= (UINT8
)(Base2ToByteWith64KUnit(&ForType0InputData
->BiosPhysicalDeviceSize
) - 1);
193 *(UINT64
*)&SmbiosRecord
->BiosCharacteristics
= PcdGet64 (PcdSMBIOSBiosChar
);
195 // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.
197 SmbiosRecord
->BIOSCharacteristicsExtensionBytes
[0] = PcdGet8 (PcdSMBIOSBiosCharEx1
);
198 SmbiosRecord
->BIOSCharacteristicsExtensionBytes
[1] = PcdGet8 (PcdSMBIOSBiosCharEx2
);
200 SmbiosRecord
->SystemBiosMajorRelease
= ForType0InputData
->BiosMajorRelease
;
201 SmbiosRecord
->SystemBiosMinorRelease
= ForType0InputData
->BiosMinorRelease
;
202 SmbiosRecord
->EmbeddedControllerFirmwareMajorRelease
= ForType0InputData
->BiosEmbeddedFirmwareMajorRelease
;
203 SmbiosRecord
->EmbeddedControllerFirmwareMinorRelease
= ForType0InputData
->BiosEmbeddedFirmwareMinorRelease
;
205 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
206 UnicodeStrToAsciiStr(VendorPtr
, OptionalStrStart
);
207 UnicodeStrToAsciiStr(VersionPtr
, OptionalStrStart
+ VendorStrLen
+ 1);
208 UnicodeStrToAsciiStr(ReleaseDatePtr
, OptionalStrStart
+ VendorStrLen
+ 1 + VerStrLen
+ 1);
210 // Now we have got the full smbios record, call smbios protocol to add this record.
212 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
213 Status
= Smbios
-> Add(
217 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
220 FreePool(SmbiosRecord
);