]>
Commit | Line | Data |
---|---|---|
275d4bd4 SV |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r | |
4 | Copyright (c) 2016 HP Development Company, L.P.\r | |
a9da96ac | 5 | Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.\r |
275d4bd4 | 6 | \r |
86094561 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
275d4bd4 SV |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include <Base.h>\r | |
12 | #include <Pi/PiMmCis.h>\r | |
a776bbab | 13 | #include <Library/Arm/StandaloneMmCoreEntryPoint.h>\r |
275d4bd4 SV |
14 | #include <Library/DebugLib.h>\r |
15 | #include <Library/ArmSvcLib.h>\r | |
16 | #include <Library/ArmLib.h>\r | |
17 | #include <Library/BaseMemoryLib.h>\r | |
18 | #include <Library/HobLib.h>\r | |
19 | \r | |
20 | #include <Protocol/DebugSupport.h> // for EFI_SYSTEM_CONTEXT\r | |
21 | \r | |
22 | #include <Guid/ZeroGuid.h>\r | |
23 | #include <Guid/MmramMemoryReserve.h>\r | |
24 | \r | |
275d4bd4 SV |
25 | #include "StandaloneMmCpu.h"\r |
26 | \r | |
27 | // GUID to identify HOB with whereabouts of communication buffer with Normal\r | |
28 | // World\r | |
91415a36 | 29 | extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid;\r |
275d4bd4 SV |
30 | \r |
31 | // GUID to identify HOB where the entry point of this CPU driver will be\r | |
32 | // populated to allow the entry point driver to invoke it upon receipt of an\r | |
33 | // event\r | |
91415a36 | 34 | extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid;\r |
275d4bd4 SV |
35 | \r |
36 | //\r | |
37 | // Private copy of the MM system table for future use\r | |
38 | //\r | |
91415a36 | 39 | EFI_MM_SYSTEM_TABLE *mMmst = NULL;\r |
275d4bd4 SV |
40 | \r |
41 | //\r | |
42 | // Globals used to initialize the protocol\r | |
43 | //\r | |
91415a36 | 44 | STATIC EFI_HANDLE mMmCpuHandle = NULL;\r |
275d4bd4 | 45 | \r |
9a0f88b5 SM |
46 | /** Returns the HOB data for the matching HOB GUID.\r |
47 | \r | |
48 | @param [in] HobList Pointer to the HOB list.\r | |
49 | @param [in] HobGuid The GUID for the HOB.\r | |
50 | @param [out] HobData Pointer to the HOB data.\r | |
51 | \r | |
52 | @retval EFI_SUCCESS The function completed successfully.\r | |
53 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
54 | @retval EFI_NOT_FOUND Could not find HOB with matching GUID.\r | |
55 | **/\r | |
275d4bd4 SV |
56 | EFI_STATUS\r |
57 | GetGuidedHobData (\r | |
91415a36 MK |
58 | IN VOID *HobList,\r |
59 | IN CONST EFI_GUID *HobGuid,\r | |
60 | OUT VOID **HobData\r | |
275d4bd4 SV |
61 | )\r |
62 | {\r | |
91415a36 | 63 | EFI_HOB_GUID_TYPE *Hob;\r |
275d4bd4 | 64 | \r |
a9da96ac | 65 | if ((HobList == NULL) || (HobGuid == NULL) || (HobData == NULL)) {\r |
275d4bd4 | 66 | return EFI_INVALID_PARAMETER;\r |
a9da96ac | 67 | }\r |
275d4bd4 SV |
68 | \r |
69 | Hob = GetNextGuidHob (HobGuid, HobList);\r | |
a9da96ac | 70 | if (Hob == NULL) {\r |
275d4bd4 | 71 | return EFI_NOT_FOUND;\r |
a9da96ac | 72 | }\r |
275d4bd4 SV |
73 | \r |
74 | *HobData = GET_GUID_HOB_DATA (Hob);\r | |
a9da96ac | 75 | if (*HobData == NULL) {\r |
275d4bd4 | 76 | return EFI_NOT_FOUND;\r |
a9da96ac | 77 | }\r |
275d4bd4 SV |
78 | \r |
79 | return EFI_SUCCESS;\r | |
80 | }\r | |
81 | \r | |
9a0f88b5 SM |
82 | /** Entry point for the Standalone MM CPU driver.\r |
83 | \r | |
84 | @param [in] ImageHandle Unused. Not actual image handle.\r | |
85 | @param [in] SystemTable Pointer to MM System table.\r | |
86 | \r | |
87 | @retval EFI_SUCCESS The function completed successfully.\r | |
88 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
89 | @retval EFI_OUT_OF_RESOURCES Out of resources.\r | |
90 | @retval EFI_NOT_FOUND Failed to find the HOB for the CPU\r | |
91 | driver endpoint descriptor.\r | |
92 | **/\r | |
275d4bd4 | 93 | EFI_STATUS\r |
c8102727 | 94 | StandaloneMmCpuInitialize (\r |
91415a36 MK |
95 | IN EFI_HANDLE ImageHandle, // not actual imagehandle\r |
96 | IN EFI_MM_SYSTEM_TABLE *SystemTable // not actual systemtable\r | |
275d4bd4 SV |
97 | )\r |
98 | {\r | |
91415a36 MK |
99 | ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc;\r |
100 | EFI_CONFIGURATION_TABLE *ConfigurationTable;\r | |
101 | MP_INFORMATION_HOB_DATA *MpInformationHobData;\r | |
102 | EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange;\r | |
275d4bd4 SV |
103 | EFI_STATUS Status;\r |
104 | EFI_HANDLE DispatchHandle;\r | |
105 | UINT32 MpInfoSize;\r | |
106 | UINTN Index;\r | |
107 | UINTN ArraySize;\r | |
91415a36 | 108 | VOID *HobStart;\r |
275d4bd4 SV |
109 | \r |
110 | ASSERT (SystemTable != NULL);\r | |
111 | mMmst = SystemTable;\r | |
112 | \r | |
113 | // publish the MM config protocol so the MM core can register its entry point\r | |
114 | Status = mMmst->MmInstallProtocolInterface (\r | |
115 | &mMmCpuHandle,\r | |
116 | &gEfiMmConfigurationProtocolGuid,\r | |
117 | EFI_NATIVE_INTERFACE,\r | |
118 | &mMmConfig\r | |
119 | );\r | |
120 | if (EFI_ERROR (Status)) {\r | |
121 | return Status;\r | |
122 | }\r | |
123 | \r | |
124 | // register the root MMI handler\r | |
125 | Status = mMmst->MmiHandlerRegister (\r | |
126 | PiMmCpuTpFwRootMmiHandler,\r | |
127 | NULL,\r | |
128 | &DispatchHandle\r | |
129 | );\r | |
130 | if (EFI_ERROR (Status)) {\r | |
131 | return Status;\r | |
132 | }\r | |
133 | \r | |
134 | // Retrieve the Hoblist from the MMST to extract the details of the NS\r | |
135 | // communication buffer that has been reserved by S-EL1/EL3\r | |
136 | ConfigurationTable = mMmst->MmConfigurationTable;\r | |
137 | for (Index = 0; Index < mMmst->NumberOfTableEntries; Index++) {\r | |
138 | if (CompareGuid (&gEfiHobListGuid, &(ConfigurationTable[Index].VendorGuid))) {\r | |
139 | break;\r | |
140 | }\r | |
141 | }\r | |
142 | \r | |
143 | // Bail out if the Hoblist could not be found\r | |
144 | if (Index >= mMmst->NumberOfTableEntries) {\r | |
31d3eeb1 | 145 | DEBUG ((DEBUG_ERROR, "Hoblist not found - 0x%x\n", Index));\r |
275d4bd4 SV |
146 | return EFI_OUT_OF_RESOURCES;\r |
147 | }\r | |
148 | \r | |
149 | HobStart = ConfigurationTable[Index].VendorTable;\r | |
150 | \r | |
151 | //\r | |
152 | // Locate the HOB with the buffer to populate the entry point of this driver\r | |
153 | //\r | |
154 | Status = GetGuidedHobData (\r | |
155 | HobStart,\r | |
156 | &gEfiArmTfCpuDriverEpDescriptorGuid,\r | |
91415a36 | 157 | (VOID **)&CpuDriverEntryPointDesc\r |
275d4bd4 SV |
158 | );\r |
159 | if (EFI_ERROR (Status)) {\r | |
31d3eeb1 | 160 | DEBUG ((DEBUG_ERROR, "ArmTfCpuDriverEpDesc HOB data extraction failed - 0x%x\n", Status));\r |
275d4bd4 SV |
161 | return Status;\r |
162 | }\r | |
163 | \r | |
164 | // Share the entry point of the CPU driver\r | |
91415a36 MK |
165 | DEBUG ((\r |
166 | DEBUG_INFO,\r | |
167 | "Sharing Cpu Driver EP *0x%lx = 0x%lx\n",\r | |
168 | (UINTN)CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr,\r | |
169 | (UINTN)PiMmStandaloneArmTfCpuDriverEntry\r | |
170 | ));\r | |
c8102727 | 171 | *(CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr) = PiMmStandaloneArmTfCpuDriverEntry;\r |
275d4bd4 SV |
172 | \r |
173 | // Find the descriptor that contains the whereabouts of the buffer for\r | |
174 | // communication with the Normal world.\r | |
175 | Status = GetGuidedHobData (\r | |
176 | HobStart,\r | |
177 | &gEfiStandaloneMmNonSecureBufferGuid,\r | |
91415a36 | 178 | (VOID **)&NsCommBufMmramRange\r |
275d4bd4 SV |
179 | );\r |
180 | if (EFI_ERROR (Status)) {\r | |
31d3eeb1 | 181 | DEBUG ((DEBUG_ERROR, "NsCommBufMmramRange HOB data extraction failed - 0x%x\n", Status));\r |
275d4bd4 SV |
182 | return Status;\r |
183 | }\r | |
184 | \r | |
91415a36 MK |
185 | DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalStart - 0x%lx\n", (UINTN)NsCommBufMmramRange->PhysicalStart));\r |
186 | DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalSize - 0x%lx\n", (UINTN)NsCommBufMmramRange->PhysicalSize));\r | |
275d4bd4 | 187 | \r |
91415a36 | 188 | CopyMem (&mNsCommBuffer, NsCommBufMmramRange, sizeof (EFI_MMRAM_DESCRIPTOR));\r |
275d4bd4 SV |
189 | DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize));\r |
190 | \r | |
191 | //\r | |
192 | // Extract the MP information from the Hoblist\r | |
193 | //\r | |
194 | Status = GetGuidedHobData (\r | |
195 | HobStart,\r | |
196 | &gMpInformationHobGuid,\r | |
91415a36 | 197 | (VOID **)&MpInformationHobData\r |
275d4bd4 SV |
198 | );\r |
199 | if (EFI_ERROR (Status)) {\r | |
31d3eeb1 | 200 | DEBUG ((DEBUG_ERROR, "MpInformationHob extraction failed - 0x%x\n", Status));\r |
275d4bd4 SV |
201 | return Status;\r |
202 | }\r | |
203 | \r | |
204 | //\r | |
205 | // Allocate memory for the MP information and copy over the MP information\r | |
206 | // passed by Trusted Firmware. Use the number of processors passed in the HOB\r | |
207 | // to copy the processor information\r | |
208 | //\r | |
209 | MpInfoSize = sizeof (MP_INFORMATION_HOB_DATA) +\r | |
210 | (sizeof (EFI_PROCESSOR_INFORMATION) *\r | |
91415a36 | 211 | MpInformationHobData->NumberOfProcessors);\r |
275d4bd4 SV |
212 | Status = mMmst->MmAllocatePool (\r |
213 | EfiRuntimeServicesData,\r | |
214 | MpInfoSize,\r | |
91415a36 | 215 | (VOID **)&mMpInformationHobData\r |
275d4bd4 SV |
216 | );\r |
217 | if (EFI_ERROR (Status)) {\r | |
31d3eeb1 | 218 | DEBUG ((DEBUG_ERROR, "mMpInformationHobData mem alloc failed - 0x%x\n", Status));\r |
275d4bd4 SV |
219 | return Status;\r |
220 | }\r | |
221 | \r | |
222 | CopyMem (mMpInformationHobData, MpInformationHobData, MpInfoSize);\r | |
223 | \r | |
224 | // Print MP information\r | |
91415a36 MK |
225 | DEBUG ((\r |
226 | DEBUG_INFO,\r | |
227 | "mMpInformationHobData: 0x%016lx - 0x%lx\n",\r | |
228 | mMpInformationHobData->NumberOfProcessors,\r | |
229 | mMpInformationHobData->NumberOfEnabledProcessors\r | |
230 | ));\r | |
275d4bd4 | 231 | for (Index = 0; Index < mMpInformationHobData->NumberOfProcessors; Index++) {\r |
91415a36 MK |
232 | DEBUG ((\r |
233 | DEBUG_INFO,\r | |
234 | "mMpInformationHobData[0x%lx]: %d, %d, %d\n",\r | |
235 | mMpInformationHobData->ProcessorInfoBuffer[Index].ProcessorId,\r | |
236 | mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Package,\r | |
237 | mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Core,\r | |
238 | mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Thread\r | |
239 | ));\r | |
275d4bd4 SV |
240 | }\r |
241 | \r | |
242 | //\r | |
243 | // Allocate memory for a table to hold pointers to a\r | |
244 | // EFI_MM_COMMUNICATE_HEADER for each CPU\r | |
245 | //\r | |
246 | ArraySize = sizeof (EFI_MM_COMMUNICATE_HEADER *) *\r | |
247 | mMpInformationHobData->NumberOfEnabledProcessors;\r | |
248 | Status = mMmst->MmAllocatePool (\r | |
249 | EfiRuntimeServicesData,\r | |
250 | ArraySize,\r | |
91415a36 | 251 | (VOID **)&PerCpuGuidedEventContext\r |
275d4bd4 SV |
252 | );\r |
253 | if (EFI_ERROR (Status)) {\r | |
31d3eeb1 | 254 | DEBUG ((DEBUG_ERROR, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", Status));\r |
275d4bd4 SV |
255 | return Status;\r |
256 | }\r | |
91415a36 | 257 | \r |
275d4bd4 SV |
258 | return Status;\r |
259 | }\r |