+ //\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
+ UINTN NewProcessorNumberByProtocol;\r
+\r
+ NewApicId = mPluggedApicIds[PluggedIdx];\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 (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