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.2663.1641618778320915186 for ; Fri, 07 Jan 2022 21:12:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=XogBZqCh; 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 (m0150245.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 2084fubV021110 for ; Sat, 8 Jan 2022 05:12:57 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=ig/u7/B4545sr6QBGezOv/8CuLKsBgHl0n8AuPiHPzM=; b=XogBZqChcRLq9POV74qxKHZdV0Ve+MC2nyMJoodVBD9yHMTuOlHnGGCa/fqDoEg9t/WC ANJ44uRpU5amliQscuZy/pr+CSt7KpKyDyx/ztUpuooyfxnnxN+d6tbLBjvxEBgz9pCo l+CvnqGCGOBlotz78dHlJC3E4wcEld3aNzRQnWqH7zeQJZiLHzfBH0PJtE/aKYSNSOxO SZnZAr5LPhCqspa2wGPgfxjrMVzC0hz+ENSlpa0rBwHGDInvgvdek0jb1OAs8+mpd0G1 faRteduPSh2C0n83UA22FuT4RUTUUj5fdtjYkQ3x2i+TYj70rLPD4PClXnLp1sC3dkhO JA== Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df3tfg4cu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 05:12:57 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id CA99A63 for ; Sat, 8 Jan 2022 05:12:56 +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 1E13B37; Sat, 8 Jan 2022 05:12:55 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 35/79] RISC-V/PlatformPkg: Fixup FDT from HOB and install into config table Date: Sat, 8 Jan 2022 12:10:55 +0800 Message-Id: <20220108041121.16005-34-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> MIME-Version: 1.0 X-Proofpoint-GUID: m78pteeKPZrlHcYYuneUrP-rtPUY-XIq X-Proofpoint-ORIG-GUID: m78pteeKPZrlHcYYuneUrP-rtPUY-XIq 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 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 priorityscore=1501 bulkscore=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) The Linux EFISTUB reads the FDT from the EFI system configuration table. Before installing the FDT needs to be patched with the booting hartid, because the kernel in S-Mode cannot determine it. Cc: Daniel Schaefer Cc: Abner Chang Cc: Sunil V L Reviewed-by: Abner Chang Signed-off-by: Daniel Schaefer --- .../RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc | 3 +- .../ProcessorPkg/Universal/FdtDxe/FdtDxe.inf | 53 ++++++++ .../ProcessorPkg/Universal/FdtDxe/FdtDxe.c | 116 ++++++++++++++++++ 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.inf create mode 100644 Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.c diff --git a/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc b/Silicon/RI= SC-V/ProcessorPkg/RiscVProcessorPkg.dsc index 1292ba1bea..531319322c 100644 --- a/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc +++ b/Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dsc @@ -1,7 +1,7 @@ #/** @file=0D # RISC-V processor package.=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 @@ -102,3 +102,4 @@ =0D Silicon/RISC-V/ProcessorPkg/Universal/CpuDxe/CpuDxe.inf=0D Silicon/RISC-V/ProcessorPkg/Universal/SmbiosDxe/RiscVSmbiosDxe.inf=0D + Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.inf=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.inf b/Sili= con/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.inf new file mode 100644 index 0000000000..ae6468f9f5 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.inf @@ -0,0 +1,53 @@ +## @file=0D +# RISC-V Flattened Device Tree DXE module.=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All righ= ts reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D FdtDxe=0D + FILE_GUID =3D a7d8f3f7-d8a7-47df-b3ec-9E5A693C380C=0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D InstallFdt=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D RISCV64=0D +#=0D +=0D +=0D +[Packages]=0D + EmbeddedPkg/EmbeddedPkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + MdePkg/MdePkg.dec=0D + Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dec=0D + EmbeddedPkg/EmbeddedPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + BaseMemoryLib=0D + DebugLib=0D + FdtLib=0D + HobLib=0D + MemoryAllocationLib=0D + RiscVCpuLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D +=0D +[Sources]=0D + FdtDxe.c=0D +=0D +[Guids]=0D + gFdtHobGuid=0D + gFdtTableGuid=0D +=0D +[Pcd]=0D + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdBootHartId ## CONSUMES=0D +=0D +[Depex]=0D + TRUE=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.c b/Silico= n/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.c new file mode 100644 index 0000000000..22b12027d3 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Universal/FdtDxe/FdtDxe.c @@ -0,0 +1,116 @@ +/** @file=0D + RISC-V Flattened Device Tree DXE module=0D +=0D + The Linux booting protocol on RISC-V requires the id of the booting hart= to=0D + be passed as a0. Therefore the EFISTUB needs to get this information. Be= cause=0D + it runs in S-Mode, it cannot get this information from mhartid. Instead = we=0D + insert the id into the device tree, that the EFIFSTUB can read from the = config table.=0D +=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 +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Fix up the device tree with booting hartid for the kernel=0D +=0D + @param DtbBlob The device tree. Is extended to fit the hart id.=0D +=0D + @retval EFI_SUCCESS The device tree was success fixed up with = the hart id.=0D + @retval EFI_OUT_OF_RESOURCES There is not enough memory available to co= mplete the operation.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +FixDtb (=0D + IN OUT VOID *DtbBlob,=0D + IN UINTN BootingHartId=0D + )=0D +{=0D + fdt32_t Size;=0D + UINT32 ChosenOffset, Err;=0D +=0D + DEBUG ((DEBUG_INFO, "Fixing up device tree with boot hart id: %d\n",=0D + BootingHartId));=0D +=0D + Size =3D fdt_totalsize(DtbBlob);=0D + Err =3D fdt_open_into(DtbBlob, DtbBlob, Size + 32);=0D + if (Err < 0) {=0D + DEBUG ((DEBUG_ERROR,=0D + "Device Tree can't be expanded to accommodate new node\n", __FUNCTIO= N__));=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D + ChosenOffset =3D fdt_path_offset(DtbBlob, "/chosen");=0D + fdt_setprop_u32(DtbBlob, ChosenOffset, "boot-hartid", BootingHartId);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Install the FDT passed in HOB into EFI system configuration table.=0D +=0D + @retval EFI_SUCCESS Successfully installed fixed up FDT in conf= ig table.=0D + @retval EFI_NOT_FOUND Did not find FDT HOB.=0D + @retval EFI_OUT_OF_RESOURCES There is not enough memory available to com= plete the operation.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +InstallFdtFromHob (VOID)=0D +{=0D + EFI_STATUS Status;=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + VOID *DataInHob;=0D + UINTN DataSize;=0D +=0D + GuidHob =3D GetFirstGuidHob (&gFdtHobGuid);=0D + if (GuidHob =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "Failed to find RISC-V DTB Hob\n",=0D + __FUNCTION__));=0D + return EFI_NOT_FOUND;=0D + }=0D + DataInHob =3D (VOID *) *((UINTN *) GET_GUID_HOB_DATA (GuidHob));=0D + DataSize =3D GET_GUID_HOB_DATA_SIZE (GuidHob);=0D +=0D + Status =3D FixDtb (DataInHob, PcdGet32(PcdBootHartId));=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + Status =3D gBS->InstallConfigurationTable (&gFdtTableGuid, DataInHob);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n"= ,=0D + __FUNCTION__));=0D + }=0D + return Status;=0D +}=0D +=0D +/**=0D + Install the FDT from the HOB into the EFI system configuration table.=0D +=0D + @param ImageHandle Image handle of this driver.=0D + @param SystemTable Pointer to the System Table.=0D +=0D + @retval EFI_SUCCESS FDT successfully installed into config table.=0D + @retval EFI_NOT_FOUND Did not find FDT HOB.=0D + @retval EFI_OUT_OF_RESOURCES There is not enough memory available to com= plete the operation.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +InstallFdt (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D InstallFdtFromHob ();=0D +=0D + return Status;=0D +}=0D --=20 2.31.1