]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Universal / Smbios / SmbiosMiscDxe / Type00 / MiscBiosVendorFunction.c
1 /** @file
2
3 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
4 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
6 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HiiLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/PrintLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18
19 #include "SmbiosMisc.h"
20
21 typedef struct {
22 CONST CHAR8 *MonthStr;
23 UINT32 MonthInt;
24 } MONTH_DESCRIPTION;
25
26 STATIC CONST
27 MONTH_DESCRIPTION mMonthDescription[] = {
28 { "Jan", 1 },
29 { "Feb", 2 },
30 { "Mar", 3 },
31 { "Apr", 4 },
32 { "May", 5 },
33 { "Jun", 6 },
34 { "Jul", 7 },
35 { "Aug", 8 },
36 { "Sep", 9 },
37 { "Oct", 10 },
38 { "Nov", 11 },
39 { "Dec", 12 },
40 { "???", 1 }, // Use 1 as default month
41 };
42
43 /**
44 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
45 as the unit.
46
47 @param Value Pointer to Base2_Data
48
49 @retval
50
51 **/
52 UINT8
53 Base2ToByteWith64KUnit (
54 IN UINTN Value
55 )
56 {
57 UINT8 Size;
58
59 Size = ((Value + (SIZE_64KB - 1)) >> 16);
60
61 return Size;
62 }
63
64 /**
65 Returns the date and time this file (and firmware) was built.
66
67 @param[out] *Time Pointer to the EFI_TIME structure to fill in.
68 **/
69 VOID
70 GetReleaseTime (
71 OUT EFI_TIME *Time
72 )
73 {
74 CONST CHAR8 *ReleaseDate = __DATE__;
75 CONST CHAR8 *ReleaseTime = __TIME__;
76 UINTN i;
77
78 for (i = 0; i < 12; i++) {
79 if (AsciiStrnCmp (ReleaseDate, mMonthDescription[i].MonthStr, 3) == 0) {
80 break;
81 }
82 }
83
84 Time->Month = mMonthDescription[i].MonthInt;
85 Time->Day = AsciiStrDecimalToUintn (ReleaseDate + 4);
86 Time->Year = AsciiStrDecimalToUintn (ReleaseDate + 7);
87 Time->Hour = AsciiStrDecimalToUintn (ReleaseTime);
88 Time->Minute = AsciiStrDecimalToUintn (ReleaseTime + 3);
89 Time->Second = AsciiStrDecimalToUintn (ReleaseTime + 6);
90 }
91
92 /**
93 Fetches the firmware ('BIOS') release date from the
94 FirmwareVersionInfo HOB.
95
96 @return The release date as a UTF-16 string
97 **/
98 CHAR16 *
99 GetBiosReleaseDate (
100 VOID
101 )
102 {
103 CHAR16 *ReleaseDate;
104 EFI_TIME BuildTime;
105
106 ReleaseDate = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH);
107 if (ReleaseDate == NULL) {
108 return NULL;
109 }
110
111 GetReleaseTime (&BuildTime);
112
113 (VOID)UnicodeSPrintAsciiFormat (
114 ReleaseDate,
115 (sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH,
116 "%02d/%02d/%4d",
117 BuildTime.Month,
118 BuildTime.Day,
119 BuildTime.Year
120 );
121
122 return ReleaseDate;
123 }
124
125 /**
126 Fetches the firmware ('BIOS') version from the
127 FirmwareVersionInfo HOB.
128
129 @return The version as a UTF-16 string
130 **/
131 CHAR16 *
132 GetBiosVersion (
133 VOID
134 )
135 {
136 CHAR16 *ReleaseString;
137
138 ReleaseString = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);
139
140 return ReleaseString;
141 }
142
143 /**
144 This function makes boot time changes to the contents of the
145 MiscBiosVendor (Type 0) record.
146
147 @param RecordData Pointer to SMBIOS table with default values.
148 @param Smbios SMBIOS protocol.
149
150 @retval EFI_SUCCESS The SMBIOS table was successfully added.
151 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
152 @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory.
153
154 **/
155 SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor) {
156 CHAR8 *OptionalStrStart;
157 CHAR8 *StrStart;
158 UINTN VendorStrLen;
159 UINTN VerStrLen;
160 UINTN DateStrLen;
161 UINTN BiosPhysicalSize;
162 CHAR16 *Vendor;
163 CHAR16 *Version;
164 CHAR16 *ReleaseDate;
165 CHAR16 *Char16String;
166 EFI_STATUS Status;
167 EFI_STRING_ID TokenToUpdate;
168 EFI_STRING_ID TokenToGet;
169 SMBIOS_TABLE_TYPE0 *SmbiosRecord;
170 SMBIOS_TABLE_TYPE0 *InputData;
171
172 //
173 // First check for invalid parameters.
174 //
175 if (RecordData == NULL) {
176 return EFI_INVALID_PARAMETER;
177 }
178
179 InputData = (SMBIOS_TABLE_TYPE0 *)RecordData;
180
181 Vendor = (CHAR16 *)PcdGetPtr (PcdFirmwareVendor);
182
183 if (StrLen (Vendor) > 0) {
184 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
185 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Vendor, NULL);
186 }
187
188 Version = GetBiosVersion ();
189
190 if (StrLen (Version) > 0) {
191 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
192 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
193 } else {
194 Version = (CHAR16 *)PcdGetPtr (PcdFirmwareVersionString);
195 if (StrLen (Version) > 0) {
196 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
197 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
198 }
199 }
200
201 Char16String = GetBiosReleaseDate ();
202 if (StrLen (Char16String) > 0) {
203 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
204 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Char16String, NULL);
205 }
206
207 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
208 Vendor = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
209 VendorStrLen = StrLen (Vendor);
210
211 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
212 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
213 VerStrLen = StrLen (Version);
214
215 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
216 ReleaseDate = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
217 DateStrLen = StrLen (ReleaseDate);
218
219 //
220 // Now update the BiosPhysicalSize
221 //
222 BiosPhysicalSize = FixedPcdGet32 (PcdFdSize);
223
224 //
225 // Two zeros following the last string.
226 //
227 SmbiosRecord = AllocateZeroPool (
228 sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 +
229 VerStrLen + 1 +
230 DateStrLen + 1 + 1
231 );
232 if (SmbiosRecord == NULL) {
233 Status = EFI_OUT_OF_RESOURCES;
234 goto Exit;
235 }
236
237 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE0));
238
239 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
240 SmbiosRecord->BiosSegment = (UINT16)(FixedPcdGet32 (PcdFdBaseAddress) / SIZE_64KB);
241 if (BiosPhysicalSize < SIZE_16MB) {
242 SmbiosRecord->BiosSize = Base2ToByteWith64KUnit (BiosPhysicalSize) - 1;
243 } else {
244 SmbiosRecord->BiosSize = 0xFF;
245 if (BiosPhysicalSize < SIZE_16GB) {
246 SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1MB;
247 SmbiosRecord->ExtendedBiosSize.Unit = 0; // Size is in MB
248 } else {
249 SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1GB;
250 SmbiosRecord->ExtendedBiosSize.Unit = 1; // Size is in GB
251 }
252 }
253
254 SmbiosRecord->SystemBiosMajorRelease = (UINT8)(PcdGet16 (PcdSystemBiosRelease) >> 8);
255 SmbiosRecord->SystemBiosMinorRelease = (UINT8)(PcdGet16 (PcdSystemBiosRelease) & 0xFF);
256
257 SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = (UINT16)
258 (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) >> 8);
259 SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = (UINT16)
260 (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) & 0xFF);
261
262 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
263 UnicodeStrToAsciiStrS (Vendor, OptionalStrStart, VendorStrLen + 1);
264 StrStart = OptionalStrStart + VendorStrLen + 1;
265 UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
266 StrStart += VerStrLen + 1;
267 UnicodeStrToAsciiStrS (ReleaseDate, StrStart, DateStrLen + 1);
268 //
269 // Now we have got the full smbios record, call smbios protocol to add this record.
270 //
271 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
272 if (EFI_ERROR (Status)) {
273 DEBUG ((
274 DEBUG_ERROR,
275 "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",
276 __FUNCTION__,
277 DEBUG_LINE_NUMBER,
278 Status
279 ));
280 }
281
282 FreePool (SmbiosRecord);
283
284 Exit:
285 if (Vendor != NULL) {
286 FreePool (Vendor);
287 }
288
289 if (Version != NULL) {
290 FreePool (Version);
291 }
292
293 if (ReleaseDate != NULL) {
294 FreePool (ReleaseDate);
295 }
296
297 if (Char16String != NULL) {
298 FreePool (Char16String);
299 }
300
301 return Status;
302 }