//\r
STATIC EFI_HANDLE mDispatchHandle;\r
\r
+/**\r
+ Process CPUs that have been hot-added, per QemuCpuhpCollectApicIds().\r
+\r
+ For each such CPU, relocate the SMBASE, and report the CPU to PiSmmCpuDxeSmm\r
+ via EFI_SMM_CPU_SERVICE_PROTOCOL. If the supposedly hot-added CPU is already\r
+ known, skip it silently.\r
+\r
+ @param[in] PluggedApicIds The APIC IDs of the CPUs that have been\r
+ hot-plugged.\r
+\r
+ @param[in] PluggedCount The number of filled-in APIC IDs in\r
+ PluggedApicIds.\r
+\r
+ @retval EFI_SUCCESS CPUs corresponding to all the APIC IDs are\r
+ populated.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Out of APIC ID space in "mCpuHotPlugData".\r
+\r
+ @return Error codes propagated from SmbaseRelocate()\r
+ and mMmCpuService->AddProcessor().\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+ProcessHotAddedCpus (\r
+ IN APIC_ID *PluggedApicIds,\r
+ IN UINT32 PluggedCount\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PluggedIdx;\r
+ UINT32 NewSlot;\r
+\r
+ //\r
+ // The Post-SMM Pen need not be reinstalled multiple times within a single\r
+ // root MMI handling. Even reinstalling once per root MMI is only prudence;\r
+ // in theory installing the pen in the driver's entry point function should\r
+ // suffice.\r
+ //\r
+ SmbaseReinstallPostSmmPen (mPostSmmPenAddress);\r
+\r
+ PluggedIdx = 0;\r
+ NewSlot = 0;\r
+ while (PluggedIdx < PluggedCount) {\r
+ APIC_ID NewApicId;\r
+ UINT32 CheckSlot;\r
+ UINTN NewProcessorNumberByProtocol;\r
+\r
+ NewApicId = PluggedApicIds[PluggedIdx];\r
+\r
+ //\r
+ // Check if the supposedly hot-added CPU is already known to us.\r
+ //\r
+ for (CheckSlot = 0;\r
+ CheckSlot < mCpuHotPlugData->ArrayLength;\r
+ CheckSlot++) {\r
+ if (mCpuHotPlugData->ApicId[CheckSlot] == NewApicId) {\r
+ break;\r
+ }\r
+ }\r
+ if (CheckSlot < mCpuHotPlugData->ArrayLength) {\r
+ DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged "\r
+ "before; ignoring it\n", __FUNCTION__, NewApicId));\r
+ PluggedIdx++;\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Find the first empty slot in CPU_HOT_PLUG_DATA.\r
+ //\r
+ while (NewSlot < mCpuHotPlugData->ArrayLength &&\r
+ mCpuHotPlugData->ApicId[NewSlot] != MAX_UINT64) {\r
+ NewSlot++;\r
+ }\r
+ if (NewSlot == mCpuHotPlugData->ArrayLength) {\r
+ DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n",\r
+ __FUNCTION__, NewApicId));\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // Store the APIC ID of the new processor to the slot.\r
+ //\r
+ mCpuHotPlugData->ApicId[NewSlot] = NewApicId;\r
+\r
+ //\r
+ // Relocate the SMBASE of the new CPU.\r
+ //\r
+ Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot],\r
+ mPostSmmPenAddress);\r
+ if (EFI_ERROR (Status)) {\r
+ goto RevokeNewSlot;\r
+ }\r
+\r
+ //\r
+ // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.\r
+ //\r
+ Status = mMmCpuService->AddProcessor (mMmCpuService, NewApicId,\r
+ &NewProcessorNumberByProtocol);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n",\r
+ __FUNCTION__, NewApicId, Status));\r
+ goto RevokeNewSlot;\r
+ }\r
+\r
+ DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%Lx, "\r
+ "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__,\r
+ NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot],\r
+ (UINT64)NewProcessorNumberByProtocol));\r
+\r
+ NewSlot++;\r
+ PluggedIdx++;\r
+ }\r
+\r
+ //\r
+ // We've processed this batch of hot-added CPUs.\r
+ //\r
+ return EFI_SUCCESS;\r
+\r
+RevokeNewSlot:\r
+ mCpuHotPlugData->ApicId[NewSlot] = MAX_UINT64;\r
+\r
+ return Status;\r
+}\r
\r
/**\r
CPU Hotplug MMI handler function.\r
UINT8 ApmControl;\r
UINT32 PluggedCount;\r
UINT32 ToUnplugCount;\r
- UINT32 PluggedIdx;\r
- UINT32 NewSlot;\r
\r
//\r
// Assert that we are entering this function due to our root MMI handler\r
goto Fatal;\r
}\r
\r
- //\r
- // Process hot-added CPUs.\r
- //\r
- // The Post-SMM Pen need not be reinstalled multiple times within a single\r
- // root MMI handling. Even reinstalling once per root MMI is only prudence;\r
- // in theory installing the pen in the driver's entry point function should\r
- // suffice.\r
- //\r
- SmbaseReinstallPostSmmPen (mPostSmmPenAddress);\r
-\r
- PluggedIdx = 0;\r
- NewSlot = 0;\r
- while (PluggedIdx < PluggedCount) {\r
- APIC_ID NewApicId;\r
- UINT32 CheckSlot;\r
- UINTN NewProcessorNumberByProtocol;\r
-\r
- NewApicId = mPluggedApicIds[PluggedIdx];\r
-\r
- //\r
- // Check if the supposedly hot-added CPU is already known to us.\r
- //\r
- for (CheckSlot = 0;\r
- CheckSlot < mCpuHotPlugData->ArrayLength;\r
- CheckSlot++) {\r
- if (mCpuHotPlugData->ApicId[CheckSlot] == NewApicId) {\r
- break;\r
- }\r
- }\r
- if (CheckSlot < mCpuHotPlugData->ArrayLength) {\r
- DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged "\r
- "before; ignoring it\n", __FUNCTION__, NewApicId));\r
- PluggedIdx++;\r
- continue;\r
- }\r
-\r
- //\r
- // Find the first empty slot in CPU_HOT_PLUG_DATA.\r
- //\r
- while (NewSlot < mCpuHotPlugData->ArrayLength &&\r
- mCpuHotPlugData->ApicId[NewSlot] != MAX_UINT64) {\r
- NewSlot++;\r
- }\r
- if (NewSlot == mCpuHotPlugData->ArrayLength) {\r
- DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n",\r
- __FUNCTION__, NewApicId));\r
- goto Fatal;\r
- }\r
-\r
- //\r
- // Store the APIC ID of the new processor to the slot.\r
- //\r
- mCpuHotPlugData->ApicId[NewSlot] = NewApicId;\r
-\r
- //\r
- // Relocate the SMBASE of the new CPU.\r
- //\r
- Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot],\r
- mPostSmmPenAddress);\r
- if (EFI_ERROR (Status)) {\r
- goto RevokeNewSlot;\r
- }\r
-\r
- //\r
- // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.\r
- //\r
- Status = mMmCpuService->AddProcessor (mMmCpuService, NewApicId,\r
- &NewProcessorNumberByProtocol);\r
+ if (PluggedCount > 0) {\r
+ Status = ProcessHotAddedCpus (mPluggedApicIds, PluggedCount);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n",\r
- __FUNCTION__, NewApicId, Status));\r
- goto RevokeNewSlot;\r
+ goto Fatal;\r
}\r
-\r
- DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%Lx, "\r
- "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__,\r
- NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot],\r
- (UINT64)NewProcessorNumberByProtocol));\r
-\r
- NewSlot++;\r
- PluggedIdx++;\r
}\r
\r
//\r
//\r
return EFI_SUCCESS;\r
\r
-RevokeNewSlot:\r
- mCpuHotPlugData->ApicId[NewSlot] = MAX_UINT64;\r
-\r
Fatal:\r
ASSERT (FALSE);\r
CpuDeadLoop ();\r