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.web09.3704.1641630364164944573 for ; Sat, 08 Jan 2022 00:26:04 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=IKKP1sY0; 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 (m0150244.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20845Woq008300 for ; Sat, 8 Jan 2022 08:26:03 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=QXsiPP/qCON+uwC/NTbORAnfzvtDJidq0p3DXWTqEKU=; b=IKKP1sY0QE5CCaw3b/OKYSpLkORvKraImi3h2i+dvNu/K4zBZNNEgXrhwBIHpDcosla9 sHyQrlbTLPSBgj3o1vdF27ST6Cr6NR+dTGH8yNueYIBJ/gCIzK/11q5NappcQ912UwzT LClrUPj1heKWy5g8B7szGBNj8WZ8AqDtr537Zp2yLRdxsp8F8SBQcqVhM8kFPhvTjBew eAMnHT6/LZp5s5IXr+BkoC+IcizfBHR68z/9JyOZiLBu8R4Wi9Ip+F0fB4Bd5zVSv7cV 6y6UjtTWMKcLJXsmt5h0kbK+Buf8rYkfVtik3FgjfaZMwNvA4qn2kSUCsUPi9nDFgQYO og== Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df395ruwt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 08:26:03 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id 9B8A881 for ; Sat, 8 Jan 2022 08:26:02 +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 E4CA636; Sat, 8 Jan 2022 08:26:01 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 58/79] RISC-V/PlatformPkg: Determine hart number from DTB Date: Sat, 8 Jan 2022 15:24:41 +0800 Message-Id: <20220108072444.17879-17-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: 8jJvPpaXamKQBaXTy8BkPPR-SSwahqcx X-Proofpoint-GUID: 8jJvPpaXamKQBaXTy8BkPPR-SSwahqcx 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 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 malwarescore=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) Determine total number of hart from DTB instead of using PCD. Signed-off-by: Abner Chang Cc: Daniel Schaefer Cc: Sunil V L Reviewed-by: Daniel Schaefer Reviewed-by: Sunil V L --- .../OpensbiPlatformLib/OpensbiPlatformLib.inf | 3 - .../PlatformPkg/Universal/Sec/SecMain.inf | 1 - .../PlatformPkg/Universal/Sec/SecMain.c | 12 ++-- .../Universal/Sec/Riscv64/SecEntry.S | 60 +++++++++++++------ 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLib/Opensbi= PlatformLib.inf b/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLib/Op= ensbiPlatformLib.inf index 2e1227733a..6661ee8204 100644 --- a/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLib/OpensbiPlatfor= mLib.inf +++ b/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLib/OpensbiPlatfor= mLib.inf @@ -46,9 +46,6 @@ RiscVSpecialPlatformLib=0D =0D [FixedPcd]=0D - gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootHartId=0D - gUefiRiscVPlatformPkgTokenSpaceGuid.PcdHartCount=0D - gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootableHartNumber=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdOpenSbiStackSize=0D =0D =0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf b/Platfo= rm/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf index ceb6d25222..b949b6c470 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.inf @@ -61,7 +61,6 @@ =0D [Pcd]=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootHartId=0D - gUefiRiscVPlatformPkgTokenSpaceGuid.PcdHartCount=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRootFirmwareDomainBaseAddress=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRootFirmwareDomainSize=0D gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootableHartNumber=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c b/Platform= /RISC-V/PlatformPkg/Universal/Sec/SecMain.c index f2b2c7b583..17f33a02cc 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c @@ -530,7 +530,7 @@ GetDeviceTreeAddress ( EFI_COMMON_SECTION_HEADER *FoundSection;=0D =0D if (FixedPcdGet32 (PcdDeviceTreeAddress)) {=0D - DEBUG ((DEBUG_INFO, "Use fixed address of DBT from PcdDeviceTreeAddr= ess 0x%x.\n", FixedPcdGet32 (PcdDeviceTreeAddress)));=0D + DEBUG ((DEBUG_INFO, "Use fixed address of DBT from PcdDeviceTreeAddr= ess 0x%x 0x%x.\n", FixedPcdGet32 (PcdDeviceTreeAddress), *((unsigned long *= )FixedPcdGet32 (PcdDeviceTreeAddress))));=0D //=0D // Device tree address is pointed by PcdDeviceTreeAddress.=0D //=0D @@ -647,11 +647,10 @@ VOID EFIAPI SecCoreStartUpWithStack( //=0D ThisSbiPlatform =3D (struct sbi_platform *)sbi_platform_ptr(Scratch);=0D ThisSbiPlatform->platform_ops_addr =3D (unsigned long)&Edk2OpensbiPlatfo= rmOps;=0D + Scratch->next_arg1 =3D (unsigned long)GetDeviceTreeAddress ();=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 + DEBUG ((DEBUG_ERROR, "Platform Device Tree is not found on boot hart= \n"));=0D ASSERT (FALSE);=0D }=0D DEBUG ((DEBUG_INFO, "Device Tree at 0x%x\n", Scratch->next_arg1));=0D @@ -685,6 +684,11 @@ VOID EFIAPI SecCoreStartUpWithStack( NonBootHartMessageLockValue =3D atomic_xchg(&NonBootHartMessageLock, T= RUE);=0D };=0D DEBUG((DEBUG_INFO, "%a: Non boot hart %d initialization.\n", __FUNCTION_= _, HartId));=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, "%a: Non boot hart %d DTB is at 0x%x.\n", __FUNCTION_= _, HartId, Scratch->next_arg1));=0D NonBootHartMessageLockValue =3D atomic_xchg(&NonBootHartMessageLock, FAL= SE);=0D //=0D // Non boot hart wiil be halted waiting for SBI_HART_STARTING.=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S b= /Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S index 96087738a3..0fc7817665 100644 --- a/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S +++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S @@ -37,14 +37,39 @@ ASM_FUNC (_ModuleEntryPoint) li a5, FixedPcdGet32 (PcdBootHartId)=0D bne a6, a5, _wait_for_boot_hart=0D =0D - li ra, 0=0D - call _reset_regs=0D + /*=0D + * Initial the hart count reported in DTB=0D + */=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 boot hart ID */=0D + call fw_platform_init=0D +skip_fw_init:=0D /* Preload HART details=0D - * s7 -> HART Count=0D + * s7 -> Total HART count from PCD or DTB=0D * s8 -> HART Stack Size=0D */=0D - li s7, FixedPcdGet32 (PcdHartCount)=0D + la a0, platform=0D +#if __riscv_xlen =3D=3D 64=0D + lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a0)=0D +#else=0D + lw s7, SBI_PLATFORM_HART_COUNT_OFFSET(a0)=0D +#endif=0D + /*=0D + * This is the number of HARTs described in=0D + * DTB for this processor. We allocate the=0D + * scratch buffer according to this number.=0D + */=0D + la a4, _pysical_hart_count=0D + sd s7, (a4)=0D +=0D li s8, FixedPcdGet32 (PcdOpenSbiStackSize)=0D =0D /*=0D @@ -113,20 +138,9 @@ _scratch_init: =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, 0x0=0D @@ -167,7 +181,11 @@ _start_warm: li s7, FixedPcdGet32 (PcdBootableHartNumber)=0D bnez s7, 1f=0D la a4, platform=0D - REG_L s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4)=0D +#if __riscv_xlen =3D=3D 64=0D + lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4)=0D +#else=0D + lw s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4)=0D +#endif=0D 1:=0D li s8, FixedPcdGet32 (PcdOpenSbiStackSize)=0D la a4, platform=0D @@ -209,7 +227,8 @@ _start_warm: csrr a0, CSR_MHARTID=0D j _uninitialized_hart_wait=0D 4:=0D - li s7, FixedPcdGet32 (PcdHartCount)=0D + la a5, _pysical_hart_count=0D + ld s7, (a5)=0D /* Find the scratch space for this hart=0D *=0D * Scratch buffer is on the top of stack buffer=0D @@ -275,6 +294,8 @@ _start_warm: .section .data, "aw"=0D _boot_hart_done:=0D RISCV_PTR 0=0D +_pysical_hart_count:=0D + RISCV_PTR 0=0D =0D .align 3=0D .section .entry, "ax", %progbits=0D @@ -293,7 +314,7 @@ _hartid_to_scratch: /*=0D * s0 -> HART Stack Size=0D * s1 -> HART Stack End=0D - * s2 -> Temporary=0D + * s2 -> Total hart count=0D */=0D la s2, platform=0D #if __riscv_xlen =3D=3D 64=0D @@ -301,8 +322,9 @@ _hartid_to_scratch: #else=0D lw s0, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(s2)=0D #endif=0D - li s2, FixedPcdGet32 (PcdHartCount)=0D =0D + la s1, _pysical_hart_count /* total HART count */=0D + ld s2, (s1)=0D mul s2, s2, s0=0D li s1, FixedPcdGet32 (PcdScratchRamBase)=0D add s1, s1, s2=0D --=20 2.31.1