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