]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type01/MiscSystemManufacturerFunction.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Universal / Smbios / SmbiosMiscDxe / Type01 / MiscSystemManufacturerFunction.c
1 /** @file
2 This driver parses the mMiscSubclassDataTable structure and reports
3 any generated data to smbios.
4
5 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
6
7 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
8 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
9 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
10 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
12
13 **/
14
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/HiiLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/OemMiscLib.h>
21 #include <Library/PrintLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23
24 #include "SmbiosMisc.h"
25
26 /**
27 This function makes boot time changes to the contents of the
28 MiscSystemManufacturer (Type 1) record.
29
30 @param RecordData Pointer to SMBIOS table with default values.
31 @param Smbios SMBIOS protocol.
32
33 @retval EFI_SUCCESS The SMBIOS table was successfully added.
34 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
35 @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory.
36
37 **/
38 SMBIOS_MISC_TABLE_FUNCTION (MiscSystemManufacturer) {
39 CHAR8 *OptionalStrStart;
40 CHAR8 *StrStart;
41 UINTN ManuStrLen;
42 UINTN VerStrLen;
43 UINTN PdNameStrLen;
44 UINTN SerialNumStrLen;
45 UINTN SKUNumStrLen;
46 UINTN FamilyStrLen;
47 UINTN RecordLength;
48 EFI_STRING Manufacturer;
49 EFI_STRING ProductName;
50 EFI_STRING Version;
51 EFI_STRING SerialNumber;
52 EFI_STRING SKUNumber;
53 EFI_STRING Family;
54 EFI_STRING_ID TokenToGet;
55 SMBIOS_TABLE_TYPE1 *SmbiosRecord;
56 SMBIOS_TABLE_TYPE1 *InputData;
57 EFI_STATUS Status;
58 EFI_STRING_ID TokenToUpdate;
59 CHAR16 *Product;
60 CHAR16 *pVersion;
61
62 Status = EFI_SUCCESS;
63
64 //
65 // First check for invalid parameters.
66 //
67 if (RecordData == NULL) {
68 return EFI_INVALID_PARAMETER;
69 }
70
71 InputData = (SMBIOS_TABLE_TYPE1 *)RecordData;
72
73 Product = (CHAR16 *)PcdGetPtr (PcdSystemProductName);
74 if (StrLen (Product) > 0) {
75 TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
76 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Product, NULL);
77 }
78
79 pVersion = (CHAR16 *)PcdGetPtr (PcdSystemVersion);
80 if (StrLen (pVersion) > 0) {
81 TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
82 HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, pVersion, NULL);
83 }
84
85 OemUpdateSmbiosInfo (
86 mSmbiosMiscHiiHandle,
87 STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER),
88 SerialNumType01
89 );
90 OemUpdateSmbiosInfo (
91 mSmbiosMiscHiiHandle,
92 STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER),
93 SystemManufacturerType01
94 );
95 OemUpdateSmbiosInfo (
96 mSmbiosMiscHiiHandle,
97 STRING_TOKEN (STR_MISC_SYSTEM_SKU_NUMBER),
98 SkuNumberType01
99 );
100 OemUpdateSmbiosInfo (
101 mSmbiosMiscHiiHandle,
102 STRING_TOKEN (STR_MISC_SYSTEM_FAMILY),
103 FamilyType01
104 );
105
106 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER);
107 Manufacturer = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
108 ManuStrLen = StrLen (Manufacturer);
109
110 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
111 ProductName = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
112 PdNameStrLen = StrLen (ProductName);
113
114 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
115 Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
116 VerStrLen = StrLen (Version);
117
118 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER);
119 SerialNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
120 SerialNumStrLen = StrLen (SerialNumber);
121
122 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SKU_NUMBER);
123 SKUNumber = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
124 SKUNumStrLen = StrLen (SKUNumber);
125
126 TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_FAMILY);
127 Family = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
128 FamilyStrLen = StrLen (Family);
129
130 //
131 // Two zeros following the last string.
132 //
133 RecordLength = sizeof (SMBIOS_TABLE_TYPE1) +
134 ManuStrLen + 1 +
135 PdNameStrLen + 1 +
136 VerStrLen + 1 +
137 SerialNumStrLen + 1 +
138 SKUNumStrLen + 1 +
139 FamilyStrLen + 1 + 1;
140 SmbiosRecord = AllocateZeroPool (RecordLength);
141
142 if (SmbiosRecord == NULL) {
143 Status = EFI_OUT_OF_RESOURCES;
144 goto Exit;
145 }
146
147 (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE1));
148
149 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1);
150
151 CopyGuid (&SmbiosRecord->Uuid, &InputData->Uuid);
152
153 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
154 UnicodeStrToAsciiStrS (Manufacturer, OptionalStrStart, ManuStrLen + 1);
155 StrStart = OptionalStrStart + ManuStrLen + 1;
156 UnicodeStrToAsciiStrS (ProductName, StrStart, PdNameStrLen + 1);
157 StrStart += PdNameStrLen + 1;
158 UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
159 StrStart += VerStrLen + 1;
160 UnicodeStrToAsciiStrS (SerialNumber, StrStart, SerialNumStrLen + 1);
161 StrStart += SerialNumStrLen + 1;
162 UnicodeStrToAsciiStrS (SKUNumber, StrStart, SKUNumStrLen + 1);
163 StrStart += SKUNumStrLen + 1;
164 UnicodeStrToAsciiStrS (Family, StrStart, FamilyStrLen + 1);
165
166 //
167 // Now we have got the full smbios record, call smbios protocol to add this record.
168 //
169 Status = SmbiosMiscAddRecord ((UINT8 *)SmbiosRecord, NULL);
170 if (EFI_ERROR (Status)) {
171 DEBUG ((
172 DEBUG_ERROR,
173 "[%a]:[%dL] Smbios Type01 Table Log Failed! %r \n",
174 __FUNCTION__,
175 DEBUG_LINE_NUMBER,
176 Status
177 ));
178 }
179
180 FreePool (SmbiosRecord);
181
182 Exit:
183 if (Manufacturer != NULL) {
184 FreePool (Manufacturer);
185 }
186
187 if (ProductName != NULL) {
188 FreePool (ProductName);
189 }
190
191 if (Version != NULL) {
192 FreePool (Version);
193 }
194
195 if (SerialNumber != NULL) {
196 FreePool (SerialNumber);
197 }
198
199 if (SKUNumber != NULL) {
200 FreePool (SKUNumber);
201 }
202
203 if (Family != NULL) {
204 FreePool (Family);
205 }
206
207 return Status;
208 }