]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBiosVendorFunction.c
MdeModulePkg/CapsuleApp: Center bitmap at bottom of screen
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmBiosMiscDxe / MiscBiosVendorFunction.c
1 /*++
2
3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
4
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.
9
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.
12
13
14
15 Module Name:
16
17 MiscBiosVendorFunction.c
18
19 Abstract:
20
21 BIOS vendor information boot time changes.
22 Misc. subclass type 2.
23 SMBIOS type 0.
24
25 --*/
26
27
28 #include "CommonHeader.h"
29
30 #include "MiscSubclassDriver.h"
31 #include <Library/BiosIdLib.h>
32 #include <Library/SpiFlash.H>
33
34 EFI_SPI_PROTOCOL *mSpiProtocol = NULL;
35
36
37 /**
38 This function read the data from Spi Rom.
39
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.
44
45 @retval Status
46
47 **/
48 EFI_STATUS
49 FlashRead (
50 IN UINTN BaseAddress,
51 IN UINT8 *Byte,
52 IN UINTN Length,
53 IN SPI_REGION_TYPE SpiRegionType
54 )
55 {
56 EFI_STATUS Status = EFI_SUCCESS;
57 UINT32 SectorSize;
58 UINT32 SpiAddress;
59 UINT8 Buffer[SECTOR_SIZE_4KB];
60
61 SpiAddress = (UINT32)(UINTN)(BaseAddress);
62 SectorSize = SECTOR_SIZE_4KB;
63
64 Status = mSpiProtocol->Execute (
65 mSpiProtocol,
66 SPI_READ,
67 SPI_WREN,
68 TRUE,
69 TRUE,
70 FALSE,
71 (UINT32) SpiAddress,
72 SectorSize,
73 Buffer,
74 SpiRegionType
75 );
76
77 if (EFI_ERROR (Status)) {
78 #ifdef _SHOW_LOG_
79 Print(L"Read SPI ROM Failed [%08x]\n", SpiAddress);
80 #endif
81 return Status;
82 }
83
84 CopyMem (Byte, (void *)Buffer, Length);
85
86 return Status;
87 }
88
89 /**
90 This function returns the value & exponent to Base2 for a given
91 Hex value. This is used to calculate the BiosPhysicalDeviceSize.
92
93 @param Value The hex value which is to be converted into value-exponent form
94 @param Exponent The exponent out of the conversion
95
96 @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.
97 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
98
99 **/
100 EFI_STATUS
101 GetValueExponentBase2(
102 IN OUT UINTN *Value,
103 OUT UINTN *Exponent
104 )
105 {
106 if ((Value == NULL) || (Exponent == NULL)) {
107 return EFI_INVALID_PARAMETER;
108 }
109
110 while ((*Value % 2) == 0) {
111 *Value=*Value/2;
112 (*Exponent)++;
113 }
114
115 return EFI_SUCCESS;
116 }
117
118 /**
119 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
120 as the unit.
121
122 @param Base2Data Pointer to Base2_Data
123
124 @retval EFI_SUCCESS Transform successfully.
125 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
126
127 **/
128 UINT16
129 Base2ToByteWith64KUnit (
130 IN EFI_EXP_BASE2_DATA *Base2Data
131 )
132 {
133 UINT16 Value;
134 UINT16 Exponent;
135
136 Value = Base2Data->Value;
137 Exponent = Base2Data->Exponent;
138 Exponent -= 16;
139 Value <<= Exponent;
140
141 return Value;
142 }
143
144
145 /**
146 This function makes boot time changes to the contents of the
147 MiscBiosVendor (Type 0).
148
149 @param RecordData Pointer to copy of RecordData from the Data Table.
150
151 @retval EFI_SUCCESS All parameters were valid.
152 @retval EFI_UNSUPPORTED Unexpected RecordType value.
153 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
154
155 **/
156 MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
157 {
158 CHAR8 *OptionalStrStart;
159 UINTN VendorStrLen;
160 UINTN VerStrLen;
161 UINTN DateStrLen;
162 CHAR16 *Version;
163 CHAR16 *ReleaseDate;
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
167 EFI_STATUS Status;
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;
175 UINT16 UVerStr[32];
176 UINTN LoopIndex;
177 UINTN CopyIndex;
178 MANIFEST_OEM_DATA *IFWIVerStruct;
179 UINT8 *Data8 = NULL;
180 UINT16 SpaceVer[2]={0x0020,0x0000};
181 UINT16 BIOSVersionTemp[100];
182
183 ForType0InputData = (EFI_MISC_BIOS_VENDOR *)RecordData;
184
185 //
186 // First check for invalid parameters.
187 //
188 if (RecordData == NULL) {
189 return EFI_INVALID_PARAMETER;
190 }
191 GetBiosId (&BiosIdImage);
192
193 //
194 // Add VLV2 BIOS Version and Release data
195 //
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);
204 }
205
206 if (StrLen(BiosReleaseDate) > 0) {
207 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
208 HiiSetString (mHiiHandle, TokenToUpdate, BiosReleaseDate, NULL);
209 }
210
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;
216 }
217
218 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
219 Version = SmbiosMiscGetString (TokenToGet);
220
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);
226
227 Status = gBS->LocateProtocol (
228 &gEfiSpiProtocolGuid,
229 NULL,
230 (VOID **)&mSpiProtocol
231 );
232 if (!EFI_ERROR(Status)) {
233 //
234 // Get data form SPI ROM.
235 //
236 Status = FlashRead (
237 MEM_IFWIVER_START,
238 Data8,
239 SECTOR_SIZE_4KB,
240 EnumSpiRegionAll
241 );
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];
250 }
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));
256 }
257 break;
258 }
259 }
260 }
261 }
262 FreePool(Data8);
263
264 VerStrLen = StrLen(BIOSVersionTemp);
265 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
266 return EFI_UNSUPPORTED;
267 }
268
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;
274 }
275
276 //
277 // Two zeros following the last string.
278 //
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);
281
282 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;
283 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
284
285 //
286 // Make handle chosen by smbios protocol.add automatically.
287 //
288 SmbiosRecord->Hdr.Handle = 0;
289
290 //
291 // Vendor will be the 1st optional string following the formatted structure.
292 //
293 SmbiosRecord->Vendor = 1;
294
295 //
296 // Version will be the 2nd optional string following the formatted structure.
297 //
298 SmbiosRecord->BiosVersion = 2;
299 SmbiosRecord->BiosSegment = (UINT16)ForType0InputData->BiosStartingAddress;
300
301 //
302 // ReleaseDate will be the 3rd optional string following the formatted structure.
303 //
304 SmbiosRecord->BiosReleaseDate = 3;
305
306 //
307 // Tiger has no PCD value to indicate BIOS Size, just fill 0 for simply.
308 //
309 SmbiosRecord->BiosSize = 0;
310 SmbiosRecord->BiosCharacteristics = *(MISC_BIOS_CHARACTERISTICS*)(&ForType0InputData->BiosCharacteristics1);
311
312 //
313 // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.
314 //
315 SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 4);
316 SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = *((UINT8 *) &ForType0InputData->BiosCharacteristics1 + 5);
317
318 SmbiosRecord->SystemBiosMajorRelease = ForType0InputData->BiosMajorRelease;
319 SmbiosRecord->SystemBiosMinorRelease = ForType0InputData->BiosMinorRelease;
320 SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = ForType0InputData->BiosEmbeddedFirmwareMajorRelease;
321 SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = ForType0InputData->BiosEmbeddedFirmwareMinorRelease;
322
323 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
324 UnicodeStrToAsciiStr(Char16String, OptionalStrStart);
325 UnicodeStrToAsciiStr(BIOSVersionTemp, OptionalStrStart + VendorStrLen + 1);
326 UnicodeStrToAsciiStr(ReleaseDate, OptionalStrStart + VendorStrLen + 1 + VerStrLen + 1);
327
328 //
329 // Now we have got the full smbios record, call smbios protocol to add this record.
330 //
331 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
332 Status = Smbios-> Add(
333 Smbios,
334 NULL,
335 &SmbiosHandle,
336 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
337 );
338
339 FreePool(SmbiosRecord);
340 return Status;
341 }