]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c
2506c03d64b17287c44cd520d67ab3656b1b4b1b
[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
22 typedef struct {
23 CONST CHAR8* MonthStr;
24 UINT32 MonthInt;
25 } MONTH_DESCRIPTION;
26
27 STATIC CONST
28 MONTH_DESCRIPTION mMonthDescription[] = {
29 { "Jan", 1 },
30 { "Feb", 2 },
31 { "Mar", 3 },
32 { "Apr", 4 },
33 { "May", 5 },
34 { "Jun", 6 },
35 { "Jul", 7 },
36 { "Aug", 8 },
37 { "Sep", 9 },
38 { "Oct", 10 },
39 { "Nov", 11 },
40 { "Dec", 12 },
41 { "???", 1 }, // Use 1 as default month
42 };
43
44 /**
45 Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
46 as the unit.
47
48 @param Value Pointer to Base2_Data
49
50 @retval
51
52 **/
53 UINT8
54 Base2ToByteWith64KUnit (
55 IN UINTN Value
56 )
57 {
58 UINT8 Size;
59
60 Size = ((Value + (SIZE_64KB - 1)) >> 16);
61
62 return Size;
63 }
64
65 /**
66 Returns the date and time this file (and firmware) was built.
67
68 @param[out] *Time Pointer to the EFI_TIME structure to fill in.
69 **/
70 VOID
71 GetReleaseTime (
72 OUT EFI_TIME *Time
73 )
74 {
75 CONST CHAR8 *ReleaseDate = __DATE__;
76 CONST CHAR8 *ReleaseTime = __TIME__;
77 UINTN i;
78
79 for (i = 0; i < 12; i++) {
80 if (AsciiStrnCmp (ReleaseDate, mMonthDescription[i].MonthStr, 3) == 0) {
81 break;
82 }
83 }
84
85 Time->Month = mMonthDescription[i].MonthInt;
86 Time->Day = AsciiStrDecimalToUintn (ReleaseDate + 4);
87 Time->Year = AsciiStrDecimalToUintn (ReleaseDate + 7);
88 Time->Hour = AsciiStrDecimalToUintn (ReleaseTime);
89 Time->Minute = AsciiStrDecimalToUintn (ReleaseTime + 3);
90 Time->Second = AsciiStrDecimalToUintn (ReleaseTime + 6);
91 }
92
93 /**
94 Fetches the firmware ('BIOS') release date from the
95 FirmwareVersionInfo HOB.
96
97 @return The release date as a UTF-16 string
98 **/
99 CHAR16 *
100 GetBiosReleaseDate (
101 VOID
102 )
103 {
104 CHAR16 *ReleaseDate;
105 EFI_TIME BuildTime;
106
107 ReleaseDate = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH);
108 if (ReleaseDate == NULL) {
109 return NULL;
110 }
111
112 GetReleaseTime (&BuildTime);
113
114 (VOID)UnicodeSPrintAsciiFormat (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 /**
145 This function makes boot time changes to the contents of the
146 MiscBiosVendor (Type 0) record.
147
148 @param RecordData Pointer to SMBIOS table with default values.
149 @param Smbios SMBIOS protocol.
150
151 @retval EFI_SUCCESS The SMBIOS table was successfully added.
152 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
153 @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory.
154
155 **/
156 SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor)
157 {
158 CHAR8 *OptionalStrStart;
159 CHAR8 *StrStart;
160 UINTN VendorStrLen;
161 UINTN VerStrLen;
162 UINTN DateStrLen;
163 UINTN BiosPhysicalSize;
164 CHAR16 *Vendor;
165 CHAR16 *Version;
166 CHAR16 *ReleaseDate;
167 CHAR16 *Char16String;
168 EFI_STATUS Status;
169 EFI_STRING_ID TokenToUpdate;
170 EFI_STRING_ID TokenToGet;
171 SMBIOS_TABLE_TYPE0 *SmbiosRecord;
172 SMBIOS_TABLE_TYPE0 *InputData;
173
174 //
175 // First check for invalid parameters.
176 //
177 if (RecordData == NULL) {
178 return EFI_INVALID_PARAMETER;
179 }
180
181 InputData = (SMBIOS_TABLE_TYPE0 *)RecordData;
182
183 Vendor = (CHAR16 *) PcdGetPtr (PcdFirmwareVendor);
184
185 if (StrLen (Vendor) > 0) {
186 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
187 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Vendor, NULL);
188 }
189
190 Version = GetBiosVersion();
191
192 if (StrLen (Version) > 0) {
193 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
194 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
195 } else {
196 Version = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);
197 if (StrLen (Version) > 0) {
198 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
199 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
200 }
201 }
202
203 Char16String = GetBiosReleaseDate ();
204 if (StrLen(Char16String) > 0) {
205 TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
206 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Char16String, NULL);
207 }
208
209 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
210 Vendor = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
211 VendorStrLen = StrLen (Vendor);
212
213 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
214 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
215 VerStrLen = StrLen (Version);
216
217 TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
218 ReleaseDate = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
219 DateStrLen = StrLen (ReleaseDate);
220
221 //
222 // Now update the BiosPhysicalSize
223 //
224 BiosPhysicalSize = FixedPcdGet32 (PcdFdSize);
225
226 //
227 // Two zeros following the last string.
228 //
229 SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 +
230 VerStrLen + 1 +
231 DateStrLen + 1 + 1);
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 ((DEBUG_ERROR, "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",
274 __FUNCTION__, DEBUG_LINE_NUMBER, Status));
275 }
276
277 FreePool (SmbiosRecord);
278
279 Exit:
280 if (Vendor != NULL) {
281 FreePool (Vendor);
282 }
283
284 if (Version != NULL) {
285 FreePool (Version);
286 }
287
288 if (ReleaseDate != NULL) {
289 FreePool (ReleaseDate);
290 }
291
292 if (Char16String != NULL) {
293 FreePool (Char16String);
294 }
295
296 return Status;
297 }