1 /** @file
2 
3 Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 
24 Module Name:
25 
26   MiscSubclassDriverEntryPoint.c
27 
28 Abstract:
29 
30   This driver parses the mMiscSubclassDataTable structure and reports
31   any generated data to the DataHub.
32 
33 
34 **/
35 
36 
37 #include "CommonHeader.h"
38 #include "MiscSubclassDriver.h"
39 #include <Protocol/HiiString.h>
SmbiosMiscGetString(IN EFI_STRING_ID StringId)40 #include <Guid/PlatformInfo.h>
41 
42 
43 EFI_HII_HANDLE  mHiiHandle;
44 EFI_HII_STRING_PROTOCOL  *mHiiString;
45 EFI_PLATFORM_INFO_HOB *mPlatformInfo=NULL;
46 
47 EFI_STRING
48 EFIAPI
49 SmbiosMiscGetString (
50   IN EFI_STRING_ID   StringId
51   ){
52 
53   EFI_STATUS  Status;
54   UINTN       StringSize;
55   CHAR16      TempString;
56   EFI_STRING  String;
57   String             = NULL;
58 
59   //
60   // Retrieve the size of the string in the string package for the BestLanguage
61   //
62   StringSize = 0;
63   Status = mHiiString->GetString (
64                          mHiiString,
65                          "en-US",
66                          mHiiHandle,
67                          StringId,
68                          &TempString,
69                          &StringSize,
70                          NULL
71                          );
72   //
73   // If GetString() returns EFI_SUCCESS for a zero size,
74   // then there are no supported languages registered for HiiHandle.  If GetString()
75   // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
76   // in the HII Database
77   //
78   if (Status != EFI_BUFFER_TOO_SMALL) {
79     goto Error;
80   }
81 
82   //
83   // Allocate a buffer for the return string
84   //
85   String = AllocateZeroPool (StringSize);
86   if (String == NULL) {
87     goto Error;
88   }
89 
90   //
91   // Retrieve the string from the string package
92   //
93   Status = mHiiString->GetString (
94                          mHiiString,
95                          "en-US",
96                          mHiiHandle,
97                          StringId,
98                          String,
99                          &StringSize,
100                          NULL
101                          );
102   if (EFI_ERROR (Status)) {
103     //
104     // Free the buffer and return NULL if the supported languages can not be retrieved.
105     //
106     FreePool (String);
107     String = NULL;
108   }
109 Error:
110 
111   return String;
112 }
113 
114 /**
115   Standard EFI driver point.  This driver parses the mMiscSubclassDataTable
116   structure and reports any generated data to the DataHub.
117 
MiscSubclassDriverEntryPoint(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)118   @param ImageHandle   - Handle for the image of this driver
119   @param SystemTable   - Pointer to the EFI System Table
120 
121   @retval EFI_SUCCESS      - The data was successfully reported to the Data Hub.
122   @retval EFI_DEVICE_ERROR - Can not locate any protocols
123 
124 **/
125 EFI_STATUS
126 EFIAPI
127 MiscSubclassDriverEntryPoint (
128   IN EFI_HANDLE         ImageHandle,
129   IN EFI_SYSTEM_TABLE   *SystemTable
130   )
131 {
132   UINTN                Index;
133   EFI_STATUS           EfiStatus;
134   EFI_SMBIOS_PROTOCOL  *Smbios;
135   EFI_PEI_HOB_POINTERS GuidHob;
136 
137 
138 
139   GuidHob.Raw = GetHobList ();
140   if (GuidHob.Raw != NULL) {
141     if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
142       mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
143     }
144   }
145 
146   DEBUG ((EFI_D_ERROR, "PlatformInfoHob->BoardId [0x%x]\n", mPlatformInfo->BoardId));
147 
148   //
149   // Retrieve the pointer to the UEFI HII String Protocol
150   //
151   EfiStatus = gBS->LocateProtocol (
152                      &gEfiHiiStringProtocolGuid,
153                      NULL,
154                      (VOID **) &mHiiString
155                      );
156   ASSERT_EFI_ERROR (EfiStatus);
157 
158   EfiStatus = gBS->LocateProtocol(
159                      &gEfiSmbiosProtocolGuid,
160                      NULL,
161                      (VOID**)&Smbios
162                      );
163 
164   if (EFI_ERROR(EfiStatus)) {
165     DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol.  %r\n", EfiStatus));
166     return EfiStatus;
167   }
168 
169   mHiiHandle = HiiAddPackages (
170                  &gEfiCallerIdGuid,
171                  NULL,
172                  MiscSubclassStrings,
173                  NULL
174                  );
175   ASSERT (mHiiHandle != NULL);
176 
177   for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {
178     //
179     // If the entry have a function pointer, just log the data.
180     //
181     if (mMiscSubclassDataTable[Index].Function != NULL) {
182       EfiStatus = (*mMiscSubclassDataTable[Index].Function)(
183         mMiscSubclassDataTable[Index].RecordData,
184         Smbios
185         );
186 
187       if (EFI_ERROR(EfiStatus)) {
188         DEBUG((EFI_D_ERROR, "Misc smbios store error.  Index=%d, ReturnStatus=%r\n", Index, EfiStatus));
189         return EfiStatus;
190       }
191     }
192   }
193 
194   return EfiStatus;
195 }
196 
197