]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerFunction.c
StdLib/LibC/StdLib/Malloc.c: Make the free() function conform to the ISO/IEC 9899...
[mirror_edk2.git] / EmulatorPkg / MiscSubClassPlatformDxe / MiscBaseBoardManufacturerFunction.c
CommitLineData
949f388f 1/** @file\r
2 BaseBoard manufacturer information boot time changes.\r
3 SMBIOS type 2.\r
4\r
2bfd90f9 5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
949f388f 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "MiscSubClassDriver.h"\r
17/**\r
18 This function makes boot time changes to the contents of the\r
19 MiscBaseBoardManufacturer (Type 2).\r
20\r
d18d8a1d 21 @param RecordData Pointer to copy of RecordData from the Data Table.\r
949f388f 22\r
23 @retval EFI_SUCCESS All parameters were valid.\r
24 @retval EFI_UNSUPPORTED Unexpected RecordType value.\r
25 @retval EFI_INVALID_PARAMETER Invalid parameter was found.\r
26\r
27**/\r
28MISC_SMBIOS_TABLE_FUNCTION(MiscBaseBoardManufacturer)\r
29{\r
30 CHAR8 *OptionalStrStart;\r
31 UINTN ManuStrLen;\r
32 UINTN ProductStrLen;\r
33 UINTN VerStrLen;\r
34 UINTN AssertTagStrLen;\r
35 UINTN SerialNumStrLen;\r
36 UINTN ChassisStrLen;\r
37 EFI_STATUS Status;\r
38 EFI_STRING Manufacturer;\r
39 EFI_STRING Product;\r
40 EFI_STRING Version;\r
41 EFI_STRING SerialNumber;\r
42 EFI_STRING AssertTag;\r
43 EFI_STRING Chassis;\r
44 STRING_REF TokenToGet;\r
45 EFI_SMBIOS_HANDLE SmbiosHandle;\r
46 SMBIOS_TABLE_TYPE2 *SmbiosRecord;\r
47 EFI_MISC_BASE_BOARD_MANUFACTURER *ForType2InputData;\r
48\r
49 ForType2InputData = (EFI_MISC_BASE_BOARD_MANUFACTURER *)RecordData;\r
50\r
51 //\r
52 // First check for invalid parameters.\r
53 //\r
54 if (RecordData == NULL) {\r
55 return EFI_INVALID_PARAMETER;\r
56 }\r
57\r
58 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_MANUFACTURER);\r
59 Manufacturer = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
60 ManuStrLen = StrLen(Manufacturer);\r
61 if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
62 return EFI_UNSUPPORTED;\r
63 }\r
64\r
65 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_PRODUCT_NAME);\r
66 Product = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
67 ProductStrLen = StrLen(Product);\r
68 if (ProductStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
69 return EFI_UNSUPPORTED;\r
70 }\r
71\r
72 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_VERSION);\r
73 Version = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
74 VerStrLen = StrLen(Version);\r
75 if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
76 return EFI_UNSUPPORTED;\r
77 }\r
78\r
79 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_SERIAL_NUMBER);\r
80 SerialNumber = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
81 SerialNumStrLen = StrLen(SerialNumber);\r
82 if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
83 return EFI_UNSUPPORTED;\r
84 }\r
85\r
86 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_ASSET_TAG);\r
87 AssertTag = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
88 AssertTagStrLen = StrLen(AssertTag);\r
89 if (AssertTagStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
90 return EFI_UNSUPPORTED;\r
91 }\r
92\r
93 TokenToGet = STRING_TOKEN (STR_MISC_BASE_BOARD_CHASSIS_LOCATION);\r
94 Chassis = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);\r
95 ChassisStrLen = StrLen(Chassis);\r
96 if (ChassisStrLen > SMBIOS_STRING_MAX_LENGTH) {\r
97 return EFI_UNSUPPORTED;\r
98 }\r
99\r
100\r
101 //\r
102 // Two zeros following the last string.\r
103 //\r
104 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);\r
105 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE3) + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1 + ChassisStrLen +1 + 1);\r
106\r
107 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION;\r
108 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE2);\r
109 //\r
110 // Make handle chosen by smbios protocol.add automatically.\r
111 //\r
d18d8a1d 112 SmbiosRecord->Hdr.Handle = 0;\r
949f388f 113 //\r
114 // Manu will be the 1st optional string following the formatted structure.\r
d18d8a1d 115 //\r
116 SmbiosRecord->Manufacturer = 1;\r
949f388f 117 //\r
118 // ProductName will be the 2st optional string following the formatted structure.\r
d18d8a1d 119 //\r
120 SmbiosRecord->ProductName = 2;\r
949f388f 121 //\r
122 // Version will be the 3rd optional string following the formatted structure.\r
123 //\r
d18d8a1d 124 SmbiosRecord->Version = 3;\r
949f388f 125 //\r
126 // SerialNumber will be the 4th optional string following the formatted structure.\r
127 //\r
d18d8a1d 128 SmbiosRecord->SerialNumber = 4;\r
949f388f 129 //\r
130 // AssertTag will be the 5th optional string following the formatted structure.\r
131 //\r
d18d8a1d 132 SmbiosRecord->AssetTag = 5;\r
949f388f 133\r
134 //\r
135 // LocationInChassis will be the 6th optional string following the formatted structure.\r
136 //\r
d18d8a1d 137 SmbiosRecord->LocationInChassis = 6;\r
949f388f 138 SmbiosRecord->FeatureFlag = (*(BASE_BOARD_FEATURE_FLAGS*)&(ForType2InputData->BaseBoardFeatureFlags));\r
139 SmbiosRecord->ChassisHandle = 0;\r
140 SmbiosRecord->BoardType = (UINT8)ForType2InputData->BaseBoardType;\r
141 SmbiosRecord->NumberOfContainedObjectHandles = 0;\r
d18d8a1d 142\r
949f388f 143 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
144 //\r
145 // Since we fill NumberOfContainedObjectHandles = 0 for simple, just after this filed to fill string\r
146 //\r
147 OptionalStrStart -= 2;\r
148 UnicodeStrToAsciiStr(Manufacturer, OptionalStrStart);\r
149 UnicodeStrToAsciiStr(Product, OptionalStrStart + ManuStrLen + 1);\r
150 UnicodeStrToAsciiStr(Version, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1);\r
151 UnicodeStrToAsciiStr(SerialNumber, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1);\r
152 UnicodeStrToAsciiStr(AssertTag, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1);\r
153 UnicodeStrToAsciiStr(Chassis, OptionalStrStart + ManuStrLen + 1 + ProductStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + AssertTagStrLen + 1);\r
154 //\r
155 // Now we have got the full smbios record, call smbios protocol to add this record.\r
156 //\r
2bfd90f9 157 Status = AddSmbiosRecord (Smbios, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord);\r
949f388f 158\r
159 FreePool(SmbiosRecord);\r
160 return Status;\r
161}\r