]> git.proxmox.com Git - mirror_edk2.git/blame - RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c
MpInitLib: Move the Above1Mb vector allocation to MpInitLibInitialize
[mirror_edk2.git] / RedfishPkg / RedfishHostInterfaceDxe / RedfishHostInterfaceDxe.c
CommitLineData
d4fae44d
AC
1/** @file\r
2 RedfishHostInterfaceDxe builds up SMBIOS Type 42h host interface\r
3 record for Redfish service host interface using EFI MBIOS Protocol.\r
4 RedfishHostInterfacePlatformLib is the platform-level library which\r
5 provides the content of Redfish host interface type 42h record.\r
6\r
7 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
8 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
9\r
10 SPDX-License-Identifier: BSD-2-Clause-Patent\r
11\r
12**/\r
13#include <Uefi.h>\r
14#include <Library/BaseLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/DebugLib.h>\r
17#include <Library/MemoryAllocationLib.h>\r
18#include <Library/PrintLib.h>\r
19#include <Library/RedfishHostInterfaceLib.h>\r
20#include <Library/UefiLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/UefiRuntimeServicesTableLib.h>\r
23\r
24/**\r
25 Create SMBIOS type 42 record for Redfish host interface.\r
26\r
a7cf2c56 27 @retval EFI_SUCCESS SMBIOS type 42 record is created.\r
d4fae44d
AC
28 @retval Others Fail to create SMBIOS 42 record.\r
29\r
30**/\r
31EFI_STATUS\r
32RedfishCreateSmbiosTable42 (\r
33 VOID\r
34 )\r
35{\r
39de741e
MK
36 REDFISH_INTERFACE_DATA *DeviceDescriptor;\r
37 UINT8 DeviceDataLength;\r
38 UINT8 DeviceType;\r
39 EFI_STATUS Status;\r
40 MC_HOST_INTERFACE_PROTOCOL_RECORD *ProtocolRecord;\r
41 VOID *ProtocolRecords;\r
42 VOID *NewProtocolRecords;\r
43 UINT8 ProtocolCount;\r
44 UINT8 CurrentProtocolsDataLength;\r
45 UINT8 NewProtocolsDataLength;\r
46 UINT8 ProtocolDataSize;\r
47 SMBIOS_TABLE_TYPE42 *Type42Record;\r
48 EFI_SMBIOS_PROTOCOL *Smbios;\r
49 EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;\r
d4fae44d
AC
50\r
51 //\r
52 // Get platform Redfish host interface device type descriptor data.\r
53 //\r
54 Status = RedfishPlatformHostInterfaceDeviceDescriptor (&DeviceType, &DeviceDescriptor);\r
55 if (EFI_ERROR (Status)) {\r
56 if (Status == EFI_NOT_FOUND) {\r
57 DEBUG ((DEBUG_ERROR, "%a: No Redfish host interface descriptor is provided on this platform.", __FUNCTION__));\r
58 return EFI_NOT_FOUND;\r
59 }\r
39de741e
MK
60\r
61 DEBUG ((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNCTION__, Status));\r
d4fae44d
AC
62 return Status;\r
63 }\r
39de741e
MK
64\r
65 if ((DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2) &&\r
66 (DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2)\r
67 )\r
68 {\r
d4fae44d
AC
69 DEBUG ((DEBUG_ERROR, "%a: Only support either protocol type 04h or 05h as Redfish host interface.", __FUNCTION__));\r
70 return EFI_UNSUPPORTED;\r
71 }\r
39de741e 72\r
d4fae44d
AC
73 if (DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {\r
74 DeviceDataLength = DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.Length;\r
75 } else {\r
76 DeviceDataLength = DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.Length;\r
77 }\r
39de741e 78\r
d4fae44d
AC
79 //\r
80 // Loop to get platform Redfish host interface protocol type data.\r
81 //\r
39de741e
MK
82 ProtocolRecord = NULL;\r
83 ProtocolRecords = NULL;\r
84 NewProtocolRecords = NULL;\r
85 Type42Record = NULL;\r
86 ProtocolCount = 0;\r
d4fae44d 87 CurrentProtocolsDataLength = 0;\r
39de741e 88 NewProtocolsDataLength = 0;\r
d4fae44d
AC
89 while (TRUE) {\r
90 Status = RedfishPlatformHostInterfaceProtocolData (&ProtocolRecord, ProtocolCount);\r
91 if (Status == EFI_NOT_FOUND) {\r
92 break;\r
93 }\r
39de741e
MK
94\r
95 if (EFI_ERROR (Status)) {\r
d4fae44d
AC
96 DEBUG ((DEBUG_ERROR, "%a: Fail to get Redfish host interafce protocol type data.", __FUNCTION__));\r
97 if (ProtocolRecords != NULL) {\r
98 FreePool (ProtocolRecords);\r
99 }\r
39de741e 100\r
d4fae44d
AC
101 if (ProtocolRecord != NULL) {\r
102 FreePool (ProtocolRecord);\r
103 }\r
39de741e 104\r
d4fae44d
AC
105 return Status;\r
106 }\r
39de741e
MK
107\r
108 ProtocolDataSize = sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - sizeof (ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeDataLen;\r
d4fae44d
AC
109 NewProtocolsDataLength += ProtocolDataSize;\r
110 if (ProtocolRecords == NULL) {\r
111 ProtocolRecords = AllocateZeroPool (NewProtocolsDataLength);\r
112 if (ProtocolRecords == NULL) {\r
113 FreePool (ProtocolRecord);\r
114 return EFI_OUT_OF_RESOURCES;\r
115 }\r
39de741e 116\r
d4fae44d
AC
117 CopyMem ((VOID *)ProtocolRecords, (VOID *)ProtocolRecord, ProtocolDataSize);\r
118 NewProtocolRecords = ProtocolRecords;\r
119 } else {\r
39de741e 120 NewProtocolRecords = ReallocatePool (CurrentProtocolsDataLength, NewProtocolsDataLength, (VOID *)ProtocolRecords);\r
d4fae44d
AC
121 if (NewProtocolRecords == NULL) {\r
122 DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for Redfish host interface protocol data."));\r
123 FreePool (ProtocolRecords);\r
124 FreePool (ProtocolRecord);\r
125 return EFI_OUT_OF_RESOURCES;\r
126 }\r
39de741e 127\r
d4fae44d
AC
128 CopyMem (\r
129 (VOID *)((UINT8 *)NewProtocolRecords + CurrentProtocolsDataLength),\r
130 (VOID *)ProtocolRecord,\r
131 ProtocolDataSize\r
132 );\r
133 }\r
39de741e 134\r
d4fae44d
AC
135 FreePool (ProtocolRecord);\r
136 CurrentProtocolsDataLength = NewProtocolsDataLength;\r
39de741e
MK
137 ProtocolCount++;\r
138 }\r
139\r
d4fae44d
AC
140 if (ProtocolCount == 0) {\r
141 goto ON_EXIT;\r
142 }\r
39de741e 143\r
d4fae44d
AC
144 //\r
145 // Construct SMBIOS Type 42h for Redfish host inteface.\r
146 //\r
147 // SMBIOS type 42 Record for Redfish Interface\r
148 // 00h Type BYTE 42 Management Controller Host Interface structure indicator\r
149 // 01h Length BYTE Varies Length of the structure, a minimum of 09h\r
150 // 02h Handle WORD Varies\r
151 // 04h Interface Type BYTE Varies Management Controller Interface Type.\r
152 // 05h Interface Specific Data Length (n)\r
153 // 06h Interface Specific data\r
154 // 06h+n number of protocols defined for the host interface (typically 1)\r
155 // 07h+n Include a Protocol Record for each protocol supported.\r
156 //\r
39de741e
MK
157 Type42Record = (SMBIOS_TABLE_TYPE42 *)AllocateZeroPool (\r
158 sizeof (SMBIOS_TABLE_TYPE42) - 4\r
159 + DeviceDataLength\r
160 + 1 /// For Protocol Record Count\r
161 + CurrentProtocolsDataLength\r
162 + 2 /// Double NULL terminator/\r
163 );\r
d4fae44d
AC
164 if (Type42Record == NULL) {\r
165 Status = EFI_OUT_OF_RESOURCES;\r
166 goto ON_EXIT;\r
167 }\r
168\r
169 Type42Record->Hdr.Type = EFI_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE;\r
170 Type42Record->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE42) - 4\r
39de741e
MK
171 + DeviceDataLength\r
172 + 1\r
173 + CurrentProtocolsDataLength;\r
174 Type42Record->Hdr.Handle = 0;\r
d4fae44d
AC
175 Type42Record->InterfaceType = MCHostInterfaceTypeNetworkHostInterface; // Network Host Interface\r
176\r
177 //\r
178 // Fill in InterfaceTypeSpecificDataLength field\r
179 //\r
180 Type42Record->InterfaceTypeSpecificDataLength = DeviceDataLength;\r
181\r
182 //\r
183 // Fill in InterfaceTypeSpecificData field\r
184 //\r
185 CopyMem (Type42Record->InterfaceTypeSpecificData, DeviceDescriptor, DeviceDataLength);\r
186 FreePool (DeviceDescriptor);\r
187 DeviceDescriptor = NULL;\r
188\r
189 //\r
190 // Fill in InterfaceTypeSpecificData Protocol Count field\r
191 //\r
192 *(Type42Record->InterfaceTypeSpecificData + DeviceDataLength) = ProtocolCount;\r
193\r
194 //\r
195 // Fill in Redfish Protocol Data\r
196 //\r
197 CopyMem (\r
198 Type42Record->InterfaceTypeSpecificData + DeviceDataLength + 1,\r
199 NewProtocolRecords,\r
200 CurrentProtocolsDataLength\r
201 );\r
202\r
203 //\r
204 // 5. Add Redfish interface data record to SMBIOS table 42\r
205 //\r
39de741e 206 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);\r
d4fae44d
AC
207 if (EFI_ERROR (Status)) {\r
208 goto ON_EXIT;\r
209 }\r
210\r
211 MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
39de741e
MK
212 Status = Smbios->Add (\r
213 Smbios,\r
214 NULL,\r
215 &MemArrayMappedAddrSmbiosHandle,\r
216 (EFI_SMBIOS_TABLE_HEADER *)Type42Record\r
217 );\r
d4fae44d
AC
218 DEBUG ((DEBUG_INFO, "RedfishPlatformDxe: Smbios->Add() - %r\n", Status));\r
219 if (EFI_ERROR (Status)) {\r
220 goto ON_EXIT;\r
221 }\r
39de741e 222\r
d4fae44d
AC
223 Status = EFI_SUCCESS;\r
224\r
225ON_EXIT:\r
226 if (DeviceDescriptor != NULL) {\r
227 FreePool (DeviceDescriptor);\r
228 }\r
39de741e 229\r
d4fae44d
AC
230 if (NewProtocolRecords != NULL) {\r
231 FreePool (NewProtocolRecords);\r
232 }\r
39de741e 233\r
d4fae44d
AC
234 if (Type42Record != NULL) {\r
235 FreePool (Type42Record);\r
236 }\r
39de741e 237\r
d4fae44d
AC
238 return Status;\r
239}\r
240\r
241/**\r
242 Main entry for this driver.\r
243\r
244 @param ImageHandle Image handle this driver.\r
245 @param SystemTable Pointer to SystemTable.\r
246\r
a7cf2c56 247 @retval EFI_SUCCESS This function always complete successfully.\r
d4fae44d
AC
248\r
249**/\r
250EFI_STATUS\r
251EFIAPI\r
252RedfishHostInterfaceDxeEntryPoint (\r
39de741e
MK
253 IN EFI_HANDLE ImageHandle,\r
254 IN EFI_SYSTEM_TABLE *SystemTable\r
d4fae44d
AC
255 )\r
256{\r
257 //\r
258 // Create SMBIOS type 42 record.\r
259 //\r
260 return RedfishCreateSmbiosTable42 ();\r
261}\r