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