]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SmBiosMiscDxe/MiscChassisManufacturerFunction.c
Vlv2TbltDevicePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Vlv2TbltDevicePkg / SmBiosMiscDxe / MiscChassisManufacturerFunction.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
10 Module Name:
11
12 MiscChassisManufacturerFunction.c
13
14 Abstract:
15
16 Chassis manufacturer information boot time changes.
17 SMBIOS type 3.
18
19 --*/
20
21
22 #include "CommonHeader.h"
23 #include "MiscSubclassDriver.h"
24 #include <Guid/PlatformInfo.h>
25
26
27 extern EFI_PLATFORM_INFO_HOB *mPlatformInfo;
28
29 /**
30 This function makes boot time changes to the contents of the
31 MiscChassisManufacturer (Type 3).
32
33 @param RecordData Pointer to copy of RecordData from the Data Table.
34
35 @retval EFI_SUCCESS All parameters were valid.
36 @retval EFI_UNSUPPORTED Unexpected RecordType value.
37 @retval EFI_INVALID_PARAMETER Invalid parameter was found.
38
39 **/
40 MISC_SMBIOS_TABLE_FUNCTION(MiscChassisManufacturer)
41 {
42 CHAR8 *OptionalStrStart;
43 UINTN ManuStrLen;
44 UINTN VerStrLen;
45 UINTN AssertTagStrLen;
46 UINTN SerialNumStrLen;
47 EFI_STATUS Status;
48 EFI_STRING Manufacturer;
49 EFI_STRING Version;
50 EFI_STRING SerialNumber;
51 EFI_STRING AssertTag;
52 STRING_REF TokenToGet;
53 EFI_SMBIOS_HANDLE SmbiosHandle;
54 SMBIOS_TABLE_TYPE3 *SmbiosRecord;
55 EFI_MISC_CHASSIS_MANUFACTURER *ForType3InputData;
56 CHAR16 Buffer[40];
57
58 ForType3InputData = (EFI_MISC_CHASSIS_MANUFACTURER *)RecordData;
59
60 //
61 // First check for invalid parameters.
62 //
63 if (RecordData == NULL || mPlatformInfo == NULL) {
64 return EFI_INVALID_PARAMETER;
65 }
66
67 if (BOARD_ID_MINNOW2_TURBOT == mPlatformInfo->BoardId) {
68 UnicodeSPrint (Buffer, sizeof (Buffer),L"ADI");
69 HiiSetString(mHiiHandle,STRING_TOKEN(STR_MISC_CHASSIS_MANUFACTURER), Buffer, NULL);
70 }
71 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_MANUFACTURER);
72 Manufacturer = SmbiosMiscGetString (TokenToGet);
73 ManuStrLen = StrLen(Manufacturer);
74 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
75 return EFI_UNSUPPORTED;
76 }
77
78 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_VERSION);
79 Version = SmbiosMiscGetString (TokenToGet);
80 VerStrLen = StrLen(Version);
81 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
82 return EFI_UNSUPPORTED;
83 }
84
85 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_SERIAL_NUMBER);
86 SerialNumber = SmbiosMiscGetString (TokenToGet);
87 SerialNumStrLen = StrLen(SerialNumber);
88 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
89 return EFI_UNSUPPORTED;
90 }
91
92 TokenToGet = STRING_TOKEN (STR_MISC_CHASSIS_ASSET_TAG);
93 AssertTag = SmbiosMiscGetString (TokenToGet);
94 AssertTagStrLen = StrLen(AssertTag);
95 if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {
96 return EFI_UNSUPPORTED;
97 }
98
99 //
100 // Two zeros following the last string.
101 //
102 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
103 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + 1);
104
105 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE;
106 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE3);
107
108 //
109 // Make handle chosen by smbios protocol.add automatically.
110 //
111 SmbiosRecord->Hdr.Handle = 0;
112
113 //
114 // Manu will be the 1st optional string following the formatted structure.
115 //
116 SmbiosRecord->Manufacturer = 1;
117 SmbiosRecord->Type = (UINT8)ForType3InputData->ChassisType.ChassisType;
118
119 //
120 // Version will be the 2nd optional string following the formatted structure.
121 //
122 SmbiosRecord->Version = 2;
123
124 //
125 // SerialNumber will be the 3rd optional string following the formatted structure.
126 //
127 SmbiosRecord->SerialNumber = 3;
128
129 //
130 // AssertTag will be the 4th optional string following the formatted structure.
131 //
132 SmbiosRecord->AssetTag = 4;
133 SmbiosRecord->BootupState = (UINT8)ForType3InputData->ChassisBootupState;
134 SmbiosRecord->PowerSupplyState = (UINT8)ForType3InputData->ChassisPowerSupplyState;
135 SmbiosRecord->ThermalState = (UINT8)ForType3InputData->ChassisThermalState;
136 SmbiosRecord->SecurityStatus = (UINT8)ForType3InputData->ChassisSecurityState;
137 CopyMem (SmbiosRecord->OemDefined,(UINT8*)&ForType3InputData->ChassisOemDefined, 4);
138
139 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
140 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);
141 UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1);
142 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1);
143 UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);
144
145 //
146 // Now we have got the full smbios record, call smbios protocol to add this record.
147 //
148 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
149 Status = Smbios-> Add(
150 Smbios,
151 NULL,
152 &SmbiosHandle,
153 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
154 );
155
156 FreePool(SmbiosRecord);
157 return Status;
158 }