From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web11.2715.1641618765358610406 for ; Fri, 07 Jan 2022 21:12:45 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=SRvqhE81; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=000704d8ca=abner.chang@hpe.com) Received: from pps.filterd (m0134422.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 2084uGgr028633 for ; Sat, 8 Jan 2022 05:12:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=lv4c6tal00Nyp/cEoeD3dhutkRpbSLJqCWaot9bDCmA=; b=SRvqhE81cwcUKKKu/Pk/X6J3nAkulNaIC3D4mtkkdqJIUFC4k62IEbFC7bs7tiGs5XDl 97MAeazM5ob7e/NB5/Dwcb7uyzA6odo/+Lry/RCRynsjKdinlsPeTnpVAaXDfZY5o6k0 slrb86K5/sDxMsEjW2PlUsCyhexJyoEUGiOHYBf6KhdFdBe39JNlXdYSoMK26fBIbyQs iwH6Fsdg/BYNe6FmHwM9URJDXKLw7wyrrJtdj8LUL8PJ0Tp2puFPwPaXzx9UFb1lRjUg ueYFKc53D90QdM4YQ8RidTHw715Gu/4yOAl0CkyBOYc9cr2BB5TW6EsvNZfzXdqLkq3c pw== Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df40k82yt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 05:12:43 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id 3B85581 for ; Sat, 8 Jan 2022 05:12:43 +0000 (UTC) Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 8495737; Sat, 8 Jan 2022 05:12:42 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 22/79] Silicon/SiFive: Handle case of NULL FirmwareContext Date: Sat, 8 Jan 2022 12:10:42 +0800 Message-Id: <20220108041121.16005-21-abner.chang@hpe.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220108041121.16005-1-abner.chang@hpe.com> References: <20220108041121.16005-1-abner.chang@hpe.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Fktklg3nfkJ0u1VwZBxUZWgtxFmX9iez X-Proofpoint-GUID: Fktklg3nfkJ0u1VwZBxUZWgtxFmX9iez X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-08_01,2022-01-07_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 phishscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201080036 Content-Transfer-Encoding: quoted-printable (This is migrated from edk2-platforms:Silicon) Abort creating the SMBIOS HOBs if there's no firmware context to get the information from. Turn SbiLib functions for getting mscratch into VOID since they can never practically fail. Signed-off-by: Daniel Schaefer Reviewed-by: Abner Chang Cc: Abner Chang Cc: Leif Lindholm --- .../Include/Library/RiscVEdk2SbiLib.h | 12 ++--- .../PlatformPkg/Universal/Sec/SecMain.c | 11 +++-- .../Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c | 46 +++++++------------ 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h = b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h index 558841a970..f81ea06b05 100644 --- a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h +++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h @@ -514,9 +514,8 @@ SbiVendorCall ( access the firmware context.=0D =0D @param[out] ScratchSpace The scratch space pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiGetMscratch (=0D OUT SBI_SCRATCH **ScratchSpace=0D @@ -527,9 +526,8 @@ SbiGetMscratch ( =0D @param[in] HartId The hart id.=0D @param[out] ScratchSpace The scratch space pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiGetMscratchHartid (=0D IN UINTN HartId,=0D @@ -540,9 +538,8 @@ SbiGetMscratchHartid ( Get firmware context of the calling hart.=0D =0D @param[out] FirmwareContext The firmware context pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiGetFirmwareContext (=0D OUT EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT **FirmwareContext=0D @@ -552,9 +549,8 @@ SbiGetFirmwareContext ( Set firmware context of the calling hart.=0D =0D @param[in] FirmwareContext The firmware context pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiSetFirmwareContext (=0D IN EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c b/Platform= /RISC-V/PlatformPkg/Universal/Sec/SecMain.c index 877777bfa1..fa9ecd789a 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c @@ -415,7 +415,10 @@ EFI_STATUS EFIAPI TemporaryRamDone ( return EFI_SUCCESS;=0D }=0D =0D -/** Handles SBI calls of EDK2's SBI FW extension=0D +/**=0D + Handles SBI calls of EDK2's SBI FW extension.=0D +=0D + The return value is the error code returned by the SBI call.=0D =0D @param[in] ExtId The extension ID of the FW extension.=0D @param[in] FuncId The called function ID.=0D @@ -424,7 +427,7 @@ EFI_STATUS EFIAPI TemporaryRamDone ( @param[out] OutTrap Trap info for trapping further, see OpenSBI cod= e.=0D Is ignored if return value is not SBI_ETRAP.=0D =0D - @retval 0 If the handler succeeds.=0D + @retval SBI_OK If the handler succeeds.=0D @retval SBI_ENOTSUPP If there's no function with the given ID.=0D @retval SBI_ETRAP If the called SBI functions wants to trap furth= er.=0D **/=0D @@ -436,7 +439,7 @@ STATIC int SbiEcallFirmwareHandler ( OUT struct sbi_trap_info *OutTrap=0D )=0D {=0D - int Ret =3D 0;=0D + int Ret =3D SBI_OK;=0D =0D switch (FuncId) {=0D case SBI_EXT_FW_MSCRATCH_FUNC:=0D @@ -447,6 +450,8 @@ STATIC int SbiEcallFirmwareHandler ( break;=0D default:=0D Ret =3D SBI_ENOTSUPP;=0D + DEBUG ((DEBUG_ERROR, "%a: Called SBI firmware ecall with invalid fun= ction ID\n", __FUNCTION__));=0D + ASSERT (FALSE);=0D };=0D =0D return Ret;=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2S= biLib.c b/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiL= ib.c index 0df505d267..9bbeaaec3f 100644 --- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c +++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c @@ -801,9 +801,8 @@ SbiVendorCall ( access the firmware context.=0D =0D @param[out] ScratchSpace The scratch space pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiGetMscratch (=0D OUT SBI_SCRATCH **ScratchSpace=0D @@ -811,11 +810,10 @@ SbiGetMscratch ( {=0D SbiRet Ret =3D SbiCall (SBI_EDK2_FW_EXT, SBI_EXT_FW_MSCRATCH_FUNC, 0);=0D =0D - if (!Ret.Error) {=0D - *ScratchSpace =3D (SBI_SCRATCH *)Ret.Value;=0D - }=0D + // Our ecall handler never returns an error, only when the func id is in= valid=0D + ASSERT (Ret.Error =3D=3D SBI_OK);=0D =0D - return EFI_SUCCESS;=0D + *ScratchSpace =3D (SBI_SCRATCH *)Ret.Value;=0D }=0D =0D /**=0D @@ -823,9 +821,8 @@ SbiGetMscratch ( =0D @param[in] HartId The hart id.=0D @param[out] ScratchSpace The scratch space pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiGetMscratchHartid (=0D IN UINTN HartId,=0D @@ -839,11 +836,10 @@ SbiGetMscratchHartid ( HartId=0D );=0D =0D - if (!Ret.Error) {=0D - *ScratchSpace =3D (SBI_SCRATCH *)Ret.Value;=0D - }=0D + // Our ecall handler never returns an error, only when the func id is in= valid=0D + ASSERT (Ret.Error =3D=3D SBI_OK);=0D =0D - return EFI_SUCCESS;=0D + *ScratchSpace =3D (SBI_SCRATCH *)Ret.Value;=0D }=0D =0D /**=0D @@ -852,7 +848,7 @@ SbiGetMscratchHartid ( @param[out] FirmwareContext The firmware context pointer.=0D @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiGetFirmwareContext (=0D OUT EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT **FirmwareContext=0D @@ -860,24 +856,18 @@ SbiGetFirmwareContext ( {=0D SBI_SCRATCH *ScratchSpace;=0D SBI_PLATFORM *SbiPlatform;=0D - SbiRet Ret =3D SbiCall (SBI_EDK2_FW_EXT, SBI_EXT_FW_MSCRATCH_FUNC, 0);=0D -=0D - if (!Ret.Error) {=0D - ScratchSpace =3D (SBI_SCRATCH *)Ret.Value;=0D - SbiPlatform =3D (SBI_PLATFORM *)sbi_platform_ptr(ScratchSpace);=0D - *FirmwareContext =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)SbiPlatform= ->firmware_context;=0D - }=0D =0D - return EFI_SUCCESS;=0D + SbiGetMscratch(&ScratchSpace);=0D + SbiPlatform =3D (SBI_PLATFORM *)sbi_platform_ptr(ScratchSpace);=0D + *FirmwareContext =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)SbiPlatform->= firmware_context;=0D }=0D =0D /**=0D Set firmware context of the calling hart.=0D =0D @param[in] FirmwareContext The firmware context pointer.=0D - @retval EFI_SUCCESS The operation succeeds.=0D **/=0D -EFI_STATUS=0D +VOID=0D EFIAPI=0D SbiSetFirmwareContext (=0D IN EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext=0D @@ -885,13 +875,9 @@ SbiSetFirmwareContext ( {=0D SBI_SCRATCH *ScratchSpace;=0D SBI_PLATFORM *SbiPlatform;=0D - SbiRet Ret =3D SbiCall (SBI_EDK2_FW_EXT, SBI_EXT_FW_MSCRATCH_FUNC, 0);=0D =0D - if (!Ret.Error) {=0D - ScratchSpace =3D (SBI_SCRATCH *)Ret.Value;=0D - SbiPlatform =3D (SBI_PLATFORM *)sbi_platform_ptr (ScratchSpace);=0D - SbiPlatform->firmware_context =3D (UINTN)FirmwareContext;=0D - }=0D + SbiGetMscratch(&ScratchSpace);=0D =0D - return EFI_SUCCESS;=0D + SbiPlatform =3D (SBI_PLATFORM *)sbi_platform_ptr (ScratchSpace);=0D + SbiPlatform->firmware_context =3D (UINTN)FirmwareContext;=0D }=0D --=20 2.31.1