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