]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c
UefiCpuPkg: Remove double \r
[mirror_edk2.git] / Nt32Pkg / MiscSubClassPlatformDxe / MiscBaseBoardManufacturerFunction.c
1 /** @file
2 BaseBoard manufacturer information boot time changes.
3 SMBIOS type 2.
4
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2017 Hewlett Packard Enterprise Development LP<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include "MiscSubclassDriver.h"
12 /**
13 This function makes boot time changes to the contents of the
14 MiscBaseBoardManufacturer (Type 2).
15
16 @param RecordData Pointer to copy of RecordData from the Data Table.
17
18 @retval EFI_SUCCESS All parameters were valid.
19 @retval EFI_UNSUPPORTED Unexpected RecordType value.
20 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
21
22 **/
23 MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)
24 {
25 CHAR8 *OptionalStrStart;
26 UINTN ManuStrLen;
27 UINTN ProductStrLen;
28 UINTN VerStrLen;
29 UINTN AssetTagStrLen;
30 UINTN SerialNumStrLen;
31 UINTN ChassisStrLen;
32 EFI_STATUS Status;
33 EFI_STRING Manufacturer;
34 EFI_STRING Product;
35 EFI_STRING Version;
36 EFI_STRING SerialNumber;
37 EFI_STRING AssetTag;
38 EFI_STRING Chassis;
39 STRING_REF TokenToGet;
40 EFI_SMBIOS_HANDLE SmbiosHandle;
41 SMBIOS_TABLE_TYPE2 *SmbiosRecord;
42 EFI_MISC_BASE_BOARD_MANUFACTURER *ForType2InputData;
43
44 ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;
45
46 //
47 // First check for invalid parameters.
48 //
49 if (RecordData == NULL) {
50 return EFI_INVALID_PARAMETER;
51 }
52
53 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);
54 Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
55 ManuStrLen = StrLen(Manufacturer);
56 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
57 return EFI_UNSUPPORTED;
58 }
59
60 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);
61 Product = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
62 ProductStrLen = StrLen(Product);
63 if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {
64 return EFI_UNSUPPORTED;
65 }
66
67 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);
68 Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
69 VerStrLen = StrLen(Version);
70 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
71 return EFI_UNSUPPORTED;
72 }
73
74 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER);
75 SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
76 SerialNumStrLen = StrLen(SerialNumber);
77 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
78 return EFI_UNSUPPORTED;
79 }
80
81 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);
82 AssetTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
83 AssetTagStrLen = StrLen(AssetTag);
84 if (AssetTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
85 return EFI_UNSUPPORTED;
86 }
87
88 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);
89 Chassis = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
90 ChassisStrLen = StrLen(Chassis);
91 if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {
92 return EFI_UNSUPPORTED;
93 }
94
95
96 //
97 // Two zeros following the last string.
98 //
99 // Since we fill NumberOfContainedObjectHandles = 0, remove sizeof (UINT16) bytes for ContainedObjectHandles[1]
100 //
101 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + ChassisStrLen + 1 + 1);
102 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1 + ChassisStrLen + 1 + 1);
103
104 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;
105 //
106 // Since we fill NumberOfContainedObjectHandles = 0, remove sizeof (UINT16) bytes for ContainedObjectHandles[1]
107 //
108 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2) - sizeof (UINT16);
109 //
110 // Make handle chosen by smbios protocol.add automatically.
111 //
112 SmbiosRecord->Hdr.Handle = 0;
113 //
114 // Manu will be the 1st optional string following the formatted structure.
115 //
116 SmbiosRecord->Manufacturer = 1;
117 //
118 // ProductName will be the 2st optional string following the formatted structure.
119 //
120 SmbiosRecord->ProductName = 2;
121 //
122 // Version will be the 3rd optional string following the formatted structure.
123 //
124 SmbiosRecord->Version = 3;
125 //
126 // SerialNumber will be the 4th optional string following the formatted structure.
127 //
128 SmbiosRecord->SerialNumber = 4;
129 //
130 // AssetTag will be the 5th optional string following the formatted structure.
131 //
132 SmbiosRecord->AssetTag = 5;
133
134 //
135 // LocationInChassis will be the 6th optional string following the formatted structure.
136 //
137 SmbiosRecord->LocationInChassis = 6;
138 SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));
139 SmbiosRecord->ChassisHandle = 0;
140 SmbiosRecord->BoardType = (UINT8)ForType2InputData->BaseBoardType;
141 SmbiosRecord->NumberOfContainedObjectHandles = 0;
142
143 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
144 //
145 // Since we fill NumberOfContainedObjectHandles = 0, just after this field to fill string
146 //
147 OptionalStrStart -= sizeof (UINT16);
148 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
149 UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);
150 UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);
151 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);
152 UnicodeStrToAsciiStr(AssetTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
153 UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssetTagStrLen + 1);
154 //
155 // Now we have got the full smbios record, call smbios protocol to add this record.
156 //
157 Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);
158
159 FreePool(SmbiosRecord);
160 return Status;
161 }