3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 MiscBiosVendorFunction.c
21 BIOS vendor information boot time changes.
22 Misc. subclass type 2.
28 #include "CommonHeader.h"
30 #include "MiscSubclassDriver.h"
31 #include <Library/BiosIdLib.h>
32 #include <Library/SpiFlash.H>
34 EFI_SPI_PROTOCOL
*mSpiProtocol
= NULL
;
38 This function read the data from Spi Rom.
40 @param BaseAddress The starting address of the read.
41 @param Byte The pointer to the destination buffer.
42 @param Length The number of bytes.
43 @param SpiRegionType Spi Region Type.
53 IN SPI_REGION_TYPE SpiRegionType
56 EFI_STATUS Status
= EFI_SUCCESS
;
59 UINT8 Buffer
[SECTOR_SIZE_4KB
];
61 SpiAddress
= (UINT32
)(UINTN
)(BaseAddress
);
62 SectorSize
= SECTOR_SIZE_4KB
;
64 Status
= mSpiProtocol
->Execute (
77 if (EFI_ERROR (Status
)) {
79 Print(L
"Read SPI ROM Failed [%08x]\n", SpiAddress
);
84 CopyMem (Byte
, (void *)Buffer
, Length
);
90 This function returns the value & exponent to Base2 for a given
91 Hex value. This is used to calculate the BiosPhysicalDeviceSize.
93 @param Value The hex value which is to be converted into value-exponent form
94 @param Exponent The exponent out of the conversion
96 @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.
97 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
101 GetValueExponentBase2(
106 if ((Value
== NULL
) || (Exponent
== NULL
)) {
107 return EFI_INVALID_PARAMETER
;
110 while ((*Value
% 2) == 0) {
119 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
122 @param Base2Data Pointer to Base2_Data
124 @retval EFI_SUCCESS Transform successfully.
125 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
129 Base2ToByteWith64KUnit (
130 IN EFI_EXP_BASE2_DATA
*Base2Data
136 Value
= Base2Data
->Value
;
137 Exponent
= Base2Data
->Exponent
;
146 This function makes boot time changes to the contents of the
147 MiscBiosVendor (Type 0).
149 @param RecordData Pointer to copy of RecordData from the Data Table.
151 @retval EFI_SUCCESS All parameters were valid.
152 @retval EFI_UNSUPPORTED Unexpected RecordType value.
153 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
156 MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor
)
158 CHAR8
*OptionalStrStart
;
164 CHAR16 BiosVersion
[100]; //Assuming that strings are < 100 UCHAR
165 CHAR16 BiosReleaseDate
[100]; //Assuming that strings are < 100 UCHAR
166 CHAR16 BiosReleaseTime
[100]; //Assuming that strings are < 100 UCHAR
168 EFI_STRING Char16String
;
169 STRING_REF TokenToGet
;
170 STRING_REF TokenToUpdate
;
171 SMBIOS_TABLE_TYPE0
*SmbiosRecord
;
172 EFI_SMBIOS_HANDLE SmbiosHandle
;
173 EFI_MISC_BIOS_VENDOR
*ForType0InputData
;
174 BIOS_ID_IMAGE BiosIdImage
;
178 MANIFEST_OEM_DATA
*IFWIVerStruct
;
180 UINT16 SpaceVer
[2]={0x0020,0x0000};
181 UINT16 BIOSVersionTemp
[100];
183 ForType0InputData
= (EFI_MISC_BIOS_VENDOR
*)RecordData
;
186 // First check for invalid parameters.
188 if (RecordData
== NULL
) {
189 return EFI_INVALID_PARAMETER
;
191 GetBiosId (&BiosIdImage
);
194 // Add VLV2 BIOS Version and Release data
196 SetMem(BiosVersion
, sizeof(BiosVersion
), 0);
197 SetMem(BiosReleaseDate
, sizeof(BiosReleaseDate
), 0);
198 SetMem(BiosReleaseTime
, sizeof(BiosReleaseTime
), 0);
199 Status
= GetBiosVersionDateTime (BiosVersion
, BiosReleaseDate
, BiosReleaseTime
);
200 DEBUG ((EFI_D_ERROR
, "GetBiosVersionDateTime :%s %s %s \n", BiosVersion
, BiosReleaseDate
, BiosReleaseTime
));
201 if (StrLen (BiosVersion
) > 0) {
202 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
203 HiiSetString (mHiiHandle
, TokenToUpdate
, BiosVersion
, NULL
);
206 if (StrLen(BiosReleaseDate
) > 0) {
207 TokenToUpdate
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
208 HiiSetString (mHiiHandle
, TokenToUpdate
, BiosReleaseDate
, NULL
);
211 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VENDOR
);
212 Char16String
= SmbiosMiscGetString (TokenToGet
);
213 VendorStrLen
= StrLen(Char16String
);
214 if (VendorStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
215 return EFI_UNSUPPORTED
;
218 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_VERSION
);
219 Version
= SmbiosMiscGetString (TokenToGet
);
221 ZeroMem (UVerStr
, 2*32);
222 ZeroMem (BIOSVersionTemp
, 2*100);
223 StrCat (BIOSVersionTemp
,Version
);
224 Data8
= AllocatePool (SECTOR_SIZE_4KB
);
225 ZeroMem (Data8
, SECTOR_SIZE_4KB
);
227 Status
= gBS
->LocateProtocol (
228 &gEfiSpiProtocolGuid
,
230 (VOID
**)&mSpiProtocol
232 if (!EFI_ERROR(Status
)) {
234 // Get data form SPI ROM.
242 if (!EFI_ERROR(Status
)) {
243 for(LoopIndex
= 0; LoopIndex
<= SECTOR_SIZE_4KB
; LoopIndex
++) {
244 IFWIVerStruct
= (MANIFEST_OEM_DATA
*)(Data8
+ LoopIndex
);
245 if(IFWIVerStruct
->Signature
== SIGNATURE_32('$','F','U','D')) {
246 DEBUG ((EFI_D_ERROR
, "the IFWI Length is:%d\n", IFWIVerStruct
->IFWIVersionLen
));
247 if(IFWIVerStruct
->IFWIVersionLen
< 32) {
248 for(CopyIndex
= 0; CopyIndex
< IFWIVerStruct
->IFWIVersionLen
; CopyIndex
++) {
249 UVerStr
[CopyIndex
] = (UINT16
)IFWIVerStruct
->IFWIVersion
[CopyIndex
];
251 UVerStr
[CopyIndex
] = 0x0000;
252 DEBUG ((EFI_D_ERROR
, "The IFWI Version is :%s,the IFWI Length is:%d\n", UVerStr
,IFWIVerStruct
->IFWIVersionLen
));
253 StrCat(BIOSVersionTemp
,SpaceVer
);
254 StrCat(BIOSVersionTemp
,UVerStr
);
255 DEBUG ((EFI_D_ERROR
, "The BIOS and IFWI Version is :%s\n", BIOSVersionTemp
));
264 VerStrLen
= StrLen(BIOSVersionTemp
);
265 if (VerStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
266 return EFI_UNSUPPORTED
;
269 TokenToGet
= STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE
);
270 ReleaseDate
= SmbiosMiscGetString (TokenToGet
);
271 DateStrLen
= StrLen(ReleaseDate
);
272 if (DateStrLen
> SMBIOS_STRING_MAX_LENGTH
) {
273 return EFI_UNSUPPORTED
;
277 // Two zeros following the last string.
279 SmbiosRecord
= AllocatePool(sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 + VerStrLen
+ 1 + DateStrLen
+ 1 + 1);
280 ZeroMem(SmbiosRecord
, sizeof (SMBIOS_TABLE_TYPE0
) + VendorStrLen
+ 1 + VerStrLen
+ 1 + DateStrLen
+ 1 + 1);
282 SmbiosRecord
->Hdr
.Type
= EFI_SMBIOS_TYPE_BIOS_INFORMATION
;
283 SmbiosRecord
->Hdr
.Length
= sizeof (SMBIOS_TABLE_TYPE0
);
286 // Make handle chosen by smbios protocol.add automatically.
288 SmbiosRecord
->Hdr
.Handle
= 0;
291 // Vendor will be the 1st optional string following the formatted structure.
293 SmbiosRecord
->Vendor
= 1;
296 // Version will be the 2nd optional string following the formatted structure.
298 SmbiosRecord
->BiosVersion
= 2;
299 SmbiosRecord
->BiosSegment
= (UINT16
)ForType0InputData
->BiosStartingAddress
;
302 // ReleaseDate will be the 3rd optional string following the formatted structure.
304 SmbiosRecord
->BiosReleaseDate
= 3;
307 // Tiger has no PCD value to indicate BIOS Size, just fill 0 for simply.
309 SmbiosRecord
->BiosSize
= 0;
310 SmbiosRecord
->BiosCharacteristics
= *(MISC_BIOS_CHARACTERISTICS
*)(&ForType0InputData
->BiosCharacteristics1
);
313 // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.
315 SmbiosRecord
->BIOSCharacteristicsExtensionBytes
[0] = *((UINT8
*) &ForType0InputData
->BiosCharacteristics1
+ 4);
316 SmbiosRecord
->BIOSCharacteristicsExtensionBytes
[1] = *((UINT8
*) &ForType0InputData
->BiosCharacteristics1
+ 5);
318 SmbiosRecord
->SystemBiosMajorRelease
= ForType0InputData
->BiosMajorRelease
;
319 SmbiosRecord
->SystemBiosMinorRelease
= ForType0InputData
->BiosMinorRelease
;
320 SmbiosRecord
->EmbeddedControllerFirmwareMajorRelease
= ForType0InputData
->BiosEmbeddedFirmwareMajorRelease
;
321 SmbiosRecord
->EmbeddedControllerFirmwareMinorRelease
= ForType0InputData
->BiosEmbeddedFirmwareMinorRelease
;
323 OptionalStrStart
= (CHAR8
*)(SmbiosRecord
+ 1);
324 UnicodeStrToAsciiStr(Char16String
, OptionalStrStart
);
325 UnicodeStrToAsciiStr(BIOSVersionTemp
, OptionalStrStart
+ VendorStrLen
+ 1);
326 UnicodeStrToAsciiStr(ReleaseDate
, OptionalStrStart
+ VendorStrLen
+ 1 + VerStrLen
+ 1);
329 // Now we have got the full smbios record, call smbios protocol to add this record.
331 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
332 Status
= Smbios
-> Add(
336 (EFI_SMBIOS_TABLE_HEADER
*) SmbiosRecord
339 FreePool(SmbiosRecord
);