• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 This driver parses the mMiscSubclassDataTable structure and reports
3 any generated data to smbios.
4 
5 Copyright (c) 2013-2015 Intel Corporation.
6 
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 
16 **/
17 
18 
19 #include "CommonHeader.h"
20 
21 #include "SmbiosMisc.h"
22 
23 /**
24   This function makes boot time changes to the contents of the
25   MiscSystemManufacturer (Type 1).
26 
27   @param  RecordData                 Pointer to copy of RecordData from the Data Table.
28 
29   @retval EFI_SUCCESS                All parameters were valid.
30   @retval EFI_UNSUPPORTED            Unexpected RecordType value.
31   @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
32 
33 **/
MISC_SMBIOS_TABLE_FUNCTION(MiscSystemManufacturer)34 MISC_SMBIOS_TABLE_FUNCTION(MiscSystemManufacturer)
35 {
36   CHAR8                             *OptionalStrStart;
37   UINTN                             ManuStrLen;
38   UINTN                             VerStrLen;
39   UINTN                             PdNameStrLen;
40   UINTN                             SerialNumStrLen;
41   UINTN                             SKUNumStrLen;
42   UINTN                             FamilyStrLen;
43   EFI_STATUS                        Status;
44   CHAR16                            Manufacturer[SMBIOS_STRING_MAX_LENGTH];
45   CHAR16                            ProductName[SMBIOS_STRING_MAX_LENGTH];
46   CHAR16                            Version[SMBIOS_STRING_MAX_LENGTH];
47   CHAR16                            SerialNumber[SMBIOS_STRING_MAX_LENGTH];
48   CHAR16                            SKUNumber[SMBIOS_STRING_MAX_LENGTH];
49   CHAR16                            Family[SMBIOS_STRING_MAX_LENGTH];
50   EFI_STRING                        ManufacturerPtr;
51   EFI_STRING                        ProductNamePtr;
52   EFI_STRING                        VersionPtr;
53   EFI_STRING                        SerialNumberPtr;
54   EFI_STRING                        SKUNumberPtr;
55   EFI_STRING                        FamilyPtr;
56   STRING_REF                        TokenToGet;
57   STRING_REF                        TokenToUpdate;
58   EFI_SMBIOS_HANDLE                 SmbiosHandle;
59   SMBIOS_TABLE_TYPE1                *SmbiosRecord;
60   EFI_MISC_SYSTEM_MANUFACTURER      *ForType1InputData;
61 
62   ForType1InputData = (EFI_MISC_SYSTEM_MANUFACTURER *)RecordData;
63 
64   //
65   // First check for invalid parameters.
66   //
67   if (RecordData == NULL) {
68     return EFI_INVALID_PARAMETER;
69   }
70 
71   //
72   // Update strings from PCD
73   //
74   AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSSystemManufacturer), Manufacturer);
75   if (StrLen (Manufacturer) > 0) {
76     TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER);
77     HiiSetString (mHiiHandle, TokenToUpdate, Manufacturer, NULL);
78   }
79   TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_MANUFACTURER);
80   ManufacturerPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
81   ManuStrLen = StrLen(ManufacturerPtr);
82   if (ManuStrLen > SMBIOS_STRING_MAX_LENGTH) {
83     return EFI_UNSUPPORTED;
84   }
85 
86   AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSSystemProductName), ProductName);
87   if (StrLen (ProductName) > 0) {
88     TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
89     HiiSetString (mHiiHandle, TokenToUpdate, ProductName, NULL);
90   }
91   TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_PRODUCT_NAME);
92   ProductNamePtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
93   PdNameStrLen = StrLen(ProductNamePtr);
94   if (PdNameStrLen > SMBIOS_STRING_MAX_LENGTH) {
95     return EFI_UNSUPPORTED;
96   }
97 
98   AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSSystemVersion), Version);
99   if (StrLen (Version) > 0) {
100     TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
101     HiiSetString (mHiiHandle, TokenToUpdate, Version, NULL);
102   }
103   TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_VERSION);
104   VersionPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
105   VerStrLen = StrLen(VersionPtr);
106   if (VerStrLen > SMBIOS_STRING_MAX_LENGTH) {
107     return EFI_UNSUPPORTED;
108   }
109 
110   AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSSystemSerialNumber), SerialNumber);
111   if (StrLen (SerialNumber) > 0) {
112     TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER);
113     HiiSetString (mHiiHandle, TokenToUpdate, SerialNumber, NULL);
114   }
115   TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SERIAL_NUMBER);
116   SerialNumberPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
117   SerialNumStrLen = StrLen(SerialNumberPtr);
118   if (SerialNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
119     return EFI_UNSUPPORTED;
120   }
121 
122   AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSSystemSKUNumber), SKUNumber);
123   if (StrLen (SKUNumber) > 0) {
124     TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_SKU_NUMBER);
125     HiiSetString (mHiiHandle, TokenToUpdate, SKUNumber, NULL);
126   }
127   TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SKU_NUMBER);
128   SKUNumberPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
129   SKUNumStrLen = StrLen(SKUNumberPtr);
130   if (SKUNumStrLen > SMBIOS_STRING_MAX_LENGTH) {
131     return EFI_UNSUPPORTED;
132   }
133 
134   AsciiStrToUnicodeStr ((CHAR8 *) PcdGetPtr(PcdSMBIOSSystemFamily), Family);
135   if (StrLen (Family) > 0) {
136     TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_FAMILY);
137     HiiSetString (mHiiHandle, TokenToUpdate, Family, NULL);
138   }
139   TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_FAMILY);
140   FamilyPtr = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
141   FamilyStrLen = StrLen(FamilyPtr);
142   if (FamilyStrLen > SMBIOS_STRING_MAX_LENGTH) {
143     return EFI_UNSUPPORTED;
144   }
145   //
146   // Two zeros following the last string.
147   //
148   SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SKUNumStrLen + 1 + FamilyStrLen + 1 + 1);
149   ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE1) + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SKUNumStrLen + 1 + FamilyStrLen + 1 + 1);
150 
151   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_INFORMATION;
152   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE1);
153   //
154   // Make handle chosen by smbios protocol.add automatically.
155   //
156   SmbiosRecord->Hdr.Handle = 0;
157   //
158   // Manu will be the 1st optional string following the formatted structure.
159   //
160   SmbiosRecord->Manufacturer = 1;
161   //
162   // ProductName will be the 2nd optional string following the formatted structure.
163   //
164   SmbiosRecord->ProductName = 2;
165   //
166   // Version will be the 3rd optional string following the formatted structure.
167   //
168   SmbiosRecord->Version = 3;
169   //
170   // Serial number will be the 4th optional string following the formatted structure.
171   //
172   SmbiosRecord->SerialNumber = 4;
173   //
174   // SKU number will be the 5th optional string following the formatted structure.
175   //
176   SmbiosRecord->SKUNumber = 5;
177   //
178   // Family will be the 6th optional string following the formatted structure.
179   //
180   SmbiosRecord->Family = 6;
181   CopyMem ((UINT8 *) (&SmbiosRecord->Uuid), (UINT8 *)PcdGetPtr(PcdSMBIOSSystemUuid),16);
182   SmbiosRecord->WakeUpType = (UINT8)ForType1InputData->SystemWakeupType;
183 
184   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
185   UnicodeStrToAsciiStr(ManufacturerPtr, OptionalStrStart);
186   UnicodeStrToAsciiStr(ProductNamePtr, OptionalStrStart + ManuStrLen + 1);
187   UnicodeStrToAsciiStr(VersionPtr, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1);
188   UnicodeStrToAsciiStr(SerialNumberPtr, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1);
189   UnicodeStrToAsciiStr(SKUNumberPtr, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen+ 1);
190   UnicodeStrToAsciiStr(FamilyPtr, OptionalStrStart + ManuStrLen + 1 + PdNameStrLen + 1 + VerStrLen + 1 + SerialNumStrLen + 1 + SKUNumStrLen+ 1);
191 
192   //
193   // Now we have got the full smbios record, call smbios protocol to add this record.
194   //
195   SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
196   Status = Smbios-> Add(
197                       Smbios,
198                       NULL,
199                       &SmbiosHandle,
200                       (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
201                       );
202   FreePool(SmbiosRecord);
203   return Status;
204 }
205