TianoCore EDK2 master
Loading...
Searching...
No Matches
SmbiosMiscEntryPoint.c
Go to the documentation of this file.
1
15#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
18#include <Library/HiiLib.h>
21
22#include "SmbiosMisc.h"
23
24STATIC EFI_HANDLE mSmbiosMiscImageHandle;
25STATIC EFI_SMBIOS_PROTOCOL *mSmbiosMiscSmbios = NULL;
26
27EFI_HII_HANDLE mSmbiosMiscHiiHandle;
28
40EFIAPI
42 IN EFI_HANDLE ImageHandle,
43 IN EFI_SYSTEM_TABLE *SystemTable
44 )
45{
46 UINTN Index;
47 EFI_STATUS EfiStatus;
48
49 mSmbiosMiscImageHandle = ImageHandle;
50
51 EfiStatus = gBS->LocateProtocol (
52 &gEfiSmbiosProtocolGuid,
53 NULL,
54 (VOID **)&mSmbiosMiscSmbios
55 );
56 if (EFI_ERROR (EfiStatus)) {
57 DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));
58 return EfiStatus;
59 }
60
61 mSmbiosMiscHiiHandle = HiiAddPackages (
62 &gEfiCallerIdGuid,
63 mSmbiosMiscImageHandle,
64 SmbiosMiscDxeStrings,
65 NULL
66 );
67 if (mSmbiosMiscHiiHandle == NULL) {
68 return EFI_OUT_OF_RESOURCES;
69 }
70
71 for (Index = 0; Index < mSmbiosMiscDataTableEntries; ++Index) {
72 //
73 // If the entry have a function pointer, just log the data.
74 //
75 if (mSmbiosMiscDataTable[Index].Function != NULL) {
76 EfiStatus = (*mSmbiosMiscDataTable[Index].Function)(
77 mSmbiosMiscDataTable[Index].RecordData,
78 mSmbiosMiscSmbios
79 );
80
81 if (EFI_ERROR (EfiStatus)) {
82 DEBUG ((
83 DEBUG_ERROR,
84 "Misc smbios store error. Index=%d,"
85 "ReturnStatus=%r\n",
86 Index,
87 EfiStatus
88 ));
89 return EfiStatus;
90 }
91 }
92 }
93
94 return EfiStatus;
95}
96
116 IN UINT8 *Buffer,
117 IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL
118 )
119{
120 EFI_STATUS Status;
121 EFI_SMBIOS_HANDLE Handle;
122
124
125 if (SmbiosHandle != NULL) {
126 Handle = *SmbiosHandle;
127 }
128
129 Status = mSmbiosMiscSmbios->Add (
130 mSmbiosMiscSmbios,
131 NULL,
132 &Handle,
134 );
135
136 if (SmbiosHandle != NULL) {
137 *SmbiosHandle = Handle;
138 }
139
140 return Status;
141}
142
150STATIC
151UINTN
153 IN UINT8 SmbiosType
154 )
155{
156 UINTN HandleCount;
157 EFI_STATUS Status;
158 EFI_SMBIOS_HANDLE SmbiosHandle;
160
161 HandleCount = 0;
162
163 // Iterate through entries to get the number
164 do {
165 Status = mSmbiosMiscSmbios->GetNext (
166 mSmbiosMiscSmbios,
167 &SmbiosHandle,
168 &SmbiosType,
169 &Record,
170 NULL
171 );
172
173 if (Status == EFI_SUCCESS) {
174 HandleCount++;
175 }
176 } while (!EFI_ERROR (Status));
177
178 return HandleCount;
179}
180
188VOID
190 IN UINT8 SmbiosType,
191 OUT SMBIOS_HANDLE **HandleArray,
192 OUT UINTN *HandleCount
193 )
194{
195 UINTN Index;
196 EFI_STATUS Status;
197 EFI_SMBIOS_HANDLE SmbiosHandle;
199
200 if (mSmbiosMiscSmbios == NULL) {
201 return;
202 }
203
204 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
205 *HandleCount = GetHandleCount (SmbiosType);
206
207 *HandleArray = AllocateZeroPool (sizeof (SMBIOS_HANDLE) * (*HandleCount));
208 if (*HandleArray == NULL) {
209 DEBUG ((DEBUG_ERROR, "HandleArray allocate memory resource failed.\n"));
210 *HandleCount = 0;
211 return;
212 }
213
214 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
215
216 for (Index = 0; Index < (*HandleCount); Index++) {
217 Status = mSmbiosMiscSmbios->GetNext (
218 mSmbiosMiscSmbios,
219 &SmbiosHandle,
220 &SmbiosType,
221 &Record,
222 NULL
223 );
224
225 if (!EFI_ERROR (Status)) {
226 (*HandleArray)[Index] = Record->Handle;
227 } else {
228 break;
229 }
230 }
231}
UINT64 UINTN
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
UINT16 SMBIOS_HANDLE
Definition: SmBios.h:152
#define SMBIOS_HANDLE_PI_RESERVED
Definition: SmBios.h:29
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI SmbiosMiscEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC UINTN GetHandleCount(IN UINT8 SmbiosType)
EFI_STATUS SmbiosMiscAddRecord(IN UINT8 *Buffer, IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL)
VOID SmbiosMiscGetLinkTypeHandle(IN UINT8 SmbiosType, OUT SMBIOS_HANDLE **HandleArray, OUT UINTN *HandleCount)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
VOID * EFI_HII_HANDLE