2 BIOS vendor information boot time changes.
6 Copyright (c) 2013-2015 Intel Corporation.
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "CommonHeader.h"
22 #include "SmbiosMisc.h"
25 This function returns the value & exponent to Base2 for a given
26 Hex value. This is used to calculate the BiosPhysicalDeviceSize.
28 @param Value The hex value which is to be converted into value-exponent form
29 @param Exponent The exponent out of the conversion
31 @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.
32 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
36 GetValueExponentBase2(
41 if ((Value
== NULL
) || (Exponent
== NULL
)) {
42 return EFI_INVALID_PARAMETER
;
45 while ((*Value
% 2) == 0) {
54 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
57 @param Base2Data Pointer to Base2_Data
59 @retval EFI_SUCCESS Transform successfully.
60 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
64 Base2ToByteWith64KUnit (
65 IN EFI_EXP_BASE2_DATA
*Base2Data
71 Value
= Base2Data
->Value
;
72 Exponent
= Base2Data
->Exponent
;
81 This function makes boot time changes to the contents of the
82 MiscBiosVendor (Type 0).
84 @param RecordData Pointer to copy of RecordData from the Data Table.
86 @retval EFI_SUCCESS All parameters were valid.
87 @retval EFI_UNSUPPORTED Unexpected RecordType value.
88 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
91 MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor
)
93 CHAR8
*OptionalStrStart
;
97 UINTN BiosPhysicalSizeHexValue
;
98 UINTN BiosPhysicalSizeExponent
;
99 CHAR16 Version
[SMBIOS_STRING_MAX_LENGTH
];
100 CHAR16 Vendor
[SMBIOS_STRING_MAX_LENGTH
];
101 CHAR16 ReleaseDate
[SMBIOS_STRING_MAX_LENGTH
];
102 EFI_STRING VersionPtr
;
103 EFI_STRING VendorPtr
;
104 EFI_STRING ReleaseDatePtr
;
106 STRING_REF TokenToGet
;
107 STRING_REF TokenToUpdate
;
108 SMBIOS_TABLE_TYPE0
*SmbiosRecord
;
109 EFI_SMBIOS_HANDLE SmbiosHandle
;
110 EFI_MISC_BIOS_VENDOR
*ForType0InputData
;
112 BiosPhysicalSizeHexValue
= 0x0;
113 BiosPhysicalSizeExponent
= 0x0;
114 ForType0InputData
= (EFI_MISC_BIOS_VENDOR
*)RecordData
;
117 // First check for invalid parameters.
119 if (RecordData
== NULL
) {
120 return EFI_INVALID_PARAMETER
;
123 // Now update the BiosPhysicalSize
125 BiosPhysicalSizeHexValue
= PcdGet32 (PcdFlashAreaSize
);
126 Status
= GetValueExponentBase2 (
127 &BiosPhysicalSizeHexValue
,
128 &BiosPhysicalSizeExponent
130 if(Status
== EFI_SUCCESS
){
131 ForType0InputData
->BiosPhysicalDeviceSize
.Value
= (UINT16
)BiosPhysicalSizeHexValue
;
132 ForType0InputData
->BiosPhysicalDeviceSize
.Exponent
= (UINT16
)BiosPhysicalSizeExponent
;
135 // Update strings from PCD
137 AsciiStrToUnicodeStr ((CHAR8
*) PcdGetPtr (PcdSMBIOSBiosVendor
), Vendor
);
138 if (StrLen (Vendor
) > 0) {
139 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
140 HiiSetString (mHiiHandle
, TokenToUpdate
, Vendor
, NULL
);
142 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
143 VendorPtr
= HiiGetPackageString(&gEfiCallerIdGuid
, TokenToGet
, NULL
);
144 VendorStrLen
= StrLen(VendorPtr
);
145 if (VendorStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
146 return EFI_UNSUPPORTED
;
149 UnicodeSPrint (Version
, sizeof (Version
), L
"0x%08x", PcdGet32 (PcdFirmwareRevision
));
150 if (StrLen (Version
) > 0) {
151 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
152 HiiSetString (mHiiHandle
, TokenToUpdate
, Version
, NULL
);
154 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
155 VersionPtr
= HiiGetPackageString(&gEfiCallerIdGuid
, TokenToGet
, NULL
);
156 VerStrLen
= StrLen(VersionPtr
);
157 if (VerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
158 return EFI_UNSUPPORTED
;
161 AsciiStrToUnicodeStr ((CHAR8
*) PcdGetPtr (PcdSMBIOSBiosReleaseDate
), ReleaseDate
);
162 if (StrLen (ReleaseDate
) > 0) {
163 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
164 HiiSetString (mHiiHandle
, TokenToUpdate
, ReleaseDate
, NULL
);
166 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
167 ReleaseDatePtr
= HiiGetPackageString(&gEfiCallerIdGuid
, TokenToGet
, NULL
);
168 DateStrLen
= StrLen(ReleaseDatePtr
);
169 if (DateStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
170 return EFI_UNSUPPORTED
;
174 // Two zeros following the last string.
176 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 + VerStrLen
+ 1 + DateStrLen
+ 1 + 1);
177 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 + VerStrLen
+ 1 + DateStrLen
+ 1 + 1);
179 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_INFORMATION
;
180 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE0
);
182 // Make handle chosen by smbios protocol.add automatically.
184 SmbiosRecord
->Hdr
.Handle
= 0;
186 // Vendor will be the 1st optional string following the formatted structure.
188 SmbiosRecord
->Vendor
= 1;
190 // Version will be the 2nd optional string following the formatted structure.
192 SmbiosRecord
->BiosVersion
= 2;
193 SmbiosRecord
->BiosSegment
= PcdGet16 (PcdSMBIOSBiosStartAddress
);
195 // ReleaseDate will be the 3rd optional string following the formatted structure.
197 SmbiosRecord
->BiosReleaseDate
= 3;
198 SmbiosRecord
->BiosSize
= (UINT8
)(Base2ToByteWith64KUnit(&ForType0InputData
->BiosPhysicalDeviceSize
) - 1);
199 *(UINT64
*)&SmbiosRecord
->BiosCharacteristics
= PcdGet64 (PcdSMBIOSBiosChar
);
201 // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.
203 SmbiosRecord
->BIOSCharacteristicsExtensionBytes
[0] = PcdGet8 (PcdSMBIOSBiosCharEx1
);
204 SmbiosRecord
->BIOSCharacteristicsExtensionBytes
[1] = PcdGet8 (PcdSMBIOSBiosCharEx2
);
206 SmbiosRecord
->SystemBiosMajorRelease
= ForType0InputData
->BiosMajorRelease
;
207 SmbiosRecord
->SystemBiosMinorRelease
= ForType0InputData
->BiosMinorRelease
;
208 SmbiosRecord
->EmbeddedControllerFirmwareMajorRelease
= ForType0InputData
->BiosEmbeddedFirmwareMajorRelease
;
209 SmbiosRecord
->EmbeddedControllerFirmwareMinorRelease
= ForType0InputData
->BiosEmbeddedFirmwareMinorRelease
;
211 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
212 UnicodeStrToAsciiStr(VendorPtr
, OptionalStrStart
);
213 UnicodeStrToAsciiStr(VersionPtr
, OptionalStrStart
+ VendorStrLen
+ 1);
214 UnicodeStrToAsciiStr(ReleaseDatePtr
, OptionalStrStart
+ VendorStrLen
+ 1 + VerStrLen
+ 1);
216 // Now we have got the full smbios record, call smbios protocol to add this record.
218 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
219 Status
= Smbios
-> Add(
223 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
226 FreePool(SmbiosRecord
);