TianoCore EDK2 master
Loading...
Searching...
No Matches
SmbiosLib.c
Go to the documentation of this file.
1
12#include <PiDxe.h>
13#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
18#include <Library/UefiLib.h>
19#include <Library/SmbiosLib.h>
20
22
33EFIAPI
36 )
37{
38 EFI_STATUS Status;
39 UINTN Index;
40
41 if (Template == NULL) {
42 return EFI_INVALID_PARAMETER;
43 }
44
45 Status = EFI_SUCCESS;
46
47 for (Index = 0; Template[Index].Entry != NULL; Index++) {
48 Status = SmbiosLibCreateEntry (Template[Index].Entry, Template[Index].StringArray);
49 }
50
51 return Status;
52}
53
82EFIAPI
84 IN SMBIOS_STRUCTURE *SmbiosEntry,
85 IN CHAR8 **StringArray
86 )
87{
88 EFI_STATUS Status;
89 EFI_SMBIOS_HANDLE SmbiosHandle;
91 UINTN Index;
92 UINTN StringSize;
93 UINTN Size;
94 CHAR8 *Str;
95
96 // Calculate the size of the fixed record and optional string pack
97 Size = SmbiosEntry->Length;
98 if (StringArray == NULL) {
99 Size += 2; // Min string section is double null
100 } else if (StringArray[0] == NULL) {
101 Size += 2; // Min string section is double null
102 } else {
103 for (Index = 0; StringArray[Index] != NULL; Index++) {
104 StringSize = AsciiStrSize (StringArray[Index]);
105 Size += StringSize;
106 }
107
108 // Don't forget the terminating double null
109 Size += 1;
110 }
111
112 // Copy over Template
113 Record = (EFI_SMBIOS_TABLE_HEADER *)AllocateZeroPool (Size);
114 if (Record == NULL) {
115 return EFI_OUT_OF_RESOURCES;
116 }
117
118 CopyMem (Record, SmbiosEntry, SmbiosEntry->Length);
119
120 if (StringArray != NULL) {
121 // Append string pack
122 Str = ((CHAR8 *)Record) + Record->Length;
123 for (Index = 0; StringArray[Index] != NULL; Index++) {
124 StringSize = AsciiStrSize (StringArray[Index]);
125 CopyMem (Str, StringArray[Index], StringSize);
126 Str += StringSize;
127 }
128
129 *Str = 0;
130 }
131
132 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
133 Status = gSmbios->Add (
134 gSmbios,
136 &SmbiosHandle,
137 Record
138 );
139
140 FreePool (Record);
141 return Status;
142}
143
160EFIAPI
162 IN EFI_SMBIOS_HANDLE SmbiosHandle,
163 IN SMBIOS_TABLE_STRING StringNumber,
164 IN CHAR8 *String
165 )
166{
167 UINTN StringIndex;
168
169 if (String == NULL) {
170 return EFI_INVALID_PARAMETER;
171 }
172
173 if (*String == '\0') {
174 // A string with no data is not legal in SMBIOS
175 return EFI_INVALID_PARAMETER;
176 }
177
178 StringIndex = StringNumber;
179 return gSmbios->UpdateString (gSmbios, &SmbiosHandle, &StringIndex, String);
180}
181
198EFIAPI
200 IN EFI_SMBIOS_HANDLE SmbiosHandle,
201 IN SMBIOS_TABLE_STRING StringNumber,
202 IN CHAR16 *String
203 )
204{
205 EFI_STATUS Status;
206 UINTN StringIndex;
207 CHAR8 *Ascii;
208
209 if (String == NULL) {
210 return EFI_INVALID_PARAMETER;
211 }
212
213 if (*String == '\0') {
214 // A string with no data is not legal in SMBIOS
215 return EFI_INVALID_PARAMETER;
216 }
217
218 Ascii = AllocateZeroPool (StrSize (String));
219 if (Ascii == NULL) {
220 return EFI_OUT_OF_RESOURCES;
221 }
222
223 UnicodeStrToAsciiStrS (String, Ascii, StrSize (String));
224
225 StringIndex = StringNumber;
226 Status = gSmbios->UpdateString (gSmbios, &SmbiosHandle, &StringIndex, Ascii);
227
228 FreePool (Ascii);
229 return Status;
230}
231
241CHAR8 *
242EFIAPI
244 IN SMBIOS_STRUCTURE *Header,
245 IN EFI_SMBIOS_STRING StringNumber
246 )
247{
248 CHAR8 *Data;
249 UINTN Match;
250
251 Data = (CHAR8 *)Header + Header->Length;
252 for (Match = 1; !(*Data == 0 && *(Data+1) == 0); ) {
253 if (StringNumber == Match) {
254 return Data;
255 }
256
257 Data++;
258 if (*(Data - 1) == '\0') {
259 Match++;
260 }
261 }
262
263 return NULL;
264}
265
277EFIAPI
279 IN EFI_SMBIOS_TYPE Type,
280 IN UINTN Instance,
281 OUT EFI_SMBIOS_HANDLE *SmbiosHandle
282 )
283{
284 EFI_STATUS Status;
286 UINTN Match;
287
288 Match = 0;
289 *SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
290 do {
291 Status = gSmbios->GetNext (gSmbios, SmbiosHandle, &Type, &Record, NULL);
292 if (!EFI_ERROR (Status)) {
293 if (Match == Instance) {
294 return (SMBIOS_STRUCTURE *)Record;
295 }
296
297 Match++;
298 }
299 } while (!EFI_ERROR (Status));
300
301 return NULL;
302}
303
315EFIAPI
317 OUT EFI_SMBIOS_HANDLE SmbiosHandle
318 )
319{
320 return gSmbios->Remove (gSmbios, SmbiosHandle);
321}
322
332EFIAPI
334 IN EFI_HANDLE ImageHandle,
335 IN EFI_SYSTEM_TABLE *SystemTable
336 )
337{
338 return gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&gSmbios);
339}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2650
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINT8 SMBIOS_TABLE_STRING
Definition: SmBios.h:208
#define SMBIOS_HANDLE_PI_RESERVED
Definition: SmBios.h:29
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
STATIC BOOLEAN Match(IN CONST CHAR16 *Translated, IN UINTN TranslatedLength, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_STATUS EFIAPI SmbiosLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SmbiosLib.c:333
SMBIOS_STRUCTURE *EFIAPI SmbiosLibGetRecord(IN EFI_SMBIOS_TYPE Type, IN UINTN Instance, OUT EFI_SMBIOS_HANDLE *SmbiosHandle)
Definition: SmbiosLib.c:278
EFI_SMBIOS_PROTOCOL * gSmbios
Definition: SmbiosLib.c:21
EFI_STATUS EFIAPI SmbiosLibRemove(OUT EFI_SMBIOS_HANDLE SmbiosHandle)
Definition: SmbiosLib.c:316
EFI_STATUS EFIAPI SmbiosLibCreateEntry(IN SMBIOS_STRUCTURE *SmbiosEntry, IN CHAR8 **StringArray)
Definition: SmbiosLib.c:83
EFI_STATUS EFIAPI SmbiosLibInitializeFromTemplate(IN SMBIOS_TEMPLATE_ENTRY *Template)
Definition: SmbiosLib.c:34
EFI_STATUS EFIAPI SmbiosLibUpdateString(IN EFI_SMBIOS_HANDLE SmbiosHandle, IN SMBIOS_TABLE_STRING StringNumber, IN CHAR8 *String)
Definition: SmbiosLib.c:161
CHAR8 *EFIAPI SmbiosLibReadString(IN SMBIOS_STRUCTURE *Header, IN EFI_SMBIOS_STRING StringNumber)
Definition: SmbiosLib.c:243
EFI_STATUS EFIAPI SmbiosLibUpdateUnicodeString(IN EFI_SMBIOS_HANDLE SmbiosHandle, IN SMBIOS_TABLE_STRING StringNumber, IN CHAR16 *String)
Definition: SmbiosLib.c:199
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS