]> git.proxmox.com Git - mirror_edk2.git/blob - StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c
85f8194687f87967773a979d750f1610beb9c09b
[mirror_edk2.git] / StandaloneMmPkg / Library / StandaloneMmCoreEntryPoint / Arm / CreateHobList.c
1 /** @file
2 Creates HOB during Standalone MM Foundation entry point
3 on ARM platforms.
4
5 Copyright (c) 2017 - 2021, Arm Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10
11 #include <PiMm.h>
12
13 #include <PiPei.h>
14 #include <Guid/MmramMemoryReserve.h>
15 #include <Guid/MpInformation.h>
16
17 #include <Library/Arm/StandaloneMmCoreEntryPoint.h>
18 #include <Library/ArmMmuLib.h>
19 #include <Library/ArmSvcLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/SerialPortLib.h>
25
26 #include <IndustryStandard/ArmStdSmc.h>
27
28 extern EFI_HOB_HANDOFF_INFO_TABLE*
29 HobConstructor (
30 IN VOID *EfiMemoryBegin,
31 IN UINTN EfiMemoryLength,
32 IN VOID *EfiFreeMemoryBottom,
33 IN VOID *EfiFreeMemoryTop
34 );
35
36 // GUID to identify HOB with whereabouts of communication buffer with Normal
37 // World
38 extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid;
39
40 // GUID to identify HOB where the entry point of the CPU driver will be
41 // populated to allow this entry point driver to invoke it upon receipt of an
42 // event
43 extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid;
44
45 /**
46 Use the boot information passed by privileged firmware to populate a HOB list
47 suitable for consumption by the MM Core and drivers.
48
49 @param [in, out] CpuDriverEntryPoint Address of MM CPU driver entrypoint
50 @param [in] PayloadBootInfo Boot information passed by privileged
51 firmware
52
53 **/
54 VOID *
55 CreateHobListFromBootInfo (
56 IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint,
57 IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo
58 )
59 {
60 EFI_HOB_HANDOFF_INFO_TABLE *HobStart;
61 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
62 UINT32 Index;
63 UINT32 BufferSize;
64 UINT32 Flags;
65 EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHob;
66 EFI_MMRAM_DESCRIPTOR *MmramRanges;
67 EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange;
68 MP_INFORMATION_HOB_DATA *MpInformationHobData;
69 EFI_PROCESSOR_INFORMATION *ProcInfoBuffer;
70 EFI_SECURE_PARTITION_CPU_INFO *CpuInfo;
71 ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc;
72
73 // Create a hoblist with a PHIT and EOH
74 HobStart = HobConstructor (
75 (VOID *) (UINTN) PayloadBootInfo->SpMemBase,
76 (UINTN) PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase,
77 (VOID *) (UINTN) PayloadBootInfo->SpHeapBase,
78 (VOID *) (UINTN) (PayloadBootInfo->SpHeapBase + PayloadBootInfo->SpHeapSize)
79 );
80
81 // Check that the Hoblist starts at the bottom of the Heap
82 ASSERT (HobStart == (VOID *) (UINTN) PayloadBootInfo->SpHeapBase);
83
84 // Build a Boot Firmware Volume HOB
85 BuildFvHob (PayloadBootInfo->SpImageBase, PayloadBootInfo->SpImageSize);
86
87 // Build a resource descriptor Hob that describes the available physical
88 // memory range
89 Attributes = (
90 EFI_RESOURCE_ATTRIBUTE_PRESENT |
91 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
92 EFI_RESOURCE_ATTRIBUTE_TESTED |
93 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
94 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
95 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
96 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
97 );
98
99 BuildResourceDescriptorHob (
100 EFI_RESOURCE_SYSTEM_MEMORY,
101 Attributes,
102 (UINTN) PayloadBootInfo->SpMemBase,
103 PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase
104 );
105
106 // Find the size of the GUIDed HOB with MP information
107 BufferSize = sizeof (MP_INFORMATION_HOB_DATA);
108 BufferSize += sizeof (EFI_PROCESSOR_INFORMATION) * PayloadBootInfo->NumCpus;
109
110 // Create a Guided MP information HOB to enable the ARM TF CPU driver to
111 // perform per-cpu allocations.
112 MpInformationHobData = BuildGuidHob (&gMpInformationHobGuid, BufferSize);
113
114 // Populate the MP information HOB with the topology information passed by
115 // privileged firmware
116 MpInformationHobData->NumberOfProcessors = PayloadBootInfo->NumCpus;
117 MpInformationHobData->NumberOfEnabledProcessors = PayloadBootInfo->NumCpus;
118 ProcInfoBuffer = MpInformationHobData->ProcessorInfoBuffer;
119 CpuInfo = PayloadBootInfo->CpuInfo;
120
121 for (Index = 0; Index < PayloadBootInfo->NumCpus; Index++) {
122 ProcInfoBuffer[Index].ProcessorId = CpuInfo[Index].Mpidr;
123 ProcInfoBuffer[Index].Location.Package = GET_CLUSTER_ID(CpuInfo[Index].Mpidr);
124 ProcInfoBuffer[Index].Location.Core = GET_CORE_ID(CpuInfo[Index].Mpidr);
125 ProcInfoBuffer[Index].Location.Thread = GET_CORE_ID(CpuInfo[Index].Mpidr);
126
127 Flags = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT;
128 if (CpuInfo[Index].Flags & CPU_INFO_FLAG_PRIMARY_CPU) {
129 Flags |= PROCESSOR_AS_BSP_BIT;
130 }
131 ProcInfoBuffer[Index].StatusFlag = Flags;
132 }
133
134 // Create a Guided HOB to tell the ARM TF CPU driver the location and length
135 // of the communication buffer shared with the Normal world.
136 NsCommBufMmramRange = (EFI_MMRAM_DESCRIPTOR *) BuildGuidHob (
137 &gEfiStandaloneMmNonSecureBufferGuid,
138 sizeof (EFI_MMRAM_DESCRIPTOR)
139 );
140 NsCommBufMmramRange->PhysicalStart = PayloadBootInfo->SpNsCommBufBase;
141 NsCommBufMmramRange->CpuStart = PayloadBootInfo->SpNsCommBufBase;
142 NsCommBufMmramRange->PhysicalSize = PayloadBootInfo->SpNsCommBufSize;
143 NsCommBufMmramRange->RegionState = EFI_CACHEABLE | EFI_ALLOCATED;
144
145 // Create a Guided HOB to enable the ARM TF CPU driver to share its entry
146 // point and populate it with the address of the shared buffer
147 CpuDriverEntryPointDesc = (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *) BuildGuidHob (
148 &gEfiArmTfCpuDriverEpDescriptorGuid,
149 sizeof (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR)
150 );
151
152 *CpuDriverEntryPoint = NULL;
153 CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr = CpuDriverEntryPoint;
154
155 // Find the size of the GUIDed HOB with SRAM ranges
156 BufferSize = sizeof (EFI_MMRAM_HOB_DESCRIPTOR_BLOCK);
157 BufferSize += PayloadBootInfo->NumSpMemRegions * sizeof (EFI_MMRAM_DESCRIPTOR);
158
159 // Create a GUIDed HOB with SRAM ranges
160 MmramRangesHob = BuildGuidHob (&gEfiMmPeiMmramMemoryReserveGuid, BufferSize);
161
162 // Fill up the number of MMRAM memory regions
163 MmramRangesHob->NumberOfMmReservedRegions = PayloadBootInfo->NumSpMemRegions;
164 // Fill up the MMRAM ranges
165 MmramRanges = &MmramRangesHob->Descriptor[0];
166
167 // Base and size of memory occupied by the Standalone MM image
168 MmramRanges[0].PhysicalStart = PayloadBootInfo->SpImageBase;
169 MmramRanges[0].CpuStart = PayloadBootInfo->SpImageBase;
170 MmramRanges[0].PhysicalSize = PayloadBootInfo->SpImageSize;
171 MmramRanges[0].RegionState = EFI_CACHEABLE | EFI_ALLOCATED;
172
173 // Base and size of buffer shared with privileged Secure world software
174 MmramRanges[1].PhysicalStart = PayloadBootInfo->SpSharedBufBase;
175 MmramRanges[1].CpuStart = PayloadBootInfo->SpSharedBufBase;
176 MmramRanges[1].PhysicalSize = PayloadBootInfo->SpPcpuSharedBufSize * PayloadBootInfo->NumCpus;
177 MmramRanges[1].RegionState = EFI_CACHEABLE | EFI_ALLOCATED;
178
179 // Base and size of buffer used for synchronous communication with Normal
180 // world software
181 MmramRanges[2].PhysicalStart = PayloadBootInfo->SpNsCommBufBase;
182 MmramRanges[2].CpuStart = PayloadBootInfo->SpNsCommBufBase;
183 MmramRanges[2].PhysicalSize = PayloadBootInfo->SpNsCommBufSize;
184 MmramRanges[2].RegionState = EFI_CACHEABLE | EFI_ALLOCATED;
185
186 // Base and size of memory allocated for stacks for all cpus
187 MmramRanges[3].PhysicalStart = PayloadBootInfo->SpStackBase;
188 MmramRanges[3].CpuStart = PayloadBootInfo->SpStackBase;
189 MmramRanges[3].PhysicalSize = PayloadBootInfo->SpPcpuStackSize * PayloadBootInfo->NumCpus;
190 MmramRanges[3].RegionState = EFI_CACHEABLE | EFI_ALLOCATED;
191
192 // Base and size of heap memory shared by all cpus
193 MmramRanges[4].PhysicalStart = (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart;
194 MmramRanges[4].CpuStart = (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart;
195 MmramRanges[4].PhysicalSize = HobStart->EfiFreeMemoryBottom - (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart;
196 MmramRanges[4].RegionState = EFI_CACHEABLE | EFI_ALLOCATED;
197
198 // Base and size of heap memory shared by all cpus
199 MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryBottom;
200 MmramRanges[5].CpuStart = HobStart->EfiFreeMemoryBottom;
201 MmramRanges[5].PhysicalSize = HobStart->EfiFreeMemoryTop - HobStart->EfiFreeMemoryBottom;
202 MmramRanges[5].RegionState = EFI_CACHEABLE;
203
204 return HobStart;
205 }