From nobody Mon Feb 9 13:38:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+91793+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91793+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1658712988; cv=none; d=zohomail.com; s=zohoarc; b=fEieTtTq+bZWiOlwVtudLYmrSP/BKU5XCej+CjfQubmDliToVOUYnVD8qCL/JobZyaWMtrGb1dORudUbcrzyvADusTfX1Qv4z5X8X3O4SCgsH4LQ6j1tCSkyx5YIsYvrGrBcOD1LTVVh3LCjRABH2ZFLy8aZVcuTWA024wpeMF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658712988; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZhA19hEI5IdKJQxio1oYsTPpzHkJOGlgQtHY4IA2SHU=; b=eO3XnYmflG+3eC+pjViS7zvM5b+kCNBdH9vZjm+6ClFnPpM49KMVxLhqStD2wbfBeuZvfCA5I2vfxvqkPpirOPHx+oIL1p0pMFsS6zWdQbb204OJ7E8daupnpMvi6YPFwQZ2m6020W1KGL+hQ6h+4ucGyDsXSv6BxFRch+ZvFTk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91793+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1658712988753120.08674181017614; Sun, 24 Jul 2022 18:36:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kYNoYY1788612xYZlv7yNOgL; Sun, 24 Jul 2022 18:36:28 -0700 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web12.23229.1658712987565887211 for ; Sun, 24 Jul 2022 18:36:27 -0700 X-Received: from pps.filterd (m0134423.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26P1XKcT006689; Mon, 25 Jul 2022 01:36:25 GMT X-Received: from p1lg14880.it.hpe.com (p1lg14880.it.hpe.com [16.230.97.201]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3hhhm3r0u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Jul 2022 01:36:25 +0000 X-Received: from p1lg14886.dc01.its.hpecorp.net (unknown [10.119.18.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14880.it.hpe.com (Postfix) with ESMTPS id 9D3868001B2; Mon, 25 Jul 2022 01:36:24 +0000 (UTC) X-Received: from WAFM3XJD5N.asiapacific.hpqcorp.net (unknown [16.231.227.36]) by p1lg14886.dc01.its.hpecorp.net (Postfix) with ESMTP id 17E1B802CF5; Mon, 25 Jul 2022 01:36:22 +0000 (UTC) From: "Nickle Wang" To: devel@edk2.groups.io Cc: Abner Chang , Yang Atom , Nick Ramirez Subject: [edk2-devel] [edk2-staging][PATCH v2 15/15] edk2-staging/RedfishClientPkg: Introduce Bios feature driver Date: Mon, 25 Jul 2022 09:35:55 +0800 Message-Id: <20220725013555.926-16-nickle.wang@hpe.com> In-Reply-To: <20220725013555.926-1-nickle.wang@hpe.com> References: <20220725013555.926-1-nickle.wang@hpe.com> MIME-Version: 1.0 X-Proofpoint-GUID: 0ggJRhNKRTF-6aqO2bY-k91vwCe8kjWS X-Proofpoint-ORIG-GUID: 0ggJRhNKRTF-6aqO2bY-k91vwCe8kjWS X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nickle.wang@hpe.com X-Gm-Message-State: 8Yk7HFPOTPtA85eVjAEU8ohgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1658712988; bh=Pk102fVPVmgkqPk5dQN3EdPEyYcG9fAHi648wyVnSxQ=; h=Cc:Date:From:Reply-To:Subject:To; b=F7KGtjlJIGqVMmFyhw8oUD60F5hFqJWNmJldQfGKycJM1CzX6FmA3h8lc8Rh5YboO1+ mc0vLYV4lis6blXxdK2+4ca3mntuW2tnT/bqdw4TbaFSBYG2DIWtN4+e92Gso7TT0rhO2 vpV8agoYhPPK3ppBrKowKdFluXy/zCAcb+Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1658712990021100009 Content-Type: text/plain; charset="utf-8" Introduce new feature driver to support Bios version 1.0.9 schema. Update corresponding FDF and DSC file to enable this feature driver. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Yang Atom Cc: Nick Ramirez --- .../Features/Bios/v1_0_9/Common/BiosCommon.c | 741 ++++++++++++++++ .../Features/Bios/v1_0_9/Common/BiosCommon.h | 30 + .../Features/Bios/v1_0_9/Dxe/BiosDxe.c | 789 ++++++++++++++++++ .../Features/Bios/v1_0_9/Dxe/BiosDxe.inf | 52 ++ RedfishClientPkg/RedfishClient.fdf.inc | 2 + .../RedfishClientComponents.dsc.inc | 2 + RedfishClientPkg/RedfishClientLibs.dsc.inc | 6 +- 7 files changed, 1621 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon= .c create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon= .h create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c create mode 100644 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c b/Re= dfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c new file mode 100644 index 0000000000..d910d0d8a9 --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c @@ -0,0 +1,741 @@ +/** @file + Redfish feature driver implementation - common functions + + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "BiosCommon.h" + +CHAR8 BiosEmptyJson[] =3D "{\"@odata.id\": \"\", \"@odata.type\": \"#Bios.= v1_0_9.Bios\", \"Id\": \"\", \"Name\": \"\", \"Attributes\":{}}"; + +REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate =3D NULL; + +/** + Consume resource from given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIV= ATE instance. + @param[in] Json The JSON to consume. + @param[in] HeaderEtag The Etag string returned in HTTP header. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishConsumeResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *Json, + IN CHAR8 *HeaderEtag OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_REDFISH_BIOS_V1_0_9 *Bios; + EFI_REDFISH_BIOS_V1_0_9_CS *BiosCs; + EFI_STRING ConfigureLang; + RedfishCS_Type_EmptyProp_CS_Data *EmptyPropCs; + + + if (Private =3D=3D NULL || IS_EMPTY_STRING (Json)) { + return EFI_INVALID_PARAMETER; + } + + Bios =3D NULL; + BiosCs =3D NULL; + ConfigureLang =3D NULL; + + Status =3D Private->JsonStructProtocol->ToStructure ( + Private->JsonStructProtocol, + NULL, + Json, + (EFI_REST_JSON_STRUCTURE_HEADER = **)&Bios + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n", __FUNCTION__, S= tatus)); + return Status; + } + + BiosCs =3D Bios->Bios; + + // + // Check ETAG to see if we need to consume it + // + if (CheckEtag (Private->Uri, HeaderEtag, BiosCs->odata_etag)) { + // + // No change + // + DEBUG ((DEBUG_INFO, "%a, ETAG: %s has no change, ignore consume action= \n", __FUNCTION__, Private->Uri)); + Status =3D EFI_ALREADY_STARTED; + goto ON_RELEASE; + } + + // + // Handle ATTRIBUTEREGISTRY + // + if (BiosCs->AttributeRegistry !=3D NULL) { + // + // Find corresponding configure language for collection resource. + // + ConfigureLang =3D GetConfigureLang (BiosCs->odata_id, "AttributeRegist= ry"); + if (ConfigureLang !=3D NULL) { + Status =3D ApplyFeatureSettingsStringType (RESOURCE_SCHEMA, RESOURCE= _SCHEMA_VERSION, ConfigureLang, BiosCs->AttributeRegistry); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, apply setting for %s failed: %r\n", __FU= NCTION__, ConfigureLang, Status)); + } + + FreePool (ConfigureLang); + } else { + DEBUG ((DEBUG_ERROR, "%a, can not get configure language for URI: %s= \n", __FUNCTION__, Private->Uri)); + } + } + + // + // Handle ATTRIBUTES + // + if (BiosCs->Attributes =3D=3D NULL) { + BiosCs->Attributes =3D AllocateZeroPool (sizeof (RedfishBios_V1_0_9_At= tributes_CS)); + ASSERT (BiosCs->Attributes !=3D NULL); + } + + // + // Handle ATTRIBUTES->EmptyProperty + // + if (BiosCs->Attributes !=3D NULL) { + // + // Validate empty property. + // + if (BiosCs->Attributes->Prop.ForwardLink =3D=3D &BiosCs->Attributes->P= rop) { + goto ON_RELEASE; + } + EmptyPropCs =3D (RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes= ->Prop.ForwardLink; + if (EmptyPropCs->Header.ResourceType =3D=3D RedfishCS_Type_JSON) { + DEBUG ((DEBUG_ERROR, "%a, Empty property with RedfishCS_Type_JSON ty= pe resource is not supported yet. (%s)\n", __FUNCTION__, Private->Uri)); + goto ON_RELEASE; + } + // + // Find corresponding configure language for collection resource. + // + ConfigureLang =3D GetConfigureLang (BiosCs->odata_id, "Attributes"); + if (ConfigureLang !=3D NULL) { + Status =3D ApplyFeatureSettingsVagueType (RESOURCE_SCHEMA, RESOURCE_= SCHEMA_VERSION, ConfigureLang, EmptyPropCs->KeyValuePtr, EmptyPropCs->NunmO= fProperties); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, apply setting for %s failed: %r\n", __FU= NCTION__, ConfigureLang, Status)); + } + + FreePool (ConfigureLang); + } else { + DEBUG ((DEBUG_ERROR, "%a, can not get configure language for URI: %s= \n", __FUNCTION__, Private->Uri)); + } + } + + +ON_RELEASE: + + // + // Release resource. + // + Private->JsonStructProtocol->DestoryStructure ( + Private->JsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)Bios + ); + + return EFI_SUCCESS; +} + +EFI_STATUS +ProvisioningBiosProperties ( + IN EFI_REST_JSON_STRUCTURE_PROTOCOL *JsonStructProtocol, + IN CHAR8 *InputJson, + IN CHAR8 *ResourceId, OPTIONAL + IN EFI_STRING ConfigureLang, + IN BOOLEAN ProvisionMode, + OUT CHAR8 **ResultJson + ) +{ + EFI_REDFISH_BIOS_V1_0_9 *Bios; + EFI_REDFISH_BIOS_V1_0_9_CS *BiosCs; + EFI_STATUS Status; + BOOLEAN PropertyChanged; + CHAR8 *AsciiStringValue; + RedfishCS_EmptyProp_KeyValue *PropertyVagueValues; + UINT32 VagueValueNumber; + + + + if (JsonStructProtocol =3D=3D NULL || ResultJson =3D=3D NULL || IS_EMPTY= _STRING (InputJson) || IS_EMPTY_STRING (ConfigureLang)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a provision for %s with: %s\n", __FUNCTIO= N__, ConfigureLang, (ProvisionMode ? L"Provision resource" : L"Update resou= rce"))); + + *ResultJson =3D NULL; + PropertyChanged =3D FALSE; + + Bios =3D NULL; + Status =3D JsonStructProtocol->ToStructure ( + JsonStructProtocol, + NULL, + InputJson, + (EFI_REST_JSON_STRUCTURE_HEADER **)&Bios + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToStructure failure: %r\n", __FUNCTION__, St= atus)); + return Status; + } + + BiosCs =3D Bios->Bios; + + // + // ID + // + if (BiosCs->Id =3D=3D NULL && !IS_EMPTY_STRING (ResourceId)) { + BiosCs->Id =3D AllocateCopyPool (AsciiStrSize (ResourceId), ResourceId= ); + } + + // + // Handle ATTRIBUTEREGISTRY + // + if (PropertyChecker (BiosCs->AttributeRegistry, ProvisionMode)) { + AsciiStringValue =3D GetPropertyStringValue (RESOURCE_SCHEMA, RESOURCE= _SCHEMA_VERSION, L"AttributeRegistry", ConfigureLang); + if (AsciiStringValue !=3D NULL) { + if (ProvisionMode || AsciiStrCmp (BiosCs->AttributeRegistry, AsciiSt= ringValue) !=3D 0) { + BiosCs->AttributeRegistry =3D AsciiStringValue; + PropertyChanged =3D TRUE; + } + } + } + // + // Handle ATTRIBUTES + // + if (BiosCs->Attributes !=3D NULL) { + // + // Handle ATTRIBUTES + // + if (PropertyChecker (BiosCs->Attributes, ProvisionMode)) { + PropertyVagueValues =3D GetPropertyVagueValue (RESOURCE_SCHEMA, RESO= URCE_SCHEMA_VERSION, L"Attributes", ConfigureLang, &VagueValueNumber); + if (PropertyVagueValues !=3D NULL) { + if (ProvisionMode || !CompareRedfishPropertyVagueValues ( + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs= ->Attributes->Prop.ForwardLink)->KeyValuePtr, + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs= ->Attributes->Prop.ForwardLink)->NunmOfProperties, + PropertyVagueValues, + VagueValueNumber)) { + // + // Use the properties on system to replace the one on Redfish se= rvice. + // + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.Fo= rwardLink)->KeyValuePtr =3D PropertyVagueValues; + ((RedfishCS_Type_EmptyProp_CS_Data *)BiosCs->Attributes->Prop.Fo= rwardLink)->NunmOfProperties =3D VagueValueNumber; + PropertyChanged =3D TRUE; + } + } + } + } + + + // + // Convert C structure back to JSON text. + // + Status =3D JsonStructProtocol->ToJson ( + JsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)Bios, + ResultJson + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, ToJson() failed: %r\n", __FUNCTION__, Status= )); + return Status; + } + + // + // Release resource. + // + JsonStructProtocol->DestoryStructure ( + JsonStructProtocol, + (EFI_REST_JSON_STRUCTURE_HEADER *)Bios + ); + + return (PropertyChanged ? EFI_SUCCESS : EFI_NOT_FOUND); +} + +EFI_STATUS +ProvisioningBiosResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN UINTN Index, + IN EFI_STRING ConfigureLang + ) +{ + CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING NewResourceLocation; + CHAR8 *EtagStr; + CHAR8 ResourceId[16]; + + if (IS_EMPTY_STRING (ConfigureLang) || Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + EtagStr =3D NULL; + AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index); + + Status =3D ProvisioningBiosProperties ( + Private->JsonStructProtocol, + BiosEmptyJson, + ResourceId, + ConfigureLang, + TRUE, + &Json + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, provisioning resource for %s failed: %r\n", = __FUNCTION__, ConfigureLang, Status)); + return Status; + } + + Status =3D CreatePayloadToPostResource (Private->RedfishService, Private= ->Payload, Json, &NewResourceLocation, &EtagStr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n", __F= UNCTION__, ConfigureLang, Status)); + goto RELEASE_RESOURCE; + } + + ASSERT (NewResourceLocation !=3D NULL); + + // + // Keep location of new resource. + // + if (NewResourceLocation !=3D NULL) { + RedfisSetRedfishUri (ConfigureLang, NewResourceLocation); + } + + // + // Handle Etag + // + if (EtagStr !=3D NULL) { + SetEtagWithUri (EtagStr, NewResourceLocation); + FreePool (EtagStr); + } + +RELEASE_RESOURCE: + + if (NewResourceLocation !=3D NULL) { + FreePool (NewResourceLocation); + } + + if (Json !=3D NULL) { + FreePool (Json); + } + + return Status; +} + +EFI_STATUS +ProvisioningBiosResources ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private + ) +{ + UINTN Index; + EFI_STATUS Status; + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST UnifiedConfigureLangList; + + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Status =3D RedfishFeatureGetUnifiedArrayTypeConfigureLang (RESOURCE_SCHE= MA, RESOURCE_SCHEMA_VERSION, REDPATH_ARRAY_PATTERN, &UnifiedConfigureLangLi= st); + if (EFI_ERROR (Status) || UnifiedConfigureLangList.Count =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "%a, No HII question found with configure languag= e: %s: %r\n", __FUNCTION__, REDPATH_ARRAY_PATTERN, Status)); + return EFI_NOT_FOUND; + } + // + // Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE. + // This information is sent back to the parent resource (e.g. the collec= tion driver). + // + EdkIIRedfishResourceSetConfigureLang (&UnifiedConfigureLangList); + + for (Index =3D 0; Index < UnifiedConfigureLangList.Count; Index++) { + DEBUG ((DEBUG_INFO, "[%d] create Bios resource from: %s\n", UnifiedCon= figureLangList.List[Index].Index, UnifiedConfigureLangList.List[Index].Conf= igureLang)); + ProvisioningBiosResource (Private, UnifiedConfigureLangList.List[Index= ].Index, UnifiedConfigureLangList.List[Index].ConfigureLang); + FreePool (UnifiedConfigureLangList.List[Index].ConfigureLang); + } + + return EFI_SUCCESS; +} + + +EFI_STATUS +ProvisioningBiosExistResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private + ) +{ + EFI_STATUS Status; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + CHAR8 *Json; + + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + EtagStr =3D NULL; + Json =3D NULL; + ConfigureLang =3D NULL; + + ConfigureLang =3D RedfishGetConfigLanguage (Private->Uri); + if (ConfigureLang =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + Status =3D ProvisioningBiosProperties ( + Private->JsonStructProtocol, + BiosEmptyJson, + NULL, + ConfigureLang, + TRUE, + &Json + ); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_NOT_FOUND) { + DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for= %s ignored. Nothing changed\n", __FUNCTION__, ConfigureLang)); + } else { + DEBUG ((DEBUG_ERROR, "%a, provisioning existing resource for %s fail= ed: %r\n", __FUNCTION__, ConfigureLang, Status)); + } + goto ON_RELEASE; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\= n", __FUNCTION__, ConfigureLang)); + // + // PUT back to instance + // + Status =3D CreatePayloadToPatchResource (Private->RedfishService, Privat= e->Payload, Json, &EtagStr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __FUNCT= ION__, ConfigureLang, Status)); + } + + // + // Handle Etag + // + if (EtagStr !=3D NULL) { + SetEtagWithUri (EtagStr, Private->Uri); + FreePool (EtagStr); + } + +ON_RELEASE: + + if (Json !=3D NULL) { + FreePool (Json); + } + + if (ConfigureLang !=3D NULL) { + FreePool (ConfigureLang); + } + + return Status; +} + +/** + Provisioning redfish resource by given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL = instance. + @param[in] ResourceExist TRUE if resource exists, PUT method wil= l be used. + FALSE if resource does not exist POST m= ethod is used. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishProvisioningResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN BOOLEAN ResourceExist + ) +{ + if (Private =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + return (ResourceExist ? ProvisioningBiosExistResource (Private) : Provis= ioningBiosResources (Private)); +} + +/** + Check resource from given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIV= ATE instance. + @param[in] Json The JSON to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishCheckResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *Json + ) +{ + UINTN Index; + EFI_STATUS Status; + EFI_STRING *ConfigureLangList; + UINTN Count; + EFI_STRING Property; + + if (Private =3D=3D NULL || IS_EMPTY_STRING (Json)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D RedfishPlatformConfigGetConfigureLang (RESOURCE_SCHEMA, RESOU= RCE_SCHEMA_VERSION, REDPATH_ARRAY_PATTERN, &ConfigureLangList, &Count); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, BiosConfigToRedfishGetConfigureLangRegex fai= led: %r\n", __FUNCTION__, Status)); + return Status; + } + + if (Count =3D=3D 0) { + return EFI_NOT_FOUND; + } + + Status =3D EFI_SUCCESS; + for (Index =3D 0; Index < Count; Index++) { + + Property =3D GetPropertyFromConfigureLang (Private->Uri, ConfigureLang= List[Index]); + if (Property =3D=3D NULL) { + continue; + } + + DEBUG ((DEBUG_INFO, "%a, [%d] check attribute for: %s\n", __FUNCTION__= , Index, Property)); + if (!MatchPropertyWithJsonContext (Property, Json)) { + DEBUG ((DEBUG_INFO, "%a, property is missing: %s\n", __FUNCTION__, P= roperty)); + Status =3D EFI_NOT_FOUND; + } + } + + FreePool (ConfigureLangList); + + return Status; +} + +/** + Update resource to given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIV= ATE instance. + @param[in] Json The JSON to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishUpdateResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *InputJson + ) +{ + EFI_STATUS Status; + CHAR8 *Json; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + + if (Private =3D=3D NULL || IS_EMPTY_STRING (InputJson)) { + return EFI_INVALID_PARAMETER; + } + + EtagStr =3D NULL; + Json =3D NULL; + ConfigureLang =3D NULL; + + ConfigureLang =3D RedfishGetConfigLanguage (Private->Uri); + if (ConfigureLang =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + Status =3D ProvisioningBiosProperties ( + Private->JsonStructProtocol, + InputJson, + NULL, + ConfigureLang, + FALSE, + &Json + ); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_NOT_FOUND) { + DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s ignored. No= thing changed\n", __FUNCTION__, ConfigureLang)); + } else { + DEBUG ((DEBUG_ERROR, "%a, update resource for %s failed: %r\n", __FU= NCTION__, ConfigureLang, Status)); + } + goto ON_RELEASE; + } + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __FUNCTION_= _, ConfigureLang)); + // + // PUT back to instance + // + Status =3D CreatePayloadToPatchResource (Private->RedfishService, Privat= e->Payload, Json, &EtagStr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __FUNCT= ION__, ConfigureLang, Status)); + } + + // + // Handle Etag + // + if (EtagStr !=3D NULL) { + SetEtagWithUri (EtagStr, Private->Uri); + FreePool (EtagStr); + } + +ON_RELEASE: + + if (Json !=3D NULL) { + FreePool (Json); + } + + if (ConfigureLang !=3D NULL) { + FreePool (ConfigureLang); + } + + return Status; +} + +/** + Identify resource from given URI. + + @param[in] This Pointer to REDFISH_RESOURCE_COMMON_PRIV= ATE instance. + @param[in] Json The JSON to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishIdentifyResourceCommon ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN CHAR8 *Json + ) +{ + BOOLEAN Supported; + EFI_STATUS Status; + EFI_STRING EndOfChar; + REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST ConfigLangList; + + Supported =3D RedfishIdentifyResource (Private->Uri, Private->Json); + if (Supported) { + Status =3D RedfishFeatureGetUnifiedArrayTypeConfigureLang (RESOURCE_SC= HEMA, RESOURCE_SCHEMA_VERSION, REDPATH_ARRAY_PATTERN, &ConfigLangList); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, BiosConfigToRedfishGetConfigureLangRegex f= ailed: %r\n", __FUNCTION__, Status)); + return Status; + } + + if (ConfigLangList.Count =3D=3D 0) { + return EFI_SUCCESS; + } + + //EndOfChar =3D StrStr (ConfigLangList.List[0].ConfigureLang, L"}"); + Status =3D IsRedpathArray (ConfigLangList.List[0].ConfigureLang, NULL,= &EndOfChar); + if (EFI_ERROR (Status) && Status !=3D EFI_NOT_FOUND) { + ASSERT (FALSE); + return EFI_DEVICE_ERROR; + } + if (Status !=3D EFI_SUCCESS) { + // + // This is not the collection redpath. + // + GetRedpathNodeByIndex (ConfigLangList.List[0].ConfigureLang, 0, &End= OfChar); + } + *(++EndOfChar) =3D '\0'; + // + // Keep URI and ConfigLang mapping + // + RedfisSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Ur= i); + // + // Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE. + // This information is sent back to the parent resource (e.g. the coll= ection driver). + // + EdkIIRedfishResourceSetConfigureLang (&ConfigLangList); + DestroyConfiglanguageList (&ConfigLangList); + return EFI_SUCCESS; + } + + return EFI_UNSUPPORTED; +} + +EFI_STATUS +HandleResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN EFI_STRING Uri + ) +{ + EFI_STATUS Status; + REDFISH_SCHEMA_INFO SchemaInfo; + EFI_STRING ConfigLang; + + if (Private =3D=3D NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + // + // Resource match + // + + DEBUG ((REDFISH_DEBUG_TRACE, "%a, process resource for: %s\n", __FUNCTIO= N__, Uri)); + + Status =3D GetRedfishSchemaInfo (Private->RedfishService, Private->JsonS= tructProtocol, Uri, &SchemaInfo); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to get schema information from: %s %r= \n", __FUNCTION__, Uri, Status)); + return Status; + } + // + // Check and see if this is target resource that we want to handle. + // Some resource is handled by other provider so we have to make sure th= is first. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%s Identify for %s\n", __FUNCTION__, Uri)); + ConfigLang =3D RedfishGetConfigLanguage (Uri); + if (ConfigLang =3D=3D NULL) { + Status =3D EdkIIRedfishResourceConfigIdentify (&SchemaInfo, Uri, Priva= te->InformationExchange); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_INFO, "%a, \"%s\" is not handled by us\n", __FUNCTIO= N__, Uri)); + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_ERROR, "%a, fail to identify resource: \"%s\": %r\n", = __FUNCTION__, Uri, Status)); + return Status; + } + } else { + DEBUG ((REDFISH_DEBUG_TRACE, "%a, history record found: %s\n", __FUNCT= ION__, ConfigLang)); + FreePool (ConfigLang); + } + + // + // Check and see if target property exist or not even when collection me= meber exists. + // If not, we sill do provision. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __FUNCTION__, Uri)); + Status =3D EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + // + // The target property does not exist, do the provision to create prop= erty. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a provision for %s\n", __FUNCTION__, Ur= i)); + Status =3D EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Uri, = Private->InformationExchange, FALSE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to provision with GET mode: %r\n", = __FUNCTION__, Status)); + } + + return Status; + } + + // + // Consume first. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a consume for %s\n", __FUNCTION__, Uri)); + Status =3D EdkIIRedfishResourceConfigConsume (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to consume resoruce for: %s: %r\n", _= _FUNCTION__, Uri, Status)); + } + + // + // Patch. + // + DEBUG ((REDFISH_DEBUG_TRACE, "%a update for %s\n", __FUNCTION__, Uri)); + Status =3D EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to update resoruce for: %s: %r\n", __= FUNCTION__, Uri, Status)); + } + + return Status; +} diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h b/Re= dfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h new file mode 100644 index 0000000000..321ded7637 --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.h @@ -0,0 +1,30 @@ +/** @file + + Redfish feature driver implementation - internal header file + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EFI_REDFISH_BIOS_COMMON_H_ +#define EFI_REDFISH_BIOS_COMMON_H_ + +#include +#include + +// +// Schema information. +// +#define REDFISH_MANAGED_URI L"Systems/{}/Bios" +#define MAX_URI_LENGTH 256 +#define RESOURCE_SCHEMA "Bios" +#define RESOURCE_SCHEMA_MAJOR "1" +#define RESOURCE_SCHEMA_MINOR "0" +#define RESOURCE_SCHEMA_ERRATA "9" +#define RESOURCE_SCHEMA_VERSION "v1_0_9" +#define REDPATH_ARRAY_PATTERN L"/Bios/.*" +#define REDPATH_ARRAY_PREFIX L"/Bios/" +#define RESOURCE_SCHEMA_FULL "x-uefi-redfish-Bios.v1_0_9" +#define REDFISH_SCHEMA_NAME "ComputerSystem" + +#endif diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishC= lientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c new file mode 100644 index 0000000000..a478061cde --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -0,0 +1,789 @@ +/** @file + Redfish feature driver implementation - Bios + + (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "../Common/BiosCommon.h" + +extern REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate; + +EFI_STATUS +HandleResource ( + IN REDFISH_RESOURCE_COMMON_PRIVATE *Private, + IN EFI_STRING Uri + ); + +EFI_HANDLE medfishResourceConfigProtocolHandle; + +/** + Provising redfish resource by given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL = instance. + @param[in] Uri Target URI to create resource. + @param[in] PostMode TRUE if the resource does not exist, po= st method is used. + FALSE if the resource exist but propert= y is missing, put method is used. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceProvisioningResource ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri, + IN BOOLEAN PostMode + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This =3D=3D NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + DEBUG ((DEBUG_INFO, "%a, provisioning in %s mode\n", __FUNCTION__, (Post= Mode ? L"POST" : L"PATCH"))); + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL = (This); + + if (Private->RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + Status =3D GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION_= _, Uri)); + return Status; + } + + Private->Uri =3D Uri; + Private->Payload =3D Response.Payload; + ASSERT (Private->Payload !=3D NULL); + + Status =3D RedfishProvisioningResourceCommon (Private, !PostMode); + + // + // Release resource + // + if (Private->Payload !=3D NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload =3D NULL; + } + + return Status; +} + +/** + Consume resource from given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL = instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceConsumeResource ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + CHAR8 *Etag; + + if (This =3D=3D NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL = (This); + + if (Private->RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + Status =3D GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION_= _, Uri)); + return Status; + } + + Private->Uri =3D Uri; + Private->Payload =3D Response.Payload; + ASSERT (Private->Payload !=3D NULL); + + Private->Json =3D JsonDumpString (RedfishJsonInPayload (Private->Payload= ), EDKII_JSON_COMPACT); + ASSERT (Private->Json !=3D NULL); + + // + // Find etag in HTTP response header + // + Etag =3D NULL; + Status =3D GetEtagAndLocation (&Response, &Etag, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __FU= NCTION__)); + } + + Status =3D RedfishConsumeResourceCommon (Private, Private->Json, Etag); + if (EFI_ERROR (Status)) { + if (Status !=3D EFI_ALREADY_STARTED) { + DEBUG ((DEBUG_ERROR, "%a, failed to consume resource from: %s: %r\n"= , __FUNCTION__, Uri, Status)); + } + } else { + // + // Keep etag after consuming pending settings. + // + if (Etag !=3D NULL) { + SetEtagWithUri (Etag, Private->Uri); + } + } + + // + // Release resource + // + if (Private->Payload !=3D NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload =3D NULL; + } + + if (Private->Json !=3D NULL) { + FreePool (Private->Json); + Private->Json =3D NULL; + } + + return Status; +} + +/** + Get information about this protocol. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL = instance. + @param[out] Schema Supported schema. + @param[out] Major Supported major number. + @param[out] Minor Supported minor number. + @param[out] Errata Supported errata number. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceGetInfo ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + OUT REDFISH_SCHEMA_INFO *Info + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + + if (This =3D=3D NULL || Info =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL = (This); + + AsciiStrCpyS (Info->Schema, REDFISH_SCHEMA_STRING_SIZE, RESOURCE_SCHEMA); + AsciiStrCpyS (Info->Major, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_= MAJOR); + AsciiStrCpyS (Info->Minor, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA_= MINOR); + AsciiStrCpyS (Info->Errata, REDFISH_SCHEMA_VERSION_SIZE, RESOURCE_SCHEMA= _ERRATA); + + return EFI_SUCCESS; +} + +/** + Update resource to given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL = instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceUpdate ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This =3D=3D NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL = (This); + + if (Private->RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + Status =3D GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION_= _, Uri)); + return Status; + } + + Private->Uri =3D Uri; + Private->Payload =3D Response.Payload; + ASSERT (Private->Payload !=3D NULL); + + Private->Json =3D JsonDumpString (RedfishJsonInPayload (Private->Payload= ), EDKII_JSON_COMPACT); + ASSERT (Private->Json !=3D NULL); + + Status =3D RedfishUpdateResourceCommon (Private, Private->Json); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to update resource from: %s: %r\n", _= _FUNCTION__, Uri, Status)); + } + + // + // Release resource + // + if (Private->Payload !=3D NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload =3D NULL; + } + + if (Private->Json !=3D NULL) { + FreePool (Private->Json); + Private->Json =3D NULL; + } + + return Status; +} + +/** + Check resource on given URI. + + @param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL = instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS Value is returned successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishResourceCheck ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This =3D=3D NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL = (This); + + if (Private->RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + Status =3D GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION_= _, Uri)); + return Status; + } + + Private->Uri =3D Uri; + Private->Payload =3D Response.Payload; + ASSERT (Private->Payload !=3D NULL); + + Private->Json =3D JsonDumpString (RedfishJsonInPayload (Private->Payload= ), EDKII_JSON_COMPACT); + ASSERT (Private->Json !=3D NULL); + + Status =3D RedfishCheckResourceCommon (Private, Private->Json); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __= FUNCTION__, Uri, Status)); + } + + // + // Release resource + // + if (Private->Payload !=3D NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload =3D NULL; + } + + if (Private->Json !=3D NULL) { + FreePool (Private->Json); + Private->Json =3D NULL; + } + + return Status; +} + +/** + Identify resource on given URI. + + @param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFI= G_PROTOCOL instance. + @param[in] Uri The target URI to consume. + + @retval EFI_SUCCESS This is target resource which we want t= o handle. + @retval EFI_UNSUPPORTED This is not the target resource. + @retval Others Some error happened. + +**/ + +EFI_STATUS +RedfishResourceIdentify ( + IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This, + IN EFI_STRING Uri + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STATUS Status; + REDFISH_RESPONSE Response; + + if (This =3D=3D NULL || IS_EMPTY_STRING (Uri)) { + return EFI_INVALID_PARAMETER; + } + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL = (This); + + if (Private->RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + Status =3D GetResourceByUri (Private->RedfishService, Uri, &Response); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION_= _, Uri)); + return Status; + } + + Private->Uri =3D Uri; + Private->Payload =3D Response.Payload; + ASSERT (Private->Payload !=3D NULL); + + Private->Json =3D JsonDumpString (RedfishJsonInPayload (Private->Payload= ), EDKII_JSON_COMPACT); + ASSERT (Private->Json !=3D NULL); + + Status =3D RedfishIdentifyResourceCommon (Private, Private->Json); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, identify %s failed: %r\n", __FUNCTION__, Uri= , Status)); + } + // + // Release resource + // + if (Private->Payload !=3D NULL) { + RedfishFreeResponse ( + Response.StatusCode, + Response.HeaderCount, + Response.Headers, + Response.Payload + ); + Private->Payload =3D NULL; + } + + if (Private->Json !=3D NULL) { + FreePool (Private->Json); + Private->Json =3D NULL; + } + + return Status; +} + +EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL mRedfishResourceConfig =3D { + RedfishResourceProvisioningResource, + RedfishResourceConsumeResource, + RedfishResourceUpdate, + RedfishResourceCheck, + RedfishResourceIdentify, + RedfishResourceGetInfo +}; + +/** + Initialize a Redfish configure handler. + + This function will be called by the Redfish config driver to initialize = each Redfish configure + handler. + + @param[in] This Pointer to EDKII_REDFISH_CONFIG_HA= NDLER_PROTOCOL instance. + @param[in] RedfishConfigServiceInfo Redfish service informaion. + + @retval EFI_SUCCESS The handler has been initialized su= ccessfully. + @retval EFI_DEVICE_ERROR Failed to create or configure the R= EST EX protocol instance. + @retval EFI_ALREADY_STARTED This handler has already been initi= alized. + @retval Other Error happens during the initializa= tion. + +**/ +EFI_STATUS +EFIAPI +RedfishResourceInit ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This, + IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (T= his); + + Private->RedfishService =3D RedfishCreateService (RedfishConfigServiceIn= fo); + if (Private->RedfishService =3D=3D NULL) { + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + +/** + Stop a Redfish configure handler. + + @param[in] This Pointer to EDKII_REDFISH_CONFIG_HANDLER= _PROTOCOL instance. + + @retval EFI_SUCCESS This handler has been stoped successful= ly. + @retval Others Some error happened. + +**/ +EFI_STATUS +EFIAPI +RedfishResourceStop ( + IN EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *This + ) +{ + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + + Private =3D REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (T= his); + + if (Private->Event !=3D NULL) { + gBS->CloseEvent (Private->Event); + Private->Event =3D NULL; + } + + if (Private->RedfishService !=3D NULL) { + RedfishCleanupService (Private->RedfishService); + Private->RedfishService =3D NULL; + } + + if (Private->Payload !=3D NULL) { + RedfishCleanupPayload (Private->Payload); + Private->Payload =3D NULL; + } + + return EFI_SUCCESS; +} + +EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler =3D { + RedfishResourceInit, + RedfishResourceStop +}; + +/** + Callback function when gEfiRestJsonStructureProtocolGuid is installed. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +EfiRestJasonStructureProtocolIsReady + ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + if (mRedfishResourcePrivate =3D=3D NULL) { + return; + } + + if (mRedfishResourcePrivate->JsonStructProtocol !=3D NULL) { + return; + } + + Status =3D gBS->LocateProtocol ( + &gEfiRestJsonStructureProtocolGuid, + NULL, + (VOID **)&mRedfishResourcePrivate->JsonStructProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEfiRestJsonStructureProtoc= olGuid: %r\n", __FUNCTION__, Status)); + } + + gBS->CloseEvent (Event); +} + +/** + Unloads an image. + + @param ImageHandle Handle that identifies the image to be unl= oaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + +**/ +EFI_STATUS +EFIAPI +RedfishResourceUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler; + + if (mRedfishResourcePrivate =3D=3D NULL) { + return EFI_NOT_READY; + } + + ConfigHandler =3D NULL; + + // + // Firstly, find ConfigHandler Protocol interface in this ImageHandle. + // + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + (VOID **) &ConfigHandler, + NULL, + NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (EFI_ERROR (Status) || ConfigHandler =3D=3D NULL) { + return Status; + } + + ConfigHandler->Stop (ConfigHandler); + + // + // Last, uninstall ConfigHandler Protocol and resource protocol. + // + Status =3D gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + ConfigHandler, + &gEdkIIRedfishResourceConfigProtocolGuid, + &mRedfishResourcePrivate->RedfishResourceConfig, + NULL + ); + + FreePool (mRedfishResourcePrivate); + mRedfishResourcePrivate =3D NULL; + + return Status; +} + +/** + The callback function provided by Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROT= OCOL instance. + @param[in] FeatureAction The action Redfish feature driver sho= uld take. + @param[in] Uri The collection URI. + @param[in] Context The context of Redfish feature driver. + @param[in,out] InformationExchange The pointer to RESOURCE_INFORMATION_E= XCHANGE + + @retval EFI_SUCCESS Redfish feature driver callback is exec= uted successfully. + @retval Others Some errors happened. + + @retval EFI_SUCCESS Redfish feature driver callback is exec= uted successfully. + @retval Others Some errors happened. + +**/ +EFI_STATUS +EFIAPI +RedfishExternalResourceResourceFeatureCallback ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN FEATURE_CALLBACK_ACTION FeatureAction, + IN VOID *Context, + IN OUT RESOURCE_INFORMATION_EXCHANGE *InformationExchange + ) +{ + EFI_STATUS Status; + REDFISH_SERVICE RedfishService; + REDFISH_RESOURCE_COMMON_PRIVATE *Private; + EFI_STRING ResourceUri; + + if (FeatureAction !=3D CallbackActionStartOperation) { + return EFI_UNSUPPORTED; + } + + Private =3D (REDFISH_RESOURCE_COMMON_PRIVATE *)Context; + + RedfishService =3D Private->RedfishService; + if (RedfishService =3D=3D NULL) { + return EFI_NOT_READY; + } + + // + // Save in private structure. + // + Private->InformationExchange =3D InformationExchange; + + // + // Find Redfish version on BMC + // + Private->RedfishVersion =3D RedfishGetVersion (RedfishService); + + // + // Create the full URI from Redfish service root. + // + ResourceUri =3D (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof(CH= AR16)); + if (ResourceUri =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for full URI.\n", __= FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + StrCatS (ResourceUri, MAX_URI_LENGTH, Private->RedfishVersion); + StrCatS (ResourceUri, MAX_URI_LENGTH, InformationExchange->SendInformati= on.FullUri); + + // + // Initialize collection path + // + Private->Uri =3D RedfishGetUri (ResourceUri); + if (Private->Uri =3D=3D NULL) { + ASSERT (FALSE); + return EFI_OUT_OF_RESOURCES; + } + + Status =3D HandleResource (Private, Private->Uri); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, process external resource: %a failed: %r\n",= __FUNCTION__, Private->Uri, Status)); + } + + FreePool (Private->Uri); + return Status; +} + +/** + Callback function when gEdkIIRedfishFeatureProtocolGuid is installed. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +EdkIIRedfishFeatureProtocolIsReady + ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EDKII_REDFISH_FEATURE_PROTOCOL *FeatureProtocol; + + if (mRedfishResourcePrivate =3D=3D NULL) { + return; + } + + if (mRedfishResourcePrivate->FeatureProtocol !=3D NULL) { + return; + } + + Status =3D gBS->LocateProtocol ( + &gEdkIIRedfishFeatureProtocolGuid, + NULL, + (VOID **)&FeatureProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to locate gEdkIIRedfishFeatureProtoco= lGuid: %r\n", __FUNCTION__, Status)); + gBS->CloseEvent (Event); + return; + } + + Status =3D FeatureProtocol->Register ( + FeatureProtocol, + REDFISH_MANAGED_URI, + RedfishExternalResourceResourceFeatureCallba= ck, + (VOID *)mRedfishResourcePrivate + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, failed to register %s: %r\n", __FUNCTION__, = REDFISH_MANAGED_URI, Status)); + } + + mRedfishResourcePrivate->FeatureProtocol =3D FeatureProtocol; + + gBS->CloseEvent (Event); +} + +/** + This is the declaration of an EFI image entry point. This entry point is + the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers includ= ing + both device drivers and bus drivers. It initialize the global variables = and + publish the driver binding protocol. + + @param[in] ImageHandle The firmware allocated handle for the UEFI= image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was inst= alled unexpectedly. + @retval Others Other errors as indicated. +**/ +EFI_STATUS +EFIAPI +RedfishResourceEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *Registration; + + if (mRedfishResourcePrivate !=3D NULL) { + return EFI_ALREADY_STARTED; + } + + medfishResourceConfigProtocolHandle =3D ImageHandle; + + mRedfishResourcePrivate =3D AllocateZeroPool (sizeof (REDFISH_RESOURCE_C= OMMON_PRIVATE)); + CopyMem (&mRedfishResourcePrivate->ConfigHandler, &mRedfishConfigHandler= , sizeof (EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL)); + CopyMem (&mRedfishResourcePrivate->RedfishResourceConfig, &mRedfishResou= rceConfig, sizeof (EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL)); + + // + // Publish config handler protocol and resource protocol. + // + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEdkIIRedfishConfigHandlerProtocolGuid, + &mRedfishResourcePrivate->ConfigHandler, + &gEdkIIRedfishResourceConfigProtocolGuid, + &mRedfishResourcePrivate->RedfishResourceConfig, + NULL + ); + + EfiCreateProtocolNotifyEvent ( + &gEfiRestJsonStructureProtocolGuid, + TPL_CALLBACK, + EfiRestJasonStructureProtocolIsReady, + NULL, + &Registration + ); + + EfiCreateProtocolNotifyEvent ( + &gEdkIIRedfishFeatureProtocolGuid, + TPL_CALLBACK, + EdkIIRedfishFeatureProtocolIsReady, + (VOID *)mRedfishResourcePrivate, + &Registration + ); + + return Status; +} diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf b/Redfis= hClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf new file mode 100644 index 0000000000..8c01a3b877 --- /dev/null +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf @@ -0,0 +1,52 @@ +## @file +# +# (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BiosDxe + FILE_GUID =3D d6c99bb0-ca18-45aa-8be6-a60c3ba5ecd8 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D RedfishResourceEntryPoint + UNLOAD_IMAGE =3D RedfishResourceUnload + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[Sources] + ../Common/BiosCommon.h + ../Common/BiosCommon.c + BiosDxe.c + +[LibraryClasses] + BaseMemoryLib + DebugLib + EdkIIRedfishResourceConfigLib + RedfishLib + RedfishFeatureUtilityLib + RedfishVersionLib + RedfishResourceIdentifyLib + UefiLib + UefiDriverEntryPoint + +[Protocols] + gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED + gEfiRestJsonStructureProtocolGuid ## CONSUMED + gEdkIIRedfishResourceConfigProtocolGuid ## PRODUCED + gEdkIIRedfishFeatureProtocolGuid ## CONSUMED + +[Pcd] + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize + +[Depex] + TRUE diff --git a/RedfishClientPkg/RedfishClient.fdf.inc b/RedfishClientPkg/Redf= ishClient.fdf.inc index 90240efbf7..fa4e53898b 100644 --- a/RedfishClientPkg/RedfishClient.fdf.inc +++ b/RedfishClientPkg/RedfishClient.fdf.inc @@ -18,6 +18,7 @@ INF RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf INF RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDx= e.inf INF RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystem= CollectionDxe.inf + INF RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf =20 !include RedfishClientPkg/RedfishJsonStructureDxe.fdf.inc # @@ -27,4 +28,5 @@ INF RedfishClientPkg/Converter/MemoryCollection/RedfishMemoryCollection_= Dxe.inf INF RedfishClientPkg/Converter/ComputerSystem/v1_5_0/RedfishComputerSyst= em_V1_5_0_Dxe.inf INF RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerS= ystemCollection_Dxe.inf + INF RedfishClientPkg/Converter/Bios/v1_0_9/RedfishBios_V1_0_9_Dxe.inf !endif diff --git a/RedfishClientPkg/RedfishClientComponents.dsc.inc b/RedfishClie= ntPkg/RedfishClientComponents.dsc.inc index 084796e4b5..e83f4bc9bf 100644 --- a/RedfishClientPkg/RedfishClientComponents.dsc.inc +++ b/RedfishClientPkg/RedfishClientComponents.dsc.inc @@ -27,6 +27,7 @@ RedfishResourceIdentifyLib|RedfishClientPkg/Library/RedfishResourceI= dentifyLibComuterSystem/v1_5_0/RedfishResourceIdentifyLibComuterSystem.inf } RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemColl= ectionDxe.inf + RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf =20 !include RedfishClientPkg/RedfishJsonStructureDxe.dsc.inc =20 @@ -37,3 +38,4 @@ RedfishClientPkg/Converter/MemoryCollection/RedfishMemoryCollection_Dxe.= inf RedfishClientPkg/Converter/ComputerSystem/v1_5_0/RedfishComputerSystem_V= 1_5_0_Dxe.inf RedfishClientPkg/Converter/ComputerSystemCollection/RedfishComputerSyste= mCollection_Dxe.inf + RedfishClientPkg/Converter/Bios/v1_0_9/RedfishBios_V1_0_9_Dxe.inf diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc b/RedfishClientPkg/= RedfishClientLibs.dsc.inc index 05ad09ef5e..fe0c4b0885 100644 --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc @@ -15,12 +15,16 @@ !endif =20 # - # Below two modules should be pulled in by build tool. + # Below modules should be pulled in by build tool. # MemoryV1_7_1Lib|RedfishClientPkg/ConverterLib/edk2library/Memory/v1_7_1/= Lib.inf MemoryCollectionLib|RedfishClientPkg/ConverterLib/edk2library/MemoryColl= ection/Lib.inf ComputerSystemV1_5_0Lib|RedfishClientPkg/ConverterLib/edk2library/Comput= erSystem/v1_5_0/Lib.inf ComputerSystemCollectionLib|RedfishClientPkg/ConverterLib/edk2library/Co= mputerSystemCollection/Lib.inf + BiosV1_0_9Lib|RedfishClientPkg/ConverterLib/edk2library/Bios/v1_0_9/Lib.= inf + # + # Above modules should be pulled in by build tool. + # =20 NetLib|NetworkPkg/Library/DxeNetLib/DxeNetLib.inf HttpLib|NetworkPkg/Library/DxeHttpLib/DxeHttpLib.inf --=20 2.32.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91793): https://edk2.groups.io/g/devel/message/91793 Mute This Topic: https://groups.io/mt/92596798/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-