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