]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Universal/Smbios/SmbiosMiscDxe/SmbiosMiscEntryPoint.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Universal / Smbios / SmbiosMiscDxe / SmbiosMiscEntryPoint.c
1 /** @file
2 This driver parses the mSmbiosMiscDataTable structure and reports
3 any generated data using SMBIOS protocol.
4
5 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
6
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
12
13 **/
14
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>
21
22 #include "SmbiosMisc.h"
23
24 STATIC EFI_HANDLE mSmbiosMiscImageHandle;
25 STATIC EFI_SMBIOS_PROTOCOL *mSmbiosMiscSmbios = NULL;
26
27 EFI_HII_HANDLE mSmbiosMiscHiiHandle;
28
29 /**
30 Standard EFI driver point. This driver parses the mSmbiosMiscDataTable
31 structure and reports any generated data using SMBIOS protocol.
32
33 @param ImageHandle Handle for the image of this driver
34 @param SystemTable Pointer to the EFI System Table
35
36 @retval EFI_SUCCESS The data was successfully stored.
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 SmbiosMiscEntryPoint (
42 IN EFI_HANDLE ImageHandle,
43 IN EFI_SYSTEM_TABLE *SystemTable
44 )
45 {
46 UINTN Index;
47 EFI_STATUS EfiStatus;
48
49 mSmbiosMiscImageHandle = ImageHandle;
50
51 EfiStatus = gBS->LocateProtocol (
52 &gEfiSmbiosProtocolGuid,
53 NULL,
54 (VOID **)&mSmbiosMiscSmbios
55 );
56 if (EFI_ERROR (EfiStatus)) {
57 DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));
58 return EfiStatus;
59 }
60
61 mSmbiosMiscHiiHandle = HiiAddPackages (
62 &gEfiCallerIdGuid,
63 mSmbiosMiscImageHandle,
64 SmbiosMiscDxeStrings,
65 NULL
66 );
67 if (mSmbiosMiscHiiHandle == NULL) {
68 return EFI_OUT_OF_RESOURCES;
69 }
70
71 for (Index = 0; Index < mSmbiosMiscDataTableEntries; ++Index) {
72 //
73 // If the entry have a function pointer, just log the data.
74 //
75 if (mSmbiosMiscDataTable[Index].Function != NULL) {
76 EfiStatus = (*mSmbiosMiscDataTable[Index].Function)(
77 mSmbiosMiscDataTable[Index].RecordData,
78 mSmbiosMiscSmbios
79 );
80
81 if (EFI_ERROR (EfiStatus)) {
82 DEBUG ((
83 DEBUG_ERROR,
84 "Misc smbios store error. Index=%d,"
85 "ReturnStatus=%r\n",
86 Index,
87 EfiStatus
88 ));
89 return EfiStatus;
90 }
91 }
92 }
93
94 return EfiStatus;
95 }
96
97 /**
98 Adds an SMBIOS record.
99
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
107 if not NULL.
108
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.
112
113 **/
114 EFI_STATUS
115 SmbiosMiscAddRecord (
116 IN UINT8 *Buffer,
117 IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL
118 )
119 {
120 EFI_STATUS Status;
121 EFI_SMBIOS_HANDLE Handle;
122
123 Handle = SMBIOS_HANDLE_PI_RESERVED;
124
125 if (SmbiosHandle != NULL) {
126 Handle = *SmbiosHandle;
127 }
128
129 Status = mSmbiosMiscSmbios->Add (
130 mSmbiosMiscSmbios,
131 NULL,
132 &Handle,
133 (EFI_SMBIOS_TABLE_HEADER *)Buffer
134 );
135
136 if (SmbiosHandle != NULL) {
137 *SmbiosHandle = Handle;
138 }
139
140 return Status;
141 }
142
143 /** Fetches the number of handles of the specified SMBIOS type.
144 *
145 * @param SmbiosType The type of SMBIOS record to look for.
146 *
147 * @return The number of handles
148 *
149 **/
150 STATIC
151 UINTN
152 GetHandleCount (
153 IN UINT8 SmbiosType
154 )
155 {
156 UINTN HandleCount;
157 EFI_STATUS Status;
158 EFI_SMBIOS_HANDLE SmbiosHandle;
159 EFI_SMBIOS_TABLE_HEADER *Record;
160
161 HandleCount = 0;
162
163 // Iterate through entries to get the number
164 do {
165 Status = mSmbiosMiscSmbios->GetNext (
166 mSmbiosMiscSmbios,
167 &SmbiosHandle,
168 &SmbiosType,
169 &Record,
170 NULL
171 );
172
173 if (Status == EFI_SUCCESS) {
174 HandleCount++;
175 }
176 } while (!EFI_ERROR (Status));
177
178 return HandleCount;
179 }
180
181 /**
182 Fetches a list of the specified SMBIOS table types.
183
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
187 **/
188 VOID
189 SmbiosMiscGetLinkTypeHandle (
190 IN UINT8 SmbiosType,
191 OUT SMBIOS_HANDLE **HandleArray,
192 OUT UINTN *HandleCount
193 )
194 {
195 UINTN Index;
196 EFI_STATUS Status;
197 EFI_SMBIOS_HANDLE SmbiosHandle;
198 EFI_SMBIOS_TABLE_HEADER *Record;
199
200 if (mSmbiosMiscSmbios == NULL) {
201 return;
202 }
203
204 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
205 *HandleCount = GetHandleCount (SmbiosType);
206
207 *HandleArray = AllocateZeroPool (sizeof (SMBIOS_HANDLE) * (*HandleCount));
208 if (*HandleArray == NULL) {
209 DEBUG ((DEBUG_ERROR, "HandleArray allocate memory resource failed.\n"));
210 *HandleCount = 0;
211 return;
212 }
213
214 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
215
216 for (Index = 0; Index < (*HandleCount); Index++) {
217 Status = mSmbiosMiscSmbios->GetNext (
218 mSmbiosMiscSmbios,
219 &SmbiosHandle,
220 &SmbiosType,
221 &Record,
222 NULL
223 );
224
225 if (!EFI_ERROR (Status)) {
226 (*HandleArray)[Index] = Record->Handle;
227 } else {
228 break;
229 }
230 }
231 }