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