VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c@ 99404

最後變更 在這個檔案從99404是 99404,由 vboxsync 提交於 22 月 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 11.0 KB
 
1/** @file
2 RedfishHostInterfaceDxe builds up SMBIOS Type 42h host interface
3 record for Redfish service host interface using EFI MBIOS Protocol.
4 RedfishHostInterfacePlatformLib is the platform-level library which
5 provides the content of Redfish host interface type 42h record.
6
7 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
8 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
9 Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
10 Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
11
12 SPDX-License-Identifier: BSD-2-Clause-Patent
13
14**/
15#include <Uefi.h>
16#include <Library/BaseLib.h>
17#include <Library/BaseMemoryLib.h>
18#include <Library/DebugLib.h>
19#include <Library/MemoryAllocationLib.h>
20#include <Library/PrintLib.h>
21#include <Library/RedfishHostInterfaceLib.h>
22#include <Library/UefiLib.h>
23#include <Library/UefiBootServicesTableLib.h>
24#include <Library/UefiRuntimeServicesTableLib.h>
25
26static EFI_EVENT mPlatformHostInterfaceReadylEvent = NULL;
27static VOID *mPlatformHostInterfaceReadyRegistration = NULL;
28
29/**
30 Create SMBIOS type 42 record for Redfish host interface.
31
32 @retval EFI_SUCCESS SMBIOS type 42 record is created.
33 @retval Others Fail to create SMBIOS 42 record.
34
35**/
36EFI_STATUS
37RedfishCreateSmbiosTable42 (
38 VOID
39 )
40{
41 REDFISH_INTERFACE_DATA *DeviceDescriptor;
42 UINT8 DeviceDataLength;
43 UINT8 DeviceType;
44 EFI_STATUS Status;
45 MC_HOST_INTERFACE_PROTOCOL_RECORD *ProtocolRecord;
46 VOID *ProtocolRecords;
47 VOID *NewProtocolRecords;
48 UINT8 ProtocolCount;
49 UINT8 CurrentProtocolsDataLength;
50 UINT8 NewProtocolsDataLength;
51 UINT8 ProtocolDataSize;
52 SMBIOS_TABLE_TYPE42 *Type42Record;
53 EFI_SMBIOS_PROTOCOL *Smbios;
54 EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;
55
56 //
57 // Get platform Redfish host interface device type descriptor data.
58 //
59 Status = RedfishPlatformHostInterfaceDeviceDescriptor (&DeviceType, &DeviceDescriptor);
60 if (EFI_ERROR (Status)) {
61 if (Status == EFI_NOT_FOUND) {
62 DEBUG ((DEBUG_ERROR, "%a: No Redfish host interface descriptor is provided on this platform.", __FUNCTION__));
63 return EFI_NOT_FOUND;
64 }
65
66 DEBUG ((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNCTION__, Status));
67 return Status;
68 }
69
70 if ((DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) &&
71 (DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2)
72 )
73 {
74 DEBUG ((DEBUG_ERROR, "%a: Only support either protocol type 04h or 05h as Redfish host interface.", __FUNCTION__));
75 return EFI_UNSUPPORTED;
76 }
77
78 if (DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {
79 DeviceDataLength = DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.Length;
80 } else {
81 DeviceDataLength = DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.Length;
82 }
83
84 //
85 // Loop to get platform Redfish host interface protocol type data.
86 //
87 ProtocolRecord = NULL;
88 ProtocolRecords = NULL;
89 NewProtocolRecords = NULL;
90 Type42Record = NULL;
91 ProtocolCount = 0;
92 CurrentProtocolsDataLength = 0;
93 NewProtocolsDataLength = 0;
94 while (TRUE) {
95 Status = RedfishPlatformHostInterfaceProtocolData (&ProtocolRecord, ProtocolCount);
96 if (Status == EFI_NOT_FOUND) {
97 break;
98 }
99
100 if (EFI_ERROR (Status)) {
101 DEBUG ((DEBUG_ERROR, "%a: Fail to get Redfish host interafce protocol type data.", __FUNCTION__));
102 if (ProtocolRecords != NULL) {
103 FreePool (ProtocolRecords);
104 }
105
106 if (ProtocolRecord != NULL) {
107 FreePool (ProtocolRecord);
108 }
109
110 return Status;
111 }
112
113 ProtocolDataSize = sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - sizeof (ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeDataLen;
114 NewProtocolsDataLength += ProtocolDataSize;
115 if (ProtocolRecords == NULL) {
116 ProtocolRecords = AllocateZeroPool (NewProtocolsDataLength);
117 if (ProtocolRecords == NULL) {
118 FreePool (ProtocolRecord);
119 return EFI_OUT_OF_RESOURCES;
120 }
121
122 CopyMem ((VOID *)ProtocolRecords, (VOID *)ProtocolRecord, ProtocolDataSize);
123 NewProtocolRecords = ProtocolRecords;
124 } else {
125 NewProtocolRecords = ReallocatePool (CurrentProtocolsDataLength, NewProtocolsDataLength, (VOID *)ProtocolRecords);
126 if (NewProtocolRecords == NULL) {
127 DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for Redfish host interface protocol data.", __FUNCTION__));
128 FreePool (ProtocolRecords);
129 FreePool (ProtocolRecord);
130 return EFI_OUT_OF_RESOURCES;
131 }
132
133 CopyMem (
134 (VOID *)((UINT8 *)NewProtocolRecords + CurrentProtocolsDataLength),
135 (VOID *)ProtocolRecord,
136 ProtocolDataSize
137 );
138 }
139
140 FreePool (ProtocolRecord);
141 CurrentProtocolsDataLength = NewProtocolsDataLength;
142 ProtocolCount++;
143 }
144
145 if (ProtocolCount == 0) {
146 goto ON_EXIT;
147 }
148
149 //
150 // Construct SMBIOS Type 42h for Redfish host inteface.
151 //
152 // SMBIOS type 42 Record for Redfish Interface
153 // 00h Type BYTE 42 Management Controller Host Interface structure indicator
154 // 01h Length BYTE Varies Length of the structure, a minimum of 09h
155 // 02h Handle WORD Varies
156 // 04h Interface Type BYTE Varies Management Controller Interface Type.
157 // 05h Interface Specific Data Length (n)
158 // 06h Interface Specific data
159 // 06h+n number of protocols defined for the host interface (typically 1)
160 // 07h+n Include a Protocol Record for each protocol supported.
161 //
162 Type42Record = (SMBIOS_TABLE_TYPE42 *)AllocateZeroPool (
163 sizeof (SMBIOS_TABLE_TYPE42) - 4
164 + DeviceDataLength
165 + 1 /// For Protocol Record Count
166 + CurrentProtocolsDataLength
167 + 2 /// Double NULL terminator/
168 );
169 if (Type42Record == NULL) {
170 Status = EFI_OUT_OF_RESOURCES;
171 goto ON_EXIT;
172 }
173
174 Type42Record->Hdr.Type = EFI_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE;
175 Type42Record->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE42) - 4
176 + DeviceDataLength
177 + 1
178 + CurrentProtocolsDataLength;
179 Type42Record->Hdr.Handle = 0;
180 Type42Record->InterfaceType = MCHostInterfaceTypeNetworkHostInterface; // Network Host Interface
181
182 //
183 // Fill in InterfaceTypeSpecificDataLength field
184 //
185 Type42Record->InterfaceTypeSpecificDataLength = DeviceDataLength;
186
187 //
188 // Fill in InterfaceTypeSpecificData field
189 //
190 CopyMem (Type42Record->InterfaceTypeSpecificData, DeviceDescriptor, DeviceDataLength);
191 FreePool (DeviceDescriptor);
192 DeviceDescriptor = NULL;
193
194 //
195 // Fill in InterfaceTypeSpecificData Protocol Count field
196 //
197 *(Type42Record->InterfaceTypeSpecificData + DeviceDataLength) = ProtocolCount;
198
199 //
200 // Fill in Redfish Protocol Data
201 //
202 CopyMem (
203 Type42Record->InterfaceTypeSpecificData + DeviceDataLength + 1,
204 NewProtocolRecords,
205 CurrentProtocolsDataLength
206 );
207
208 //
209 // 5. Add Redfish interface data record to SMBIOS table 42
210 //
211 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);
212 if (EFI_ERROR (Status)) {
213 goto ON_EXIT;
214 }
215
216 MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
217 Status = Smbios->Add (
218 Smbios,
219 NULL,
220 &MemArrayMappedAddrSmbiosHandle,
221 (EFI_SMBIOS_TABLE_HEADER *)Type42Record
222 );
223 DEBUG ((DEBUG_INFO, "RedfishPlatformDxe: Smbios->Add() - %r\n", Status));
224 if (EFI_ERROR (Status)) {
225 goto ON_EXIT;
226 }
227
228 Status = EFI_SUCCESS;
229
230ON_EXIT:
231 if (DeviceDescriptor != NULL) {
232 FreePool (DeviceDescriptor);
233 }
234
235 if (NewProtocolRecords != NULL) {
236 FreePool (NewProtocolRecords);
237 }
238
239 if (Type42Record != NULL) {
240 FreePool (Type42Record);
241 }
242
243 return Status;
244}
245
246/**
247 Notification event of platform Redfish Host Interface readiness.
248
249 @param[in] Event Event whose notification function is being invoked.
250 @param[in] Context The pointer to the notification function's context,
251 which is implementation-dependent.
252
253**/
254VOID
255EFIAPI
256PlatformHostInterfaceInformationReady (
257 IN EFI_EVENT Event,
258 IN VOID *Context
259 )
260{
261 DEBUG ((DEBUG_INFO, "%a: Platform Redfish Host Interface informtion is ready\n", __FUNCTION__));
262
263 RedfishCreateSmbiosTable42 ();
264
265 //
266 // Close event so we don't create multiple type 42 records
267 //
268 gBS->CloseEvent (Event);
269 mPlatformHostInterfaceReadylEvent = NULL;
270
271 return;
272}
273
274/**
275 Main entry for this driver.
276
277 @param ImageHandle Image handle this driver.
278 @param SystemTable Pointer to SystemTable.
279
280 @retval EFI_SUCCESS This function always complete successfully.
281
282**/
283EFI_STATUS
284EFIAPI
285RedfishHostInterfaceDxeEntryPoint (
286 IN EFI_HANDLE ImageHandle,
287 IN EFI_SYSTEM_TABLE *SystemTable
288 )
289{
290 EFI_STATUS Status;
291 EFI_GUID *ReadyGuid;
292
293 DEBUG ((DEBUG_INFO, "%a: Entry\n.", __FUNCTION__));
294
295 //
296 // Check if the Redfish Host Interface depends on
297 // the specific protocol installation.
298 //
299 Status = RedfishPlatformHostInterfaceNotification (&ReadyGuid);
300 if (Status == EFI_SUCCESS) {
301 DEBUG ((DEBUG_INFO, " Create protocol install notification to know the installation of platform Redfish host interface readiness\n"));
302 DEBUG ((DEBUG_INFO, " Protocol GUID: %g\n", ReadyGuid));
303 //
304 // Register event for ReadyGuid protocol installed by
305 // platform Redfish host interface library.
306 //
307 Status = gBS->CreateEvent (
308 EVT_NOTIFY_SIGNAL,
309 TPL_CALLBACK,
310 PlatformHostInterfaceInformationReady,
311 NULL,
312 &mPlatformHostInterfaceReadylEvent
313 );
314 if (EFI_ERROR (Status)) {
315 DEBUG ((DEBUG_ERROR, " Fail to create event for the installation of platform Redfish host interface readiness.\n"));
316 return Status;
317 }
318
319 Status = gBS->RegisterProtocolNotify (
320 ReadyGuid,
321 mPlatformHostInterfaceReadylEvent,
322 &mPlatformHostInterfaceReadyRegistration
323 );
324 if (EFI_ERROR (Status)) {
325 DEBUG ((DEBUG_ERROR, " Fail to register event for the installation of platform Redfish host interface readiness.\n"));
326 return Status;
327 }
328
329 return EFI_SUCCESS;
330 }
331
332 if ((Status == EFI_UNSUPPORTED) || (Status == EFI_ALREADY_STARTED)) {
333 Status = RedfishCreateSmbiosTable42 ();
334 }
335
336 // Return other erros.
337 return Status;
338}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette