public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nishant Sharma" <nishant.sharma@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Thomas Abraham <thomas.abraham@arm.com>,
	Sayanta Pattanayak <sayanta.pattanayak@arm.com>,
	Achin Gupta <achin.gupta@arm.com>
Subject: [edk2-platforms][PATCH V1 10/20] StandaloneMmPkg: Populate Hoblist for SP init from StMM boot information
Date: Tue, 11 Jul 2023 15:36:48 +0100	[thread overview]
Message-ID: <20230711143658.781597-11-nishant.sharma@arm.com> (raw)
In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com>

From: Achin Gupta <achin.gupta@arm.com>

This patch adds support for creating a hoblist from the reduced boot
information retrieved from the SP manifest.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Signed-off-by: Nishant Sharma <nishant.sharma@arm.com>
---
 StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h                    |  16 ++
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c              | 186 +++++++++++++++++++-
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c |   6 +-
 3 files changed, 206 insertions(+), 2 deletions(-)

diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
index 90d67a2f25b5..9daa76324221 100644
--- a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
+++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h
@@ -170,6 +170,22 @@ CreateHobListFromBootInfo (
   IN       EFI_SECURE_PARTITION_BOOT_INFO      *PayloadBootInfo
   );
 
+/**
+  Use the boot information passed by the SPMC to populate a HOB list
+  suitable for consumption by the MM Core and drivers.
+
+  @param  [in, out] CpuDriverEntryPoint   Address of MM CPU driver entrypoint
+  @param  [in]      StmmBootInfo          Boot information passed by privileged
+                                          firmware
+
+**/
+VOID *
+EFIAPI
+CreateHobListFromStmmBootInfo (
+  IN  OUT  PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint,
+  IN       EFI_STMM_BOOT_INFO     *StmmBootInfo
+  );
+
 /**
   The entry point of Standalone MM Foundation.
 
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
index 2ac2d354f06a..4592089a6020 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
@@ -2,7 +2,7 @@
   Creates HOB during Standalone MM Foundation entry point
   on ARM platforms.
 
-Copyright (c) 2017 - 2021, Arm Ltd. All rights reserved.<BR>
+Copyright (c) 2017 - 2023, Arm Ltd. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -203,3 +203,187 @@ CreateHobListFromBootInfo (
 
   return HobStart;
 }
+
+STATIC
+VOID
+CreateMmramInformationHobFromImageLayout (
+  IN       EFI_STMM_BOOT_INFO              *StmmBootInfo,
+  IN       EFI_HOB_HANDOFF_INFO_TABLE      *HobStart
+)
+{
+  UINT32                          *Idx;
+  UINT32                          BufferSize;
+  EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHob;
+  EFI_MMRAM_DESCRIPTOR            *MmramRanges;
+
+  // Find the size of the GUIDed HOB with SRAM ranges. This excludes any memory
+  // shared with the normal world or the SPMC. It includes the memory allocated
+  // to the SP image, used and unused heap.
+  BufferSize = sizeof (EFI_MMRAM_HOB_DESCRIPTOR_BLOCK);
+  BufferSize += 4 * sizeof (EFI_MMRAM_DESCRIPTOR);
+
+  // Create a GUIDed HOB with SRAM ranges
+  MmramRangesHob = BuildGuidHob (&gEfiMmPeiMmramMemoryReserveGuid, BufferSize);
+
+  // Initialise the number of MMRAM memory regions
+  MmramRangesHob->NumberOfMmReservedRegions = 0;
+  Idx = &MmramRangesHob->NumberOfMmReservedRegions ;
+
+  // Fill up the MMRAM ranges
+  MmramRanges = &MmramRangesHob->Descriptor[0];
+
+  // Base and size of memory occupied by the Standalone MM image
+  MmramRanges[*Idx].PhysicalStart = StmmBootInfo->SpMemBase;
+  MmramRanges[*Idx].CpuStart      = StmmBootInfo->SpMemBase;
+  MmramRanges[*Idx].PhysicalSize  = StmmBootInfo->SpMemSize;
+  MmramRanges[*Idx].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
+  (*Idx)++;
+
+  // Base and size of memory occupied by the Standalone MM image
+  MmramRanges[*Idx].PhysicalStart = StmmBootInfo->SpSharedBufBase;
+  MmramRanges[*Idx].CpuStart      = StmmBootInfo->SpSharedBufBase;
+  MmramRanges[*Idx].PhysicalSize  = StmmBootInfo->SpSharedBufSize;
+  MmramRanges[*Idx].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
+  (*Idx)++;
+
+  // Base and size of memory occupied by the hoblist
+  MmramRanges[*Idx].PhysicalStart = (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart;
+  MmramRanges[*Idx].CpuStart      = (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart;
+  MmramRanges[*Idx].PhysicalSize  = HobStart->EfiFreeMemoryBottom - (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart;
+  MmramRanges[*Idx].RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
+  (*Idx)++;
+
+  // Base and size of heap memory shared by all cpus
+  MmramRanges[*Idx].PhysicalStart = HobStart->EfiFreeMemoryBottom;
+  MmramRanges[*Idx].CpuStart      = HobStart->EfiFreeMemoryBottom;
+  MmramRanges[*Idx].PhysicalSize  = HobStart->EfiFreeMemoryTop - HobStart->EfiFreeMemoryBottom;
+  MmramRanges[*Idx].RegionState   = EFI_CACHEABLE;
+  (*Idx)++;
+
+  // Sanity check number of MMRAM regions
+  ASSERT (MmramRangesHob->NumberOfMmReservedRegions == 3);
+
+  return;
+}
+
+STATIC
+VOID
+CreateMpInformationHobFromCpuInfo (
+  IN       EFI_SECURE_PARTITION_CPU_INFO     *CpuInfo
+)
+{
+  MP_INFORMATION_HOB_DATA         *MpInformationHobData;
+  EFI_PROCESSOR_INFORMATION       *ProcInfoBuffer;
+  UINT32                          BufferSize;
+  UINT32                          Flags;
+
+  // Find the size of the GUIDed HOB with MP information
+  BufferSize = sizeof (MP_INFORMATION_HOB_DATA);
+  BufferSize += sizeof (EFI_PROCESSOR_INFORMATION);
+
+  // Create a Guided MP information HOB to enable the ARM TF CPU driver to
+  // perform per-cpu allocations.
+  MpInformationHobData = BuildGuidHob (&gMpInformationHobGuid, BufferSize);
+
+  // Populate the MP information HOB under the assumption that this is a
+  // uniprocessor partition. Hence, only a single CPU is exposed to the MM Core.
+  MpInformationHobData->NumberOfProcessors = 1;
+  MpInformationHobData->NumberOfEnabledProcessors = 1;
+
+  // Populate the processor information
+  ProcInfoBuffer = MpInformationHobData->ProcessorInfoBuffer;
+  ProcInfoBuffer[0].ProcessorId      = CpuInfo[0].Mpidr;
+  ProcInfoBuffer[0].Location.Package = GET_CLUSTER_ID(CpuInfo[0].Mpidr);
+  ProcInfoBuffer[0].Location.Core    = GET_CORE_ID(CpuInfo[0].Mpidr);
+  ProcInfoBuffer[0].Location.Thread  = GET_CORE_ID(CpuInfo[0].Mpidr);
+
+  // Populate the processor information flags
+  Flags = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT | PROCESSOR_AS_BSP_BIT;
+  ProcInfoBuffer[0].StatusFlag = Flags;
+
+  return;
+}
+
+/**
+  Use the FF-A boot information passed by the SPMC to populate a HOB list
+  suitable for consumption by the MM Core and drivers.
+
+  @param  [in, out] CpuDriverEntryPoint   Address of MM CPU driver entrypoint
+  @param  [in]      StmmBootInfo          Boot information passed by the SPMC
+
+**/
+VOID *
+CreateHobListFromStmmBootInfo (
+  IN  OUT  PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint,
+  IN       EFI_STMM_BOOT_INFO                 *StmmBootInfo
+)
+{
+  EFI_HOB_HANDOFF_INFO_TABLE      *HobStart;
+  EFI_RESOURCE_ATTRIBUTE_TYPE     Attributes;
+  EFI_MMRAM_DESCRIPTOR            *NsCommBufMmramRange;
+  ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc;
+
+  // Create a hoblist with a PHIT and EOH
+  HobStart = HobConstructor (
+               (VOID *) (UINTN) StmmBootInfo->SpMemBase,
+               (UINTN)  StmmBootInfo->SpMemSize,
+               (VOID *) (UINTN) StmmBootInfo->SpHeapBase,
+               (VOID *) (UINTN) (StmmBootInfo->SpHeapBase + StmmBootInfo->SpHeapSize)
+               );
+
+  // Check that the Hoblist starts at the bottom of the Heap
+  ASSERT (HobStart == (VOID *) (UINTN) StmmBootInfo->SpHeapBase);
+
+  // Build a Boot Firmware Volume HOB
+  BuildFvHob (StmmBootInfo->SpMemBase, StmmBootInfo->SpMemSize);
+
+  // Build a resource descriptor Hob that describes the available physical
+  // memory range
+  Attributes = (
+    EFI_RESOURCE_ATTRIBUTE_PRESENT |
+    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+    EFI_RESOURCE_ATTRIBUTE_TESTED |
+    EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
+  );
+
+  BuildResourceDescriptorHob (
+    EFI_RESOURCE_SYSTEM_MEMORY,
+    Attributes,
+    (UINTN) StmmBootInfo->SpMemBase,
+    StmmBootInfo->SpMemSize
+    );
+
+  // Create an MP information hob from cpu information passed in the boot
+  // information structure
+  CreateMpInformationHobFromCpuInfo(&StmmBootInfo->CpuInfo);
+
+  // Create a Guided HOB to tell the ARM TF CPU driver the location and length
+  // of the communication buffer shared with the Normal world.
+  NsCommBufMmramRange = (EFI_MMRAM_DESCRIPTOR *) BuildGuidHob (
+                                                   &gEfiStandaloneMmNonSecureBufferGuid,
+                                                   sizeof (EFI_MMRAM_DESCRIPTOR)
+                                                   );
+  NsCommBufMmramRange->PhysicalStart = StmmBootInfo->SpNsCommBufBase;
+  NsCommBufMmramRange->CpuStart      = StmmBootInfo->SpNsCommBufBase;
+  NsCommBufMmramRange->PhysicalSize  = StmmBootInfo->SpNsCommBufSize;
+  NsCommBufMmramRange->RegionState   = EFI_CACHEABLE | EFI_ALLOCATED;
+
+  // Create a Guided HOB to enable the ARM TF CPU driver to share its entry
+  // point and populate it with the address of the shared buffer
+  CpuDriverEntryPointDesc =
+    (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *) BuildGuidHob (
+        &gEfiArmTfCpuDriverEpDescriptorGuid,
+        sizeof (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR)
+        );
+
+  *CpuDriverEntryPoint = NULL;
+  CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr = CpuDriverEntryPoint;
+
+  // Create Mmram range hob from SP image layout
+  CreateMmramInformationHobFromImageLayout(StmmBootInfo, HobStart);
+
+  return HobStart;
+}
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
index 505786aff07c..8131b1984969 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
@@ -823,7 +823,11 @@ ModuleEntryPoint (
   //
   // Create Hoblist based upon boot information passed by privileged software
   //
-  HobStart = CreateHobListFromBootInfo (&CpuDriverEntryPoint, PayloadBootInfo);
+  if (UseOnlyFfaAbis) {
+    HobStart = CreateHobListFromStmmBootInfo (&CpuDriverEntryPoint, &StmmBootInfo);
+  } else {
+    HobStart = CreateHobListFromBootInfo (&CpuDriverEntryPoint, PayloadBootInfo);
+  }
 
   //
   // Call the MM Core entry point
-- 
2.34.1


  parent reply	other threads:[~2023-07-11 14:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11 14:36 [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 01/20] ArmPkg: Change PcdFfaEnable flag datatype Nishant Sharma
2023-07-12 17:21   ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 17:23     ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 02/20] StandaloneMmPkg: Allocate and initialise SP stack from internal memory Nishant Sharma
2023-07-12 17:47   ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 03/20] StandaloneMmPkg: Include libfdt in the StMM Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 04/20] ArmPkg: Add data structures to receive FF-A boot information Nishant Sharma
2023-07-12 17:27   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 05/20] ArmPkg/ArmFfaSvc: Add helper macros and fids Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 06/20] ArmPkg: Add support for FFA_MEM_PERM_GET/SET ABIs Nishant Sharma
2023-07-12 17:43   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 07/20] StandaloneMmPkg: define new data structure to stage FF-A boot information Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 08/20] StandaloneMmPkg: Add backwards compatible support to detect FF-A v1.1 Nishant Sharma
2023-07-12 20:31   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 09/20] StandaloneMmPkg: parse SP manifest and populate new boot information Nishant Sharma
2023-07-13 15:24   ` [edk2-devel] " Girish Mahadevan
2023-07-13 16:48     ` Chris Fernald
2023-07-13 20:49       ` Achin Gupta
2023-07-11 14:36 ` Nishant Sharma [this message]
2023-07-12 20:52   ` [edk2-devel] [edk2-platforms][PATCH V1 10/20] StandaloneMmPkg: Populate Hoblist for SP init from StMM " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 11/20] StandaloneMmPkg: Skip zero sized sections while tweaking page permissions Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 12/20] StandaloneMmPkg: Add global check for FF-A abis Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 13/20] ArmPkg: Bump the StMM SP FF-A minor version to 1 Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 14/20] ArmPkg/MmCommunicationDxe: Introduce FF-A version check Nishant Sharma
2023-07-13 16:56   ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 15/20] ArmPkg/MmCommunicationDxe: Add support for obtaining FF-A partition ID Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 16/20] ArmPkg/MmCommunicationDxe: Register FF-A RX/TX buffers Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 17/20] ArmPkg/MmCommunicationDxe: Unmap FF-A RX/TX buffers during ExitBootServices Nishant Sharma
2023-07-12 20:59   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 18/20] ArmPkg/MmCommunicationDxe: Discover the StMM SP Nishant Sharma
2023-07-12 21:10   ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 21:48   ` Girish Mahadevan
2023-07-13 17:16   ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 19/20] ArmPkg/MmCommunicationDxe: Use the FF-A transport for MM requests Nishant Sharma
2023-07-11 19:22   ` [edk2-devel] " Kun Qin
2023-07-12 14:21     ` achin.gupta
2023-07-12 17:13       ` Kun Qin
2023-07-12 21:49   ` Girish Mahadevan
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 20/20] StandaloneMmPkg: Add support for MM requests as FF-A direct messages Nishant Sharma
2023-07-12 21:13 ` [edk2-devel] [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Oliver Smith-Denny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230711143658.781597-11-nishant.sharma@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox