From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ma1-aaemail-dr-lapp01.apple.com (ma1-aaemail-dr-lapp01.apple.com [17.171.2.60]) by mx.groups.io with SMTP id smtpd.web08.503.1627692286357180730 for ; Fri, 30 Jul 2021 17:44:46 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=Ck/Dncfa; spf=pass (domain: apple.com, ip: 17.171.2.60, mailfrom: afish@apple.com) Received: from pps.filterd (ma1-aaemail-dr-lapp01.apple.com [127.0.0.1]) by ma1-aaemail-dr-lapp01.apple.com (8.16.0.42/8.16.0.42) with SMTP id 16V0Xcht027462; Fri, 30 Jul 2021 17:44:43 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=0aaQUJEnsbaWS9dEqTRyFBsnjXZvQtInNQctjlbSXEo=; b=Ck/DncfapYW0k8z4mWV/EGJaoebCqkgcXk6JzqLgpjfG9rMzDe2Ms9dPTgFIOC+MSuCR 5unmLmBKzU/NiBYhzxJgmx9+Ns2Dwgnyx1dkqFewjcy5/dFO5wXHEi/zPe/modQvkQnN oNh3LXY4iVL/yGSg9Cp/LUSjCs4md6T5HDFBGtdOpek+d0Ng+dqPnXQhJE8M0WGtB3xm 9zSg7JrHvv8MJ7RMhaPv7Ac1vsWP5sfO0IVUe9/W7CJzlLjq+t2CKY6Ps1cJx8HSMOCH 2etp/6rt+rg2930F76MV5FBuNKHGJqcjyzL6zVWMkq7tm/EZ/xczRoy8wIEtiOU+2Ibw xw== Received: from rn-mailsvcp-mta-lapp01.rno.apple.com (rn-mailsvcp-mta-lapp01.rno.apple.com [10.225.203.149]) by ma1-aaemail-dr-lapp01.apple.com with ESMTP id 3a41bg3bpy-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 30 Jul 2021 17:44:43 -0700 Received: from rn-mailsvcp-mmp-lapp03.rno.apple.com (rn-mailsvcp-mmp-lapp03.rno.apple.com [17.179.253.16]) by rn-mailsvcp-mta-lapp01.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) with ESMTPS id <0QX300HVW3EIKH60@rn-mailsvcp-mta-lapp01.rno.apple.com>; Fri, 30 Jul 2021 17:44:42 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp03.rno.apple.com by rn-mailsvcp-mmp-lapp03.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) id <0QX300300336M300@rn-mailsvcp-mmp-lapp03.rno.apple.com>; Fri, 30 Jul 2021 17:44:42 -0700 (PDT) X-Va-A: X-Va-T-CD: fcd940a3063d28518664f76484c3e186 X-Va-E-CD: 157724f6973f396a8722e6b790e2d8b4 X-Va-R-CD: 8693dfea2f72201df5a024d833260994 X-Va-CD: 0 X-Va-ID: 949efa6a-1d73-41ae-a703-5d9d6d550b68 X-V-A: X-V-T-CD: fcd940a3063d28518664f76484c3e186 X-V-E-CD: 157724f6973f396a8722e6b790e2d8b4 X-V-R-CD: 8693dfea2f72201df5a024d833260994 X-V-CD: 0 X-V-ID: 5a6df647-68a6-4fea-b4b7-439ab4cc5d33 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-30_11:2021-07-30,2021-07-30 signatures=0 Received: from [17.235.58.45] (unknown [17.235.58.45]) by rn-mailsvcp-mmp-lapp03.rno.apple.com (Oracle Communications Messaging Server 8.1.0.9.20210415 64bit (built Apr 15 2021)) with ESMTPSA id <0QX3011CF3EB0K00@rn-mailsvcp-mmp-lapp03.rno.apple.com>; Fri, 30 Jul 2021 17:44:41 -0700 (PDT) From: "Andrew Fish" Message-id: MIME-version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.1\)) Subject: Re: [EXTERNAL] [edk2-devel] [edk2][PATCH v1 1/1] StandaloneMmPkg: add support to populate StMM boot data from device tree Date: Fri, 30 Jul 2021 17:44:35 -0700 In-reply-to: Cc: "sayanta.pattanayak@arm.com" , Ard Biesheuvel , Sami Mujawar To: edk2-devel-groups-io , bret.barkelew@microsoft.com References: <20210730173510.24235-1-sayanta.pattanayak@arm.com> X-Mailer: Apple Mail (2.3654.20.0.2.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-30_11:2021-07-30,2021-07-30 signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_B6B6DA6D-7523-40E5-8999-92CC06E29A2A" --Apple-Mail=_B6B6DA6D-7523-40E5-8999-92CC06E29A2A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jul 30, 2021, at 12:34 PM, Bret Barkelew via groups.io > wrote: >=20 > I don=E2=80=99t think this is a good dependency. StandaloneMmCore should= n=E2=80=99t require anything from EmbeddedPkg, and if it does there=E2=80= =99s probably some more generalization necessary. > > Further, we can=E2=80=99t require the MmCore (which should be considered= generic at the level of PEI Core or DXE Core) include some external librar= y like Libfdt without significant justification. > I think we should understand if this is being driven by some kind of stand= ard? Maybe the Flat Device Tree lib should be part of the MdePkg? Or maybe = MdeModulePkg? Thanks, Andrew Fish > - Bret=20 > > From: Sayanta Pattanayak via groups.io > Sent: Friday, July 30, 2021 10:36 AM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Sami Mujawar ; Achin Gupta > Subject: [EXTERNAL] [edk2-devel] [edk2][PATCH v1 1/1] StandaloneMmPkg: a= dd support to populate StMM boot data from device tree > > Introduce support to populate StMM boot data via DTS parsing. The DTB is > passed as a boot argument by a binary of higer exception level. > Previously it was achieved by placing the boot data structure in a > shared buffer and the address of this shared buffer was passed by the > binary of higher exception level. Now either of the option can be used > for populating StMM boot info. >=20 > StMM boot information structure binding in device tree can be of followi= ng > prototype. Property values are not mentioned here. >=20 > bootarg { > compatible =3D "bootargs"; > h_type =3D <..>; > h_version =3D <..>; > h_size =3D <..>; > h_attr =3D <..>; > sp_mem_base =3D <..>; > sp_mem_limit =3D <..>; > sp_image_base =3D <..>; > sp_stack_base =3D <..>; > sp_heap_base =3D <..>; > sp_ns_comm_buf_base =3D <..>;fc > sp_shared_buf_base =3D <..>; > sp_image_size =3D <..>; > sp_pcpu_stack_size =3D <..>; > sp_heap_size =3D <..>; > sp_ns_comm_buf_size =3D <..>; > sp_shared_buf_size =3D <..>; > num_sp_mem_regions =3D <..>; > num_cpus =3D <..>; > }; >=20 > Addition of DTS supoort involves a dependency on FdtLib from EmbeddedPkg= . >=20 > Signed-off-by: Sayanta Pattanayak > > --- > Link to github branch with this patch - > https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgit= hub.com%2FSayantaP-arm%2Fedk2%2Ftree%2Fstmm-dts&data=3D04%7C01%7Cbret.b= arkelew%40microsoft.com%7Cb365266c83cb433d1e0108d953806c83%7C72f988bf86f141= af91ab2d7cd011db47%7C1%7C0%7C637632633786132182%7CUnknown%7CTWFpbGZsb3d8eyJ= WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&= sdata=3DgJw%2BH8Dj9lih1DNrIzbNPToJn9nH%2BHqpvpSr2JJrS4I%3D&reserved=3D0= >=20 > StandaloneMmPkg/StandaloneMmPkg.dsc = | 1 + > StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntr= yPoint.inf | 3 + > StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMm= CoreEntryPoint.c | 153 ++++++++++++++++++-- > 3 files changed, 143 insertions(+), 14 deletions(-) >=20 > diff --git a/StandaloneMmPkg/StandaloneMmPkg.dsc b/StandaloneMmPkg/Stand= aloneMmPkg.dsc > index 0c45df95e2dd..e3a3a6ee3ba1 100644 > --- a/StandaloneMmPkg/StandaloneMmPkg.dsc > +++ b/StandaloneMmPkg/StandaloneMmPkg.dsc > @@ -49,6 +49,7 @@ > HobLib|StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.= inf > IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf > MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.= inf > + FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf > MemoryAllocationLib|StandaloneMmPkg/Library/StandaloneMmCoreMemoryAll= ocationLib/StandaloneMmCoreMemoryAllocationLib.inf > MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standa= loneMmServicesTableLib.inf > PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf > diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Standalo= neMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint= /StandaloneMmCoreEntryPoint.inf > index 4fa426f58ef4..0a2e519dd664 100644 > --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor= eEntryPoint.inf > +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor= eEntryPoint.inf > @@ -30,6 +30,7 @@ > X64/StandaloneMmCoreEntryPoint.c > > [Packages] > + EmbeddedPkg/EmbeddedPkg.dec > MdePkg/MdePkg.dec > MdeModulePkg/MdeModulePkg.dec > StandaloneMmPkg/StandaloneMmPkg.dec > @@ -40,10 +41,12 @@ > [LibraryClasses] > BaseLib > DebugLib > + FdtLib > > [LibraryClasses.AARCH64] > StandaloneMmMmuLib > ArmSvcLib > + FdtLib > > [Guids] > gMpInformationHobGuid > diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/= StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntr= yPoint/AArch64/StandaloneMmCoreEntryPoint.c > index 6c50f470aa35..cc09d75dac36 100644 > --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standal= oneMmCoreEntryPoint.c > +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standal= oneMmCoreEntryPoint.c > @@ -16,6 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include > #include > > +#include > #include > #include > #include > @@ -45,33 +46,31 @@ STATIC CONST UINT32 mSpmMinorVerFfa =3D SPM_MINOR_VE= RSION_FFA; > PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT CpuDriverEntryPoint =3D NULL; > > /** > - Retrieve a pointer to and print the boot information passed by privil= eged > - secure firmware. > + Prints boot information. > > - @param [in] SharedBufAddress The pointer memory shared with privil= eged > - firmware. > + This function prints the boot information, which is passed by privile= ged > + secure firmware through shared buffer or other mechanism. > > + @param [in] PayloadBootInfo Pointer to StandaloneMM Boot Info stru= cture. > **/ > -EFI_SECURE_PARTITION_BOOT_INFO * > -GetAndPrintBootinformation ( > - IN VOID *SharedBufAddress > +VOID > +PrintBootinformation ( > + IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo > ) > { > - EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; > EFI_SECURE_PARTITION_CPU_INFO *PayloadCpuInfo; > UINTN Index; > > - PayloadBootInfo =3D (EFI_SECURE_PARTITION_BOOT_INFO *) SharedBufAddre= ss; > > if (PayloadBootInfo =3D=3D NULL) { > DEBUG ((DEBUG_ERROR, "PayloadBootInfo NULL\n")); > - return NULL; > + return; > } > > if (PayloadBootInfo->Header.Version !=3D BOOT_PAYLOAD_VERSION) { > DEBUG ((DEBUG_ERROR, "Boot Information Version Mismatch. Current=3D= 0x%x, Expected=3D0x%x.\n", > PayloadBootInfo->Header.Version, BOOT_PAYLOAD_VERSION)); > - return NULL; > + return; > } > > DEBUG ((DEBUG_INFO, "NumSpMemRegions - 0x%x\n", PayloadBootInfo->NumS= pMemRegions)); > @@ -96,7 +95,7 @@ GetAndPrintBootinformation ( > > if (PayloadCpuInfo =3D=3D NULL) { > DEBUG ((DEBUG_ERROR, "PayloadCpuInfo NULL\n")); > - return NULL; > + return; > } > > for (Index =3D 0; Index < PayloadBootInfo->NumCpus; Index++) { > @@ -105,7 +104,7 @@ GetAndPrintBootinformation ( > DEBUG ((DEBUG_INFO, "Flags - 0x%x\n", PayloadCpuInfo[Inde= x].Flags)); > } > > - return PayloadBootInfo; > + return; > } > > /** > @@ -194,6 +193,119 @@ DelegatedEventLoop ( > } > } > > +/** > + Populates StandAloneMM boot information structure. > + > + This function receives dtb Address, where StMM Boot information speci= fic > + properties will be looked out to form the booting structure of type > + EFI_SECURE_PARTITION_BOOT_INFO. At first, the properties for StandAlo= neMM > + ConfigSize and Memory limit will be checked out. Boot information wi= ll > + be stored at address (Memory Limit - ConfigSize). Thereafter all boot > + information specific properties will be parsed and corresponding valu= es > + will be obtained. > + > + @param [out] BootInfo Pointer, where Boot Info structure will be p= opulated. > + @param [in] DtbAddress Address of the Device tree from where Boot > + information will be fetched. > +**/ > +VOID > +PopulateBootinformation ( > + OUT EFI_SECURE_PARTITION_BOOT_INFO **BootInfo, > + IN VOID *DtbAddress > +) > +{ > + INT32 Offset; > + CONST UINT32 *Property; > + CONST UINT64 *Property64; > + UINT32 ConfigSize; > + UINT64 SpMemLimit; > + EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; > + > + Offset =3D fdt_node_offset_by_compatible (DtbAddress, -1, "config-siz= e"); > + if (Offset < 0) { > + DEBUG ((DEBUG_WARN, "Total Config Size is not defined\n")); > + } else { > + Property =3D fdt_getprop (DtbAddress, Offset, "size", NULL); > + if (Property) { > + ConfigSize =3D fdt32_to_cpu (*Property); > + DEBUG ((DEBUG_INFO, "stmm dtb config-size =3D 0x%x \n", ConfigSi= ze)); > + } > + } > + > + Offset =3D fdt_node_offset_by_compatible (DtbAddress, -1, "bootargs")= ; > + if (Offset >=3D 0) { > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_mem_limit", NU= LL); > + SpMemLimit =3D fdt64_to_cpu (*Property64); > + } > + > + if (SpMemLimit && ConfigSize) > + PayloadBootInfo =3D > + (EFI_SECURE_PARTITION_BOOT_INFO *)(SpMemLimit - ConfigSize); > + > + if (PayloadBootInfo) { > + PayloadBootInfo->SpMemLimit =3D SpMemLimit; > + > + Property =3D fdt_getprop (DtbAddress, Offset, "h_type", NULL); > + PayloadBootInfo->Header.Type =3D (UINT8) fdt32_to_cpu(*Property); > + > + Property =3D fdt_getprop (DtbAddress, Offset, "h_version", NULL); > + PayloadBootInfo->Header.Version =3D (UINT8) fdt32_to_cpu(*Property)= ; > + > + Property =3D fdt_getprop (DtbAddress, Offset, "h_size", NULL); > + PayloadBootInfo->Header.Size =3D (UINT8) fdt32_to_cpu(*Property); > + > + Property =3D fdt_getprop (DtbAddress, Offset, "h_attr", NULL); > + PayloadBootInfo->Header.Attr =3D fdt32_to_cpu(*Property); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_mem_base", NUL= L); > + PayloadBootInfo->SpMemBase =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_image_base", N= ULL); > + PayloadBootInfo->SpImageBase =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_stack_base", N= ULL); > + PayloadBootInfo->SpStackBase =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_heap_base", NU= LL); > + PayloadBootInfo->SpHeapBase =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_ns_comm_buf_ba= se", NULL); > + PayloadBootInfo->SpNsCommBufBase =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_shared_buf_bas= e", NULL); > + PayloadBootInfo->SpSharedBufBase =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_image_size", N= ULL); > + PayloadBootInfo->SpImageSize =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_pcpu_stack_siz= e", NULL); > + PayloadBootInfo->SpPcpuStackSize =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_heap_size", NU= LL); > + PayloadBootInfo->SpHeapSize =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_ns_comm_buf_si= ze", NULL); > + PayloadBootInfo->SpNsCommBufSize =3D fdt64_to_cpu(*Property64); > + > + Property64 =3D fdt_getprop (DtbAddress, Offset, "sp_shared_buf_siz= e", NULL); > + PayloadBootInfo->SpPcpuSharedBufSize =3D fdt64_to_cpu(*Property64); > + > + Property =3D fdt_getprop (DtbAddress, Offset, "num_sp_mem_regions"= , NULL); > + PayloadBootInfo->NumSpMemRegions =3D fdt32_to_cpu(*Property); > + > + Property =3D fdt_getprop (DtbAddress, Offset, "num_cpus", NULL); > + PayloadBootInfo->NumCpus =3D fdt32_to_cpu(*Property); > + > + PayloadBootInfo->CpuInfo =3D > + (EFI_SECURE_PARTITION_CPU_INFO *)((UINT64)PayloadBootInfo + > + sizeof(EFI_SECURE_PARTITION_BOO= T_INFO)); > + } > + > + *BootInfo =3D PayloadBootInfo; > + > + return; > +} > + > /** > Query the SPM version, check compatibility and return success if comp= atible. > > @@ -313,6 +425,7 @@ _ModuleEntryPoint ( > VOID *TeData; > UINTN TeDataSize; > EFI_PHYSICAL_ADDRESS ImageBase; > + VOID *DtbAddress; > > // Get Secure Partition Manager Version Information > Status =3D GetSpmVersion (); > @@ -320,12 +433,24 @@ _ModuleEntryPoint ( > goto finish; > } > > - PayloadBootInfo =3D GetAndPrintBootinformation (SharedBufAddress); > + // In cookie1 the DTB address is passed. With reference to DTB, Boot > + // info structure can be populated. > + // If cookie1 doesn't have any value, then Boot info is copied from > + // Sharedbuffer. > + if (cookie1) { > + DtbAddress =3D (void *)cookie1; > + PopulateBootinformation (&PayloadBootInfo, DtbAddress); > + } else { > + PayloadBootInfo =3D (EFI_SECURE_PARTITION_BOOT_INFO *)SharedBufAddr= ess; > + } > + > if (PayloadBootInfo =3D=3D NULL) { > Status =3D EFI_UNSUPPORTED; > goto finish; > } > > + PrintBootinformation (PayloadBootInfo); > + > // Locate PE/COFF File information for the Standalone MM core module > Status =3D LocateStandaloneMmCorePeCoffData ( > (EFI_FIRMWARE_VOLUME_HEADER *) PayloadBootInfo->SpImageBas= e, > --=20 > 2.17.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to th= is group. > View/Reply Online (#78449): https://nam06.safelinks.protection.outlook.c= om/?url=3Dhttps%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F78449&da= ta=3D04%7C01%7Cbret.barkelew%40microsoft.com%7Cb365266c83cb433d1e0108d95380= 6c83%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637632633786132182%7CUnkn= own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV= CI6Mn0%3D%7C3000&sdata=3D0DbkyBJe0prgx2vSCVVsrI0GoVbCipcfmbZp83LREjo%3D= &reserved=3D0 > Mute This Topic: https://nam06.safelinks.protection.outlook.com/?url=3Dh= ttps%3A%2F%2Fgroups.io%2Fmt%2F84555304%2F1852292&data=3D04%7C01%7Cbret.= barkelew%40microsoft.com%7Cb365266c83cb433d1e0108d953806c83%7C72f988bf86f14= 1af91ab2d7cd011db47%7C1%7C0%7C637632633786132182%7CUnknown%7CTWFpbGZsb3d8ey= JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&= ;sdata=3D1u3cr0MmJmjrkxtGgfOe1mb8%2F7vUXaoyUr5%2FmC1Uq%2F8%3D&reserved= =3D0 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps= %3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Funsub&data=3D04%7C01%7Cbret.barke= lew%40microsoft.com%7Cb365266c83cb433d1e0108d953806c83%7C72f988bf86f141af91= ab2d7cd011db47%7C1%7C0%7C637632633786142135%7CUnknown%7CTWFpbGZsb3d8eyJWIjo= iMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdat= a=3DYr%2BSNqWHllfxHkFqBhCyP2TE4IGRLFLm%2FCCWexjB0AM%3D&reserved=3D0 [bret.barkelew@micro= soft.com ] > -=3D-=3D-=3D-=3D-=3D-=3D >=20 >=20 > >=20 --Apple-Mail=_B6B6DA6D-7523-40E5-8999-92CC06E29A2A Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8


On Jul 30, 2021= , at 12:34 PM, Bret Barkelew via g= roups.io <bret.barkelew=3Dmicrosoft.com@groups.io> wrote:
I don=E2=80=99t think this is a good dependency. S= tandaloneMmCore shouldn=E2=80=99t require anything from EmbeddedPkg, and if= it does there=E2=80=99s probably some more generalization necessary.
=
 
Further, we= can=E2=80=99t require the MmCore (which should be considered generic at th= e level of PEI Core or DXE Core) include some external library like Libfdt = without significant justification.
&nbs= p;

I think we should understand if this is being driven by so= me kind of standard? Maybe the Flat Device Tree lib should be part of the M= dePkg? Or maybe MdeModulePkg?

Thanks,

Andrew Fish

- Bret&n= bsp;
 = ;
From: Sayanta Pattanayak via groups.io
Sent: Friday, = July 30, 2021 10:36 AM
To: devel@edk2.gro= ups.io
Cc: Ard Biesheuvel; Sami Mujawar; Achin Gupta
Subject: [EXTERNAL] [edk2-devel= ] [edk2][PATCH v1 1/1] StandaloneMmPkg: add support to populate StMM boot d= ata from device tree
 =

Introduce support to populate StMM boo= t data via DTS parsing. The DTB is
passed as a boot argument = by a binary of higer exception level.
Previously it was achie= ved by placing the boot data structure in a
shared buffer and= the address of this shared buffer was passed by the
binary o= f higher exception level. Now either of the option can be used
for populating StMM boot info.

StMM boot inf= ormation structure binding in device tree can be of following
prototype. Property values are not mentioned here.

bootarg {
  compatible =3D "bootargs";
  h_type  =3D <..>;
  h_version = =3D <..>;
  h_size    =3D <..&g= t;;
  h_attr    =3D <..>;
  sp_mem_base         = =3D <..>;
  sp_mem_limit    &= nbsp;   =3D <..>;
  sp_image_base &= nbsp;     =3D <..>;
  sp_stack= _base       =3D <..>;
&nb= sp; sp_heap_base        =3D <..>;<= br class=3D"">  sp_ns_comm_buf_base =3D <..>;fc
&n= bsp; sp_shared_buf_base  =3D <..>;
  sp_image= _size       =3D <..>;
&nb= sp; sp_pcpu_stack_size  =3D <..>;
  sp_heap_s= ize        =3D <..>;
  sp_ns_comm_buf_size =3D <..>;
  sp_shared_= buf_size  =3D <..>;
  num_sp_mem_regions = ; =3D <..>;
  num_cpus    &nbs= p;       =3D <..>;
};

Addition of DTS supoort involves a dependency on = FdtLib from EmbeddedPkg.

Signed-off-by: Sayant= a Pattanayak <sayanta.pattanayak@arm.co= m>
---
 Link to github branch with = this patch -
 https://nam06.safelinks.protection= .outlook.com/?url=3Dhttps%3A%2F%2Fgithub.com%2FSayantaP-arm%2Fedk2%2Ftree%2= Fstmm-dts&amp;data=3D04%7C01%7Cbret.barkelew%40microsoft.com%7Cb365266c= 83cb433d1e0108d953806c83%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63763= 2633786132182%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiL= CJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=3DgJw%2BH8Dj9lih1DNrIzbN= PToJn9nH%2BHqpvpSr2JJrS4I%3D&amp;reserved=3D0

 StandaloneMmPkg/StandaloneMmPkg.dsc    &n= bsp;            = ;            &n= bsp;            = ;           |  = 1 +
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint= /StandaloneMmCoreEntryPoint.inf       | =   3 +
 StandaloneMmPkg/Library/StandaloneMmCoreEntr= yPoint/AArch64/StandaloneMmCoreEntryPoint.c | 153 ++++++++++++++++++--
 3 files changed, 143 insertions(+), 14 deletions(-)

diff --git a/StandaloneMmPkg/StandaloneMmPkg.dsc b/St= andaloneMmPkg/StandaloneMmPkg.dsc
index 0c45df95e2dd..e3a3a6e= e3ba1 100644
--- a/StandaloneMmPkg/StandaloneMmPkg.dsc
+++ b/StandaloneMmPkg/StandaloneMmPkg.dsc
@@ -49,6 +4= 9,7 @@
   HobLib|StandaloneMmPkg/Library/Standalone= MmHobLib/StandaloneMmHobLib.inf
   IoLib|MdePkg/Lib= rary/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
   M= emLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
+  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
   MemoryAllocationLib|StandaloneMmPkg/Library/StandaloneMmCor= eMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.inf
=    MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib= /StandaloneMmServicesTableLib.inf
   PcdLib|MdePkg/= Library/BasePcdLibNull/BasePcdLibNull.inf
diff --git a/Standa= loneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf= b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntry= Point.inf
index 4fa426f58ef4..0a2e519dd664 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor= eEntryPoint.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCor= eEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -30,6 +30,7 @@<= br class=3D"">   X64/StandaloneMmCoreEntryPoint.c
&= nbsp;
 [Packages]
+  EmbeddedPkg/Embe= ddedPkg.dec
   MdePkg/MdePkg.dec
&nbs= p;  MdeModulePkg/MdeModulePkg.dec
   Standalon= eMmPkg/StandaloneMmPkg.dec
@@ -40,10 +41,12 @@
=  [LibraryClasses]
   BaseLib
&nb= sp;  DebugLib
+  FdtLib
 
 [LibraryClasses.AARCH64]
   Standalon= eMmMmuLib
   ArmSvcLib
+  FdtLib=
 
 [Guids]
  = ; gMpInformationHobGuid
diff --git a/StandaloneMmPkg/Library/= StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/Standalon= eMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoin= t.c
index 6c50f470aa35..cc09d75dac36 100644
---= a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmC= oreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCor= eEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
@@ -16,6 +16= ,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #inc= lude <Guid/MmramMemoryReserve.h>
 #include <Gui= d/MpInformation.h>
 
+#include <libf= dt.h>
 #include <Library/ArmMmuLib.h>
 #include <Library/ArmSvcLib.h>
 #incl= ude <Library/DebugLib.h>
@@ -45,33 +46,31 @@ STATIC CON= ST UINT32 mSpmMinorVerFfa =3D SPM_MINOR_VERSION_FFA;
 PI= _MM_ARM_TF_CPU_DRIVER_ENTRYPOINT      CpuDriverEnt= ryPoint =3D NULL;
 
 /**
-  Retrieve a pointer to and print the boot information passed by pr= ivileged
-  secure firmware.
+  Print= s boot information.
 
-  @param = [in] SharedBufAddress   The pointer memory shared with privilege= d
-         &nbs= p;            &= nbsp;           firmware.=
+  This function prints the boot information, which is = passed by privileged
+  secure firmware through shared b= uffer or other mechanism.
 
+  @param=   [in] PayloadBootInfo   Pointer to StandaloneMM Boot Info s= tructure.
 **/
