]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Universal/Smbios/SmbiosMiscDxe/SmbiosMiscEntryPoint.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Universal / Smbios / SmbiosMiscDxe / SmbiosMiscEntryPoint.c
CommitLineData
ecc267fe
RC
1/** @file\r
2 This driver parses the mSmbiosMiscDataTable structure and reports\r
3 any generated data using SMBIOS protocol.\r
4\r
5 Based on files under Nt32Pkg/MiscSubClassPlatformDxe/\r
6\r
7 Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>\r
8 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
9 Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>\r
10 Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>\r
11 SPDX-License-Identifier: BSD-2-Clause-Patent\r
12\r
13**/\r
14\r
15#include <Library/BaseLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/HiiLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20#include <Library/UefiBootServicesTableLib.h>\r
21\r
22#include "SmbiosMisc.h"\r
23\r
ecc267fe
RC
24STATIC EFI_HANDLE mSmbiosMiscImageHandle;\r
25STATIC EFI_SMBIOS_PROTOCOL *mSmbiosMiscSmbios = NULL;\r
26\r
429309e0 27EFI_HII_HANDLE mSmbiosMiscHiiHandle;\r
ecc267fe
RC
28\r
29/**\r
30 Standard EFI driver point. This driver parses the mSmbiosMiscDataTable\r
31 structure and reports any generated data using SMBIOS protocol.\r
32\r
33 @param ImageHandle Handle for the image of this driver\r
34 @param SystemTable Pointer to the EFI System Table\r
35\r
36 @retval EFI_SUCCESS The data was successfully stored.\r
37\r
38**/\r
39EFI_STATUS\r
40EFIAPI\r
429309e0
MK
41SmbiosMiscEntryPoint (\r
42 IN EFI_HANDLE ImageHandle,\r
43 IN EFI_SYSTEM_TABLE *SystemTable\r
ecc267fe
RC
44 )\r
45{\r
429309e0
MK
46 UINTN Index;\r
47 EFI_STATUS EfiStatus;\r
ecc267fe
RC
48\r
49 mSmbiosMiscImageHandle = ImageHandle;\r
50\r
429309e0
MK
51 EfiStatus = gBS->LocateProtocol (\r
52 &gEfiSmbiosProtocolGuid,\r
53 NULL,\r
54 (VOID **)&mSmbiosMiscSmbios\r
55 );\r
ecc267fe
RC
56 if (EFI_ERROR (EfiStatus)) {\r
57 DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol. %r\n", EfiStatus));\r
58 return EfiStatus;\r
59 }\r
60\r
429309e0
MK
61 mSmbiosMiscHiiHandle = HiiAddPackages (\r
62 &gEfiCallerIdGuid,\r
63 mSmbiosMiscImageHandle,\r
64 SmbiosMiscDxeStrings,\r
65 NULL\r
66 );\r
ecc267fe
RC
67 if (mSmbiosMiscHiiHandle == NULL) {\r
68 return EFI_OUT_OF_RESOURCES;\r
69 }\r
70\r
71 for (Index = 0; Index < mSmbiosMiscDataTableEntries; ++Index) {\r
72 //\r
73 // If the entry have a function pointer, just log the data.\r
74 //\r
75 if (mSmbiosMiscDataTable[Index].Function != NULL) {\r
429309e0
MK
76 EfiStatus = (*mSmbiosMiscDataTable[Index].Function)(\r
77 mSmbiosMiscDataTable[Index].RecordData,\r
78 mSmbiosMiscSmbios\r
79 );\r
80\r
81 if (EFI_ERROR (EfiStatus)) {\r
82 DEBUG ((\r
83 DEBUG_ERROR,\r
84 "Misc smbios store error. Index=%d,"\r
85 "ReturnStatus=%r\n",\r
86 Index,\r
87 EfiStatus\r
88 ));\r
ecc267fe
RC
89 return EfiStatus;\r
90 }\r
91 }\r
92 }\r
93\r
94 return EfiStatus;\r
95}\r
96\r
ecc267fe
RC
97/**\r
98 Adds an SMBIOS record.\r
99\r
100 @param Buffer The data for the SMBIOS record.\r
101 The format of the record is determined by\r
102 EFI_SMBIOS_TABLE_HEADER.Type. The size of the\r
103 formatted area is defined by EFI_SMBIOS_TABLE_HEADER.Length\r
104 and either followed by a double-null (0x0000) or a set\r
105 of null terminated strings and a null.\r
106 @param SmbiosHandle A unique handle will be assigned to the SMBIOS record\r
107 if not NULL.\r
108\r
109 @retval EFI_SUCCESS Record was added.\r
110 @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system resources.\r
111 @retval EFI_ALREADY_STARTED The SmbiosHandle passed in was already in use.\r
112\r
113**/\r
114EFI_STATUS\r
115SmbiosMiscAddRecord (\r
116 IN UINT8 *Buffer,\r
117 IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle OPTIONAL\r
118 )\r
119{\r
120 EFI_STATUS Status;\r
121 EFI_SMBIOS_HANDLE Handle;\r
122\r
123 Handle = SMBIOS_HANDLE_PI_RESERVED;\r
124\r
125 if (SmbiosHandle != NULL) {\r
126 Handle = *SmbiosHandle;\r
127 }\r
128\r
129 Status = mSmbiosMiscSmbios->Add (\r
429309e0
MK
130 mSmbiosMiscSmbios,\r
131 NULL,\r
132 &Handle,\r
133 (EFI_SMBIOS_TABLE_HEADER *)Buffer\r
134 );\r
ecc267fe
RC
135\r
136 if (SmbiosHandle != NULL) {\r
137 *SmbiosHandle = Handle;\r
138 }\r
139\r
140 return Status;\r
141}\r
142\r
ecc267fe
RC
143/** Fetches the number of handles of the specified SMBIOS type.\r
144 *\r
145 * @param SmbiosType The type of SMBIOS record to look for.\r
146 *\r
147 * @return The number of handles\r
148 *\r
149**/\r
150STATIC\r
151UINTN\r
152GetHandleCount (\r
429309e0 153 IN UINT8 SmbiosType\r
ecc267fe
RC
154 )\r
155{\r
156 UINTN HandleCount;\r
157 EFI_STATUS Status;\r
158 EFI_SMBIOS_HANDLE SmbiosHandle;\r
159 EFI_SMBIOS_TABLE_HEADER *Record;\r
160\r
161 HandleCount = 0;\r
162\r
163 // Iterate through entries to get the number\r
164 do {\r
429309e0
MK
165 Status = mSmbiosMiscSmbios->GetNext (\r
166 mSmbiosMiscSmbios,\r
167 &SmbiosHandle,\r
168 &SmbiosType,\r
169 &Record,\r
170 NULL\r
171 );\r
ecc267fe
RC
172\r
173 if (Status == EFI_SUCCESS) {\r
174 HandleCount++;\r
175 }\r
176 } while (!EFI_ERROR (Status));\r
177\r
178 return HandleCount;\r
179}\r
180\r
181/**\r
182 Fetches a list of the specified SMBIOS table types.\r
183\r
184 @param[in] SmbiosType The type of table to fetch\r
185 @param[out] **HandleArray The array of handles\r
186 @param[out] *HandleCount Number of handles in the array\r
187**/\r
188VOID\r
429309e0
MK
189SmbiosMiscGetLinkTypeHandle (\r
190 IN UINT8 SmbiosType,\r
191 OUT SMBIOS_HANDLE **HandleArray,\r
192 OUT UINTN *HandleCount\r
ecc267fe
RC
193 )\r
194{\r
195 UINTN Index;\r
196 EFI_STATUS Status;\r
197 EFI_SMBIOS_HANDLE SmbiosHandle;\r
198 EFI_SMBIOS_TABLE_HEADER *Record;\r
199\r
200 if (mSmbiosMiscSmbios == NULL) {\r
201 return;\r
202 }\r
203\r
204 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
205 *HandleCount = GetHandleCount (SmbiosType);\r
206\r
207 *HandleArray = AllocateZeroPool (sizeof (SMBIOS_HANDLE) * (*HandleCount));\r
208 if (*HandleArray == NULL) {\r
209 DEBUG ((DEBUG_ERROR, "HandleArray allocate memory resource failed.\n"));\r
210 *HandleCount = 0;\r
211 return;\r
212 }\r
213\r
214 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
215\r
216 for (Index = 0; Index < (*HandleCount); Index++) {\r
429309e0
MK
217 Status = mSmbiosMiscSmbios->GetNext (\r
218 mSmbiosMiscSmbios,\r
219 &SmbiosHandle,\r
220 &SmbiosType,\r
221 &Record,\r
222 NULL\r
223 );\r
ecc267fe
RC
224\r
225 if (!EFI_ERROR (Status)) {\r
226 (*HandleArray)[Index] = Record->Handle;\r
227 } else {\r
228 break;\r
229 }\r
230 }\r
231}\r