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=S6NKSHOA; spf=pass (domain: linaro.org, ip: 209.85.221.67, mailfrom: leif.lindholm@linaro.org) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by groups.io with SMTP; Mon, 30 Sep 2019 13:44:49 -0700 Received: by mail-wr1-f67.google.com with SMTP id r3so12877610wrj.6 for ; Mon, 30 Sep 2019 13:44:48 -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=b48HXZs4HPRFktoBCzBrwQSfZYYtXbdg6AEPD07vAhc=; b=S6NKSHOAW1McTIoiKNd+qqRrEdUNiONE7iSDiwdT939yQnZrKYKM3UKJMFa9bkkZPE YPn63/zzLszGMbPpUYuaBM2kucDhqCQcWCwpmwSTT2ABAcUbt2PPypOdB9PACp5d5Sqx lGqJOeFHScViESbN5mv2On+03f4rpju2yU1gPCFvFYtpoaQkjjcCFmszIvLgyCuRXwoM 0Jae+4CwFLOEbQ07VSGYJSjbnr9k3GMXnWiLBs44FMfaMonjr3TEZhKqaly2ajdKYzJu Mw+rUFq5Sc9dTSt2OkM1TDD7JPWPs5S030NB+MtBUZnAe0XGHxG2EEU+/4zHhncIQdsZ 6UNg== 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=b48HXZs4HPRFktoBCzBrwQSfZYYtXbdg6AEPD07vAhc=; b=dxWKyeFXG3oAZCC0Q66ae+BX60atkBOjCucbJx2IZ856L/VBKg8GOwO0g/oS5uygYc ScZAbqXJoVdVnQxc2BWVQqdsAE4utMY0HImBYrtHIezjJCTreSpA0Bcyi/tEpeeDU/fX S7CKXkwmsSk5Ikv2tFPlF+W8xgpHFT8zm6ZgdO4oErGdLvfKcu2Et8FnvyJTHmQKwhR7 7tr5emqnct5R8TAXGZnkoYs7tbJkw3+NXay4MJ0AdaLkRc/4wy87VVKv6lEXZQC1Nin6 TH+fYtqGvlZ0ddF8VD/jSS3kGtLvISbVkiihFd+I4tOr6bQEI3IYKAmeVMm2ysnZyxSG RApA== X-Gm-Message-State: APjAAAWKzClC2tK2aK0xxpmja2RAbyWeDWgmYD1f/yaU63R+ZS4BbPRb BZDVg748yiPzO4qePt9/rYjZbSCjNTg= X-Google-Smtp-Source: APXvYqye9aGBlcEigQUaw59XLAy9bgkkXbyM774vbDXySScMA5LUAb3YeowM/IxoOfqLBTj4Z+AhMg== X-Received: by 2002:adf:e849:: with SMTP id d9mr14933537wrn.358.1569876287095; Mon, 30 Sep 2019 13:44:47 -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 b16sm16996485wrh.5.2019.09.30.13.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 13:44:46 -0700 (PDT) Date: Mon, 30 Sep 2019 21:44:45 +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: <20190930204445.GF25504@bivouac.eciton.net> References: <1569198715-31552-1-git-send-email-abner.chang@hpe.com> <1569198715-31552-21-git-send-email-abner.chang@hpe.com> <20190930201557.GD25504@bivouac.eciton.net> MIME-Version: 1.0 In-Reply-To: <20190930201557.GD25504@bivouac.eciton.net> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 30, 2019 at 09:15:57PM +0100, Leif Lindholm wrote: > 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; Oh yes - these (unsigned long) statements need to be be replaced with something better. Is UINTN insufficient? In fact, there are several additional instances in Include/sbi/sbi.h. / Leif > > + 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 > > > > > > > >