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.web12.2691.1641618750985694451 for ; Fri, 07 Jan 2022 21:12:31 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=V0ZO7KZI; 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 2084t3tT027641 for ; Sat, 8 Jan 2022 05:12:29 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 : content-transfer-encoding : mime-version; s=pps0720; bh=khw8F0XlCoZsaLDmd+cG/naIcpuXGpcXttJVXPiBW3s=; b=V0ZO7KZIKNDDVMHGdsoLN1w9QiUNQklAgIFRP41SD4d4r/HP7QurgoRTblMVsMoJN+Cl SRv09dytRLaMYa2NVjVy+nv4QLt/0sLMKeOal67gQbs5/gGBzrhiNyByWDMfKVnPXG3e M4h3lcucj+lqtaemHjQovQxoyDyrIOu89OqOZTdJyA+RgZnQ5U6wnCr/sOx9e34Nkdt2 AsDzob8ipv+2t8YJgpresnek6Or6BCo0jNbLIbLmWsUY1kYPDz1CAXWKMfPCBM60KKxT RmywDX7Kc5gjSZPtJ956wiD0QkX5nxHyyAWU7nreSm6HJdbHncfvYkpe4kjqUUoN66J6 bA== Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df40k82y4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 05:12:29 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id 9C39791 for ; Sat, 8 Jan 2022 05:12:28 +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 E53C036; Sat, 8 Jan 2022 05:12:27 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 08/79] ProcessorPkg/Library: RISC-V PEI Service Table Pointer library Date: Sat, 8 Jan 2022 12:10:28 +0800 Message-Id: <20220108041121.16005-7-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> X-Proofpoint-ORIG-GUID: wEHP6F2bh0bTwbqSNXUfmjBDVCFuSoL8 X-Proofpoint-GUID: wEHP6F2bh0bTwbqSNXUfmjBDVCFuSoL8 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 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=925 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/RISC-V) Implementation of RISC-V PEI Service Table Pointer library using RISC-V OpenSbi. Signed-off-by: Abner Chang Co-authored-by: Daniel Schaefer Co-authored-by: Gilbert Chen Reviewed-by: Leif Lindholm Cc: Leif Lindholm Cc: Gilbert Chen --- .../PeiServicesTablePointerLibOpenSbi.inf | 39 ++++++ .../PeiServicesTablePointerOpenSbi.c | 117 ++++++++++++++++++ .../PeiServicesTablePointerLibOpenSbi.uni | 23 ++++ 3 files changed, 179 insertions(+) create mode 100644 Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePoi= nterLibOpenSbi/PeiServicesTablePointerLibOpenSbi.inf create mode 100644 Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePoi= nterLibOpenSbi/PeiServicesTablePointerOpenSbi.c create mode 100644 Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePoi= nterLibOpenSbi/PeiServicesTablePointerLibOpenSbi.uni diff --git a/Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLib= OpenSbi/PeiServicesTablePointerLibOpenSbi.inf b/Silicon/RISC-V/ProcessorPkg= /Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSb= i.inf new file mode 100644 index 0000000000..f23272016b --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLibOpenSbi= /PeiServicesTablePointerLibOpenSbi.inf @@ -0,0 +1,39 @@ +## @file=0D +# Instance of PEI Services Table Pointer Library using RISC-V OpenSBI Firm= wareContext.=0D +#=0D +# PEI Services Table Pointer Library implementation that retrieves a poin= ter to the=0D +# PEI Services Table from a RISC-V OpenSBI sbi_platform firmware context = structure.=0D +#=0D +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D PeiServicesTablePointerLibOpenSbi=0D + MODULE_UNI_FILE =3D PeiServicesTablePointerLibOpenSbi.uni= =0D + FILE_GUID =3D B4054E46-FE75-4290-B442-4836B1265D8F= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D PeiServicesTablePointerLib|PEIM PEI_C= ORE=0D +=0D + CONSTRUCTOR =3D PeiServicesTablePointerLibOpenSbiCons= tructor=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +=0D +[Sources]=0D + PeiServicesTablePointerOpenSbi.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + RiscVCpuLib=0D + RiscVEdk2SbiLib=0D +=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLib= OpenSbi/PeiServicesTablePointerOpenSbi.c b/Silicon/RISC-V/ProcessorPkg/Libr= ary/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerOpenSbi.c new file mode 100644 index 0000000000..0c1473e932 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLibOpenSbi= /PeiServicesTablePointerOpenSbi.c @@ -0,0 +1,117 @@ +/** @file=0D + PEI Services Table Pointer Library.=0D +=0D + Copyright (c) 2019 - 2020, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Caches a pointer PEI Services Table.=0D +=0D + Caches the pointer to the PEI Services Table specified by PeiServicesTab= lePointer=0D + in a CPU specific manner as specified in the CPU binding section of the = Platform Initialization=0D + Pre-EFI Initialization Core Interface Specification.=0D +=0D + If PeiServicesTablePointer is NULL, then ASSERT().=0D +=0D + @param PeiServicesTablePointer The address of PeiServices pointer.= =0D +**/=0D +VOID=0D +EFIAPI=0D +SetPeiServicesTablePointer (=0D + IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer=0D + )=0D +{=0D + EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext;=0D + SbiGetFirmwareContext (&FirmwareContext);=0D +=0D + FirmwareContext->PeiServiceTable =3D (VOID *)(UINTN)PeiServicesTablePoin= ter;=0D +=0D + DEBUG ((DEBUG_INFO, "Set PEI Service 0x%x at OpenSBI Firmware Context at= 0x%x\n",=0D + PeiServicesTablePointer,=0D + FirmwareContext=0D + ));=0D +}=0D +=0D +/**=0D + Retrieves the cached value of the PEI Services Table pointer.=0D +=0D + Returns the cached value of the PEI Services Table pointer in a CPU spec= ific manner=0D + as specified in the CPU binding section of the Platform Initialization P= re-EFI=0D + Initialization Core Interface Specification.=0D +=0D + If the cached PEI Services Table pointer is NULL, then ASSERT().=0D +=0D + @return The pointer to PeiServices.=0D +=0D +**/=0D +CONST EFI_PEI_SERVICES **=0D +EFIAPI=0D +GetPeiServicesTablePointer (=0D + VOID=0D + )=0D +{=0D + EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext;=0D + SbiGetFirmwareContext (&FirmwareContext);=0D +=0D + return (CONST EFI_PEI_SERVICES **)FirmwareContext->PeiServiceTable;=0D +}=0D +=0D +/**=0D + The constructor function caches the pointer to PEI services.=0D +=0D + The constructor function caches the pointer to PEI services.=0D + It will always return EFI_SUCCESS.=0D +=0D + @param FileHandle The handle of FFS header the loaded driver.=0D + @param PeiServices The pointer to the PEI services.=0D +=0D + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiServicesTablePointerLibOpenSbiConstructor (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + )=0D +{=0D + SetPeiServicesTablePointer (PeiServices);=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Perform CPU specific actions required to migrate the PEI Services Table= =0D + pointer from temporary RAM to permanent RAM.=0D +=0D + For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes=0D + immediately preceding the Interrupt Descriptor Table (IDT) in memory.=0D + For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes=0D + immediately preceding the Interrupt Descriptor Table (IDT) in memory.=0D + For Itanium, ARM or RISC-V CPUs, a the PEI Services Table Pointer is sto= red in=0D + a dedicated CPU register. This means that there is no memory storage=0D + associated with storing the PEI Services Table pointer, so no additional= =0D + migration actions are required for Itanium, ARM or RISC-V CPUs.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +MigratePeiServicesTablePointer (=0D + VOID=0D + )=0D +{=0D + //=0D + // PEI Services Table pointer is cached in the global variable. No addi= tional=0D + // migration actions are required.=0D + //=0D + return;=0D +}=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLib= OpenSbi/PeiServicesTablePointerLibOpenSbi.uni b/Silicon/RISC-V/ProcessorPkg= /Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePointerLibOpenSb= i.uni new file mode 100644 index 0000000000..f6fad8bcb5 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Library/PeiServicesTablePointerLibOpenSbi= /PeiServicesTablePointerLibOpenSbi.uni @@ -0,0 +1,23 @@ +// /** @file=0D +//=0D +// Instance of PEI Services Table Pointer Library using RISC-V OpenSBI Fir= mwareContext.=0D +//=0D +// PEI Services Table Pointer Library implementation that retrieves a poin= ter to the=0D +// PEI Services Table from a RISC-V OpenSBI sbi_platform firmware context = structure.=0D +//=0D +// Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +//=0D +// This program and the accompanying materials=0D +// are licensed and made available under the terms and conditions of the B= SD License=0D +// which accompanies this distribution. The full text of the license may b= e found at=0D +// http://opensource.org/licenses/bsd-license.php.=0D +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED.=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Instance of PEI S= ervices Table Pointer Library using global variable for the table pointer"= =0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "The PEI Services = Table Pointer Library implementation that retrieves a pointer to the PEI Se= rvices Table from a global variable. Not available to modules that execute = from read-only memory."=0D +=0D --=20 2.31.1