]> git.proxmox.com Git - mirror_edk2.git/blame - RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c
RedfishPkg: Use DSC include file
[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
27 @retval EFI_SUCESS SMBIOS type 42 record is created.\r
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
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
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
60 DEBUG((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNCTION__, Status));\r
61 return Status;\r
62 }\r
63 if (DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2 &&\r
64 DeviceType != REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2\r
65 ) {\r
66 DEBUG ((DEBUG_ERROR, "%a: Only support either protocol type 04h or 05h as Redfish host interface.", __FUNCTION__));\r
67 return EFI_UNSUPPORTED;\r
68 }\r
69 if (DeviceType == REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) {\r
70 DeviceDataLength = DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV2.Length;\r
71 } else {\r
72 DeviceDataLength = DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.Length;\r
73 }\r
74 //\r
75 // Loop to get platform Redfish host interface protocol type data.\r
76 //\r
77 ProtocolRecord = NULL;\r
78 ProtocolRecords = NULL;\r
79 NewProtocolRecords = NULL;\r
80 Type42Record = NULL;\r
81 ProtocolCount = 0;\r
82 CurrentProtocolsDataLength = 0;\r
83 NewProtocolsDataLength = 0;\r
84 while (TRUE) {\r
85 Status = RedfishPlatformHostInterfaceProtocolData (&ProtocolRecord, ProtocolCount);\r
86 if (Status == EFI_NOT_FOUND) {\r
87 break;\r
88 }\r
89 if (EFI_ERROR(Status)) {\r
90 DEBUG ((DEBUG_ERROR, "%a: Fail to get Redfish host interafce protocol type data.", __FUNCTION__));\r
91 if (ProtocolRecords != NULL) {\r
92 FreePool (ProtocolRecords);\r
93 }\r
94 if (ProtocolRecord != NULL) {\r
95 FreePool (ProtocolRecord);\r
96 }\r
97 return Status;\r
98 }\r
99 ProtocolDataSize = sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - sizeof(ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeDataLen;\r
100 NewProtocolsDataLength += ProtocolDataSize;\r
101 if (ProtocolRecords == NULL) {\r
102 ProtocolRecords = AllocateZeroPool (NewProtocolsDataLength);\r
103 if (ProtocolRecords == NULL) {\r
104 FreePool (ProtocolRecord);\r
105 return EFI_OUT_OF_RESOURCES;\r
106 }\r
107 CopyMem ((VOID *)ProtocolRecords, (VOID *)ProtocolRecord, ProtocolDataSize);\r
108 NewProtocolRecords = ProtocolRecords;\r
109 } else {\r
110 NewProtocolRecords = ReallocatePool(CurrentProtocolsDataLength, NewProtocolsDataLength, (VOID *)ProtocolRecords);\r
111 if (NewProtocolRecords == NULL) {\r
112 DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for Redfish host interface protocol data."));\r
113 FreePool (ProtocolRecords);\r
114 FreePool (ProtocolRecord);\r
115 return EFI_OUT_OF_RESOURCES;\r
116 }\r
117 CopyMem (\r
118 (VOID *)((UINT8 *)NewProtocolRecords + CurrentProtocolsDataLength),\r
119 (VOID *)ProtocolRecord,\r
120 ProtocolDataSize\r
121 );\r
122 }\r
123 FreePool (ProtocolRecord);\r
124 CurrentProtocolsDataLength = NewProtocolsDataLength;\r
125 ProtocolCount ++;\r
126 };\r
127 if (ProtocolCount == 0) {\r
128 goto ON_EXIT;\r
129 }\r
130 //\r
131 // Construct SMBIOS Type 42h for Redfish host inteface.\r
132 //\r
133 // SMBIOS type 42 Record for Redfish Interface\r
134 // 00h Type BYTE 42 Management Controller Host Interface structure indicator\r
135 // 01h Length BYTE Varies Length of the structure, a minimum of 09h\r
136 // 02h Handle WORD Varies\r
137 // 04h Interface Type BYTE Varies Management Controller Interface Type.\r
138 // 05h Interface Specific Data Length (n)\r
139 // 06h Interface Specific data\r
140 // 06h+n number of protocols defined for the host interface (typically 1)\r
141 // 07h+n Include a Protocol Record for each protocol supported.\r
142 //\r
143 Type42Record = (SMBIOS_TABLE_TYPE42 *) AllocateZeroPool (\r
144 sizeof (SMBIOS_TABLE_TYPE42) - 4\r
145 + DeviceDataLength\r
146 + 1 /// For Protocol Record Count\r
147 + CurrentProtocolsDataLength\r
148 + 2 /// Double NULL terminator/\r
149 );\r
150 if (Type42Record == NULL) {\r
151 Status = EFI_OUT_OF_RESOURCES;\r
152 goto ON_EXIT;\r
153 }\r
154\r
155 Type42Record->Hdr.Type = EFI_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE;\r
156 Type42Record->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE42) - 4\r
157 + DeviceDataLength\r
158 + 1\r
159 + CurrentProtocolsDataLength;\r
160 Type42Record->Hdr.Handle = 0;\r
161 Type42Record->InterfaceType = MCHostInterfaceTypeNetworkHostInterface; // Network Host Interface\r
162\r
163 //\r
164 // Fill in InterfaceTypeSpecificDataLength field\r
165 //\r
166 Type42Record->InterfaceTypeSpecificDataLength = DeviceDataLength;\r
167\r
168 //\r
169 // Fill in InterfaceTypeSpecificData field\r
170 //\r
171 CopyMem (Type42Record->InterfaceTypeSpecificData, DeviceDescriptor, DeviceDataLength);\r
172 FreePool (DeviceDescriptor);\r
173 DeviceDescriptor = NULL;\r
174\r
175 //\r
176 // Fill in InterfaceTypeSpecificData Protocol Count field\r
177 //\r
178 *(Type42Record->InterfaceTypeSpecificData + DeviceDataLength) = ProtocolCount;\r
179\r
180 //\r
181 // Fill in Redfish Protocol Data\r
182 //\r
183 CopyMem (\r
184 Type42Record->InterfaceTypeSpecificData + DeviceDataLength + 1,\r
185 NewProtocolRecords,\r
186 CurrentProtocolsDataLength\r
187 );\r
188\r
189 //\r
190 // 5. Add Redfish interface data record to SMBIOS table 42\r
191 //\r
192 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
193 if (EFI_ERROR (Status)) {\r
194 goto ON_EXIT;\r
195 }\r
196\r
197 MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
198 Status = Smbios->Add (\r
199 Smbios,\r
200 NULL,\r
201 &MemArrayMappedAddrSmbiosHandle,\r
202 (EFI_SMBIOS_TABLE_HEADER*) Type42Record\r
203 );\r
204 DEBUG ((DEBUG_INFO, "RedfishPlatformDxe: Smbios->Add() - %r\n", Status));\r
205 if (EFI_ERROR (Status)) {\r
206 goto ON_EXIT;\r
207 }\r
208 Status = EFI_SUCCESS;\r
209\r
210ON_EXIT:\r
211 if (DeviceDescriptor != NULL) {\r
212 FreePool (DeviceDescriptor);\r
213 }\r
214 if (NewProtocolRecords != NULL) {\r
215 FreePool (NewProtocolRecords);\r
216 }\r
217 if (Type42Record != NULL) {\r
218 FreePool (Type42Record);\r
219 }\r
220 return Status;\r
221}\r
222\r
223/**\r
224 Main entry for this driver.\r
225\r
226 @param ImageHandle Image handle this driver.\r
227 @param SystemTable Pointer to SystemTable.\r
228\r
229 @retval EFI_SUCESS This function always complete successfully.\r
230\r
231**/\r
232EFI_STATUS\r
233EFIAPI\r
234RedfishHostInterfaceDxeEntryPoint (\r
235 IN EFI_HANDLE ImageHandle,\r
236 IN EFI_SYSTEM_TABLE *SystemTable\r
237 )\r
238{\r
239 //\r
240 // Create SMBIOS type 42 record.\r
241 //\r
242 return RedfishCreateSmbiosTable42 ();\r
243}\r