TianoCore EDK2 master
Loading...
Searching...
No Matches
StandaloneMmCpu.c
Go to the documentation of this file.
1
12#include <Base.h>
13#include <Pi/PiMmCis.h>
14#include <Library/DebugLib.h>
16#include <Library/HobLib.h>
17
18#include <Protocol/DebugSupport.h> // for EFI_SYSTEM_CONTEXT
19
20#include <Guid/ZeroGuid.h>
22
23#include <StandaloneMmCpu.h>
24
25// GUID to identify HOB with whereabouts of communication buffer with Normal
26// World
27extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid;
28
29// GUID to identify HOB where the entry point of this CPU driver will be
30// populated to allow the entry point driver to invoke it upon receipt of an
31// event
32extern EFI_GUID gEfiMmCpuDriverEpDescriptorGuid;
33
34//
35// Private copy of the MM system table for future use
36//
38
39//
40// Globals used to initialize the protocol
41//
42STATIC EFI_HANDLE mMmCpuHandle = NULL;
43
56 IN VOID *HobList,
57 IN CONST EFI_GUID *HobGuid,
58 OUT VOID **HobData
59 )
60{
62
63 if ((HobList == NULL) || (HobGuid == NULL) || (HobData == NULL)) {
64 return EFI_INVALID_PARAMETER;
65 }
66
67 Hob = GetNextGuidHob (HobGuid, HobList);
68 if (Hob == NULL) {
69 return EFI_NOT_FOUND;
70 }
71
72 *HobData = GET_GUID_HOB_DATA (Hob);
73 if (*HobData == NULL) {
74 return EFI_NOT_FOUND;
75 }
76
77 return EFI_SUCCESS;
78}
79
93 IN EFI_HANDLE ImageHandle, // not actual imagehandle
94 IN EFI_MM_SYSTEM_TABLE *SystemTable // not actual systemtable
95 )
96{
97 MM_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc;
98 EFI_CONFIGURATION_TABLE *ConfigurationTable;
99 MP_INFORMATION_HOB_DATA *MpInformationHobData;
100 EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange;
101 EFI_STATUS Status;
102 EFI_HANDLE DispatchHandle;
103 UINT32 MpInfoSize;
104 UINTN Index;
105 UINTN ArraySize;
106 VOID *HobStart;
107 EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHob;
108
109 ASSERT (SystemTable != NULL);
110 mMmst = SystemTable;
111
112 // publish the MM config protocol so the MM core can register its entry point
113 Status = mMmst->MmInstallProtocolInterface (
114 &mMmCpuHandle,
115 &gEfiMmConfigurationProtocolGuid,
117 &mMmConfig
118 );
119 if (EFI_ERROR (Status)) {
120 return Status;
121 }
122
123 // register the root MMI handler
124 Status = mMmst->MmiHandlerRegister (
126 NULL,
127 &DispatchHandle
128 );
129 if (EFI_ERROR (Status)) {
130 return Status;
131 }
132
133 // Retrieve the Hoblist from the MMST to extract the details of the NS
134 // communication buffer that has been reserved for StandaloneMmPkg
135 ConfigurationTable = mMmst->MmConfigurationTable;
136 for (Index = 0; Index < mMmst->NumberOfTableEntries; Index++) {
137 if (CompareGuid (&gEfiHobListGuid, &(ConfigurationTable[Index].VendorGuid))) {
138 break;
139 }
140 }
141
142 // Bail out if the Hoblist could not be found
143 if (Index >= mMmst->NumberOfTableEntries) {
144 DEBUG ((DEBUG_ERROR, "Hoblist not found - 0x%x\n", Index));
145 return EFI_OUT_OF_RESOURCES;
146 }
147
148 HobStart = ConfigurationTable[Index].VendorTable;
149
150 //
151 // Locate the HOB with the buffer to populate the entry point of this driver
152 //
153 Status = GetGuidedHobData (
154 HobStart,
155 &gEfiMmCpuDriverEpDescriptorGuid,
156 (VOID **)&CpuDriverEntryPointDesc
157 );
158 if (EFI_ERROR (Status)) {
159 DEBUG ((DEBUG_ERROR, "MmCpuDriverEpDesc HOB data extraction failed - 0x%x\n", Status));
160 return Status;
161 }
162
163 // Share the entry point of the CPU driver
164 DEBUG ((
165 DEBUG_INFO,
166 "Sharing Cpu Driver EP *0x%lx = 0x%lx\n",
167 (UINTN)CpuDriverEntryPointDesc->MmCpuDriverEpPtr,
169 ));
170 *(CpuDriverEntryPointDesc->MmCpuDriverEpPtr) = PiMmStandaloneMmCpuDriverEntry;
171
172 // Find the descriptor that contains the whereabouts of the buffer for
173 // communication with the Normal world.
174 Status = GetGuidedHobData (
175 HobStart,
176 &gEfiStandaloneMmNonSecureBufferGuid,
177 (VOID **)&NsCommBufMmramRange
178 );
179 if (EFI_ERROR (Status)) {
180 DEBUG ((DEBUG_ERROR, "NsCommBufMmramRange HOB data extraction failed - 0x%x\n", Status));
181 return Status;
182 }
183
184 DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalStart - 0x%lx\n", (UINTN)NsCommBufMmramRange->PhysicalStart));
185 DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalSize - 0x%lx\n", (UINTN)NsCommBufMmramRange->PhysicalSize));
186
187 CopyMem (&mNsCommBuffer, NsCommBufMmramRange, sizeof (EFI_MMRAM_DESCRIPTOR));
188 DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize));
189
190 Status = GetGuidedHobData (
191 HobStart,
192 &gEfiMmPeiMmramMemoryReserveGuid,
193 (VOID **)&MmramRangesHob
194 );
195 if (EFI_ERROR (Status)) {
196 DEBUG ((DEBUG_ERROR, "MmramRangesHob data extraction failed - 0x%x\n", Status));
197 return Status;
198 }
199
200 //
201 // As CreateHobListFromBootInfo(), the base and size of buffer shared with
202 // privileged Secure world software is in second one.
203 //
204 CopyMem (
205 &mSCommBuffer,
206 &MmramRangesHob->Descriptor[0] + 1,
207 sizeof (EFI_MMRAM_DESCRIPTOR)
208 );
209
210 //
211 // Extract the MP information from the Hoblist
212 //
213 Status = GetGuidedHobData (
214 HobStart,
215 &gMpInformationHobGuid,
216 (VOID **)&MpInformationHobData
217 );
218 if (EFI_ERROR (Status)) {
219 DEBUG ((DEBUG_ERROR, "MpInformationHob extraction failed - 0x%x\n", Status));
220 return Status;
221 }
222
223 //
224 // Allocate memory for the MP information and copy over the MP information
225 // passed by Trusted Firmware. Use the number of processors passed in the HOB
226 // to copy the processor information
227 //
228 MpInfoSize = sizeof (MP_INFORMATION_HOB_DATA) +
229 (sizeof (EFI_PROCESSOR_INFORMATION) *
230 MpInformationHobData->NumberOfProcessors);
231 Status = mMmst->MmAllocatePool (
233 MpInfoSize,
234 (VOID **)&mMpInformationHobData
235 );
236 if (EFI_ERROR (Status)) {
237 DEBUG ((DEBUG_ERROR, "mMpInformationHobData mem alloc failed - 0x%x\n", Status));
238 return Status;
239 }
240
241 CopyMem (mMpInformationHobData, MpInformationHobData, MpInfoSize);
242
243 // Print MP information
244 DEBUG ((
245 DEBUG_INFO,
246 "mMpInformationHobData: 0x%016lx - 0x%lx\n",
247 mMpInformationHobData->NumberOfProcessors,
248 mMpInformationHobData->NumberOfEnabledProcessors
249 ));
250 for (Index = 0; Index < mMpInformationHobData->NumberOfProcessors; Index++) {
251 DEBUG ((
252 DEBUG_INFO,
253 "mMpInformationHobData[0x%lx]: %d, %d, %d\n",
254 mMpInformationHobData->ProcessorInfoBuffer[Index].ProcessorId,
255 mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Package,
256 mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Core,
257 mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Thread
258 ));
259 }
260
261 //
262 // Allocate memory for a table to hold pointers to a
263 // EFI_MM_COMMUNICATE_HEADER for each CPU
264 //
265 ArraySize = sizeof (EFI_MM_COMMUNICATE_HEADER *) *
266 mMpInformationHobData->NumberOfEnabledProcessors;
267 Status = mMmst->MmAllocatePool (
269 ArraySize,
270 (VOID **)&PerCpuGuidedEventContext
271 );
272 if (EFI_ERROR (Status)) {
273 DEBUG ((DEBUG_ERROR, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", Status));
274 return Status;
275 }
276
277 return Status;
278}
UINT64 UINTN
VOID *EFIAPI GetNextGuidHob(IN CONST EFI_GUID *Guid, IN CONST VOID *HobStart)
Definition: HobLib.c:176
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS EFIAPI PiMmCpuTpFwRootMmiHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: EventHandle.c:241
EFI_STATUS PiMmStandaloneMmCpuDriverEntry(IN UINTN EventId, IN UINTN CpuNumber, IN UINTN NsCommBufferAddr)
Definition: EventHandle.c:120
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS GetGuidedHobData(IN VOID *HobList, IN CONST EFI_GUID *HobGuid, OUT VOID **HobData)
EFI_STATUS StandaloneMmCpuInitialize(IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *SystemTable)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
@ EfiRuntimeServicesData
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
EFI_INSTALL_PROTOCOL_INTERFACE MmInstallProtocolInterface
Definition: PiMmCis.h:327
EFI_CONFIGURATION_TABLE * MmConfigurationTable
Definition: PiMmCis.h:322
EFI_ALLOCATE_POOL MmAllocatePool
Definition: PiMmCis.h:274
UINTN NumberOfTableEntries
Definition: PiMmCis.h:317
EFI_PHYSICAL_ADDRESS CpuStart
Definition: PiMultiPhase.h:127
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: PiMultiPhase.h:122
EFI_MMRAM_DESCRIPTOR Descriptor[1]
EFI_CPU_PHYSICAL_LOCATION Location
Definition: MpService.h:178
Definition: Base.h:213