From nobody Sun Feb 8 21:21:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49497+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49497+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1572229916; cv=none; d=zoho.com; s=zohoarc; b=Hwwn/bjxdvcXfSkpISZdmn0zIiFAD2C4Vg4xG1kqxXc6/PkxSPICNW75+CNQ5h1gMHqoFqlZiFU0pRKRYaoMfHHwSW/mpQ9NCsXCMpucPJDc7ZR8hIlmgSpE+7j+bhazSdSUwCRdN2ZuGH38bPCX4yR+ZVpJ/d+tthHaLIgPLJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572229916; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uQ7QMZcsONVIhXGeYt/9NLDaZWjVO3mN6KI357AjYdM=; b=Qbyvs39yui756ogS1paFeZoEMASj4cedWSfKWpu3M5OeuveSRn5/OmzhWOEpc9AhWlBDt7kiUBOVRXmWoFXxWXmYSZN7IOKBo9C7qYZC1yzGPM+w3uHEC/kMIk7xawILoG/4SIw0U+YTCl4egRUcjiQyPItHjMPJeFRnVXDJzJc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49497+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 157222991615341.84806548207007; Sun, 27 Oct 2019 19:31:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZIsqYY1788612x21UTzZJsbk; Sun, 27 Oct 2019 19:31:55 -0700 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web09.616.1572229914731054507 for ; Sun, 27 Oct 2019 19:31:54 -0700 X-Received: from pps.filterd (m0134424.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9S2Vjiw007234; Mon, 28 Oct 2019 02:31:54 GMT X-Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0b-002e3701.pphosted.com with ESMTP id 2vvd4qrwg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 02:31:53 +0000 X-Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id 56FEF54; Mon, 28 Oct 2019 02:31:53 +0000 (UTC) X-Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 04B0447; Mon, 28 Oct 2019 02:31:51 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com, Leif Lindholm , Gilbert Chen Subject: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v3 21/39] RiscVPkg/PeiServicesTablePointerLibOpenSbi: RISC-V PEI Service Table Pointer library Date: Mon, 28 Oct 2019 09:58:59 +0800 Message-Id: <1572227957-13169-22-git-send-email-abner.chang@hpe.com> In-Reply-To: <1572227957-13169-1-git-send-email-abner.chang@hpe.com> References: <1572227957-13169-1-git-send-email-abner.chang@hpe.com> X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: qUZ1EtFhrijmEO9Wt5MkWQfWx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572229915; bh=CEspXM73QUj4mFkOW20UjsGzgkYMdzitVWvHFvNrv7E=; h=Cc:Date:From:Reply-To:Subject:To; b=S7eqZCOTBnGgxJPO62PgbtIsVA3NPM7+ybDQzdhrhD9xDcIjdh06aMICJ0Cj241F/L1 fkZJk7b8gdb6450re/X8LcCJ29McIdpC76wvWW2n5SzcfOulIa01LShCc/ux5+iJcrIxl 99l5uL8LlkpWA85sfFqlp/YT3m74xdT7QOY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implementation of RISC-V PEI Service Table Pointer library using RISC-V OpenSbi. Signed-off-by: Abner Chang Cc: Leif Lindholm Cc: Gilbert Chen --- .../PeiServicesTablePointerLibOpenSbi.inf | 38 +++++++ .../PeiServicesTablePointerOpenSbi.c | 121 +++++++++++++++++= ++++ .../PeiServicesTablePointerLibOpenSbi.uni | 23 ++++ 3 files changed, 182 insertions(+) create mode 100644 RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiS= ervicesTablePointerLibOpenSbi.inf create mode 100644 RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiS= ervicesTablePointerOpenSbi.c create mode 100644 RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiS= ervicesTablePointerLibOpenSbi.uni diff --git a/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServices= TablePointerLibOpenSbi.inf b/RiscVPkg/Library/PeiServicesTablePointerLibOpe= nSbi/PeiServicesTablePointerLibOpenSbi.inf new file mode 100644 index 0000000..0b029ae --- /dev/null +++ b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePo= interLibOpenSbi.inf @@ -0,0 +1,38 @@ +## @file +# Instance of PEI Services Table Pointer Library using RISC-V OpenSBI Firm= wareContext. +# +# PEI Services Table Pointer Library implementation that retrieves a poin= ter to the +# PEI Services Table from a RISC-V OpenSBI sbi_platform firmware context = structure. +# +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D PeiServicesTablePointerLibOpenSbi + MODULE_UNI_FILE =3D PeiServicesTablePointerLibOpenSbi.uni + FILE_GUID =3D B4054E46-FE75-4290-B442-4836B1265D8F + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PeiServicesTablePointerLib|PEIM PEI_C= ORE + + CONSTRUCTOR =3D PeiServicesTablePointerLibOpenSbiCons= tructor + +# +# VALID_ARCHITECTURES =3D RISCV64 +# + +[Sources] + PeiServicesTablePointerOpenSbi.c + +[Packages] + MdePkg/MdePkg.dec + RiscVPkg/RiscVPkg.dec + +[LibraryClasses] + DebugLib + RiscVCpuLib + RiscVOpensbiLib diff --git a/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServices= TablePointerOpenSbi.c b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/= PeiServicesTablePointerOpenSbi.c new file mode 100644 index 0000000..4f09e67 --- /dev/null +++ b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePo= interOpenSbi.c @@ -0,0 +1,121 @@ +/** @file + PEI Services Table Pointer Library. + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include + +/** + Caches a pointer PEI Services Table. + + Caches the pointer to the PEI Services Table specified by PeiServicesTab= lePointer + 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 =3D (struct sbi_platform *)sbi_platform_ptr(sbi_scratch_= thishart_ptr()); + FirmwareContext =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)ThisSbiPlatfor= m->firmware_context; + FirmwareContext->PeiServiceTable =3D (VOID *)(UINTN)PeiServicesTablePoin= ter; + + DEBUG ((DEBUG_INFO, "Set PEI Service 0x%x at OpenSBI Firmware Context at= 0x%x\n", + PeiServicesTablePointer, + ThisSbiPlatform->firmware_context + )); +} + +/** + Retrieves the cached value of the PEI Services Table pointer. + + Returns the cached value of the PEI Services Table pointer in a CPU spec= ific manner + as specified in the CPU binding section of the Platform Initialization P= re-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 =3D (struct sbi_platform *)sbi_platform_ptr(sbi_scratch_= thishart_ptr()); + FirmwareContext =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)ThisSbiPlatfor= m->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 addi= tional + // migration actions are required. + // + return; +} diff --git a/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServices= TablePointerLibOpenSbi.uni b/RiscVPkg/Library/PeiServicesTablePointerLibOpe= nSbi/PeiServicesTablePointerLibOpenSbi.uni new file mode 100644 index 0000000..f6fad8b --- /dev/null +++ b/RiscVPkg/Library/PeiServicesTablePointerLibOpenSbi/PeiServicesTablePo= interLibOpenSbi.uni @@ -0,0 +1,23 @@ +// /** @file +// +// Instance of PEI Services Table Pointer Library using RISC-V OpenSBI Fir= mwareContext. +// +// PEI Services Table Pointer Library implementation that retrieves a poin= ter to the +// PEI Services Table from a RISC-V OpenSBI sbi_platform firmware context = structure. +// +// Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD License +// which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of PEI S= ervices 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 Se= rvices Table from a global variable. Not available to modules that execute = from read-only memory." + --=20 2.7.4 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#49497): https://edk2.groups.io/g/devel/message/49497 Mute This Topic: https://groups.io/mt/38757525/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-