From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web12.3718.1641630353316287302 for ; Sat, 08 Jan 2022 00:25:53 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=W/OavJKU; 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.143.35, mailfrom: prvs=000704d8ca=abner.chang@hpe.com) Received: from pps.filterd (m0134425.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 2084nbfh021995 for ; Sat, 8 Jan 2022 08:25:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=kAkjJJBDRdvd/xiPuYzrlyNI+xBDsMsB01BFv3T4gA0=; b=W/OavJKU3nJCTxc4xM8edliUoZfvaqwzMIBwMKHHahl5wzJDRskqlxlYK1IKtYOqrcvr VW6cMjqUrvGLmghabkObzOMcguBknWbNgp3ioieqgQ+uEHrh0QTAaqnALUVD2mSyPcJA ZKMeksc9DUHbKJZj4JZz1suWvf4ZbdnjfF2Zv8pKM9Mgw3VMEehh4hKQNi5N2LJ5xnIe o5Nwh2vApS+kjFaWzzJrijWw3NkxXxrXxz4qNN1q3t7b+EhvfsNT8Rha8XNx9Rmzh+xG 7Dr7RSFoNukYNtYeD2zn1bubd2hoClrsl4YwoBU2gTQthxK216Juoam03Xg/6vcpoN1Y Gg== Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df3wtgqsm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 08:25:52 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id B0B0281 for ; Sat, 8 Jan 2022 08:25:45 +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 EBDC53B; Sat, 8 Jan 2022 08:25:44 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 42/79] RISC-V: Use RISC-V PeiCoreEntryPoint library Date: Sat, 8 Jan 2022 15:24:25 +0800 Message-Id: <20220108072444.17879-1-abner.chang@hpe.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: qSkgZGKQXYtvpDkvnK0QC_Zrq_rR8MIF X-Proofpoint-ORIG-GUID: qSkgZGKQXYtvpDkvnK0QC_Zrq_rR8MIF 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_03,2022-01-07_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 mlxscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201080064 Content-Transfer-Encoding: quoted-printable (This is migrated from edk2-platforms) 1. Use RISC-V PeiCoreEntryPoint library instance for opensbi to switch to the next phase with arg0 as HART Id and arg1 as the SEC to PEI handoff data. 2. Introduce EDK2 opensbi platform operation functions. With this, OEM can has its won platform initialization code before and/or after opensbi vendor platform functions. Cc: Sunil V L Cc: Daniel Schaefer Signed-off-by: Abner Chang Reviewed-by: Daniel Schaefer Reviewed-by: Sunil V L --- .../PlatformPkg/Universal/Sec/SecMain.inf | 2 + .../PlatformPkg/Universal/Sec/SecMain.h | 10 + .../Include/IndustryStandard/RiscVOpensbi.h | 8 +- .../Universal/Sec/Edk2OpenSbiPlatform.c | 426 ++++++++++++++++++ .../PlatformPkg/Universal/Sec/SecMain.c | 152 +++++-- 5 files changed, 545 insertions(+), 53 deletions(-) create mode 100644 Platform/RISC-V/PlatformPkg/Universal/Sec/Edk2OpenSbiPl= atform.c diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf b/Platfo= rm/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf index bcb8b9f908..4207c83413 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf @@ -23,11 +23,13 @@ =0D [Sources]=0D SecMain.c=0D + Edk2OpenSbiPlatform.c=0D =0D [Sources.RISCV64]=0D Riscv64/SecEntry.S=0D =0D [Packages]=0D + EmbeddedPkg/EmbeddedPkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D MdePkg/MdePkg.dec=0D Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.h b/Platform= /RISC-V/PlatformPkg/Universal/Sec/SecMain.h index 94ea46263c..c04ddbad7f 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.h +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.h @@ -28,6 +28,16 @@ #include =0D #include =0D =0D +int=0D +SecPostOpenSbiPlatformEarlylInit(=0D + IN BOOLEAN ColdBoot=0D + );=0D +=0D +int=0D +SecPostOpenSbiPlatformFinalInit (=0D + IN BOOLEAN ColdBoot=0D + );=0D +=0D VOID=0D SecMachineModeTrapHandler (=0D IN VOID=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpen= sbi.h b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h index e7ac6d26ee..d639429306 100644 --- a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h +++ b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscVOpensbi.h @@ -1,7 +1,7 @@ /** @file=0D SBI inline function calls.=0D =0D - Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -46,8 +46,10 @@ typedef struct { // structure. Referr= ed by both C code and assembly code.=0D =0D typedef struct {=0D - VOID *PeiServiceTable; // PEI Service table=0D - UINT64 FlattenedDeviceTree; // Pointer to Flattened Device t= ree=0D + UINT64 BootHartId;=0D + VOID *PeiServiceTable; // PEI Service table=0D + UINT64 FlattenedDeviceTree; // Pointer to Flattened Devic= e tree=0D + UINT64 SecPeiHandOffData; // This is EFI_SEC_PEI_HAND_O= FF passed to PEI Core.=0D EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartSpecific[RISC_V_MAX_HART_= SUPPORTED];=0D } EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT;=0D =0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/Edk2OpenSbiPlatform.= c b/Platform/RISC-V/PlatformPkg/Universal/Sec/Edk2OpenSbiPlatform.c new file mode 100644 index 0000000000..79b2f33675 --- /dev/null +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/Edk2OpenSbiPlatform.c @@ -0,0 +1,426 @@ +/*=0D + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D + */=0D +=0D +#include =0D +#include =0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include "SecMain.h"=0D +=0D +extern struct sbi_platform_operations platform_ops;=0D +=0D +int Edk2OpensbiPlatformEarlyInit (=0D + BOOLEAN ColdBoot=0D + )=0D +{=0D + int ReturnCode;=0D +=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.early_init) {=0D + ReturnCode =3D platform_ops.early_init (ColdBoot);=0D + if (ReturnCode) {=0D + return ReturnCode;=0D + }=0D + }=0D + if (ColdBoot =3D=3D TRUE) {=0D + return SecPostOpenSbiPlatformEarlylInit(ColdBoot);=0D + }=0D + return 0;=0D +}=0D +=0D +int Edk2OpensbiPlatformFinalInit (=0D + BOOLEAN ColdBoot=0D + )=0D +{=0D + int ReturnCode;=0D +=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.final_init) {=0D + ReturnCode =3D platform_ops.final_init (ColdBoot);=0D + if (ReturnCode) {=0D + return ReturnCode;=0D + }=0D + }=0D + if (ColdBoot =3D=3D TRUE) {=0D + return SecPostOpenSbiPlatformFinalInit(ColdBoot);=0D + }=0D + return 0;=0D +}=0D +=0D +VOID Edk2OpensbiPlatformEarlyExit (=0D + VOID=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.early_exit) {=0D + return platform_ops.early_exit ();=0D + }=0D +}=0D +=0D +/** Platform final exit */=0D +VOID Edk2OpensbiPlatformFinalExit (=0D + VOID=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.early_exit) {=0D + return platform_ops.early_exit ();=0D + }=0D +}=0D +=0D +/**=0D + For platforms that do not implement misa, non-standard=0D + methods are needed to determine cpu extension.=0D +**/=0D +int Edk2OpensbiPlatforMMISACheckExtension (=0D + CHAR8 Extension=0D + )=0D +{=0D + if (platform_ops.misa_check_extension) {=0D + return platform_ops.misa_check_extension (Extension);=0D + }=0D + return 0;=0D +}=0D +=0D +/**=0D + For platforms that do not implement misa, non-standard=0D + methods are needed to get MXL field of misa.=0D +**/=0D +int Edk2OpensbiPlatforMMISAGetXLEN (VOID)=0D +{=0D + if (platform_ops.misa_get_xlen) {=0D + return platform_ops.misa_get_xlen ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Get platform specific root domain memory regions */=0D +struct sbi_domain_memregion *=0D +Edk2OpensbiPlatformGetMemRegions (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.domains_root_regions) {=0D + return platform_ops.domains_root_regions ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Initialize (or populate) domains for the platform */=0D +int Edk2OpensbiPlatformDomainsInit (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.domains_init) {=0D + return platform_ops.domains_init ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Write a character to the platform console output */=0D +VOID Edk2OpensbiPlatformSerialPutc (=0D + CHAR8 Ch=0D + )=0D +{=0D + if (platform_ops.console_putc) {=0D + return platform_ops.console_putc (Ch);=0D + }=0D +}=0D +=0D +/** Read a character from the platform console input */=0D +int Edk2OpensbiPlatformSerialGetc (VOID)=0D +{=0D + if (platform_ops.console_getc) {=0D + return platform_ops.console_getc ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Initialize the platform console */=0D +int Edk2OpensbiPlatformSerialInit (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.console_init) {=0D + return platform_ops.console_init ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Initialize the platform interrupt controller for current HART */=0D +int Edk2OpensbiPlatformIrqchipInit (=0D + BOOLEAN ColdBoot=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.irqchip_init) {=0D + return platform_ops.irqchip_init (ColdBoot);=0D + }=0D + return 0;=0D +}=0D +=0D +/** Exit the platform interrupt controller for current HART */=0D +VOID Edk2OpensbiPlatformIrqchipExit (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.irqchip_exit) {=0D + return platform_ops.irqchip_exit ();=0D + }=0D +}=0D +=0D +/** Send IPI to a target HART */=0D +VOID Edk2OpensbiPlatformIpiSend (=0D + UINT32 TargetHart=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.ipi_send) {=0D + return platform_ops.ipi_send (TargetHart);=0D + }=0D +}=0D +=0D +/** Clear IPI for a target HART */=0D +VOID Edk2OpensbiPlatformIpiClear (=0D + UINT32 TargetHart=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.ipi_clear) {=0D + return platform_ops.ipi_clear (TargetHart);=0D + }=0D +}=0D +=0D +/** Initialize IPI for current HART */=0D +int Edk2OpensbiPlatformIpiInit (=0D + BOOLEAN ColdBoot=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.ipi_init) {=0D + return platform_ops.ipi_init (ColdBoot);=0D + }=0D + return 0;=0D +}=0D +=0D +/** Exit IPI for current HART */=0D +VOID Edk2OpensbiPlatformIpiExit (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.ipi_exit) {=0D + return platform_ops.ipi_exit ();=0D + }=0D +}=0D +=0D +/** Get tlb flush limit value **/=0D +UINT64 Edk2OpensbiPlatformTlbrFlushLimit (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.get_tlbr_flush_limit) {=0D + return platform_ops.get_tlbr_flush_limit ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Get platform timer value */=0D +UINT64 Edk2OpensbiPlatformTimerValue (VOID)=0D +{=0D + if (platform_ops.timer_value) {=0D + return platform_ops.timer_value ();=0D + }=0D + return 0;=0D +}=0D +=0D +/** Start platform timer event for current HART */=0D +VOID Edk2OpensbiPlatformTimerEventStart (=0D + UINT64 NextEvent=0D + )=0D +{=0D + if (platform_ops.timer_event_start) {=0D + return platform_ops.timer_event_start (NextEvent);=0D + }=0D +}=0D +=0D +/** Stop platform timer event for current HART */=0D +VOID Edk2OpensbiPlatformTimerEventStop (VOID)=0D +{=0D + if (platform_ops.timer_event_stop) {=0D + return platform_ops.timer_event_stop ();=0D + }=0D +}=0D +=0D +/** Initialize platform timer for current HART */=0D +int Edk2OpensbiPlatformTimerInit (=0D + BOOLEAN ColdBoot=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.timer_init) {=0D + return platform_ops.timer_init (ColdBoot);=0D + }=0D + return 0;=0D +}=0D +=0D +/** Exit platform timer for current HART */=0D +VOID Edk2OpensbiPlatformTimerExit (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.timer_exit) {=0D + return platform_ops.timer_exit ();=0D + }=0D +}=0D +=0D +/** Bringup the given hart */=0D +int Edk2OpensbiPlatformHartStart (=0D + UINT32 HartId,=0D + ulong Saddr=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.hart_start) {=0D + return platform_ops.hart_start (HartId, Saddr);=0D + }=0D + return 0;=0D +}=0D +/**=0D + Stop the current hart from running. This call doesn't expect to=0D + return if success.=0D +**/=0D +int Edk2OpensbiPlatformHartStop (VOID)=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.hart_stop) {=0D + return platform_ops.hart_stop ();=0D + }=0D + return 0;=0D +}=0D +=0D +/**=0D + Check whether reset type and reason supported by the platform*=0D +=0D +**/=0D +int Edk2OpensbiPlatformSystemResetCheck (=0D + UINT32 ResetType,=0D + UINT32 ResetReason=0D + )=0D +{=0D + if (platform_ops.system_reset_check) {=0D + return platform_ops.system_reset_check (ResetType, ResetReason);=0D + }=0D + return 0;=0D +}=0D +=0D +/** Reset the platform */=0D +VOID Edk2OpensbiPlatformSystemReset (=0D + UINT32 ResetType,=0D + UINT32 ResetReason=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.system_reset) {=0D + return platform_ops.system_reset (ResetType, ResetReason);=0D + }=0D +}=0D +=0D +/** platform specific SBI extension implementation probe function */=0D +int Edk2OpensbiPlatformVendorExtCheck (=0D + long ExtId=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.vendor_ext_check) {=0D + return platform_ops.vendor_ext_check (ExtId);=0D + }=0D + return 0;=0D +}=0D +=0D +=0D +/** platform specific SBI extension implementation provider */=0D +int Edk2OpensbiPlatformVendorExtProvider (=0D + long ExtId,=0D + long FuncId,=0D + const struct sbi_trap_regs *Regs,=0D + unsigned long *OutValue,=0D + struct sbi_trap_info *OutTrap=0D + )=0D +{=0D + DEBUG((DEBUG_INFO, "%a: Entry\n", __FUNCTION__));=0D +=0D + if (platform_ops.vendor_ext_provider) {=0D + return platform_ops.vendor_ext_provider (=0D + ExtId,=0D + FuncId,=0D + Regs,=0D + OutValue,=0D + OutTrap=0D + );=0D + }=0D + return 0;=0D +}=0D +=0D +const struct sbi_platform_operations Edk2OpensbiPlatformOps =3D {=0D + .early_init =3D Edk2OpensbiPlatformEarlyInit,=0D + .final_init =3D Edk2OpensbiPlatformFinalInit,=0D + .early_exit =3D Edk2OpensbiPlatformEarlyExit,=0D + .final_exit =3D Edk2OpensbiPlatformFinalExit,=0D + .misa_check_extension =3D Edk2OpensbiPlatforMMISACheckExtension,=0D + .misa_get_xlen =3D Edk2OpensbiPlatforMMISAGetXLEN,=0D + .domains_root_regions =3D Edk2OpensbiPlatformGetMemRegions,=0D + .domains_init =3D Edk2OpensbiPlatformDomainsInit,=0D + .console_putc =3D Edk2OpensbiPlatformSerialPutc,=0D + .console_getc =3D Edk2OpensbiPlatformSerialGetc,=0D + .console_init =3D Edk2OpensbiPlatformSerialInit,=0D + .irqchip_init =3D Edk2OpensbiPlatformIrqchipInit,=0D + .irqchip_exit =3D Edk2OpensbiPlatformIrqchipExit,=0D + .ipi_send =3D Edk2OpensbiPlatformIpiSend,=0D + .ipi_clear =3D Edk2OpensbiPlatformIpiClear,=0D + .ipi_init =3D Edk2OpensbiPlatformIpiInit,=0D + .ipi_exit =3D Edk2OpensbiPlatformIpiExit,=0D + .get_tlbr_flush_limit =3D Edk2OpensbiPlatformTlbrFlushLimit,=0D + .timer_value =3D Edk2OpensbiPlatformTimerValue,=0D + .timer_event_stop =3D Edk2OpensbiPlatformTimerEventStop,=0D + .timer_event_start =3D Edk2OpensbiPlatformTimerEventStart,=0D + .timer_init =3D Edk2OpensbiPlatformTimerInit,=0D + .timer_exit =3D Edk2OpensbiPlatformTimerExit,=0D + .hart_start =3D Edk2OpensbiPlatformHartStart,=0D + .hart_stop =3D Edk2OpensbiPlatformHartStop,=0D + .system_reset_check =3D Edk2OpensbiPlatformSystemResetCheck,=0D + .system_reset =3D Edk2OpensbiPlatformSystemReset,=0D + .vendor_ext_check =3D Edk2OpensbiPlatformVendorExtCheck,=0D + .vendor_ext_provider =3D Edk2OpensbiPlatformVendorExtProvider,=0D +};=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c b/Platform= /RISC-V/PlatformPkg/Universal/Sec/SecMain.c index e88a7b8e80..44984b0078 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c @@ -23,6 +23,8 @@ #include // Reference to header file in opensbi=0D #include // Reference to header file in opensbi=0D =0D +extern struct sbi_platform_operations Edk2OpensbiPlatformOps;=0D +=0D //=0D // Indicates the boot hart (PcdBootHartId) OpenSBI initialization is done.= =0D //=0D @@ -31,27 +33,6 @@ atomic_t NonBootHartMessageLock =3D ATOMIC_INITIALIZER(0= ); =0D typedef struct sbi_scratch *(*hartid2scratch)(ulong hartid, ulong hartinde= x);=0D =0D -STATIC EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi =3D {=0D - TemporaryRamMigration=0D -};=0D -=0D -STATIC EFI_PEI_TEMPORARY_RAM_DONE_PPI mTemporaryRamDonePpi =3D {=0D - TemporaryRamDone=0D -};=0D -=0D -STATIC EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable[] =3D {=0D - {=0D - EFI_PEI_PPI_DESCRIPTOR_PPI,=0D - &gEfiTemporaryRamSupportPpiGuid,=0D - &mTemporaryRamSupportPpi=0D - },=0D - {=0D - (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),= =0D - &gEfiTemporaryRamDonePpiGuid,=0D - &mTemporaryRamDonePpi=0D - },=0D -};=0D -=0D /**=0D Locates a section within a series of sections=0D with the specified section type.=0D @@ -491,6 +472,91 @@ RegisterFirmwareSbiExtension ( =0D return EFI_SUCCESS;=0D }=0D +=0D +/**=0D + OpenSBI platform early init hook.=0D +=0D +**/=0D +int=0D +SecPostOpenSbiPlatformEarlylInit(=0D + IN BOOLEAN ColdBoot=0D + )=0D +{=0D + //=0D + // Boot HART is already in the process of OpenSBI initialization.=0D + // We can let other HART to keep booting.=0D + //=0D + DEBUG ((DEBUG_INFO, "%a: Set boot hart done.\n", __FUNCTION__));=0D + atomic_write (&BootHartDone, (UINT64)TRUE);=0D + return 0;=0D +}=0D +=0D +/**=0D + OpenSBI platform final init hook.=0D + We restore the next_arg1 to the pointer of EFI_RISCV_OPENSBI_FIRMWARE_CO= NTEXT.=0D +=0D +**/=0D +int=0D +SecPostOpenSbiPlatformFinalInit (=0D + IN BOOLEAN ColdBoot=0D + )=0D +{=0D + UINT32 HartId;=0D + struct sbi_scratch *SbiScratch;=0D + struct sbi_scratch *ScratchSpace;=0D + struct sbi_platform *SbiPlatform;=0D + EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext;=0D +=0D + DEBUG((DEBUG_INFO, "%a: Entry, preparing to jump to PEI Core\n\n", __FUN= CTION__));=0D +=0D + SbiScratch =3D sbi_scratch_thishart_ptr();=0D + SbiPlatform =3D (struct sbi_platform *)sbi_platform_ptr(SbiScratch);=0D + FirmwareContext =3D (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)SbiPlatform->f= irmware_context;=0D +=0D + //=0D + // Print out scratch address of each hart=0D + //=0D + DEBUG ((DEBUG_INFO, "%a: OpenSBI scratch address for each hart:\n", __FU= NCTION__));=0D + for (HartId =3D 0; HartId < SBI_HARTMASK_MAX_BITS; HartId ++) {=0D + if (sbi_platform_hart_invalid(SbiPlatform, HartId)) {=0D + continue;=0D + }=0D + ScratchSpace =3D sbi_hartid_to_scratch (HartId);=0D + if(ScratchSpace !=3D NULL) {=0D + DEBUG((DEBUG_INFO, " Hart %d: 0x%x\n", HartId, ScratchSpace= ));=0D + } else {=0D + DEBUG((DEBUG_INFO, " Hart %d not initialized yet\n", HartId= ));=0D + }=0D + }=0D +=0D + //=0D + // Set firmware context Hart-specific pointer=0D + //=0D + for (HartId =3D 0; HartId < SBI_HARTMASK_MAX_BITS; HartId ++) {=0D + if (sbi_platform_hart_invalid(SbiPlatform, HartId)) {=0D + continue;=0D + }=0D + ScratchSpace =3D sbi_hartid_to_scratch (HartId);=0D + if (ScratchSpace !=3D NULL) {=0D + FirmwareContext->HartSpecific[HartId] =3D=0D + (EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *)((UINT8 *)ScratchSpace= - FIRMWARE_CONTEXT_HART_SPECIFIC_SIZE);=0D + DEBUG ((DEBUG_INFO, "%a: OpenSBI Hart %d Firmware Context Hart-spe= cific at address: 0x%x\n",=0D + __FUNCTION__,=0D + HartId,=0D + FirmwareContext->HartSpecific [HartId]=0D + ));=0D + }=0D + }=0D +=0D + DEBUG((DEBUG_INFO, "%a: Jump to PEI Core with \n", __FUNCTION__));=0D + DEBUG((DEBUG_INFO, " sbi_scratch =3D %x\n", SbiScratch));=0D + DEBUG((DEBUG_INFO, " sbi_platform =3D %x\n", SbiPlatform));=0D + DEBUG((DEBUG_INFO, " FirmwareContext =3D %x\n", FirmwareContext));=0D + SbiScratch->next_arg1 =3D (unsigned long)FirmwareContext;=0D +=0D + return 0;=0D +}=0D +=0D /** Transion from SEC phase to PEI phase.=0D =0D This function transits to S-mode PEI phase from M-mode SEC phase.=0D @@ -508,9 +574,7 @@ VOID EFIAPI PeiCore ( EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;=0D EFI_FIRMWARE_VOLUME_HEADER *BootFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)Fix= edPcdGet32(PcdRiscVPeiFvBase);=0D EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT FirmwareContext;=0D - struct sbi_scratch *ScratchSpace;=0D struct sbi_platform *ThisSbiPlatform;=0D - UINT32 HartId;=0D =0D FindAndReportEntryPoints (&BootFv, &PeiCoreEntryPoint);=0D =0D @@ -524,17 +588,6 @@ VOID EFIAPI PeiCore ( SecCoreData.StackBase =3D (UINT8 *)SecCoreData.TemporaryRam= Base + (SecCoreData.TemporaryRamSize >> 1);=0D SecCoreData.StackSize =3D SecCoreData.TemporaryRamSize >> 1= ;=0D =0D - //=0D - // Print out scratch address of each hart=0D - //=0D - DEBUG ((DEBUG_INFO, "%a: OpenSBI scratch address for each hart:\n", __FU= NCTION__));=0D - for (HartId =3D 0; HartId < SBI_HARTMASK_MAX_BITS; HartId ++) {=0D - ScratchSpace =3D sbi_hartid_to_scratch (HartId);=0D - if(ScratchSpace !=3D NULL) {=0D - DEBUG((DEBUG_INFO, " Hart %d: 0x%x\n", HartId, ScratchSpace= ));=0D - }=0D - }=0D -=0D //=0D // Set up OpepSBI firmware context pointer on boot hart OpenSbi scratch.= =0D // Firmware context residents in stack and will be switched to memory wh= en=0D @@ -564,20 +617,10 @@ VOID EFIAPI PeiCore ( FirmwareContext.FlattenedDeviceTree =3D Scratch->next_arg1;=0D =0D //=0D - // Set firmware context Hart-specific pointer=0D + // Transfer the control to the PEI core=0D //=0D - for (HartId =3D 0; HartId < SBI_HARTMASK_MAX_BITS; HartId ++) {=0D - ScratchSpace =3D sbi_hartid_to_scratch (HartId);=0D - if (ScratchSpace !=3D NULL) {=0D - FirmwareContext.HartSpecific[HartId] =3D=0D - (EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *)((UINT8 *)ScratchSpace= - FIRMWARE_CONTEXT_HART_SPECIFIC_SIZE);=0D - DEBUG ((DEBUG_INFO, "%a: OpenSBI Hart %d Firmware Context Hart-spe= cific at address: 0x%x\n",=0D - __FUNCTION__,=0D - HartId,=0D - FirmwareContext.HartSpecific [HartId]=0D - ));=0D - }=0D - }=0D + FirmwareContext.SecPeiHandOffData =3D (UINT64)&SecCoreData;=0D +=0D //=0D // Set supervisor translation mode to Bare mode=0D //=0D @@ -585,13 +628,12 @@ VOID EFIAPI PeiCore ( RiscVSetSupervisorAddressTranslationRegister ((UINT64)RISCV_SATP_MODE_OF= F << RISCV_SATP_MODE_BIT_POSITION);=0D =0D //=0D - // Transfer the control to the PEI core=0D + // Scratch->next_arg1 is the device tree.=0D //=0D - Scratch->next_addr =3D (UINTN)(*PeiCoreEntryPoint);=0D + Scratch->next_addr =3D (UINTN)(PeiCoreEntryPoint);=0D Scratch->next_mode =3D PRV_S;=0D DEBUG ((DEBUG_INFO, "%a: Initializing OpenSBI library for booting hart %= d\n", __FUNCTION__, BootHartId));=0D sbi_init(Scratch);=0D - (*PeiCoreEntryPoint) (&SecCoreData, (EFI_PEI_PPI_DESCRIPTOR *)&mPrivateD= ispatchTable);=0D }=0D =0D /**=0D @@ -715,6 +757,7 @@ VOID EFIAPI SecCoreStartUpWithStack( {=0D UINT64 BootHartDoneSbiInit;=0D UINT64 NonBootHartMessageLockValue;=0D + struct sbi_platform *ThisSbiPlatform;=0D EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *HartFirmwareContext;=0D =0D Scratch->next_arg1 =3D (unsigned long)GetDeviceTreeAddress ();=0D @@ -737,6 +780,14 @@ VOID EFIAPI SecCoreStartUpWithStack( HartFirmwareContext->MachineImplId.Value64_H =3D 0;=0D HartFirmwareContext->HartSwitchMode =3D RiscVOpenSbiHartSwitchMode;=0D =0D + //=0D + // Hook platorm_ops with EDK2 one. Thus we can have interface=0D + // call out to OEM EDK2 platform code in M-mode before switching=0D + // to S-mode in opensbo init.=0D + //=0D + ThisSbiPlatform =3D (struct sbi_platform *)sbi_platform_ptr(Scratch);=0D + ThisSbiPlatform->platform_ops_addr =3D (unsigned long)&Edk2OpensbiPlatfo= rmOps;=0D +=0D if (HartId =3D=3D FixedPcdGet32(PcdBootHartId)) {=0D LaunchPeiCore (HartId, Scratch);=0D }=0D @@ -768,6 +819,7 @@ VOID EFIAPI SecCoreStartUpWithStack( // Non boot hart wiil be halted waiting for SBI_HART_STARTING.=0D // Use HSM ecall to start non boot hart (SBI_EXT_HSM_HART_START) later o= n,=0D //=0D + Scratch->next_mode =3D PRV_S;=0D sbi_init(Scratch);=0D }=0D =0D --=20 2.31.1