]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscBaseBoardManufacturerFunction.c
ArmPkg/CompilerIntrinsicsLib: Add uread, uwrite GCC assembly sources
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmBiosMiscDxe / MiscBaseBoardManufacturerFunction.c
1 /*++
2
3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7
8
9 Module Name:
10
11 MiscBaseBoardManufacturerFunction.c
12
13 Abstract:
14
15 BaseBoard manufacturer information boot time changes.
16 SMBIOS type 2.
17
18 --*/
19
20
21 #include "CommonHeader.h"
22 #include "MiscSubclassDriver.h"
23 #include <Library/NetLib.h>
24 #include "Library/DebugLib.h"
25 #include <Uefi/UefiBaseType.h>
26 #include <Guid/PlatformInfo.h>
27
28
29 extern EFI_PLATFORM_INFO_HOB *mPlatformInfo;
30
31 /**
32 This function makes boot time changes to the contents of the
33 MiscBaseBoardManufacturer (Type 2).
34
35 @param RecordData Pointer to copy of RecordData from the Data Table.
36
37 @retval EFI_SUCCESS All parameters were valid.
38 @retval EFI_UNSUPPORTED Unexpected RecordType value.
39 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
40
41 **/
42 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
43 {
44 CHAR8 *OptionalStrStart;
45 UINTN ManuStrLen;
46 UINTN ProductStrLen;
47 UINTN VerStrLen;
48 UINTN AssertTagStrLen;
49 UINTN SerialNumStrLen;
50 UINTN ChassisStrLen;
51 EFI_STATUS Status;
52 EFI_STRING Manufacturer;
53 EFI_STRING Product;
54 EFI_STRING Version;
55 EFI_STRING SerialNumber;
56 EFI_STRING AssertTag;
57 EFI_STRING Chassis;
58 STRING_REF TokenToGet;
59 EFI_SMBIOS_HANDLE SmbiosHandle;
60 SMBIOS_TABLE_TYPE2 *SmbiosRecord;
61 EFI_MISC_BASE_BOARD_MANUFACTURER *ForType2InputData;
62
63 CHAR16 *MacStr;
64 EFI_HANDLE *Handles;
65 UINTN BufferSize;
66 CHAR16 Buffer[40];
67
68 ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;
69
70 //
71 // First check for invalid parameters.
72 //
73 if (RecordData == NULL || mPlatformInfo == NULL) {
74 return EFI_INVALID_PARAMETER;
75 }
76
77 if (BOARD_ID_MINNOW2_TURBOT == mPlatformInfo->BoardId) {
78 UnicodeSPrint (Buffer, sizeof (Buffer),L"ADI");
79 HiiSetString(mHiiHandle,STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER), Buffer, NULL);
80 }
81 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
82 Manufacturer = SmbiosMiscGetString (TokenToGet);
83 ManuStrLen = StrLen(Manufacturer);
84 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
85 return EFI_UNSUPPORTED;
86 }
87
88 if (BOARD_ID_MINNOW2_TURBOT == mPlatformInfo->BoardId) {
89 UnicodeSPrint (Buffer, sizeof (Buffer),L"MinnowBoard Turbot");
90 HiiSetString(mHiiHandle,STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME1), Buffer, NULL);
91 }
92 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME1);
93 Product = SmbiosMiscGetString (TokenToGet);
94 ProductStrLen = StrLen(Product);
95 if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {
96 return EFI_UNSUPPORTED;
97 }
98 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
99 Version = SmbiosMiscGetString (TokenToGet);
100 VerStrLen = StrLen(Version);
101 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
102 return EFI_UNSUPPORTED;
103 }
104
105 //
106 //Get handle infomation
107 //
108 BufferSize = 0;
109 Handles = NULL;
110 Status = gBS->LocateHandle (
111 ByProtocol,
112 &gEfiSimpleNetworkProtocolGuid,
113 NULL,
114 &BufferSize,
115 Handles
116 );
117
118 if (Status == EFI_BUFFER_TOO_SMALL) {
119 Handles = AllocateZeroPool(BufferSize);
120 if (Handles == NULL) {
121 return (EFI_OUT_OF_RESOURCES);
122 }
123 Status = gBS->LocateHandle(
124 ByProtocol,
125 &gEfiSimpleNetworkProtocolGuid,
126 NULL,
127 &BufferSize,
128 Handles
129 );
130 }
131
132 //
133 //Get the MAC string
134 //
135 Status = NetLibGetMacString (
136 *Handles,
137 NULL,
138 &MacStr
139 );
140 if (EFI_ERROR (Status)) {
141 return Status;
142 }
143 SerialNumber = MacStr;
144 SerialNumStrLen = StrLen(SerialNumber);
145 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
146 return EFI_UNSUPPORTED;
147 }
148 DEBUG ((EFI_D_ERROR, "MAC Address: %S\n", MacStr));
149
150 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);
151 AssertTag = SmbiosMiscGetString (TokenToGet);
152 AssertTagStrLen = StrLen(AssertTag);
153 if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
154 return EFI_UNSUPPORTED;
155 }
156
157 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);
158 Chassis = SmbiosMiscGetString (TokenToGet);
159 ChassisStrLen = StrLen(Chassis);
160 if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {
161 return EFI_UNSUPPORTED;
162 }
163
164
165 //
166 // Two zeros following the last string.
167 //
168 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);
169 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);
170
171 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
172 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);
173
174 //
175 // Make handle chosen by smbios protocol.add automatically.
176 //
177 SmbiosRecord->Hdr.Handle = 0;
178
179 //
180 // Manu will be the 1st optional string following the formatted structure.
181 //
182 SmbiosRecord->Manufacturer = 1;
183
184 //
185 // ProductName will be the 2st optional string following the formatted structure.
186 //
187 SmbiosRecord->ProductName = 2;
188
189 //
190 // Version will be the 3rd optional string following the formatted structure.
191 //
192 SmbiosRecord->Version = 3;
193
194 //
195 // SerialNumber will be the 4th optional string following the formatted structure.
196 //
197 SmbiosRecord->SerialNumber = 4;
198
199 //
200 // AssertTag will be the 5th optional string following the formatted structure.
201 //
202 SmbiosRecord->AssetTag = 5;
203
204 //
205 // LocationInChassis will be the 6th optional string following the formatted structure.
206 //
207 SmbiosRecord->LocationInChassis = 6;
208 SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));
209 SmbiosRecord->ChassisHandle = 0;
210 SmbiosRecord->BoardType = (UINT8)ForType2InputData->BaseBoardType;
211 SmbiosRecord->NumberOfContainedObjectHandles = 0;
212
213 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
214
215 //
216 // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string
217 //
218 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
219 UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);
220 UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);
221 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);
222 UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
223 UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1);
224
225 //
226 // Now we have got the full smbios record, call smbios protocol to add this record.
227 //
228 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
229 Status = Smbios-> Add(
230 Smbios,
231 NULL,
232 &SmbiosHandle,
233 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
234 );
235
236 FreePool(SmbiosRecord);
237 return Status;
238 }