]>
Commit | Line | Data |
---|---|---|
5d73d92f | 1 | /** @file\r |
2 | API for SMBIOS table.\r | |
3 | \r | |
ba0014b9 | 4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
5d73d92f | 6 | \r |
7 | **/\r | |
ba0014b9 | 8 | \r |
5d73d92f | 9 | \r |
8a765da2 | 10 | #include "UefiShellDebug1CommandsLib.h"\r |
2b578de0 | 11 | #include <Guid/SmBios.h>\r |
5d73d92f | 12 | #include "LibSmbiosView.h"\r |
a1d4bfcc | 13 | #include "SmbiosView.h"\r |
5d73d92f | 14 | \r |
15 | STATIC UINT8 mInit = 0;\r | |
ec8a502e EL |
16 | STATIC UINT8 m64Init = 0;\r |
17 | STATIC SMBIOS_TABLE_ENTRY_POINT *mSmbiosTable = NULL;\r | |
18 | STATIC SMBIOS_TABLE_3_0_ENTRY_POINT *mSmbios64BitTable = NULL;\r | |
5d73d92f | 19 | STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;\r |
20 | STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;\r | |
ec8a502e EL |
21 | STATIC SMBIOS_STRUCTURE_POINTER m_Smbios64BitStruct;\r |
22 | STATIC SMBIOS_STRUCTURE_POINTER *mSmbios64BitStruct = &m_Smbios64BitStruct;\r | |
5d73d92f | 23 | \r |
a1d4bfcc | 24 | /**\r |
25 | Init the SMBIOS VIEW API's environment.\r | |
26 | \r | |
27 | @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.\r | |
28 | **/\r | |
5d73d92f | 29 | EFI_STATUS\r |
30 | LibSmbiosInit (\r | |
31 | VOID\r | |
32 | )\r | |
5d73d92f | 33 | {\r |
34 | EFI_STATUS Status;\r | |
35 | \r | |
36 | //\r | |
37 | // Init only once\r | |
38 | //\r | |
39 | if (mInit == 1) {\r | |
40 | return EFI_SUCCESS;\r | |
41 | }\r | |
42 | //\r | |
43 | // Get SMBIOS table from System Configure table\r | |
44 | //\r | |
45 | Status = GetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID**)&mSmbiosTable);\r | |
46 | \r | |
47 | if (mSmbiosTable == NULL) {\r | |
5d73d92f | 48 | return EFI_NOT_FOUND;\r |
49 | }\r | |
50 | \r | |
51 | if (EFI_ERROR (Status)) {\r | |
52 | ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);\r | |
53 | return Status;\r | |
54 | }\r | |
55 | //\r | |
56 | // Init SMBIOS structure table address\r | |
57 | //\r | |
58 | mSmbiosStruct->Raw = (UINT8 *) (UINTN) (mSmbiosTable->TableAddress);\r | |
59 | \r | |
60 | mInit = 1;\r | |
61 | return EFI_SUCCESS;\r | |
62 | }\r | |
63 | \r | |
ec8a502e EL |
64 | /**\r |
65 | Init the SMBIOS VIEW API's environment.\r | |
66 | \r | |
67 | @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.\r | |
68 | **/\r | |
69 | EFI_STATUS\r | |
70 | LibSmbios64BitInit (\r | |
71 | VOID\r | |
72 | )\r | |
73 | {\r | |
74 | EFI_STATUS Status;\r | |
75 | \r | |
76 | //\r | |
77 | // Init only once\r | |
78 | //\r | |
79 | if (m64Init == 1) {\r | |
80 | return EFI_SUCCESS;\r | |
81 | }\r | |
82 | //\r | |
83 | // Get SMBIOS table from System Configure table\r | |
84 | //\r | |
85 | Status = GetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID**)&mSmbios64BitTable);\r | |
86 | \r | |
87 | if (mSmbios64BitTable == NULL) {\r | |
88 | return EFI_NOT_FOUND;\r | |
89 | }\r | |
90 | \r | |
91 | if (EFI_ERROR (Status)) {\r | |
92 | ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);\r | |
93 | return Status;\r | |
94 | }\r | |
95 | //\r | |
96 | // Init SMBIOS structure table address\r | |
97 | //\r | |
98 | mSmbios64BitStruct->Raw = (UINT8 *) (UINTN) (mSmbios64BitTable->TableAddress);\r | |
99 | \r | |
100 | m64Init = 1;\r | |
101 | return EFI_SUCCESS;\r | |
102 | }\r | |
103 | \r | |
a1d4bfcc | 104 | /**\r |
105 | Cleanup the Smbios information.\r | |
106 | **/\r | |
5d73d92f | 107 | VOID\r |
108 | LibSmbiosCleanup (\r | |
109 | VOID\r | |
110 | )\r | |
111 | {\r | |
112 | //\r | |
113 | // Release resources\r | |
114 | //\r | |
115 | if (mSmbiosTable != NULL) {\r | |
116 | mSmbiosTable = NULL;\r | |
117 | }\r | |
118 | \r | |
119 | mInit = 0;\r | |
120 | }\r | |
121 | \r | |
ec8a502e EL |
122 | /**\r |
123 | Cleanup the Smbios information.\r | |
124 | **/\r | |
125 | VOID\r | |
126 | LibSmbios64BitCleanup (\r | |
127 | VOID\r | |
128 | )\r | |
129 | {\r | |
130 | //\r | |
131 | // Release resources\r | |
132 | //\r | |
133 | if (mSmbios64BitTable != NULL) {\r | |
134 | mSmbios64BitTable = NULL;\r | |
135 | }\r | |
136 | \r | |
137 | m64Init = 0;\r | |
138 | }\r | |
139 | \r | |
a1d4bfcc | 140 | /**\r |
141 | Get the entry point structure for the table.\r | |
142 | \r | |
143 | @param[out] EntryPointStructure The pointer to populate.\r | |
144 | **/\r | |
5d73d92f | 145 | VOID\r |
146 | LibSmbiosGetEPS (\r | |
187cb3dd | 147 | OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure\r |
5d73d92f | 148 | )\r |
149 | {\r | |
150 | //\r | |
151 | // return SMBIOS Table address\r | |
152 | //\r | |
a1d4bfcc | 153 | *EntryPointStructure = mSmbiosTable;\r |
5d73d92f | 154 | }\r |
155 | \r | |
ec8a502e EL |
156 | /**\r |
157 | Get the entry point structure for the table.\r | |
158 | \r | |
159 | @param[out] EntryPointStructure The pointer to populate.\r | |
160 | **/\r | |
161 | VOID\r | |
162 | LibSmbios64BitGetEPS (\r | |
163 | OUT SMBIOS_TABLE_3_0_ENTRY_POINT **EntryPointStructure\r | |
164 | )\r | |
165 | {\r | |
166 | //\r | |
167 | // return SMBIOS Table address\r | |
168 | //\r | |
169 | *EntryPointStructure = mSmbios64BitTable;\r | |
170 | }\r | |
171 | \r | |
a1d4bfcc | 172 | /**\r |
187cb3dd SZ |
173 | Return SMBIOS string for the given string number.\r |
174 | \r | |
175 | @param[in] Smbios Pointer to SMBIOS structure.\r | |
176 | @param[in] StringNumber String number to return. -1 is used to skip all strings and\r | |
177 | point to the next SMBIOS structure.\r | |
178 | \r | |
179 | @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1\r | |
180 | **/\r | |
181 | CHAR8*\r | |
182 | LibGetSmbiosString (\r | |
183 | IN SMBIOS_STRUCTURE_POINTER *Smbios,\r | |
184 | IN UINT16 StringNumber\r | |
185 | )\r | |
186 | {\r | |
187 | UINT16 Index;\r | |
188 | CHAR8 *String;\r | |
189 | \r | |
190 | ASSERT (Smbios != NULL);\r | |
191 | \r | |
192 | //\r | |
193 | // Skip over formatted section\r | |
194 | //\r | |
195 | String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r | |
196 | \r | |
197 | //\r | |
198 | // Look through unformated section\r | |
199 | //\r | |
200 | for (Index = 1; Index <= StringNumber; Index++) {\r | |
201 | if (StringNumber == Index) {\r | |
202 | return String;\r | |
203 | }\r | |
204 | //\r | |
205 | // Skip string\r | |
206 | //\r | |
207 | for (; *String != 0; String++);\r | |
208 | String++;\r | |
209 | \r | |
210 | if (*String == 0) {\r | |
211 | //\r | |
212 | // If double NULL then we are done.\r | |
213 | // Return pointer to next structure in Smbios.\r | |
214 | // if you pass in a -1 you will always get here\r | |
215 | //\r | |
216 | Smbios->Raw = (UINT8 *)++String;\r | |
217 | return NULL;\r | |
218 | }\r | |
219 | }\r | |
220 | \r | |
221 | return NULL;\r | |
222 | }\r | |
223 | \r | |
224 | /**\r | |
225 | Get SMBIOS structure for the given Handle,\r | |
a1d4bfcc | 226 | Handle is changed to the next handle or 0xFFFF when the end is\r |
227 | reached or the handle is not found.\r | |
5d73d92f | 228 | \r |
4ff7e37b ED |
229 | @param[in, out] Handle 0xFFFF: get the first structure\r |
230 | Others: get a structure according to this value.\r | |
187cb3dd SZ |
231 | @param[out] Buffer The pointer to the pointer to the structure.\r |
232 | @param[out] Length Length of the structure.\r | |
5d73d92f | 233 | \r |
187cb3dd | 234 | @retval DMI_SUCCESS Handle is updated with next structure handle or\r |
a1d4bfcc | 235 | 0xFFFF(end-of-list).\r |
5d73d92f | 236 | \r |
187cb3dd | 237 | @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or\r |
a1d4bfcc | 238 | 0xFFFF(end-of-list).\r |
5d73d92f | 239 | **/\r |
5d73d92f | 240 | EFI_STATUS\r |
241 | LibGetSmbiosStructure (\r | |
242 | IN OUT UINT16 *Handle,\r | |
187cb3dd | 243 | OUT UINT8 **Buffer,\r |
5d73d92f | 244 | OUT UINT16 *Length\r |
245 | )\r | |
5d73d92f | 246 | {\r |
247 | SMBIOS_STRUCTURE_POINTER Smbios;\r | |
248 | SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r | |
249 | UINT8 *Raw;\r | |
250 | \r | |
187cb3dd | 251 | if (*Handle == INVALID_HANDLE) {\r |
5d73d92f | 252 | *Handle = mSmbiosStruct->Hdr->Handle;\r |
253 | return DMI_INVALID_HANDLE;\r | |
254 | }\r | |
255 | \r | |
187cb3dd SZ |
256 | if ((Buffer == NULL) || (Length == NULL)) {\r |
257 | ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);\r | |
5d73d92f | 258 | return DMI_INVALID_HANDLE;\r |
259 | }\r | |
260 | \r | |
261 | *Length = 0;\r | |
262 | Smbios.Hdr = mSmbiosStruct->Hdr;\r | |
263 | SmbiosEnd.Raw = Smbios.Raw + mSmbiosTable->TableLength;\r | |
264 | while (Smbios.Raw < SmbiosEnd.Raw) {\r | |
265 | if (Smbios.Hdr->Handle == *Handle) {\r | |
266 | Raw = Smbios.Raw;\r | |
267 | //\r | |
268 | // Walk to next structure\r | |
269 | //\r | |
270 | LibGetSmbiosString (&Smbios, (UINT16) (-1));\r | |
271 | //\r | |
272 | // Length = Next structure head - this structure head\r | |
273 | //\r | |
274 | *Length = (UINT16) (Smbios.Raw - Raw);\r | |
187cb3dd | 275 | *Buffer = Raw;\r |
5d73d92f | 276 | //\r |
277 | // update with the next structure handle.\r | |
278 | //\r | |
279 | if (Smbios.Raw < SmbiosEnd.Raw) {\r | |
280 | *Handle = Smbios.Hdr->Handle;\r | |
281 | } else {\r | |
187cb3dd | 282 | *Handle = INVALID_HANDLE;\r |
5d73d92f | 283 | }\r |
284 | return DMI_SUCCESS;\r | |
285 | }\r | |
286 | //\r | |
287 | // Walk to next structure\r | |
288 | //\r | |
289 | LibGetSmbiosString (&Smbios, (UINT16) (-1));\r | |
290 | }\r | |
291 | \r | |
187cb3dd | 292 | *Handle = INVALID_HANDLE;\r |
5d73d92f | 293 | return DMI_INVALID_HANDLE;\r |
294 | }\r | |
295 | \r | |
ec8a502e EL |
296 | /**\r |
297 | Get SMBIOS structure for the given Handle,\r | |
298 | Handle is changed to the next handle or 0xFFFF when the end is\r | |
299 | reached or the handle is not found.\r | |
300 | \r | |
301 | @param[in, out] Handle 0xFFFF: get the first structure\r | |
302 | Others: get a structure according to this value.\r | |
303 | @param[out] Buffer The pointer to the pointer to the structure.\r | |
304 | @param[out] Length Length of the structure.\r | |
305 | \r | |
306 | @retval DMI_SUCCESS Handle is updated with next structure handle or\r | |
307 | 0xFFFF(end-of-list).\r | |
308 | \r | |
309 | @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or\r | |
310 | 0xFFFF(end-of-list).\r | |
311 | **/\r | |
312 | EFI_STATUS\r | |
313 | LibGetSmbios64BitStructure (\r | |
314 | IN OUT UINT16 *Handle,\r | |
315 | OUT UINT8 **Buffer,\r | |
316 | OUT UINT16 *Length\r | |
317 | )\r | |
318 | {\r | |
319 | SMBIOS_STRUCTURE_POINTER Smbios;\r | |
320 | SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r | |
321 | UINT8 *Raw;\r | |
322 | \r | |
323 | if (*Handle == INVALID_HANDLE) {\r | |
324 | *Handle = mSmbios64BitStruct->Hdr->Handle;\r | |
325 | return DMI_INVALID_HANDLE;\r | |
326 | }\r | |
327 | \r | |
328 | if ((Buffer == NULL) || (Length == NULL)) {\r | |
329 | ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);\r | |
330 | return DMI_INVALID_HANDLE;\r | |
331 | }\r | |
332 | \r | |
333 | *Length = 0;\r | |
334 | Smbios.Hdr = mSmbios64BitStruct->Hdr;\r | |
335 | \r | |
336 | SmbiosEnd.Raw = Smbios.Raw + mSmbios64BitTableLength;\r | |
337 | while (Smbios.Raw < SmbiosEnd.Raw) {\r | |
338 | if (Smbios.Hdr->Handle == *Handle) {\r | |
339 | Raw = Smbios.Raw;\r | |
340 | //\r | |
341 | // Walk to next structure\r | |
342 | //\r | |
343 | LibGetSmbiosString (&Smbios, (UINT16) (-1));\r | |
344 | //\r | |
345 | // Length = Next structure head - this structure head\r | |
346 | //\r | |
347 | *Length = (UINT16) (Smbios.Raw - Raw);\r | |
348 | *Buffer = Raw;\r | |
349 | //\r | |
350 | // update with the next structure handle.\r | |
351 | //\r | |
352 | if (Smbios.Raw < SmbiosEnd.Raw) {\r | |
353 | *Handle = Smbios.Hdr->Handle;\r | |
354 | } else {\r | |
355 | *Handle = INVALID_HANDLE;\r | |
356 | }\r | |
357 | return DMI_SUCCESS;\r | |
358 | }\r | |
359 | //\r | |
360 | // Walk to next structure\r | |
361 | //\r | |
362 | LibGetSmbiosString (&Smbios, (UINT16) (-1));\r | |
363 | }\r | |
364 | \r | |
365 | *Handle = INVALID_HANDLE;\r | |
366 | return DMI_INVALID_HANDLE;\r | |
88ff5ba7 | 367 | }\r |