]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.c
Add SMBIOS 2.7.1 support to SmbiosView command.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SmbiosView / LibSmbiosView.c
CommitLineData
5d73d92f 1/** @file\r
2 API for SMBIOS table.\r
3\r
187cb3dd 4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r
5d73d92f 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
2b578de0 17#include <Guid/SmBios.h>\r
5d73d92f 18#include "LibSmbiosView.h"\r
a1d4bfcc 19#include "SmbiosView.h"\r
5d73d92f 20\r
21STATIC UINT8 mInit = 0;\r
187cb3dd 22STATIC SMBIOS_TABLE_ENTRY_POINT *mSmbiosTable = NULL;\r
5d73d92f 23STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;\r
24STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;\r
25\r
a1d4bfcc 26/**\r
27 Init the SMBIOS VIEW API's environment.\r
28\r
29 @retval EFI_SUCCESS Successful to init the SMBIOS VIEW Lib.\r
30**/\r
5d73d92f 31EFI_STATUS\r
32LibSmbiosInit (\r
33 VOID\r
34 )\r
5d73d92f 35{\r
36 EFI_STATUS Status;\r
37\r
38 //\r
39 // Init only once\r
40 //\r
41 if (mInit == 1) {\r
42 return EFI_SUCCESS;\r
43 }\r
44 //\r
45 // Get SMBIOS table from System Configure table\r
46 //\r
47 Status = GetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID**)&mSmbiosTable);\r
48\r
49 if (mSmbiosTable == NULL) {\r
50 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle);\r
51 return EFI_NOT_FOUND;\r
52 }\r
53\r
54 if (EFI_ERROR (Status)) {\r
55 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), gShellDebug1HiiHandle, Status);\r
56 return Status;\r
57 }\r
58 //\r
59 // Init SMBIOS structure table address\r
60 //\r
61 mSmbiosStruct->Raw = (UINT8 *) (UINTN) (mSmbiosTable->TableAddress);\r
62\r
63 mInit = 1;\r
64 return EFI_SUCCESS;\r
65}\r
66\r
a1d4bfcc 67/**\r
68 Cleanup the Smbios information.\r
69**/\r
5d73d92f 70VOID\r
71LibSmbiosCleanup (\r
72 VOID\r
73 )\r
74{\r
75 //\r
76 // Release resources\r
77 //\r
78 if (mSmbiosTable != NULL) {\r
79 mSmbiosTable = NULL;\r
80 }\r
81\r
82 mInit = 0;\r
83}\r
84\r
a1d4bfcc 85/**\r
86 Get the entry point structure for the table.\r
87\r
88 @param[out] EntryPointStructure The pointer to populate.\r
89**/\r
5d73d92f 90VOID\r
91LibSmbiosGetEPS (\r
187cb3dd 92 OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure\r
5d73d92f 93 )\r
94{\r
95 //\r
96 // return SMBIOS Table address\r
97 //\r
a1d4bfcc 98 *EntryPointStructure = mSmbiosTable;\r
5d73d92f 99}\r
100\r
a1d4bfcc 101/**\r
187cb3dd
SZ
102 Return SMBIOS string for the given string number.\r
103\r
104 @param[in] Smbios Pointer to SMBIOS structure.\r
105 @param[in] StringNumber String number to return. -1 is used to skip all strings and\r
106 point to the next SMBIOS structure.\r
107\r
108 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1\r
109**/\r
110CHAR8*\r
111LibGetSmbiosString (\r
112 IN SMBIOS_STRUCTURE_POINTER *Smbios,\r
113 IN UINT16 StringNumber\r
114 )\r
115{\r
116 UINT16 Index;\r
117 CHAR8 *String;\r
118\r
119 ASSERT (Smbios != NULL);\r
120\r
121 //\r
122 // Skip over formatted section\r
123 //\r
124 String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r
125\r
126 //\r
127 // Look through unformated section\r
128 //\r
129 for (Index = 1; Index <= StringNumber; Index++) {\r
130 if (StringNumber == Index) {\r
131 return String;\r
132 }\r
133 //\r
134 // Skip string\r
135 //\r
136 for (; *String != 0; String++);\r
137 String++;\r
138\r
139 if (*String == 0) {\r
140 //\r
141 // If double NULL then we are done.\r
142 // Return pointer to next structure in Smbios.\r
143 // if you pass in a -1 you will always get here\r
144 //\r
145 Smbios->Raw = (UINT8 *)++String;\r
146 return NULL;\r
147 }\r
148 }\r
149\r
150 return NULL;\r
151}\r
152\r
153/**\r
154 Get SMBIOS structure for the given Handle,\r
a1d4bfcc 155 Handle is changed to the next handle or 0xFFFF when the end is\r
156 reached or the handle is not found.\r
5d73d92f 157\r
4ff7e37b
ED
158 @param[in, out] Handle 0xFFFF: get the first structure\r
159 Others: get a structure according to this value.\r
187cb3dd
SZ
160 @param[out] Buffer The pointer to the pointer to the structure.\r
161 @param[out] Length Length of the structure.\r
5d73d92f 162\r
187cb3dd 163 @retval DMI_SUCCESS Handle is updated with next structure handle or\r
a1d4bfcc 164 0xFFFF(end-of-list).\r
5d73d92f 165\r
187cb3dd 166 @retval DMI_INVALID_HANDLE Handle is updated with first structure handle or\r
a1d4bfcc 167 0xFFFF(end-of-list).\r
5d73d92f 168**/\r
5d73d92f 169EFI_STATUS\r
170LibGetSmbiosStructure (\r
171 IN OUT UINT16 *Handle,\r
187cb3dd 172 OUT UINT8 **Buffer,\r
5d73d92f 173 OUT UINT16 *Length\r
174 )\r
5d73d92f 175{\r
176 SMBIOS_STRUCTURE_POINTER Smbios;\r
177 SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r
178 UINT8 *Raw;\r
179\r
187cb3dd 180 if (*Handle == INVALID_HANDLE) {\r
5d73d92f 181 *Handle = mSmbiosStruct->Hdr->Handle;\r
182 return DMI_INVALID_HANDLE;\r
183 }\r
184\r
187cb3dd
SZ
185 if ((Buffer == NULL) || (Length == NULL)) {\r
186 ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);\r
5d73d92f 187 return DMI_INVALID_HANDLE;\r
188 }\r
189\r
190 *Length = 0;\r
191 Smbios.Hdr = mSmbiosStruct->Hdr;\r
192 SmbiosEnd.Raw = Smbios.Raw + mSmbiosTable->TableLength;\r
193 while (Smbios.Raw < SmbiosEnd.Raw) {\r
194 if (Smbios.Hdr->Handle == *Handle) {\r
195 Raw = Smbios.Raw;\r
196 //\r
197 // Walk to next structure\r
198 //\r
199 LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
200 //\r
201 // Length = Next structure head - this structure head\r
202 //\r
203 *Length = (UINT16) (Smbios.Raw - Raw);\r
187cb3dd 204 *Buffer = Raw;\r
5d73d92f 205 //\r
206 // update with the next structure handle.\r
207 //\r
208 if (Smbios.Raw < SmbiosEnd.Raw) {\r
209 *Handle = Smbios.Hdr->Handle;\r
210 } else {\r
187cb3dd 211 *Handle = INVALID_HANDLE;\r
5d73d92f 212 }\r
213 return DMI_SUCCESS;\r
214 }\r
215 //\r
216 // Walk to next structure\r
217 //\r
218 LibGetSmbiosString (&Smbios, (UINT16) (-1));\r
219 }\r
220\r
187cb3dd 221 *Handle = INVALID_HANDLE;\r
5d73d92f 222 return DMI_INVALID_HANDLE;\r
223}\r
224\r