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