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