2 This driver parses the mSmbiosMiscDataTable structure and reports
3 any generated data using SMBIOS protocol.
5 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
7 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
8 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
9 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
10 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/HiiLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
22 #include "SmbiosMisc.h"
24 STATIC EFI_HANDLE mSmbiosMiscImageHandle
;
25 STATIC EFI_SMBIOS_PROTOCOL
*mSmbiosMiscSmbios
= NULL
;
27 EFI_HII_HANDLE mSmbiosMiscHiiHandle
;
30 Standard EFI driver point. This driver parses the mSmbiosMiscDataTable
31 structure and reports any generated data using SMBIOS protocol.
33 @param ImageHandle Handle for the image of this driver
34 @param SystemTable Pointer to the EFI System Table
36 @retval EFI_SUCCESS The data was successfully stored.
41 SmbiosMiscEntryPoint (
42 IN EFI_HANDLE ImageHandle
,
43 IN EFI_SYSTEM_TABLE
*SystemTable
49 mSmbiosMiscImageHandle
= ImageHandle
;
51 EfiStatus
= gBS
->LocateProtocol (
52 &gEfiSmbiosProtocolGuid
,
54 (VOID
**)&mSmbiosMiscSmbios
56 if (EFI_ERROR (EfiStatus
)) {
57 DEBUG ((DEBUG_ERROR
, "Could not locate SMBIOS protocol. %r\n", EfiStatus
));
61 mSmbiosMiscHiiHandle
= HiiAddPackages (
63 mSmbiosMiscImageHandle
,
67 if (mSmbiosMiscHiiHandle
== NULL
) {
68 return EFI_OUT_OF_RESOURCES
;
71 for (Index
= 0; Index
< mSmbiosMiscDataTableEntries
; ++Index
) {
73 // If the entry have a function pointer, just log the data.
75 if (mSmbiosMiscDataTable
[Index
].Function
!= NULL
) {
76 EfiStatus
= (*mSmbiosMiscDataTable
[Index
].Function
)(
77 mSmbiosMiscDataTable
[Index
].RecordData
,
81 if (EFI_ERROR (EfiStatus
)) {
84 "Misc smbios store error. Index=%d,"
98 Adds an SMBIOS record.
100 @param Buffer The data for the SMBIOS record.
101 The format of the record is determined by
102 EFI_SMBIOS_TABLE_HEADER.Type. The size of the
103 formatted area is defined by EFI_SMBIOS_TABLE_HEADER.Length
104 and either followed by a double-null (0x0000) or a set
105 of null terminated strings and a null.
106 @param SmbiosHandle A unique handle will be assigned to the SMBIOS record
109 @retval EFI_SUCCESS Record was added.
110 @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system resources.
111 @retval EFI_ALREADY_STARTED The SmbiosHandle passed in was already in use.
115 SmbiosMiscAddRecord (
117 IN OUT EFI_SMBIOS_HANDLE
*SmbiosHandle OPTIONAL
121 EFI_SMBIOS_HANDLE Handle
;
123 Handle
= SMBIOS_HANDLE_PI_RESERVED
;
125 if (SmbiosHandle
!= NULL
) {
126 Handle
= *SmbiosHandle
;
129 Status
= mSmbiosMiscSmbios
->Add (
133 (EFI_SMBIOS_TABLE_HEADER
*)Buffer
136 if (SmbiosHandle
!= NULL
) {
137 *SmbiosHandle
= Handle
;
143 /** Fetches the number of handles of the specified SMBIOS type.
145 * @param SmbiosType The type of SMBIOS record to look for.
147 * @return The number of handles
158 EFI_SMBIOS_HANDLE SmbiosHandle
;
159 EFI_SMBIOS_TABLE_HEADER
*Record
;
163 // Iterate through entries to get the number
165 Status
= mSmbiosMiscSmbios
->GetNext (
173 if (Status
== EFI_SUCCESS
) {
176 } while (!EFI_ERROR (Status
));
182 Fetches a list of the specified SMBIOS table types.
184 @param[in] SmbiosType The type of table to fetch
185 @param[out] **HandleArray The array of handles
186 @param[out] *HandleCount Number of handles in the array
189 SmbiosMiscGetLinkTypeHandle (
191 OUT SMBIOS_HANDLE
**HandleArray
,
192 OUT UINTN
*HandleCount
197 EFI_SMBIOS_HANDLE SmbiosHandle
;
198 EFI_SMBIOS_TABLE_HEADER
*Record
;
200 if (mSmbiosMiscSmbios
== NULL
) {
204 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
205 *HandleCount
= GetHandleCount (SmbiosType
);
207 *HandleArray
= AllocateZeroPool (sizeof (SMBIOS_HANDLE
) * (*HandleCount
));
208 if (*HandleArray
== NULL
) {
209 DEBUG ((DEBUG_ERROR
, "HandleArray allocate memory resource failed.\n"));
214 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
216 for (Index
= 0; Index
< (*HandleCount
); Index
++) {
217 Status
= mSmbiosMiscSmbios
->GetNext (
225 if (!EFI_ERROR (Status
)) {
226 (*HandleArray
)[Index
] = Record
->Handle
;