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.web11.3753.1641630353606902894 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=ToDifCVc; 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 2084t0qF027565 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 : in-reply-to : references : mime-version : content-transfer-encoding; s=pps0720; bh=BUwqhQ6z6XFwO0Q4sxjIye/Oq4yiPxKsyQhPqd3JpvM=; b=ToDifCVcojnJBJ17V7IxcN1VdBv5qLk6L4IMnc3toIxSLtMChRJnWXIsCOXNb31PdECC 4G5lLHC6lZLRauaO+GcxzDmFsev+498OVrObQEfjAL7eUDDZFOJVpX/6rI4ySsQH7xul P5Cj4ZZiL0bQ7R4Fl+geUTFMokcBmHG69Xawr+MRR5FxjizDkHVGX84IiDAJZopdRnjo q1HjxCoO2A7me+L3j7ZXK8IrJFIKPJlxg1cxSu6lSF0u6ScvNuZtcKzBgd0T3K3cTmpM Yo9G7perj2F71JS9js4nzciW1fGpGK8tIrYl9nGHDmGzfXQdGRl9B2mysm2Z2bve+yFq wA== Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df40k8pmr-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 E0D8F91 for ; Sat, 8 Jan 2022 08:25:51 +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 34B1039; Sat, 8 Jan 2022 08:25:51 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 48/79] RiscVPlatformPkg/Sec: Initial hart_index2Id array Date: Sat, 8 Jan 2022 15:24:31 +0800 Message-Id: <20220108072444.17879-7-abner.chang@hpe.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220108072444.17879-1-abner.chang@hpe.com> References: <20220108072444.17879-1-abner.chang@hpe.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: d6E38YSPX9hYjn10qRSmwiGPsSKGbVdW X-Proofpoint-GUID: d6E38YSPX9hYjn10qRSmwiGPsSKGbVdW 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 suspectscore=0 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 phishscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201080063 Content-Transfer-Encoding: quoted-printable (This is migrated from edk2-platforms:Platform) Initial hart index to Id array by invoking OpenSBI fw_platform_init function. Introduce PcdBootableHartIndexToId PCD which could be used to overwrite the hart_index2Id arrary built from Devie tree according to platform demand. Cc: Sunil V L Cc: Daniel Schaefer Signed-off-by: Abner Chang Reviewed-by: Daniel Schaefer Reviewed-by: Sunil V L --- .../RISC-V/PlatformPkg/RiscVPlatformPkg.dec | 13 +++- .../RISC-V/PlatformPkg/RiscVPlatformPkg.dsc | 3 +- .../PlatformPkg/Universal/Sec/SecMain.inf | 2 + .../PlatformPkg/Universal/Sec/SecMain.c | 62 ++++++++++++++++--- .../Universal/Sec/Riscv64/SecEntry.S | 29 ++++++++- 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dec b/Platform/RI= SC-V/PlatformPkg/RiscVPlatformPkg.dec index 7e41e7bdb2..947ae40e20 100644 --- a/Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dec +++ b/Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dec @@ -55,10 +55,21 @@ gUefiRiscVPlatformPkgTokenSpaceGuid.PcdHartCount|0|UINT32|0x00001083=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootHartId|0|UINT32|0x00001084=0D #=0D -# The bootable hart core number, which is incorporate with OpenSBI platfor= m hart_index2id value.=0D +# The bootable hart core number, which incorporates with OpenSBI platform = hart_index2id value.=0D +# PcdBootableHartNumber =3D 0 means the number of bootable hart comes from= Device Tree.=0D +# Otherwise the number assigned in PcdBootableHartNumber overwrite it.=0D #=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootableHartNumber|0|UINT32|0x000= 01085=0D #=0D +# PcdBootableHartIndexToId is valid if PcdBootableHartNumber !=3D 0.=0D +# If PcdBootableHartNumber !=3D 0, then PcdBootableHartIndexToId is an arr= ay of=0D +# bootable hart ID.=0D +# For example,=0D +# if PcdBootableHartNumber =3D=3D 3 then PcdBootableHartIndexToId could be= defined=0D +# as {0x1, 0x2, 0x3}.=0D +#=0D + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootableHartIndexToId|NULL|VOID*|= 0x00001086=0D +#=0D # Definitions for OpenSbi=0D #=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdScratchRamBase|0|UINT32|0x0000110= 0=0D diff --git a/Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dsc b/Platform/RI= SC-V/PlatformPkg/RiscVPlatformPkg.dsc index 93b3cd8de9..97d5dd08a0 100644 --- a/Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dsc +++ b/Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dsc @@ -39,7 +39,8 @@ !include MdePkg/MdeLibs.dsc.inc=0D =0D [LibraryClasses.common]=0D - RiscVOpensbiPlatformLib|Platform/RISC-V/PlatformPkg/Library/OpensbiPlatf= ormLibNull/OpensbiPlatformLibNull.inf=0D + FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf=0D + RiscVOpensbiPlatformLib|Platform/RISC-V/PlatformPkg/Library/OpensbiPlatf= ormLib/OpensbiPlatformLib.inf=0D RiscVCpuLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVCpuLib/RiscVCpuLib.= inf=0D RiscVEdk2SbiLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/Risc= VEdk2SbiLib.inf=0D RiscVOpensbiLib|Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/Risc= VOpensbiLib.inf=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf b/Platfo= rm/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf index 9736277fa1..1cfbef961f 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf @@ -41,6 +41,7 @@ DebugAgentLib=0D DebugLib=0D ExtractGuidedSectionLib=0D + FdtLib=0D IoLib=0D PcdLib=0D PeCoffLib=0D @@ -62,6 +63,7 @@ gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootHartId=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdHartCount=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootableHartNumber=0D + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootableHartIndexToId=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRootFirmwareDomainBaseAddress=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRootFirmwareDomainSize=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdOpenSbiStackSize=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c b/Platform= /RISC-V/PlatformPkg/Universal/Sec/SecMain.c index fb0adbca54..51d9edfe75 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c @@ -615,16 +615,17 @@ GetDeviceTreeAddress ( EFI_COMMON_SECTION_HEADER *FoundSection;=0D =0D if (FixedPcdGet32 (PcdDeviceTreeAddress)) {=0D + DEBUG ((DEBUG_INFO, "Use fixed address of DBT from PcdDeviceTreeAddr= ess.\n"));=0D return (VOID *)*((unsigned long *)FixedPcdGet32 (PcdDeviceTreeAddres= s));=0D } else if (FixedPcdGet32 (PcdRiscVDtbFvBase)) {=0D + DEBUG ((DEBUG_INFO, "Use DBT FV\n"));=0D Status =3D FindFfsFileAndSection (=0D (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32 (PcdRiscVDtbF= vBase),=0D EFI_FV_FILETYPE_FREEFORM,=0D EFI_SECTION_RAW,=0D &FoundSection=0D - );=0D + );=0D if (EFI_ERROR(Status)) {=0D - DEBUG ((DEBUG_ERROR, "Platform Device Tree is not found from FV.\n= "));=0D return NULL;=0D }=0D FoundSection ++;=0D @@ -635,6 +636,35 @@ GetDeviceTreeAddress ( }=0D return NULL;=0D }=0D +/**=0D + Overwrite hart_index2id array if platform would like to use the=0D + bootable harts other than those declared in Device Tree=0D +=0D + @param[in] SbiPlatform Pointer to SBI platform=0D + @retval hart_index2id Index to ID value may be overwrote.=0D + @retval hart_count Index to ID value may be overwrote.=0D +=0D +**/=0D +VOID=0D +Edk2PlatformHartIndex2Id (=0D + IN struct sbi_platform *SbiPlatform=0D + )=0D +{=0D + UINT32 Index;=0D + UINT32 *HartIndexToId;=0D + UINT32 BootableHartCount;=0D + UINT8 *PlatformHartIndex2IdArray;=0D +=0D + BootableHartCount =3D FixedPcdGet32(PcdBootableHartNumber);=0D + if (BootableHartCount !=3D 0) {=0D + HartIndexToId =3D (UINT32 *)SbiPlatform->hart_index2id;=0D + PlatformHartIndex2IdArray =3D (UINT8 *)FixedPcdGetPtr (PcdBootableHart= IndexToId);=0D + for (Index =3D 0; Index < BootableHartCount; Index++) {=0D + *(HartIndexToId + Index) =3D (UINT32)(*(PlatformHartIndex2IdArray + = Index));=0D + }=0D + SbiPlatform->hart_count =3D BootableHartCount;=0D + }=0D +}=0D =0D /**=0D This function initilizes hart specific information and SBI.=0D @@ -671,17 +701,13 @@ VOID EFIAPI SecCoreStartUpWithStack( IN struct sbi_scratch *Scratch=0D )=0D {=0D + UINT32 HardIndex;=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 - if (Scratch->next_arg1 =3D=3D (unsigned long)NULL) {=0D - DEBUG ((DEBUG_ERROR, "Platform Device Tree is not found\n"));=0D - ASSERT (FALSE);=0D - }=0D - DEBUG ((DEBUG_INFO, "DTB address: 0x%08x\n", Scratch->next_arg1));=0D + DEBUG ((DEBUG_INFO, "HART ID: 0x%x enter SecCoreStartUpWithStack\n", Har= tId));=0D =0D //=0D // Setup EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC for each hart.=0D @@ -705,6 +731,18 @@ VOID EFIAPI SecCoreStartUpWithStack( ThisSbiPlatform->platform_ops_addr =3D (unsigned long)&Edk2OpensbiPlatfo= rmOps;=0D =0D if (HartId =3D=3D FixedPcdGet32(PcdBootHartId)) {=0D +=0D + Scratch->next_arg1 =3D (unsigned long)GetDeviceTreeAddress ();=0D + if (Scratch->next_arg1 =3D=3D (unsigned long)NULL) {=0D + DEBUG ((DEBUG_ERROR, "Platform Device Tree is not found\n"));=0D + ASSERT (FALSE);=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "HART number: 0x%x\n", ThisSbiPlatform->hart_count= ));=0D + DEBUG ((DEBUG_INFO, "HART index to HART ID:\n"));=0D + for (HardIndex =3D 0; HardIndex < ThisSbiPlatform->hart_count; HardInd= ex ++) {=0D + DEBUG ((DEBUG_INFO, " Index: %d -> Hard ID: %x\n", HardIndex, ThisS= biPlatform->hart_index2id [HardIndex]));=0D + }=0D LaunchPeiCore (HartId, Scratch);=0D }=0D =0D @@ -739,3 +777,11 @@ VOID EFIAPI SecCoreStartUpWithStack( sbi_init(Scratch);=0D }=0D =0D +void xxxx (char *debugstr, ...)=0D +{=0D + VA_LIST Marker;=0D +=0D + VA_START (Marker, debugstr);=0D + DebugVPrint (DEBUG_INFO, debugstr, Marker);=0D + VA_END (Marker);=0D +}=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S b= /Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S index b3eccf92eb..f0c3dff0d9 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S @@ -101,16 +101,35 @@ _scratch_init: /* Loop to next hart */=0D blt t1, s7, _scratch_init=0D =0D - /* Fill-out temporary memory with 55aa*/=0D + li a4, FixedPcdGet32 (PcdTemporaryRamBase)=0D + li a5, FixedPcdGet32 (PcdTemporaryRamSize)=0D +=0D + /* Use Temp memory as the stack for calling to C code */=0D + add sp, a4, a5=0D + /* Get the address of device tree and call generic fw_platform_init */=0D + call GetDeviceTreeAddress /* a0 return the device tree address */=0D + beqz a0, skip_fw_init=0D + add a1, a0, 0 /* a1 is device tree */=0D + csrr a0, CSR_MHARTID /* a0 is hart ID */=0D + call fw_platform_init=0D +skip_fw_init:=0D +=0D + /* Zero out temporary memory */=0D li a4, FixedPcdGet32 (PcdTemporaryRamBase)=0D li a5, FixedPcdGet32 (PcdTemporaryRamSize)=0D add a5, a4, a5=0D 1:=0D - li a3, 0x5AA55AA55AA55AA5=0D + li a3, 0x0=0D sd a3, (a4)=0D add a4, a4, __SIZEOF_POINTER__=0D blt a4, a5, 1b=0D =0D + /* Overwrite hart_index2id array of=0D + platform would like to use the bootable hart=0D + other than it defined in Device Tree */=0D + la a0, platform=0D + call Edk2PlatformHartIndex2Id=0D +=0D /* Update boot hart flag */=0D la a4, _boot_hart_done=0D li a5, 1=0D @@ -136,6 +155,10 @@ _start_warm: csrw CSR_MIP, zero=0D =0D li s7, FixedPcdGet32 (PcdBootableHartNumber)=0D + bnez s7, 1f=0D + la a4, platform=0D + REG_L s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4)=0D +1:=0D li s8, FixedPcdGet32 (PcdOpenSbiStackSize)=0D la a4, platform=0D =0D @@ -205,7 +228,7 @@ _start_warm: /* Setup stack */=0D add sp, tp, zero=0D =0D - /* Setup stack for the Hart executing EFI to top of temporary ram*/=0D + /* Setup stack for the boot hart executing EFI to top of temporary ram*/= =0D csrr a6, CSR_MHARTID=0D li a5, FixedPcdGet32 (PcdBootHartId)=0D bne a6, a5, 1f=0D --=20 2.31.1