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