-EFI_SECURE_PARTITION_BOOT_= INFO *
-GetAndPrintBootinformation (
-  IN= VOID           &nbs= p;          *SharedBufAddress<= br class=3D"">+VOID
+PrintBootinformation (
+&n= bsp; IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo
 = ;)
 {
-  EFI_SECURE_PARTITION_BOOT_IN= FO *PayloadBootInfo;
   EFI_SECURE_PARTITION_CPU_IN= FO  *PayloadCpuInfo;
   UINTN   = ;            &n= bsp;          Index;
 
-  PayloadBootInfo =3D (EFI_SECURE_PARTITI= ON_BOOT_INFO *) SharedBufAddress;
 
 =   if (PayloadBootInfo =3D=3D NULL) {
   &= nbsp; DEBUG ((DEBUG_ERROR, "PayloadBootInfo NULL\n"));
- = ;   return NULL;
+    return;
   }
 
   if (= PayloadBootInfo->Header.Version !=3D BOOT_PAYLOAD_VERSION) {
     DEBUG ((DEBUG_ERROR, "Boot Information Version = Mismatch. Current=3D0x%x, Expected=3D0x%x.\n",
  &n= bsp;          PayloadBootInfo-= >Header.Version, BOOT_PAYLOAD_VERSION));
-  &nbs= p; return NULL;
+    return;
&nb= sp;  }
 
   DEBUG ((DEBUG_I= NFO, "NumSpMemRegions - 0x%x\n", PayloadBootInfo->NumSpMemRegions));
@@ -96,7 +95,7 @@ GetAndPrintBootinformation (
&nb= sp;
   if (PayloadCpuInfo =3D=3D NULL) {
     DEBUG ((DEBUG_ERROR, "PayloadCpuInfo NULL\n= "));
-    return NULL;
+ &n= bsp;  return;
   }
 
   for (Index =3D 0; Index < PayloadBootInfo->NumCp= us; Index++) {
@@ -105,7 +104,7 @@ GetAndPrintBootinformation= (
     DEBUG ((DEBUG_INFO, "Flags &= nbsp;         - 0x%x\n", PayloadCpu= Info[Index].Flags));
   }
 
-  return PayloadBootInfo;
+  return;
 }
 
 /**
@@ -194,6 +193,119 @@ DelegatedEventLoop (
   }<= br class=3D""> }
 
+/**
+  Populates StandAloneMM boot information structure.
+=
+  This function receives dtb Address, where StMM Boot = information specific
+  properties will be looked out to= form the booting structure of type
+  EFI_SECURE_PARTIT= ION_BOOT_INFO. At first, the properties for StandAloneMM
+&nb= sp; ConfigSize and  Memory limit will be checked out. Boot information= will
+  be stored at address (Memory Limit - ConfigSize= ). Thereafter all boot
+  information specific propertie= s will be parsed and corresponding values
+  will be obt= ained.
+
+  @param  [out] BootInfo&nb= sp;  Pointer, where Boot Info structure will be populated.
+  @param  [in] DtbAddress  Address of the Device tree fr= om where Boot
+       &nbs= p;            &= nbsp;      information will be fetched.
+**/
+VOID
+PopulateBootinformation (+  OUT EFI_SECURE_PARTITION_BOOT_INFO **BootInfo,
+  IN VOID   *DtbAddress
+)
+{
+  INT32       =     Offset;
+  CONST UINT32  &n= bsp; *Property;
+  CONST UINT64    *Prope= rty64;
+  UINT32      &nbs= p;   ConfigSize;
+  UINT64   &n= bsp;      SpMemLimit;
+  EFI_SE= CURE_PARTITION_BOOT_INFO *PayloadBootInfo;
+
+&= nbsp; Offset =3D fdt_node_offset_by_compatible (DtbAddress, -1, "config-siz= e");
+  if (Offset < 0) {
+  =   DEBUG ((DEBUG_WARN, "Total Config Size is not  defined\n"));+  } else {
+    Property =3D= fdt_getprop (DtbAddress, Offset, "size", NULL);
+  = ;  if (Property) {
+      Confi= gSize =3D fdt32_to_cpu (*Property);
+    =   DEBUG ((DEBUG_INFO, "stmm dtb config-size  =3D 0x%x \n", Config= Size));
+    }
+  }
+
+  Offset =3D fdt_node_offset_by_compatible (Dt= bAddress, -1, "bootargs");
+  if (Offset >=3D 0) {+    Property64 =3D  fdt_getprop (DtbAddres= s, Offset, "sp_mem_limit", NULL);
+    SpMemLi= mit =3D fdt64_to_cpu (*Property64);
+  }
+=
+  if (SpMemLimit && ConfigSize)
= +    PayloadBootInfo =3D
+   &n= bsp;  (EFI_SECURE_PARTITION_BOOT_INFO *)(SpMemLimit - ConfigSize);
+
+  if (PayloadBootInfo) {
+&n= bsp;   PayloadBootInfo->SpMemLimit =3D SpMemLimit;
+
+    Property =3D  fdt_getprop (DtbA= ddress, Offset, "h_type", NULL);
+    PayloadB= ootInfo->Header.Type =3D (UINT8) fdt32_to_cpu(*Property);
= +
+    Property =3D  fdt_getprop (DtbAddr= ess, Offset, "h_version", NULL);
+    PayloadB= ootInfo->Header.Version =3D (UINT8) fdt32_to_cpu(*Property);
+
+    Property =3D  fdt_getprop (DtbA= ddress, Offset, "h_size", NULL);
+    PayloadB= ootInfo->Header.Size =3D (UINT8) fdt32_to_cpu(*Property);
= +
+    Property =3D  fdt_getprop (DtbAddr= ess, Offset, "h_attr", NULL);
+    PayloadBoot= Info->Header.Attr =3D fdt32_to_cpu(*Property);
+
+    Property64 =3D  fdt_getprop (DtbAddress, Of= fset, "sp_mem_base", NULL);
+    PayloadBootIn= fo->SpMemBase =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop (DtbAddress, Offset= , "sp_image_base", NULL);
+    PayloadBootInfo= ->SpImageBase =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop (DtbAddress, Offset= , "sp_stack_base", NULL);
+    PayloadBootInfo= ->SpStackBase =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop (DtbAddress, Offset= , "sp_heap_base", NULL);
+    PayloadBootInfo-= >SpHeapBase =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop (DtbAddress, Offset, = "sp_ns_comm_buf_base", NULL);
+    PayloadBoot= Info->SpNsCommBufBase =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop (DtbAddress= , Offset, "sp_shared_buf_base", NULL);
+    Pa= yloadBootInfo->SpSharedBufBase =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop= (DtbAddress, Offset, "sp_image_size", NULL);
+  &n= bsp; PayloadBootInfo->SpImageSize =3D fdt64_to_cpu(*Property64);
+
+    Property64 =3D  fdt_getprop= (DtbAddress, Offset, "sp_pcpu_stack_size", NULL);
+ &nb= sp;  PayloadBootInfo->SpPcpuStackSize =3D fdt64_to_cpu(*Property64)= ;
+
+    Property64 =3D  fd= t_getprop (DtbAddress, Offset, "sp_heap_size", NULL);
+ =    PayloadBootInfo->SpHeapSize =3D fdt64_to_cpu(*Property64);<= br class=3D"">+
+    Property64 =3D  fdt_= getprop (DtbAddress, Offset, "sp_ns_comm_buf_size", NULL);
+&= nbsp;   PayloadBootInfo->SpNsCommBufSize =3D fdt64_to_cpu(*Pro= perty64);
+
+    Property64 =3D&= nbsp; fdt_getprop (DtbAddress, Offset, "sp_shared_buf_size", NULL);
+    PayloadBootInfo->SpPcpuSharedBufSize =3D fdt6= 4_to_cpu(*Property64);
+
+    Pr= operty =3D  fdt_getprop (DtbAddress, Offset, "num_sp_mem_regions", NUL= L);
+    PayloadBootInfo->NumSpMemRegions = =3D fdt32_to_cpu(*Property);
+
+  &n= bsp; Property =3D  fdt_getprop (DtbAddress, Offset, "num_cpus", NULL);=
+    PayloadBootInfo->NumCpus =3D fdt32_to= _cpu(*Property);
+
+    PayloadB= ootInfo->CpuInfo =3D
+      (EFI_= SECURE_PARTITION_CPU_INFO *)((UINT64)PayloadBootInfo +
+ = ;            &n= bsp;            = ;            &n= bsp; sizeof(EFI_SECURE_PARTITION_BOOT_INFO));
+  }
+
+  *BootInfo =3D PayloadBootInfo;
+
+  return;
+}
+
 /**
   Query the SPM version, check co= mpatibility and return success if compatible.
 
@@ -313,6 +425,7 @@ _ModuleEntryPoint (
   V= OID            =             &nb= sp;           *TeData;   UINTN       &nb= sp;            =             &nb= sp;  TeDataSize;
   EFI_PHYSICAL_ADDRESS =             &nb= sp;      ImageBase;
+  VOID&nbs= p;            &= nbsp;           &nbs= p;          *DtbAddress;
 
   // Get Secure Partition Manager = Version Information
   Status =3D GetSpmVersion ();=
@@ -320,12 +433,24 @@ _ModuleEntryPoint (
&nbs= p;    goto finish;
   }
 
-  PayloadBootInfo =3D GetAndPrintBootinformati= on (SharedBufAddress);
+  // In cookie1 the DTB address = is passed. With reference to DTB, Boot
+  // info struct= ure can be populated.
+  // If cookie1 doesn't have any = value, then Boot info is copied from
+  // Sharedbuffer.=
+  if (cookie1) {
+    Dtb= Address =3D (void *)cookie1;
+    PopulateBoot= information (&PayloadBootInfo, DtbAddress);
+  } els= e {
+    PayloadBootInfo =3D (EFI_SECURE_PARTI= TION_BOOT_INFO *)SharedBufAddress;
+  }
+<= br class=3D"">   if (PayloadBootInfo =3D=3D NULL) {
     Status =3D EFI_UNSUPPORTED;
 &= nbsp;   goto finish;
   }
&= nbsp;
+  PrintBootinformation (PayloadBootInfo);
+
   // Locate PE/COFF File information for = the Standalone MM core module
   Status =3D LocateS= tandaloneMmCorePeCoffData (
     &nb= sp;        (EFI_FIRMWARE_VOLUME_HEADER *= ) PayloadBootInfo->SpImageBase,
-- 
2.17.1



-=3D-=3D-=3D-=3D-=3D-=3D
Groups.io Links: You receive all messages sent to this group.
View/R= eply Online (#78449): https= ://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.groups.= io%2Fg%2Fdevel%2Fmessage%2F78449&amp;data=3D04%7C01%7Cbret.barkelew%40m= icrosoft.com%7Cb365266c83cb433d1e0108d953806c83%7C72f988bf86f141af91ab2d7cd= 011db47%7C1%7C0%7C637632633786132182%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj= AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata= =3D0DbkyBJe0prgx2vSCVVsrI0GoVbCipcfmbZp83LREjo%3D&amp;reserved=3D0=
Mute This Topic: = https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroup= s.io%2Fmt%2F84555304%2F1852292&amp;data=3D04%7C01%7Cbret.barkelew%40mic= rosoft.com%7Cb365266c83cb433d1e0108d953806c83%7C72f988bf86f141af91ab2d7cd01= 1db47%7C1%7C0%7C637632633786132182%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw= MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=3D1= u3cr0MmJmjrkxtGgfOe1mb8%2F7vUXaoyUr5%2FmC1Uq%2F8%3D&amp;reserved=3D0
Group Owner: 
devel+owner@edk2.groups.io
Unsubscribe: https://nam= 06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.groups.io%2Fg= %2Fdevel%2Funsub&amp;data=3D04%7C01%7Cbret.barkelew%40microsoft.com%7Cb= 365266c83cb433d1e0108d953806c83%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%= 7C637632633786142135%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2= luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=3DYr%2BSNqWHllfxH= kFqBhCyP2TE4IGRLFLm%2FCCWexjB0AM%3D&amp;reserved=3D0 [bret= .barkelew@microsoft.com]
-=3D-=3D-=3D-=3D-=3D-=3D

 

--Apple-Mail=_B6B6DA6D-7523-40E5-8999-92CC06E29A2A--