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