]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Platform/Dxe/SmbiosMiscDxe/MiscBiosVendorFunction.c
QuarkPlatformPkg: Add new package for Galileo boards
[mirror_edk2.git] / QuarkPlatformPkg / Platform / Dxe / SmbiosMiscDxe / MiscBiosVendorFunction.c
1 /** @file
2 BIOS vendor information boot time changes.
3 Misc. subclass type 2.
4 SMBIOS type 0.
5
6 Copyright (c) 2013-2015 Intel Corporation.
7
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
12
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.
15
16
17 **/
18
19
20 #include "CommonHeader.h"
21
22 #include "SmbiosMisc.h"
23
24 /**
25 This function returns the value & exponent to Base2 for a given
26 Hex value. This is used to calculate the BiosPhysicalDeviceSize.
27
28 @param Value The hex value which is to be converted into value-exponent form
29 @param Exponent The exponent out of the conversion
30
31 @retval EFI_SUCCESS All parameters were valid and *Value & *Exponent have been set.
32 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
33
34 **/
35 EFI_STATUS
36 GetValueExponentBase2(
37 IN OUT UINTN *Value,
38 OUT UINTN *Exponent
39 )
40 {
41 if ((Value == NULL) || (Exponent == NULL)) {
42 return EFI_INVALID_PARAMETER;
43 }
44
45 while ((*Value % 2) == 0) {
46 *Value=*Value/2;
47 (*Exponent)++;
48 }
49
50 return EFI_SUCCESS;
51 }
52
53 /**
54 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
55 as the unit.
56
57 @param Base2Data Pointer to Base2_Data
58
59 @retval EFI_SUCCESS Transform successfully.
60 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
61
62 **/
63 UINT16
64 Base2ToByteWith64KUnit (
65 IN EFI_EXP_BASE2_DATA *Base2Data
66 )
67 {
68 UINT16 Value;
69 UINT16 Exponent;
70
71 Value = Base2Data->Value;
72 Exponent = Base2Data->Exponent;
73 Exponent -= 16;
74 Value <<= Exponent;
75
76 return Value;
77 }
78
79
80 /**
81 This function makes boot time changes to the contents of the
82 MiscBiosVendor (Type 0).
83
84 @param RecordData Pointer to copy of RecordData from the Data Table.
85
86 @retval EFI_SUCCESS All parameters were valid.
87 @retval EFI_UNSUPPORTED Unexpected RecordType value.
88 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
89
90 **/
91 MISC_SMBIOS_TABLE_FUNCTION(MiscBiosVendor)
92 {
93 CHAR8 *OptionalStrStart;
94 UINTN VendorStrLen;
95 UINTN VerStrLen;
96 UINTN DateStrLen;
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;
105 EFI_STATUS Status;
106 STRING_REF TokenToGet;
107 STRING_REF TokenToUpdate;
108 SMBIOS_TABLE_TYPE0 *SmbiosRecord;
109 EFI_SMBIOS_HANDLE SmbiosHandle;
110 EFI_MISC_BIOS_VENDOR *ForType0InputData;
111
112 BiosPhysicalSizeHexValue = 0x0;
113 BiosPhysicalSizeExponent = 0x0;
114 ForType0InputData = (EFI_MISC_BIOS_VENDOR *)RecordData;
115
116 //
117 // First check for invalid parameters.
118 //
119 if (RecordData == NULL) {
120 return EFI_INVALID_PARAMETER;
121 }
122 //
123 // Now update the BiosPhysicalSize
124 //
125 BiosPhysicalSizeHexValue = PcdGet32 (PcdFlashAreaSize);
126 Status= GetValueExponentBase2 (
127 &BiosPhysicalSizeHexValue,
128 &BiosPhysicalSizeExponent
129 );
130 if(Status == EFI_SUCCESS){
131 ForType0InputData->BiosPhysicalDeviceSize.Value = (UINT16)BiosPhysicalSizeHexValue;
132 ForType0InputData->BiosPhysicalDeviceSize.Exponent = (UINT16)BiosPhysicalSizeExponent;
133 }
134 //
135 // Update strings from PCD
136 //
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);
141 }
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;
147 }
148
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);
153 }
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;
159 }
160
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);
165 }
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;
171 }
172
173 //
174 // Two zeros following the last string.
175 //
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);
178
179 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BIOS_INFORMATION;
180 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
181 //
182 // Make handle chosen by smbios protocol.add automatically.
183 //
184 SmbiosRecord->Hdr.Handle = 0;
185 //
186 // Vendor will be the 1st optional string following the formatted structure.
187 //
188 SmbiosRecord->Vendor = 1;
189 //
190 // Version will be the 2nd optional string following the formatted structure.
191 //
192 SmbiosRecord->BiosVersion = 2;
193 SmbiosRecord->BiosSegment = PcdGet16 (PcdSMBIOSBiosStartAddress);
194 //
195 // ReleaseDate will be the 3rd optional string following the formatted structure.
196 //
197 SmbiosRecord->BiosReleaseDate = 3;
198 SmbiosRecord->BiosSize = (UINT8)(Base2ToByteWith64KUnit(&ForType0InputData->BiosPhysicalDeviceSize) - 1);
199 *(UINT64 *)&SmbiosRecord->BiosCharacteristics = PcdGet64 (PcdSMBIOSBiosChar);
200 //
201 // CharacterExtensionBytes also store in ForType0InputData->BiosCharacteristics1 later two bytes to save size.
202 //
203 SmbiosRecord->BIOSCharacteristicsExtensionBytes[0] = PcdGet8 (PcdSMBIOSBiosCharEx1);
204 SmbiosRecord->BIOSCharacteristicsExtensionBytes[1] = PcdGet8 (PcdSMBIOSBiosCharEx2);
205
206 SmbiosRecord->SystemBiosMajorRelease = ForType0InputData->BiosMajorRelease;
207 SmbiosRecord->SystemBiosMinorRelease = ForType0InputData->BiosMinorRelease;
208 SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = ForType0InputData->BiosEmbeddedFirmwareMajorRelease;
209 SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = ForType0InputData->BiosEmbeddedFirmwareMinorRelease;
210
211 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
212 UnicodeStrToAsciiStr(VendorPtr, OptionalStrStart);
213 UnicodeStrToAsciiStr(VersionPtr, OptionalStrStart + VendorStrLen + 1);
214 UnicodeStrToAsciiStr(ReleaseDatePtr, OptionalStrStart + VendorStrLen + 1 + VerStrLen + 1);
215 //
216 // Now we have got the full smbios record, call smbios protocol to add this record.
217 //
218 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
219 Status = Smbios-> Add(
220 Smbios,
221 NULL,
222 &SmbiosHandle,
223 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
224 );
225
226 FreePool(SmbiosRecord);
227 return Status;
228 }