//\r
// We use this protocol for accessing IO Ports.\r
//\r
-STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo;\r
+STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo;\r
//\r
// The following protocol is used to report the addition or removal of a CPU to\r
// the SMM CPU driver (PiSmmCpuDxeSmm).\r
//\r
-STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService;\r
+STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService;\r
//\r
// These structures serve as communication side-channels between the\r
// EFI_SMM_CPU_SERVICE_PROTOCOL consumer (i.e., this driver) and provider\r
// (i.e., PiSmmCpuDxeSmm).\r
//\r
-STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData;\r
-STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData;\r
+STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData;\r
+STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData;\r
//\r
// SMRAM arrays for fetching the APIC IDs of processors with pending events (of\r
// known event types), for the time of just one MMI.\r
// in a single MMI. The numbers of used (populated) elements in the arrays are\r
// determined on every MMI separately.\r
//\r
-STATIC APIC_ID *mPluggedApicIds;\r
-STATIC APIC_ID *mToUnplugApicIds;\r
-STATIC UINT32 *mToUnplugSelectors;\r
+STATIC APIC_ID *mPluggedApicIds;\r
+STATIC APIC_ID *mToUnplugApicIds;\r
+STATIC UINT32 *mToUnplugSelectors;\r
//\r
// Address of the non-SMRAM reserved memory page that contains the Post-SMM Pen\r
// for hot-added CPUs.\r
//\r
-STATIC UINT32 mPostSmmPenAddress;\r
+STATIC UINT32 mPostSmmPenAddress;\r
//\r
// Represents the registration of the CPU Hotplug MMI handler.\r
//\r
-STATIC EFI_HANDLE mDispatchHandle;\r
+STATIC EFI_HANDLE mDispatchHandle;\r
\r
/**\r
Process CPUs that have been hot-added, per QemuCpuhpCollectApicIds().\r
STATIC\r
EFI_STATUS\r
ProcessHotAddedCpus (\r
- IN APIC_ID *PluggedApicIds,\r
- IN UINT32 PluggedCount\r
+ IN APIC_ID *PluggedApicIds,\r
+ IN UINT32 PluggedCount\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT32 PluggedIdx;\r
- UINT32 NewSlot;\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
SmbaseReinstallPostSmmPen (mPostSmmPenAddress);\r
\r
PluggedIdx = 0;\r
- NewSlot = 0;\r
+ NewSlot = 0;\r
while (PluggedIdx < PluggedCount) {\r
- APIC_ID NewApicId;\r
- UINT32 CheckSlot;\r
- UINTN NewProcessorNumberByProtocol;\r
+ APIC_ID NewApicId;\r
+ UINT32 CheckSlot;\r
+ UINTN NewProcessorNumberByProtocol;\r
\r
NewApicId = PluggedApicIds[PluggedIdx];\r
\r
//\r
for (CheckSlot = 0;\r
CheckSlot < mCpuHotPlugData->ArrayLength;\r
- CheckSlot++) {\r
+ CheckSlot++)\r
+ {\r
if (mCpuHotPlugData->ApicId[CheckSlot] == NewApicId) {\r
break;\r
}\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
+ DEBUG ((\r
+ DEBUG_VERBOSE,\r
+ "%a: APIC ID " FMT_APIC_ID " was hot-plugged "\r
+ "before; ignoring it\n",\r
+ __FUNCTION__,\r
+ NewApicId\r
+ ));\r
PluggedIdx++;\r
continue;\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
+ mCpuHotPlugData->ApicId[NewSlot] != MAX_UINT64)\r
+ {\r
NewSlot++;\r
}\r
+\r
if (NewSlot == mCpuHotPlugData->ArrayLength) {\r
- DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n",\r
- __FUNCTION__, NewApicId));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: no room for APIC ID " FMT_APIC_ID "\n",\r
+ __FUNCTION__,\r
+ NewApicId\r
+ ));\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
//\r
// Relocate the SMBASE of the new CPU.\r
//\r
- Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot],\r
- mPostSmmPenAddress);\r
+ Status = SmbaseRelocate (\r
+ NewApicId,\r
+ mCpuHotPlugData->SmBase[NewSlot],\r
+ mPostSmmPenAddress\r
+ );\r
if (EFI_ERROR (Status)) {\r
goto RevokeNewSlot;\r
}\r
//\r
// Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.\r
//\r
- Status = mMmCpuService->AddProcessor (mMmCpuService, NewApicId,\r
- &NewProcessorNumberByProtocol);\r
+ Status = mMmCpuService->AddProcessor (\r
+ mMmCpuService,\r
+ NewApicId,\r
+ &NewProcessorNumberByProtocol\r
+ );\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n",\r
- __FUNCTION__, NewApicId, Status));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: AddProcessor(" FMT_APIC_ID "): %r\n",\r
+ __FUNCTION__,\r
+ NewApicId,\r
+ Status\r
+ ));\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
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%Lx, "\r
+ "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n",\r
+ __FUNCTION__,\r
+ NewApicId,\r
+ (UINT64)mCpuHotPlugData->SmBase[NewSlot],\r
+ (UINT64)NewProcessorNumberByProtocol\r
+ ));\r
\r
NewSlot++;\r
PluggedIdx++;\r
VOID\r
)\r
{\r
- MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;\r
- BOOLEAN IsBsp;\r
+ MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;\r
+ BOOLEAN IsBsp;\r
\r
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);\r
- IsBsp = (BOOLEAN)(ApicBaseMsr.Bits.BSP == 1);\r
+ IsBsp = (BOOLEAN)(ApicBaseMsr.Bits.BSP == 1);\r
return IsBsp;\r
}\r
\r
VOID\r
EFIAPI\r
EjectCpu (\r
- IN UINTN ProcessorNum\r
+ IN UINTN ProcessorNum\r
)\r
{\r
- UINT64 QemuSelector;\r
+ UINT64 QemuSelector;\r
\r
if (CheckIfBsp ()) {\r
- UINT32 Idx;\r
+ UINT32 Idx;\r
\r
for (Idx = 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) {\r
QemuSelector = mCpuHotEjectData->QemuSelectorMap[Idx];\r
//\r
// Tell QEMU to context-switch it out.\r
//\r
- QemuCpuhpWriteCpuSelector (mMmCpuIo, (UINT32) QemuSelector);\r
+ QemuCpuhpWriteCpuSelector (mMmCpuIo, (UINT32)QemuSelector);\r
QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECT);\r
\r
//\r
mCpuHotEjectData->QemuSelectorMap[Idx] =\r
CPU_EJECT_QEMU_SELECTOR_INVALID;\r
\r
- DEBUG ((DEBUG_INFO, "%a: Unplugged ProcessorNum %u, "\r
- "QemuSelector %Lu\n", __FUNCTION__, Idx, QemuSelector));\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a: Unplugged ProcessorNum %u, "\r
+ "QemuSelector %Lu\n",\r
+ __FUNCTION__,\r
+ Idx,\r
+ QemuSelector\r
+ ));\r
}\r
}\r
\r
//\r
// Keep them penned here until the BSP tells QEMU to eject them.\r
//\r
- for (;;) {\r
+ for ( ; ;) {\r
DisableInterrupts ();\r
CpuSleep ();\r
}\r
STATIC\r
EFI_STATUS\r
UnplugCpus (\r
- IN APIC_ID *ToUnplugApicIds,\r
- IN UINT32 *ToUnplugSelectors,\r
- IN UINT32 ToUnplugCount\r
+ IN APIC_ID *ToUnplugApicIds,\r
+ IN UINT32 *ToUnplugSelectors,\r
+ IN UINT32 ToUnplugCount\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT32 ToUnplugIdx;\r
- UINT32 EjectCount;\r
- UINTN ProcessorNum;\r
+ EFI_STATUS Status;\r
+ UINT32 ToUnplugIdx;\r
+ UINT32 EjectCount;\r
+ UINTN ProcessorNum;\r
\r
ToUnplugIdx = 0;\r
- EjectCount = 0;\r
+ EjectCount = 0;\r
while (ToUnplugIdx < ToUnplugCount) {\r
- APIC_ID RemoveApicId;\r
- UINT32 QemuSelector;\r
+ APIC_ID RemoveApicId;\r
+ UINT32 QemuSelector;\r
\r
RemoveApicId = ToUnplugApicIds[ToUnplugIdx];\r
QemuSelector = ToUnplugSelectors[ToUnplugIdx];\r
\r
for (ProcessorNum = 0;\r
ProcessorNum < mCpuHotPlugData->ArrayLength;\r
- ProcessorNum++) {\r
+ ProcessorNum++)\r
+ {\r
if (mCpuHotPlugData->ApicId[ProcessorNum] == RemoveApicId) {\r
break;\r
}\r
// Ignore the unplug if APIC ID not found\r
//\r
if (ProcessorNum == mCpuHotPlugData->ArrayLength) {\r
- DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID\r
- " to unplug\n", __FUNCTION__, RemoveApicId));\r
+ DEBUG ((\r
+ DEBUG_VERBOSE,\r
+ "%a: did not find APIC ID " FMT_APIC_ID\r
+ " to unplug\n",\r
+ __FUNCTION__,\r
+ RemoveApicId\r
+ ));\r
ToUnplugIdx++;\r
continue;\r
}\r
//\r
Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",\r
- __FUNCTION__, RemoveApicId, Status));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",\r
+ __FUNCTION__,\r
+ RemoveApicId,\r
+ Status\r
+ ));\r
return Status;\r
}\r
\r
if (mCpuHotEjectData->QemuSelectorMap[ProcessorNum] !=\r
- CPU_EJECT_QEMU_SELECTOR_INVALID) {\r
+ CPU_EJECT_QEMU_SELECTOR_INVALID)\r
+ {\r
//\r
// mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is set to\r
// CPU_EJECT_QEMU_SELECTOR_INVALID when mCpuHotEjectData->QemuSelectorMap\r
// never match more than one APIC ID -- nor, by transitivity, designate\r
// more than one QemuSelector -- in a single invocation of UnplugCpus().\r
//\r
- DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %Lu maps to QemuSelector %Lu, "\r
- "cannot also map to %u\n", __FUNCTION__, (UINT64)ProcessorNum,\r
- mCpuHotEjectData->QemuSelectorMap[ProcessorNum], QemuSelector));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: ProcessorNum %Lu maps to QemuSelector %Lu, "\r
+ "cannot also map to %u\n",\r
+ __FUNCTION__,\r
+ (UINT64)ProcessorNum,\r
+ mCpuHotEjectData->QemuSelectorMap[ProcessorNum],\r
+ QemuSelector\r
+ ));\r
\r
return EFI_ALREADY_STARTED;\r
}\r
//\r
mCpuHotEjectData->QemuSelectorMap[ProcessorNum] = (UINT64)QemuSelector;\r
\r
- DEBUG ((DEBUG_INFO, "%a: Started hot-unplug on ProcessorNum %Lu, APIC ID "\r
- FMT_APIC_ID ", QemuSelector %u\n", __FUNCTION__, (UINT64)ProcessorNum,\r
- RemoveApicId, QemuSelector));\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a: Started hot-unplug on ProcessorNum %Lu, APIC ID "\r
+ FMT_APIC_ID ", QemuSelector %u\n",\r
+ __FUNCTION__,\r
+ (UINT64)ProcessorNum,\r
+ RemoveApicId,\r
+ QemuSelector\r
+ ));\r
\r
EjectCount++;\r
ToUnplugIdx++;\r
EFI_STATUS\r
EFIAPI\r
CpuHotplugMmi (\r
- IN EFI_HANDLE DispatchHandle,\r
- IN CONST VOID *Context OPTIONAL,\r
- IN OUT VOID *CommBuffer OPTIONAL,\r
- IN OUT UINTN *CommBufferSize OPTIONAL\r
+ IN EFI_HANDLE DispatchHandle,\r
+ IN CONST VOID *Context OPTIONAL,\r
+ IN OUT VOID *CommBuffer OPTIONAL,\r
+ IN OUT UINTN *CommBufferSize OPTIONAL\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT8 ApmControl;\r
- UINT32 PluggedCount;\r
- UINT32 ToUnplugCount;\r
+ EFI_STATUS Status;\r
+ UINT8 ApmControl;\r
+ UINT32 PluggedCount;\r
+ UINT32 ToUnplugCount;\r
\r
//\r
// Assert that we are entering this function due to our root MMI handler\r
// Read the MMI command value from the APM Control Port, to see if this is an\r
// MMI we should care about.\r
//\r
- Status = mMmCpuIo->Io.Read (mMmCpuIo, MM_IO_UINT8, ICH9_APM_CNT, 1,\r
- &ApmControl);\r
+ Status = mMmCpuIo->Io.Read (\r
+ mMmCpuIo,\r
+ MM_IO_UINT8,\r
+ ICH9_APM_CNT,\r
+ 1,\r
+ &ApmControl\r
+ );\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: failed to read ICH9_APM_CNT: %r\n", __FUNCTION__,\r
- Status));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: failed to read ICH9_APM_CNT: %r\n",\r
+ __FUNCTION__,\r
+ Status\r
+ ));\r
//\r
// We couldn't even determine if the MMI was for us or not.\r
//\r
return EFI_INTERRUPT_PENDING;\r
}\r
\r
-\r
//\r
// Entry point function of this driver.\r
//\r
EFI_STATUS\r
EFIAPI\r
CpuHotplugEntry (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
- EFI_STATUS Status;\r
- UINTN Len;\r
- UINTN Size;\r
- UINTN SizeSel;\r
+ EFI_STATUS Status;\r
+ UINTN Len;\r
+ UINTN Size;\r
+ UINTN SizeSel;\r
\r
//\r
// This module should only be included when SMM support is required.\r
// First, collect the protocols needed later. All of these protocols are\r
// listed in our module DEPEX.\r
//\r
- Status = gMmst->MmLocateProtocol (&gEfiMmCpuIoProtocolGuid,\r
- NULL /* Registration */, (VOID **)&mMmCpuIo);\r
+ Status = gMmst->MmLocateProtocol (\r
+ &gEfiMmCpuIoProtocolGuid,\r
+ NULL /* Registration */,\r
+ (VOID **)&mMmCpuIo\r
+ );\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "%a: locate MmCpuIo: %r\n", __FUNCTION__, Status));\r
goto Fatal;\r
}\r
- Status = gMmst->MmLocateProtocol (&gEfiSmmCpuServiceProtocolGuid,\r
- NULL /* Registration */, (VOID **)&mMmCpuService);\r
+\r
+ Status = gMmst->MmLocateProtocol (\r
+ &gEfiSmmCpuServiceProtocolGuid,\r
+ NULL /* Registration */,\r
+ (VOID **)&mMmCpuService\r
+ );\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: locate MmCpuService: %r\n", __FUNCTION__,\r
- Status));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: locate MmCpuService: %r\n",\r
+ __FUNCTION__,\r
+ Status\r
+ ));\r
goto Fatal;\r
}\r
\r
// - PcdCpuHotEjectDataAddress to CPU_HOT_EJECT_DATA in SMRAM, if the\r
// possible CPU count is greater than 1.\r
//\r
- mCpuHotPlugData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress);\r
+ mCpuHotPlugData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress);\r
mCpuHotEjectData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotEjectDataAddress);\r
\r
if (mCpuHotPlugData == NULL) {\r
DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_PLUG_DATA: %r\n", __FUNCTION__, Status));\r
goto Fatal;\r
}\r
+\r
//\r
// If the possible CPU count is 1, there's nothing for this driver to do.\r
//\r
} else {\r
Status = EFI_SUCCESS;\r
}\r
+\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_EJECT_DATA: %r\n", __FUNCTION__, Status));\r
goto Fatal;\r
//\r
if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Len)) ||\r
RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Len, &Size)) ||\r
- RETURN_ERROR (SafeUintnMult (sizeof (UINT32), Len, &SizeSel))) {\r
+ RETURN_ERROR (SafeUintnMult (sizeof (UINT32), Len, &SizeSel)))\r
+ {\r
Status = EFI_ABORTED;\r
DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__));\r
goto Fatal;\r
}\r
- Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, Size,\r
- (VOID **)&mPluggedApicIds);\r
+\r
+ Status = gMmst->MmAllocatePool (\r
+ EfiRuntimeServicesData,\r
+ Size,\r
+ (VOID **)&mPluggedApicIds\r
+ );\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status));\r
goto Fatal;\r
}\r
- Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, Size,\r
- (VOID **)&mToUnplugApicIds);\r
+\r
+ Status = gMmst->MmAllocatePool (\r
+ EfiRuntimeServicesData,\r
+ Size,\r
+ (VOID **)&mToUnplugApicIds\r
+ );\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status));\r
goto ReleasePluggedApicIds;\r
}\r
- Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, SizeSel,\r
- (VOID **)&mToUnplugSelectors);\r
+\r
+ Status = gMmst->MmAllocatePool (\r
+ EfiRuntimeServicesData,\r
+ SizeSel,\r
+ (VOID **)&mToUnplugSelectors\r
+ );\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status));\r
goto ReleaseToUnplugApicIds;\r
//\r
// Allocate the Post-SMM Pen for hot-added CPUs.\r
//\r
- Status = SmbaseAllocatePostSmmPen (&mPostSmmPenAddress,\r
- SystemTable->BootServices);\r
+ Status = SmbaseAllocatePostSmmPen (\r
+ &mPostSmmPenAddress,\r
+ SystemTable->BootServices\r
+ );\r
if (EFI_ERROR (Status)) {\r
goto ReleaseToUnplugSelectors;\r
}\r
QemuCpuhpWriteCommand (mMmCpuIo, QEMU_CPUHP_CMD_GET_PENDING);\r
if (QemuCpuhpReadCommandData2 (mMmCpuIo) != 0) {\r
Status = EFI_NOT_FOUND;\r
- DEBUG ((DEBUG_ERROR, "%a: modern CPU hotplug interface: %r\n",\r
- __FUNCTION__, Status));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: modern CPU hotplug interface: %r\n",\r
+ __FUNCTION__,\r
+ Status\r
+ ));\r
goto ReleasePostSmmPen;\r
}\r
\r
&mDispatchHandle\r
);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_ERROR, "%a: MmiHandlerRegister(): %r\n", __FUNCTION__,\r
- Status));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: MmiHandlerRegister(): %r\n",\r
+ __FUNCTION__,\r
+ Status\r
+ ));\r
goto ReleasePostSmmPen;\r
}\r
\r