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