From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=GYEdZcu1; spf=pass (domain: linaro.org, ip: 209.85.221.68, mailfrom: leif.lindholm@linaro.org) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by groups.io with SMTP; Mon, 30 Sep 2019 13:16:02 -0700 Received: by mail-wr1-f68.google.com with SMTP id b9so12812646wrs.0 for ; Mon, 30 Sep 2019 13:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ynb4qGDs/ruvUhcj/7OZttAv7NRT0muJ4fqRwc4C790=; b=GYEdZcu16wnbOaecaan7uBp6HOQapg0KP+OE/yuYsZjsbLZGcd62UQKdDxN04W0M0q C9g14/fAWT7BNNXH5uuWeNG5LPzq/mBZ7hSJ+HdLgsp6LTgvOkcJjrxu4+lVTTUUmHiK XOnQf1kLoVr+Lr56y8Tqsei3dSYPZxvmvN+mDeTuDJKfUNiepwTI2CtiMdMiqDcSBMOv 18rMorXGSGhlVuEik9S13RQ96mPx9jnz/PIJfCXzoLLuN+V2gTfXXjFRZhed0m01+5eZ dKDalETo7uvAevE03N1IO0UB168umba7vsVfUYWNyI7XKuAsVT6ZE81pmlI5peHc8i8J xlJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ynb4qGDs/ruvUhcj/7OZttAv7NRT0muJ4fqRwc4C790=; b=BSdBVuF/0miJwpJxfqgSC41xIP36NM5bhwQPtgv8vNvdmIMRQ9Fc45Xd07FdxVe4nZ 77O/KAFH2IZuzPlqKOYJzHcRqnSRLel+8w9I1S6LG4yc0t0okQtbdusOnmBdWjkxF8RM BS4PJ8nOKosWImWf0/kaD497XRbdbWoAeupnzWMCASfk3JR3+QdVkbfpVBw04dYe8lX3 wif17D83etGWAa1WkqT+iWcJn/I4/wlBYC0zDdQOf3thrITl7zILCOhH/VknkhZ9XGtj 58rnNOugLw4wYsS+ylKAP7usQZyC3S+jdiXoOtuRgXEgPad8oE72nXs4LlOx5EBW4BVT SXWg== X-Gm-Message-State: APjAAAX9sOOGAnQbKO1Bshe2RATRVBPJ+qtViQ4zj04ZlfRXr+OOLKGy N5r0BzXT5GtJFYzphh26d3JqPPeVfPc= X-Google-Smtp-Source: APXvYqwAkWCAMMKa/OEeV10XxelnvdO5qWWVHJuIBsCproNhIXglg2ajxLsO6FTYIpjw53DDw6sPug== X-Received: by 2002:a5d:500b:: with SMTP id e11mr15218680wrt.285.1569874560079; Mon, 30 Sep 2019 13:16:00 -0700 (PDT) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id h17sm339710wmb.33.2019.09.30.13.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 13:15:59 -0700 (PDT) Date: Mon, 30 Sep 2019 21:15:57 +0100 From: "Leif Lindholm" To: devel@edk2.groups.io, abner.chang@hpe.com Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 19/29] RiscVPkg/Library: RISC-V platform level DxeIPL libraries. Message-ID: <20190930201557.GD25504@bivouac.eciton.net> References: <1569198715-31552-1-git-send-email-abner.chang@hpe.com> <1569198715-31552-21-git-send-email-abner.chang@hpe.com> MIME-Version: 1.0 In-Reply-To: <1569198715-31552-21-git-send-email-abner.chang@hpe.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 23, 2019 at 08:31:45AM +0800, Abner Chang wrote: > RiscVDxeIplHandoffLib.inf: Simply use stack switch to hand off to DXE > phase. > > RiscVDxeIplHandoffOpenSbiLib.inf: Hand off to DXE phase using OpenSBI > interface. > > Signed-off-by: Abner Chang > --- > .../RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.c | 41 +++++++++ > .../RiscVDxeIplHandoffLib.inf | 32 +++++++ > .../RiscVDxeIplHandoffOpenSbiLib.c | 102 +++++++++++++++++++++ > .../RiscVDxeIplHandoffOpenSbiLib.inf | 33 +++++++ > 4 files changed, 208 insertions(+) > create mode 100644 RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.c > create mode 100644 RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.inf > create mode 100644 RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.c > create mode 100644 RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.inf > > diff --git a/RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.c b/RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.c > new file mode 100644 > index 0000000..211b4e8 > --- /dev/null > +++ b/RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.c > @@ -0,0 +1,41 @@ > +/** @file > + RISC-V platform level DXE core hand off library > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +/** > + RISC-V platform DXE IPL to DXE core handoff process. > + > + This function performs a CPU architecture specific operations to execute > + the entry point of DxeCore with the parameters of HobList. > + It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. > + > + @param BaseOfStack Base address of stack > + @param TopOfStack Top address of stack > + @param DxeCoreEntryPoint The entry point of DxeCore. > + @param HobList The start of HobList passed to DxeCore. > + > +**/ > + > +VOID > +RiscVPlatformHandOffToDxeCore ( > + IN VOID *BaseOfStack, > + IN VOID *TopOfStack, > + IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, > + IN EFI_PEI_HOB_POINTERS HobList > + ) > +{ > + > + // > + // Transfer the control to the entry point of DxeCore. > + // > + SwitchStack ( > + (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint, > + HobList.Raw, > + NULL, > + TopOfStack > + ); > +} > diff --git a/RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.inf b/RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.inf > new file mode 100644 > index 0000000..986db1d > --- /dev/null > +++ b/RiscVPkg/Library/RiscVDxeIplHandoffLib/RiscVDxeIplHandoffLib.inf > @@ -0,0 +1,32 @@ > +## @file > +# Instance of RISC-V DXE IPL to DXE core handoff platform library > +# > +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +## > + > +[Defines] > + INF_VERSION = 0x0001001b > + BASE_NAME = RiscVPlatformDxeIplLib > + FILE_GUID = 2A77EE71-9F55-43F9-8773-7854A5B56086 > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = RiscVPlatformDxeIplLib|PEIM PEI_CORE > + > +# > +# VALID_ARCHITECTURES = RISCV64 > +# > + > +[Sources] > + RiscVDxeIplHandoffLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + RiscVPkg/RiscVPkg.dec > + > +[LibraryClasses] > + DebugLib > + RiscVCpuLib > + RiscVOpensbiLib > + > diff --git a/RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.c b/RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.c > new file mode 100644 > index 0000000..c640fd2 > --- /dev/null > +++ b/RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.c > @@ -0,0 +1,102 @@ > +/** @file > + RISC-V DXE IPL to DXE core handoff platform library using OpenSBI > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include Please sort include files alphabetically. > + > +/** > + RISC-V platform DXE IPL to DXE OpenSBI mdoe switch handler. > + This function is executed in RISC-V Supervisor mode. > + > + This function performs a CPU architecture specific operations to execute > + the entry point of DxeCore with the parameters of HobList. > + It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. > + > + @param BaseOfStack Base address of stack > + @param TopOfStack Top address of stack > + @param DxeCoreEntryPoint The entry point of DxeCore. > + @param HobList The start of HobList passed to DxeCore. > + > +**/ > +VOID > +RiscVDxeIplHandoffOpenSbiHandler ( > + IN UINTN HardId, > + IN OPENSBI_SWITCH_MODE_CONTEXT *ThisSwitchContext > + ) > +{ > + DEBUG ((DEBUG_INFO, "[OpenSBI]: OpenSBI mode switch DXE IPL Handoff handler entry\n")); I would prefer not having [OpenSBI] tags all over EDK2 code. Use %a __FUNCTION__ if you want to indicate location. This applies to the whole file. > + > + SwitchStack ( > + (SWITCH_STACK_ENTRY_POINT)(UINTN)ThisSwitchContext->DxeCoreEntryPoint, > + ThisSwitchContext->HobList.Raw, > + NULL, > + ThisSwitchContext->TopOfStack > + ); > + > + // > + // Shold never came back. > + // > + __builtin_unreachable(); Please use the UNREACHABLE () macro from Base.h. / Leif > +} > + > + > +/** > + RISC-V platform DXE IPL to DXE core handoff process. > + > + This function performs a CPU architecture specific operations to execute > + the entry point of DxeCore with the parameters of HobList. > + It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase. > + > + @param BaseOfStack Base address of stack > + @param TopOfStack Top address of stack > + @param DxeCoreEntryPoint The entry point of DxeCore. > + @param HobList The start of HobList passed to DxeCore. > + > +**/ > +VOID > +RiscVPlatformHandOffToDxeCore ( > + IN VOID *BaseOfStack, > + IN VOID *TopOfStack, > + IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, > + IN EFI_PEI_HOB_POINTERS HobList > + ) > +{ > + struct sbi_scratch *ThisScratch; > + OPENSBI_SWITCH_MODE_CONTEXT OpenSbiSwitchModeContext; > + > + DEBUG ((DEBUG_INFO, "[OpenSBI]: DXE IPL to DXE Core using OpenSBI\n")); > + // > + // Setup next address in OpenSBI scratch > + // > + OpenSbiSwitchModeContext.BaseOfStack = BaseOfStack; > + OpenSbiSwitchModeContext.TopOfStack = TopOfStack; > + OpenSbiSwitchModeContext.HobList = HobList; > + OpenSbiSwitchModeContext.DxeCoreEntryPoint = DxeCoreEntryPoint; > + ThisScratch = sbi_scratch_thishart_ptr (); > + ThisScratch->next_arg1 = (unsigned long)(UINTN)&OpenSbiSwitchModeContext; > + ThisScratch->next_addr = (unsigned long)(UINTN)RiscVDxeIplHandoffOpenSbiHandler; > + ThisScratch->next_mode = PRV_S; > + > + DEBUG ((DEBUG_INFO, " Base address of satck: 0x%x\n", BaseOfStack)); > + DEBUG ((DEBUG_INFO, " Top address of satck: 0x%x\n", TopOfStack)); > + DEBUG ((DEBUG_INFO, " HOB list address: 0x%x\n", &HobList)); > + DEBUG ((DEBUG_INFO, " DXE core entry pointer: 0x%x\n", DxeCoreEntryPoint)); > + DEBUG ((DEBUG_INFO, " OpenSBI Switch mode arg1: 0x%x\n", (UINTN)&OpenSbiSwitchModeContext)); > + DEBUG ((DEBUG_INFO, " OpenSBI Switch mode handler address: 0x%x\n", (UINTN)RiscVDxeIplHandoffOpenSbiHandler)); > + DEBUG ((DEBUG_INFO, " OpenSBI Switch mode to privilege 0x%x\n", PRV_S)); > + sbi_init (ThisScratch); > +} > diff --git a/RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.inf b/RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.inf > new file mode 100644 > index 0000000..262071d > --- /dev/null > +++ b/RiscVPkg/Library/RiscVDxeIplHandoffOpenSbiLib/RiscVDxeIplHandoffOpenSbiLib.inf > @@ -0,0 +1,33 @@ > +## @file > +# Instance of RISC-V DXE IPL to DXE core handoff platform library using OpenSBI > +# > +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001b > + BASE_NAME = RiscVPlatformDxeIplLib > + FILE_GUID = 906A4BB9-8DE2-4CE0-A609-23818A8FF514 > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = RiscVPlatformDxeIplLib|PEIM PEI_CORE > + > +# > +# VALID_ARCHITECTURES = RISCV64 > +# > + > +[Sources] > + RiscVDxeIplHandoffOpenSbiLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + RiscVPkg/RiscVPkg.dec > + > +[LibraryClasses] > + DebugLib > + RiscVCpuLib > + RiscVOpensbiLib > + > -- > 2.7.4 > > > >