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.web11.2719.1641618777123307343 for ; Fri, 07 Jan 2022 21:12:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=BxviotW9; 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 20845H61007890 for ; Sat, 8 Jan 2022 05:12:56 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=USf4iIqJns746re7nQuY0TX+VmG9NQHIeggzHz5JfpE=; b=BxviotW9TEgZqb+M4Ngi9F+LsHAbPcq4IHmOPhTfTsaxAD0Chtpn3f9IPjdzIdwDCp8j pkKontDrvxMqGjUx3p3Ilo4pQsBoWQqRRbvpxNYLFEp2fF1JzqkaGfQiX6wqJFSpnWBA nriUlGqw47B5ahkEynwGAkfUKd4ufDOJri1ktM7+Ess3pzT2S9oTsJxi+RX7htEHSyZc 1V8993TV4ZBQV3ybt6PbiGUyVd7Zjv2S7vz7meclQ7O+PVibIPUdKs+884qmnIO8JQij p3UtgR+azZF23nQxOt4XhyOuvIvc0P68mMR8Y7F2DghBCb/mtYepHf+5WHyrLKsE4LQ7 aQ== Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3df395r7sf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 05:12:56 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id C07EAA0 for ; Sat, 8 Jan 2022 05:12:55 +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 14B5B37; Sat, 8 Jan 2022 05:12:54 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 34/79] RISC-V/PlatformPkg: Add FdtPeim to pass DTB from PEI to DXE via HOB Date: Sat, 8 Jan 2022 12:10:54 +0800 Message-Id: <20220108041121.16005-33-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-ORIG-GUID: jvkCFqnv_LRd43tnRVaIW8JPucdYRvRo X-Proofpoint-GUID: jvkCFqnv_LRd43tnRVaIW8JPucdYRvRo 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 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-2201080036 Content-Transfer-Encoding: quoted-printable (This is migrated from edk2-platforms) Cc: Daniel Schaefer Cc: Abner Chang Cc: Sunil V L Reviewed-by: Abner Chang Signed-off-by: Daniel Schaefer --- .../PlatformPkg/Universal/FdtPeim/FdtPeim.inf | 49 +++++++++++++ .../PlatformPkg/Universal/FdtPeim/FdtPeim.c | 70 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.i= nf create mode 100644 Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c diff --git a/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf b/Pl= atform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf new file mode 100644 index 0000000000..8dc58f0a8b --- /dev/null +++ b/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.inf @@ -0,0 +1,49 @@ +## @file=0D +# The FDT Peim driver is used to pass the device tree to DXE phase.=0D +#=0D +# Copyright (c) 2021, Hewlett Packard Enterprise Developmente LP. All righ= ts reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D FdtPei=0D + MODULE_UNI_FILE =3D FdtPei.uni=0D + FILE_GUID =3D 724FD5E9-F35E-4386-B1E1-2ADA6103C4F9= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D +=0D + ENTRY_POINT =3D PeimPassFdt=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 +[Sources]=0D + FdtPeim.c=0D +=0D +[Packages]=0D + EmbeddedPkg/EmbeddedPkg.dec=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + DebugLib=0D + HobLib=0D + FdtLib=0D + PcdLib=0D + PeiServicesLib=0D + PeimEntryPoint=0D + RiscVFirmwareContextLib=0D +=0D +[Guids]=0D + gFdtHobGuid ## PRODUCES=0D +=0D +[Depex]=0D + TRUE=0D diff --git a/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c b/Plat= form/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c new file mode 100644 index 0000000000..2cd94f291c --- /dev/null +++ b/Platform/RISC-V/PlatformPkg/Universal/FdtPeim/FdtPeim.c @@ -0,0 +1,70 @@ +/** @file=0D +The module to pass the device tree to DXE via HOB.=0D +=0D +Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights = reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include =0D +=0D +#include =0D +=0D +/**=0D + The entrypoint of the module, it will pass the FDT via a HOB.=0D +=0D + @param FileHandle Handle of the file being invoked.=0D + @param PeiServices Describes the list of possible PEI Servic= es.=0D +=0D + @retval TODO=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeimPassFdt (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + )=0D +{=0D + VOID *FdtPointer;=0D + VOID *Base;=0D + VOID *NewBase;=0D + UINTN FdtSize;=0D + UINTN FdtPages;=0D + UINT64 *FdtHobData;=0D + EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *FirmwareContext;=0D +=0D + FirmwareContext =3D NULL;=0D + GetFirmwareContextPointer (&FirmwareContext);=0D +=0D + if (FirmwareContext =3D=3D NULL) {=0D + DEBUG((DEBUG_ERROR, "%a: OpenSBI Firmware Context is NULL\n", __FUNCTI= ON__));=0D + return EFI_UNSUPPORTED;=0D + }=0D + FdtPointer =3D (VOID *)FirmwareContext->FlattenedDeviceTree;=0D + if (FdtPointer =3D=3D NULL) {=0D + DEBUG((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__));=0D + return EFI_UNSUPPORTED;=0D + }=0D + DEBUG((DEBUG_ERROR, "%a: Build FDT HOB - FDT at address: 0x%x \n", __FUN= CTION__, FdtPointer));=0D + Base =3D FdtPointer;=0D + ASSERT (Base !=3D NULL);=0D + ASSERT (fdt_check_header (Base) =3D=3D 0);=0D +=0D + FdtSize =3D fdt_totalsize (Base);=0D + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize);=0D + NewBase =3D AllocatePages (FdtPages);=0D + ASSERT (NewBase !=3D NULL);=0D + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));=0D +=0D + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);=0D + ASSERT (FdtHobData !=3D NULL);=0D + *FdtHobData =3D (UINTN)NewBase;=0D +=0D + return EFI_SUCCESS;=0D +}=0D --=20 2.31.1