TianoCore EDK2 master
Loading...
Searching...
No Matches
LibSmbiosView.c
Go to the documentation of this file.
1
10#include <Guid/SmBios.h>
11#include "LibSmbiosView.h"
12#include "SmbiosView.h"
13
14STATIC UINT8 mInit = 0;
15STATIC UINT8 m64Init = 0;
17STATIC SMBIOS_TABLE_3_0_ENTRY_POINT *mSmbios64BitTable = NULL;
18STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;
19STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;
20STATIC SMBIOS_STRUCTURE_POINTER m_Smbios64BitStruct;
21STATIC SMBIOS_STRUCTURE_POINTER *mSmbios64BitStruct = &m_Smbios64BitStruct;
22
30 VOID
31 )
32{
33 EFI_STATUS Status;
34
35 //
36 // Init only once
37 //
38 if (mInit == 1) {
39 return EFI_SUCCESS;
40 }
41
42 //
43 // Get SMBIOS table from System Configure table
44 //
45 Status = GetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **)&mSmbiosTable);
46
47 if (mSmbiosTable == NULL) {
48 return EFI_NOT_FOUND;
49 }
50
51 if (EFI_ERROR (Status)) {
52 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);
53 return Status;
54 }
55
56 //
57 // Init SMBIOS structure table address
58 //
59 mSmbiosStruct->Raw = (UINT8 *)(UINTN)(mSmbiosTable->TableAddress);
60
61 mInit = 1;
62 return EFI_SUCCESS;
63}
64
72 VOID
73 )
74{
75 EFI_STATUS Status;
76
77 //
78 // Init only once
79 //
80 if (m64Init == 1) {
81 return EFI_SUCCESS;
82 }
83
84 //
85 // Get SMBIOS table from System Configure table
86 //
87 Status = GetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **)&mSmbios64BitTable);
88
89 if (mSmbios64BitTable == NULL) {
90 return EFI_NOT_FOUND;
91 }
92
93 if (EFI_ERROR (Status)) {
94 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);
95 return Status;
96 }
97
98 //
99 // Init SMBIOS structure table address
100 //
101 mSmbios64BitStruct->Raw = (UINT8 *)(UINTN)(mSmbios64BitTable->TableAddress);
102
103 m64Init = 1;
104 return EFI_SUCCESS;
105}
106
110VOID
112 VOID
113 )
114{
115 //
116 // Release resources
117 //
118 if (mSmbiosTable != NULL) {
119 mSmbiosTable = NULL;
120 }
121
122 mInit = 0;
123}
124
128VOID
130 VOID
131 )
132{
133 //
134 // Release resources
135 //
136 if (mSmbios64BitTable != NULL) {
137 mSmbios64BitTable = NULL;
138 }
139
140 m64Init = 0;
141}
142
148VOID
150 OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure
151 )
152{
153 //
154 // return SMBIOS Table address
155 //
156 *EntryPointStructure = mSmbiosTable;
157}
158
164VOID
166 OUT SMBIOS_TABLE_3_0_ENTRY_POINT **EntryPointStructure
167 )
168{
169 //
170 // return SMBIOS Table address
171 //
172 *EntryPointStructure = mSmbios64BitTable;
173}
174
184CHAR8 *
187 IN UINT16 StringNumber
188 )
189{
190 UINT16 Index;
191 CHAR8 *String;
192
193 ASSERT (Smbios != NULL);
194
195 //
196 // Skip over formatted section
197 //
198 String = (CHAR8 *)(Smbios->Raw + Smbios->Hdr->Length);
199
200 //
201 // Look through unformated section
202 //
203 for (Index = 1; Index <= StringNumber; Index++) {
204 if (StringNumber == Index) {
205 return String;
206 }
207
208 //
209 // Skip string
210 //
211 for ( ; *String != 0; String++) {
212 }
213
214 String++;
215
216 if (*String == 0) {
217 //
218 // If double NULL then we are done.
219 // Return pointer to next structure in Smbios.
220 // if you pass in a -1 you will always get here
221 //
222 Smbios->Raw = (UINT8 *)++String;
223 return NULL;
224 }
225 }
226
227 return NULL;
228}
229
248 IN OUT UINT16 *Handle,
249 OUT UINT8 **Buffer,
250 OUT UINT16 *Length
251 )
252{
254 SMBIOS_STRUCTURE_POINTER SmbiosEnd;
255 UINT8 *Raw;
256
257 if (*Handle == INVALID_HANDLE) {
258 *Handle = mSmbiosStruct->Hdr->Handle;
259 return DMI_INVALID_HANDLE;
260 }
261
262 if ((Buffer == NULL) || (Length == NULL)) {
263 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);
264 return DMI_INVALID_HANDLE;
265 }
266
267 *Length = 0;
268 Smbios.Hdr = mSmbiosStruct->Hdr;
269 SmbiosEnd.Raw = Smbios.Raw + mSmbiosTable->TableLength;
270 while (Smbios.Raw < SmbiosEnd.Raw) {
271 if (Smbios.Hdr->Handle == *Handle) {
272 Raw = Smbios.Raw;
273 //
274 // Walk to next structure
275 //
276 LibGetSmbiosString (&Smbios, (UINT16)(-1));
277 //
278 // Length = Next structure head - this structure head
279 //
280 *Length = (UINT16)(Smbios.Raw - Raw);
281 *Buffer = Raw;
282 //
283 // update with the next structure handle.
284 //
285 if (Smbios.Raw < SmbiosEnd.Raw) {
286 *Handle = Smbios.Hdr->Handle;
287 } else {
288 *Handle = INVALID_HANDLE;
289 }
290
291 return DMI_SUCCESS;
292 }
293
294 //
295 // Walk to next structure
296 //
297 LibGetSmbiosString (&Smbios, (UINT16)(-1));
298 }
299
300 *Handle = INVALID_HANDLE;
301 return DMI_INVALID_HANDLE;
302}
303
322 IN OUT UINT16 *Handle,
323 OUT UINT8 **Buffer,
324 OUT UINT16 *Length
325 )
326{
328 SMBIOS_STRUCTURE_POINTER SmbiosEnd;
329 UINT8 *Raw;
330
331 if (*Handle == INVALID_HANDLE) {
332 *Handle = mSmbios64BitStruct->Hdr->Handle;
333 return DMI_INVALID_HANDLE;
334 }
335
336 if ((Buffer == NULL) || (Length == NULL)) {
337 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);
338 return DMI_INVALID_HANDLE;
339 }
340
341 *Length = 0;
342 Smbios.Hdr = mSmbios64BitStruct->Hdr;
343
344 SmbiosEnd.Raw = Smbios.Raw + mSmbios64BitTableLength;
345 while (Smbios.Raw < SmbiosEnd.Raw) {
346 if (Smbios.Hdr->Handle == *Handle) {
347 Raw = Smbios.Raw;
348 //
349 // Walk to next structure
350 //
351 LibGetSmbiosString (&Smbios, (UINT16)(-1));
352 //
353 // Length = Next structure head - this structure head
354 //
355 *Length = (UINT16)(Smbios.Raw - Raw);
356 *Buffer = Raw;
357 //
358 // update with the next structure handle.
359 //
360 if (Smbios.Raw < SmbiosEnd.Raw) {
361 *Handle = Smbios.Hdr->Handle;
362 } else {
363 *Handle = INVALID_HANDLE;
364 }
365
366 return DMI_SUCCESS;
367 }
368
369 //
370 // Walk to next structure
371 //
372 LibGetSmbiosString (&Smbios, (UINT16)(-1));
373 }
374
375 *Handle = INVALID_HANDLE;
376 return DMI_INVALID_HANDLE;
377}
UINT64 UINTN
EFI_STATUS LibSmbiosInit(VOID)
Definition: LibSmbiosView.c:29
EFI_STATUS LibGetSmbios64BitStructure(IN OUT UINT16 *Handle, OUT UINT8 **Buffer, OUT UINT16 *Length)
VOID LibSmbios64BitGetEPS(OUT SMBIOS_TABLE_3_0_ENTRY_POINT **EntryPointStructure)
EFI_STATUS LibGetSmbiosStructure(IN OUT UINT16 *Handle, OUT UINT8 **Buffer, OUT UINT16 *Length)
EFI_STATUS LibSmbios64BitInit(VOID)
Definition: LibSmbiosView.c:71
CHAR8 * LibGetSmbiosString(IN SMBIOS_STRUCTURE_POINTER *Smbios, IN UINT16 StringNumber)
VOID LibSmbios64BitCleanup(VOID)
VOID LibSmbiosCleanup(VOID)
VOID LibSmbiosGetEPS(OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define STRING_TOKEN(t)
EFI_STATUS GetSystemConfigurationTable(IN EFI_GUID *TableGuid, IN OUT VOID **Table)