1 | /** @file
|
---|
2 | API for SMBIOS table.
|
---|
3 |
|
---|
4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "UefiShellDebug1CommandsLib.h"
|
---|
10 | #include <Guid/SmBios.h>
|
---|
11 | #include "LibSmbiosView.h"
|
---|
12 | #include "SmbiosView.h"
|
---|
13 |
|
---|
14 | STATIC UINT8 mInit = 0;
|
---|
15 | STATIC UINT8 m64Init = 0;
|
---|
16 | STATIC SMBIOS_TABLE_ENTRY_POINT *mSmbiosTable = NULL;
|
---|
17 | STATIC SMBIOS_TABLE_3_0_ENTRY_POINT *mSmbios64BitTable = NULL;
|
---|
18 | STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;
|
---|
19 | STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;
|
---|
20 | STATIC SMBIOS_STRUCTURE_POINTER m_Smbios64BitStruct;
|
---|
21 | STATIC SMBIOS_STRUCTURE_POINTER *mSmbios64BitStruct = &m_Smbios64BitStruct;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Init the SMBIOS VIEW API's environment.
|
---|
25 |
|
---|
26 | @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
|
---|
27 | **/
|
---|
28 | EFI_STATUS
|
---|
29 | LibSmbiosInit (
|
---|
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 |
|
---|
65 | /**
|
---|
66 | Init the SMBIOS VIEW API's environment.
|
---|
67 |
|
---|
68 | @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.
|
---|
69 | **/
|
---|
70 | EFI_STATUS
|
---|
71 | LibSmbios64BitInit (
|
---|
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 |
|
---|
107 | /**
|
---|
108 | Cleanup the Smbios information.
|
---|
109 | **/
|
---|
110 | VOID
|
---|
111 | LibSmbiosCleanup (
|
---|
112 | VOID
|
---|
113 | )
|
---|
114 | {
|
---|
115 | //
|
---|
116 | // Release resources
|
---|
117 | //
|
---|
118 | if (mSmbiosTable != NULL) {
|
---|
119 | mSmbiosTable = NULL;
|
---|
120 | }
|
---|
121 |
|
---|
122 | mInit = 0;
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | Cleanup the Smbios information.
|
---|
127 | **/
|
---|
128 | VOID
|
---|
129 | LibSmbios64BitCleanup (
|
---|
130 | VOID
|
---|
131 | )
|
---|
132 | {
|
---|
133 | //
|
---|
134 | // Release resources
|
---|
135 | //
|
---|
136 | if (mSmbios64BitTable != NULL) {
|
---|
137 | mSmbios64BitTable = NULL;
|
---|
138 | }
|
---|
139 |
|
---|
140 | m64Init = 0;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /**
|
---|
144 | Get the entry point structure for the table.
|
---|
145 |
|
---|
146 | @param[out] EntryPointStructure The pointer to populate.
|
---|
147 | **/
|
---|
148 | VOID
|
---|
149 | LibSmbiosGetEPS (
|
---|
150 | OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure
|
---|
151 | )
|
---|
152 | {
|
---|
153 | //
|
---|
154 | // return SMBIOS Table address
|
---|
155 | //
|
---|
156 | *EntryPointStructure = mSmbiosTable;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /**
|
---|
160 | Get the entry point structure for the table.
|
---|
161 |
|
---|
162 | @param[out] EntryPointStructure The pointer to populate.
|
---|
163 | **/
|
---|
164 | VOID
|
---|
165 | LibSmbios64BitGetEPS (
|
---|
166 | OUT SMBIOS_TABLE_3_0_ENTRY_POINT **EntryPointStructure
|
---|
167 | )
|
---|
168 | {
|
---|
169 | //
|
---|
170 | // return SMBIOS Table address
|
---|
171 | //
|
---|
172 | *EntryPointStructure = mSmbios64BitTable;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /**
|
---|
176 | Return SMBIOS string for the given string number.
|
---|
177 |
|
---|
178 | @param[in] Smbios Pointer to SMBIOS structure.
|
---|
179 | @param[in] StringNumber String number to return. -1 is used to skip all strings and
|
---|
180 | point to the next SMBIOS structure.
|
---|
181 |
|
---|
182 | @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
|
---|
183 | **/
|
---|
184 | CHAR8 *
|
---|
185 | LibGetSmbiosString (
|
---|
186 | IN SMBIOS_STRUCTURE_POINTER *Smbios,
|
---|
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 |
|
---|
230 | /**
|
---|
231 | Get SMBIOS structure for the given Handle,
|
---|
232 | Handle is changed to the next handle or 0xFFFF when the end is
|
---|
233 | reached or the handle is not found.
|
---|
234 |
|
---|
235 | @param[in, out] Handle 0xFFFF: get the first structure
|
---|
236 | Others: get a structure according to this value.
|
---|
237 | @param[out] Buffer The pointer to the pointer to the structure.
|
---|
238 | @param[out] Length Length of the structure.
|
---|
239 |
|
---|
240 | @retval DMI_SUCCESS Handle is updated with next structure handle or
|
---|
241 | 0xFFFF(end-of-list).
|
---|
242 |
|
---|
243 | @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or
|
---|
244 | 0xFFFF(end-of-list).
|
---|
245 | **/
|
---|
246 | EFI_STATUS
|
---|
247 | LibGetSmbiosStructure (
|
---|
248 | IN OUT UINT16 *Handle,
|
---|
249 | OUT UINT8 **Buffer,
|
---|
250 | OUT UINT16 *Length
|
---|
251 | )
|
---|
252 | {
|
---|
253 | SMBIOS_STRUCTURE_POINTER Smbios;
|
---|
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 |
|
---|
304 | /**
|
---|
305 | Get SMBIOS structure for the given Handle,
|
---|
306 | Handle is changed to the next handle or 0xFFFF when the end is
|
---|
307 | reached or the handle is not found.
|
---|
308 |
|
---|
309 | @param[in, out] Handle 0xFFFF: get the first structure
|
---|
310 | Others: get a structure according to this value.
|
---|
311 | @param[out] Buffer The pointer to the pointer to the structure.
|
---|
312 | @param[out] Length Length of the structure.
|
---|
313 |
|
---|
314 | @retval DMI_SUCCESS Handle is updated with next structure handle or
|
---|
315 | 0xFFFF(end-of-list).
|
---|
316 |
|
---|
317 | @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or
|
---|
318 | 0xFFFF(end-of-list).
|
---|
319 | **/
|
---|
320 | EFI_STATUS
|
---|
321 | LibGetSmbios64BitStructure (
|
---|
322 | IN OUT UINT16 *Handle,
|
---|
323 | OUT UINT8 **Buffer,
|
---|
324 | OUT UINT16 *Length
|
---|
325 | )
|
---|
326 | {
|
---|
327 | SMBIOS_STRUCTURE_POINTER Smbios;
|
---|
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 | }
|
---|