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