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=nAFNCGAO; 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:55:02 -0700 Received: by mail-wr1-f68.google.com with SMTP id b9so12913463wrs.0 for ; Mon, 30 Sep 2019 13:55: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=bxU13+vW0NH2BgEOw7q5JE5zrcR8z1GSJJAfHo5LTmE=; b=nAFNCGAOTq/xIW+mqoWJuSymOH8LccopR95LYxmHIIq5udPTFVe6FR8dnQsg7PfJyY FUZOsdrWmLnkO52bpexpCritcfXIxi2NrvXcNWFOaOtW16zMtOHbXApj3AWYGLeQynyJ Dz4WypIuyasUWhPosvYy8KNILsrBLhS3wV9V3E+LNiwdyeejAHUWpIQcumBb8BtPgzoP LtJ+5SHck9DOCKT7qzJxsn5c7eqWWmyX9lJIyyVgncnIPu25Y3b+SoCWaCNFG+tVCMQZ LcaJiCWwEuAcQPCYApjXcruCKoMjq2MfArT4/sMJtXoioSxhaViCE2U+Do8n4eXsNWuI MN4Q== 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=bxU13+vW0NH2BgEOw7q5JE5zrcR8z1GSJJAfHo5LTmE=; b=SztQxmtQXebb/SsYU4tQKiox3JR1oGuO8sN9OLiwAlYUk3ytHwDQE5ESsoo4YqrMiL PuNmgTEJzsUgUyHvr4dNe4yx0XFnWUwPWcuFAjwnAwyFlsV+qmA205+dT7vFoMV349XL DqiUZhqjDWhJvrOeZee/GIDyWmPi+38Aoo2xk4jBU1pdsxiH5WqcfB/4ynea2LjVV9Vt fKS/Y1K+THBAdkTPnAAHN+kzzl45nUAUZflXbve/qFw4O1c7Lc7JGItWQUKcAWCK9VpS PYskOBa4GV52fp1C1+ZHwidmaaLuhwwyqHKPLu1AtziS+hpvIK8KPtbQKtbyJUTsAI1F 7DPA== X-Gm-Message-State: APjAAAV6qxNGZYNaubJKplMvNprsQcXxGXmb1q3FnodiSAs0PSdr5W1f kNcpfArrTnt7TIHFOjXJNB1ap2uVhpE= X-Google-Smtp-Source: APXvYqzb+rZpYfbIytiKalRIQtL/X7o6aUXsV6CG502IQ9MzXYOLi+PA0jMUazlXpRGaPRJzjZGJqQ== X-Received: by 2002:a05:6000:14c:: with SMTP id r12mr14539348wrx.303.1569876900227; Mon, 30 Sep 2019 13:55: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 s1sm19435046wrg.80.2019.09.30.13.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 13:54:59 -0700 (PDT) Date: Mon, 30 Sep 2019 21:54: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 21/29] RiscVPkg/PeiServicesTablePointerLibOpenSbi: RISC-V PEI Service Table Pointer library Message-ID: <20190930205457.GG25504@bivouac.eciton.net> References: <1569198715-31552-1-git-send-email-abner.chang@hpe.com> <1569198715-31552-23-git-send-email-abner.chang@hpe.com> MIME-Version: 1.0 In-Reply-To: <1569198715-31552-23-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:47AM +0800, Abner Chang wrote: > Implementation of RISC-V PEI Service Table Pointer library using > RISC-V OpenSbi. > > Signed-off-by: Abner Chang > --- > .../PeiServicesTablePointerLibOpenSbi.inf | 38 +++++++ > .../PeiServicesTablePointerLibOpenSbi.uni | 23 ++++ > .../PeiServicesTablePointerOpenSbi.c | 121 +++++++++++++++++++++ > 3 files changed, 182 insertions(+) > create mode 100644 RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf > create mode 100644 RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.uni > create mode 100644 RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerOpenSbi.c > > diff --git a/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf > new file mode 100644 > index 0000000..0b029ae > --- /dev/null > +++ b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf > @@ -0,0 +1,38 @@ > +## @file > +# Instance of PEI Services Table Pointer Library using RISC-V OpenSBI FirmwareContext. > +# > +# PEI Services Table Pointer Library implementation that retrieves a pointer to the > +# PEI Services Table from a RISC-V OpenSBI sbi_platform firmware context structure. > +# > +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001b > + BASE_NAME = PeiServicesTablePointerLibOpenSbi > + MODULE_UNI_FILE = PeiServicesTablePointerLibOpenSbi.uni > + FILE_GUID = B4054E46-FE75-4290-B442-4836B1265D8F > + MODULE_TYPE = PEIM > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM PEI_CORE > + > + CONSTRUCTOR = PeiServicesTablePointerLibOpenSbiConstructor > + > +# > +# VALID_ARCHITECTURES = RISCV64 > +# > + > +[Sources] > + PeiServicesTablePointerOpenSbi.c > + > +[Packages] > + MdePkg/MdePkg.dec > + RiscVPkg/RiscVPkg.dec > + > +[LibraryClasses] > + DebugLib > + RiscVCpuLib > + RiscVOpensbiLib > diff --git a/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.uni b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.uni > new file mode 100644 > index 0000000..f6fad8b > --- /dev/null > +++ b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSbi.uni > @@ -0,0 +1,23 @@ > +// /** @file > +// > +// Instance of PEI Services Table Pointer Library using RISC-V OpenSBI FirmwareContext. > +// > +// PEI Services Table Pointer Library implementation that retrieves a pointer to the > +// PEI Services Table from a RISC-V OpenSBI sbi_platform firmware context structure. > +// > +// Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
> +// > +// This program and the accompanying materials > +// are licensed and made available under the terms and conditions of the BSD License > +// which accompanies this distribution. The full text of the license may be found at > +// http://opensource.org/licenses/bsd-license.php. > +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "Instance of PEI Services Table Pointer Library using global variable for the table pointer" > + > +#string STR_MODULE_DESCRIPTION #language en-US "The PEI Services Table Pointer Library implementation that retrieves a pointer to the PEI Services Table from a global variable. Not available to modules that execute from read-only memory." > + > diff --git a/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerOpenSbi.c b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerOpenSbi.c > new file mode 100644 > index 0000000..915964f > --- /dev/null > +++ b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerOpenSbi.c > @@ -0,0 +1,121 @@ > +/** @file > + PEI Services Table Pointer Library. > + > + 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 Please sort the include files alphabetically. > + > +/** > + Caches a pointer PEI Services Table. > + > + Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer > + in a CPU specific manner as specified in the CPU binding section of the Platform Initialization > + Pre-EFI Initialization Core Interface Specification. > + > + If PeiServicesTablePointer is NULL, then ASSERT(). > + > + @param PeiServicesTablePointer The address of PeiServices pointer. > +**/ > +VOID > +EFIAPI > +SetPeiServicesTablePointer ( > + IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer > + ) > +{ > + struct sbi_platform *ThisSbiPlatform; > + EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext; > + > + ThisSbiPlatform = (struct sbi_platform *)sbi_platform_ptr(sbi_scratch_thishart_ptr()); > + FirmwareContext = (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)ThisSbiPlatform->firmware_context; > + FirmwareContext->PeiServiceTable = (VOID *)(UINTN)PeiServicesTablePointer; > + > + DEBUG ((DEBUG_ERROR, "[OpenSBI]: Set PEI Service 0x%x at Firmware Context at 0x%x\n", Please drop the [OpenSBI] tag from the message. > + PeiServicesTablePointer, > + ThisSbiPlatform->firmware_context > + )); Indentation is off. / Leif > +} > + > +/** > + Retrieves the cached value of the PEI Services Table pointer. > + > + Returns the cached value of the PEI Services Table pointer in a CPU specific manner > + as specified in the CPU binding section of the Platform Initialization Pre-EFI > + Initialization Core Interface Specification. > + > + If the cached PEI Services Table pointer is NULL, then ASSERT(). > + > + @return The pointer to PeiServices. > + > +**/ > +CONST EFI_PEI_SERVICES ** > +EFIAPI > +GetPeiServicesTablePointer ( > + VOID > + ) > +{ > + struct sbi_platform *ThisSbiPlatform; > + EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext; > + > + ThisSbiPlatform = (struct sbi_platform *)sbi_platform_ptr(sbi_scratch_thishart_ptr()); > + FirmwareContext = (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)ThisSbiPlatform->firmware_context; > + return (CONST EFI_PEI_SERVICES **)FirmwareContext->PeiServiceTable; > +} > + > +/** > + The constructor function caches the pointer to PEI services. > + > + The constructor function caches the pointer to PEI services. > + It will always return EFI_SUCCESS. > + > + @param FileHandle The handle of FFS header the loaded driver. > + @param PeiServices The pointer to the PEI services. > + > + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. > + > +**/ > +EFI_STATUS > +EFIAPI > +PeiServicesTablePointerLibOpenSbiConstructor ( > + IN EFI_PEI_FILE_HANDLE FileHandle, > + IN CONST EFI_PEI_SERVICES **PeiServices > + ) > +{ > + SetPeiServicesTablePointer (PeiServices); > + return EFI_SUCCESS; > +} > + > +/** > + Perform CPU specific actions required to migrate the PEI Services Table > + pointer from temporary RAM to permanent RAM. > + > + For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes > + immediately preceding the Interrupt Descriptor Table (IDT) in memory. > + For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes > + immediately preceding the Interrupt Descriptor Table (IDT) in memory. > + For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in > + a dedicated CPU register. This means that there is no memory storage > + associated with storing the PEI Services Table pointer, so no additional > + migration actions are required for Itanium or ARM CPUs. > + > +**/ > +VOID > +EFIAPI > +MigratePeiServicesTablePointer ( > + VOID > + ) > +{ > + // > + // PEI Services Table pointer is cached in the global variable. No additional > + // migration actions are required. > + // > + return; > +} > -- > 2.7.4 > > > >