OvmfPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the OvmfPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:09 -08:00
committed by mergify[bot]
parent d1050b9dff
commit ac0a286f4d
445 changed files with 30894 additions and 26369 deletions

View File

@@ -18,6 +18,6 @@ typedef UINT32 APIC_ID;
//
// The PrintLib conversion specification for formatting an APIC_ID.
//
#define FMT_APIC_ID "0x%08x"
#define FMT_APIC_ID "0x%08x"
#endif // APIC_ID_H_

View File

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

View File

@@ -29,18 +29,18 @@ typedef struct {
// This field is intentionally wider than APIC_ID (UINT32) because we need a
// "gate locked" value that is different from all possible APIC_IDs.
//
UINT64 ApicIdGate;
UINT64 ApicIdGate;
//
// The new SMBASE value for the hot-added CPU to set in the SMRAM Save State
// Map, before leaving SMM with the RSM instruction.
//
UINT32 NewSmbase;
UINT32 NewSmbase;
//
// The hot-added CPU sets this field to 1 right before executing the RSM
// instruction. This tells the SMM Monarch to proceed to polling the last
// byte of the normal RAM reserved page (Post-SMM Pen).
//
UINT8 AboutToLeaveSmm;
UINT8 AboutToLeaveSmm;
} FIRST_SMI_HANDLER_CONTEXT;
#pragma pack ()

View File

@@ -21,83 +21,86 @@
UINT32
QemuCpuhpReadCommandData2 (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
)
{
UINT32 CommandData2;
EFI_STATUS Status;
UINT32 CommandData2;
EFI_STATUS Status;
CommandData2 = 0;
Status = MmCpuIo->Io.Read (
MmCpuIo,
MM_IO_UINT32,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CMD_DATA2,
1,
&CommandData2
);
Status = MmCpuIo->Io.Read (
MmCpuIo,
MM_IO_UINT32,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CMD_DATA2,
1,
&CommandData2
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
ASSERT (FALSE);
CpuDeadLoop ();
}
return CommandData2;
}
UINT8
QemuCpuhpReadCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
)
{
UINT8 CpuStatus;
EFI_STATUS Status;
UINT8 CpuStatus;
EFI_STATUS Status;
CpuStatus = 0;
Status = MmCpuIo->Io.Read (
MmCpuIo,
MM_IO_UINT8,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CPU_STAT,
1,
&CpuStatus
);
Status = MmCpuIo->Io.Read (
MmCpuIo,
MM_IO_UINT8,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CPU_STAT,
1,
&CpuStatus
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
ASSERT (FALSE);
CpuDeadLoop ();
}
return CpuStatus;
}
UINT32
QemuCpuhpReadCommandData (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
)
{
UINT32 CommandData;
EFI_STATUS Status;
UINT32 CommandData;
EFI_STATUS Status;
CommandData = 0;
Status = MmCpuIo->Io.Read (
MmCpuIo,
MM_IO_UINT32,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_RW_CMD_DATA,
1,
&CommandData
);
Status = MmCpuIo->Io.Read (
MmCpuIo,
MM_IO_UINT32,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_RW_CMD_DATA,
1,
&CommandData
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
ASSERT (FALSE);
CpuDeadLoop ();
}
return CommandData;
}
VOID
QemuCpuhpWriteCpuSelector (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 Selector
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 Selector
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MmCpuIo->Io.Write (
MmCpuIo,
@@ -115,11 +118,11 @@ QemuCpuhpWriteCpuSelector (
VOID
QemuCpuhpWriteCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 CpuStatus
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 CpuStatus
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MmCpuIo->Io.Write (
MmCpuIo,
@@ -137,11 +140,11 @@ QemuCpuhpWriteCpuStatus (
VOID
QemuCpuhpWriteCommand (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 Command
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 Command
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MmCpuIo->Io.Write (
MmCpuIo,
@@ -206,33 +209,33 @@ QemuCpuhpWriteCommand (
**/
EFI_STATUS
QemuCpuhpCollectApicIds (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 PossibleCpuCount,
IN UINT32 ApicIdCount,
OUT APIC_ID *PluggedApicIds,
OUT UINT32 *PluggedCount,
OUT APIC_ID *ToUnplugApicIds,
OUT UINT32 *ToUnplugSelectors,
OUT UINT32 *ToUnplugCount
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 PossibleCpuCount,
IN UINT32 ApicIdCount,
OUT APIC_ID *PluggedApicIds,
OUT UINT32 *PluggedCount,
OUT APIC_ID *ToUnplugApicIds,
OUT UINT32 *ToUnplugSelectors,
OUT UINT32 *ToUnplugCount
)
{
UINT32 CurrentSelector;
UINT32 CurrentSelector;
if (PossibleCpuCount == 0 || ApicIdCount == 0) {
if ((PossibleCpuCount == 0) || (ApicIdCount == 0)) {
return EFI_INVALID_PARAMETER;
}
*PluggedCount = 0;
*PluggedCount = 0;
*ToUnplugCount = 0;
CurrentSelector = 0;
do {
UINT32 PendingSelector;
UINT8 CpuStatus;
APIC_ID *ExtendIds;
UINT32 *ExtendSels;
UINT32 *ExtendCount;
APIC_ID NewApicId;
UINT32 PendingSelector;
UINT8 CpuStatus;
APIC_ID *ExtendIds;
UINT32 *ExtendSels;
UINT32 *ExtendCount;
APIC_ID NewApicId;
//
// Write CurrentSelector (which is valid) to the CPU selector register.
@@ -259,10 +262,17 @@ QemuCpuhpCollectApicIds (
QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_PENDING);
PendingSelector = QemuCpuhpReadCommandData (MmCpuIo);
if (PendingSelector < CurrentSelector) {
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u PendingSelector=%u: "
"wrap-around\n", __FUNCTION__, CurrentSelector, PendingSelector));
DEBUG ((
DEBUG_VERBOSE,
"%a: CurrentSelector=%u PendingSelector=%u: "
"wrap-around\n",
__FUNCTION__,
CurrentSelector,
PendingSelector
));
break;
}
CurrentSelector = PendingSelector;
//
@@ -274,16 +284,26 @@ QemuCpuhpCollectApicIds (
// The "insert" event guarantees the "enabled" status; plus it excludes
// the "fw_remove" event.
//
if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0 ||
(CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) != 0) {
DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=%u CpuStatus=0x%x: "
"inconsistent CPU status\n", __FUNCTION__, CurrentSelector,
CpuStatus));
if (((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0) ||
((CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) != 0))
{
DEBUG ((
DEBUG_ERROR,
"%a: CurrentSelector=%u CpuStatus=0x%x: "
"inconsistent CPU status\n",
__FUNCTION__,
CurrentSelector,
CpuStatus
));
return EFI_PROTOCOL_ERROR;
}
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: insert\n", __FUNCTION__,
CurrentSelector));
DEBUG ((
DEBUG_VERBOSE,
"%a: CurrentSelector=%u: insert\n",
__FUNCTION__,
CurrentSelector
));
ExtendIds = PluggedApicIds;
ExtendSels = NULL;
@@ -293,14 +313,23 @@ QemuCpuhpCollectApicIds (
// "fw_remove" event guarantees "enabled".
//
if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0) {
DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=%u CpuStatus=0x%x: "
"inconsistent CPU status\n", __FUNCTION__, CurrentSelector,
CpuStatus));
DEBUG ((
DEBUG_ERROR,
"%a: CurrentSelector=%u CpuStatus=0x%x: "
"inconsistent CPU status\n",
__FUNCTION__,
CurrentSelector,
CpuStatus
));
return EFI_PROTOCOL_ERROR;
}
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: fw_remove\n",
__FUNCTION__, CurrentSelector));
DEBUG ((
DEBUG_VERBOSE,
"%a: CurrentSelector=%u: fw_remove\n",
__FUNCTION__,
CurrentSelector
));
ExtendIds = ToUnplugApicIds;
ExtendSels = ToUnplugSelectors;
@@ -309,15 +338,23 @@ QemuCpuhpCollectApicIds (
//
// Let the OSPM deal with the "remove" event.
//
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: remove (ignored)\n",
__FUNCTION__, CurrentSelector));
DEBUG ((
DEBUG_VERBOSE,
"%a: CurrentSelector=%u: remove (ignored)\n",
__FUNCTION__,
CurrentSelector
));
ExtendIds = NULL;
ExtendSels = NULL;
ExtendCount = NULL;
} else {
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: no event\n",
__FUNCTION__, CurrentSelector));
DEBUG ((
DEBUG_VERBOSE,
"%a: CurrentSelector=%u: no event\n",
__FUNCTION__,
CurrentSelector
));
break;
}
@@ -334,15 +371,22 @@ QemuCpuhpCollectApicIds (
DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__));
return EFI_BUFFER_TOO_SMALL;
}
QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID);
NewApicId = QemuCpuhpReadCommandData (MmCpuIo);
DEBUG ((DEBUG_VERBOSE, "%a: ApicId=" FMT_APIC_ID "\n", __FUNCTION__,
NewApicId));
DEBUG ((
DEBUG_VERBOSE,
"%a: ApicId=" FMT_APIC_ID "\n",
__FUNCTION__,
NewApicId
));
if (ExtendSels != NULL) {
ExtendSels[(*ExtendCount)] = CurrentSelector;
}
ExtendIds[(*ExtendCount)++] = NewApicId;
}
//
// We've processed the CPU with (known) pending events, but we must never
// clear events. Therefore we need to advance past this CPU manually;
@@ -352,7 +396,12 @@ QemuCpuhpCollectApicIds (
CurrentSelector++;
} while (CurrentSelector < PossibleCpuCount);
DEBUG ((DEBUG_VERBOSE, "%a: PluggedCount=%u ToUnplugCount=%u\n",
__FUNCTION__, *PluggedCount, *ToUnplugCount));
DEBUG ((
DEBUG_VERBOSE,
"%a: PluggedCount=%u ToUnplugCount=%u\n",
__FUNCTION__,
*PluggedCount,
*ToUnplugCount
));
return EFI_SUCCESS;
}

View File

@@ -22,47 +22,47 @@
UINT32
QemuCpuhpReadCommandData2 (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
);
UINT8
QemuCpuhpReadCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
);
UINT32
QemuCpuhpReadCommandData (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
);
VOID
QemuCpuhpWriteCpuSelector (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 Selector
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 Selector
);
VOID
QemuCpuhpWriteCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 CpuStatus
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 CpuStatus
);
VOID
QemuCpuhpWriteCommand (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 Command
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 Command
);
EFI_STATUS
QemuCpuhpCollectApicIds (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 PossibleCpuCount,
IN UINT32 ApicIdCount,
OUT APIC_ID *PluggedApicIds,
OUT UINT32 *PluggedCount,
OUT APIC_ID *ToUnplugApicIds,
OUT UINT32 *ToUnplugSelectors,
OUT UINT32 *ToUnplugCount
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 PossibleCpuCount,
IN UINT32 ApicIdCount,
OUT APIC_ID *PluggedApicIds,
OUT UINT32 *PluggedCount,
OUT APIC_ID *ToUnplugApicIds,
OUT UINT32 *ToUnplugSelectors,
OUT UINT32 *ToUnplugCount
);
#endif // QEMU_CPUHP_H_

View File

@@ -18,10 +18,10 @@
#include "Smbase.h"
extern CONST UINT8 mPostSmmPen[];
extern CONST UINT16 mPostSmmPenSize;
extern CONST UINT8 mFirstSmiHandler[];
extern CONST UINT16 mFirstSmiHandlerSize;
extern CONST UINT8 mPostSmmPen[];
extern CONST UINT16 mPostSmmPenSize;
extern CONST UINT8 mFirstSmiHandler[];
extern CONST UINT16 mFirstSmiHandlerSize;
/**
Allocate a non-SMRAM reserved memory page for the Post-SMM Pen for hot-added
@@ -46,12 +46,12 @@ extern CONST UINT16 mFirstSmiHandlerSize;
**/
EFI_STATUS
SmbaseAllocatePostSmmPen (
OUT UINT32 *PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
OUT UINT32 *PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Address;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Address;
//
// The pen code must fit in one page, and the last byte must remain free for
@@ -59,14 +59,23 @@ SmbaseAllocatePostSmmPen (
//
if (mPostSmmPenSize >= EFI_PAGE_SIZE) {
Status = EFI_BAD_BUFFER_SIZE;
DEBUG ((DEBUG_ERROR, "%a: mPostSmmPenSize=%u: %r\n", __FUNCTION__,
mPostSmmPenSize, Status));
DEBUG ((
DEBUG_ERROR,
"%a: mPostSmmPenSize=%u: %r\n",
__FUNCTION__,
mPostSmmPenSize,
Status
));
return Status;
}
Address = BASE_1MB - 1;
Status = BootServices->AllocatePages (AllocateMaxAddress,
EfiReservedMemoryType, 1, &Address);
Status = BootServices->AllocatePages (
AllocateMaxAddress,
EfiReservedMemoryType,
1,
&Address
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: AllocatePages(): %r\n", __FUNCTION__, Status));
return Status;
@@ -90,7 +99,7 @@ SmbaseAllocatePostSmmPen (
**/
VOID
SmbaseReinstallPostSmmPen (
IN UINT32 PenAddress
IN UINT32 PenAddress
)
{
CopyMem ((VOID *)(UINTN)PenAddress, mPostSmmPen, mPostSmmPenSize);
@@ -110,8 +119,8 @@ SmbaseReinstallPostSmmPen (
**/
VOID
SmbaseReleasePostSmmPen (
IN UINT32 PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
IN UINT32 PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
)
{
BootServices->FreePages (PenAddress, 1);
@@ -133,12 +142,15 @@ SmbaseInstallFirstSmiHandler (
VOID
)
{
FIRST_SMI_HANDLER_CONTEXT *Context;
FIRST_SMI_HANDLER_CONTEXT *Context;
CopyMem ((VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET),
mFirstSmiHandler, mFirstSmiHandlerSize);
CopyMem (
(VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET),
mFirstSmiHandler,
mFirstSmiHandlerSize
);
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
Context->ApicIdGate = MAX_UINT64;
}
@@ -184,25 +196,31 @@ SmbaseInstallFirstSmiHandler (
**/
EFI_STATUS
SmbaseRelocate (
IN APIC_ID ApicId,
IN UINTN Smbase,
IN UINT32 PenAddress
IN APIC_ID ApicId,
IN UINTN Smbase,
IN UINT32 PenAddress
)
{
EFI_STATUS Status;
volatile UINT8 *SmmVacated;
volatile FIRST_SMI_HANDLER_CONTEXT *Context;
UINT64 ExchangeResult;
EFI_STATUS Status;
volatile UINT8 *SmmVacated;
volatile FIRST_SMI_HANDLER_CONTEXT *Context;
UINT64 ExchangeResult;
if (Smbase > MAX_UINT32) {
Status = EFI_INVALID_PARAMETER;
DEBUG ((DEBUG_ERROR, "%a: ApicId=" FMT_APIC_ID " Smbase=0x%Lx: %r\n",
__FUNCTION__, ApicId, (UINT64)Smbase, Status));
DEBUG ((
DEBUG_ERROR,
"%a: ApicId=" FMT_APIC_ID " Smbase=0x%Lx: %r\n",
__FUNCTION__,
ApicId,
(UINT64)Smbase,
Status
));
return Status;
}
SmmVacated = (UINT8 *)(UINTN)PenAddress + (EFI_PAGE_SIZE - 1);
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
//
// Clear AboutToLeaveSmm, so we notice when the hot-added CPU is just about
@@ -261,12 +279,21 @@ SmbaseRelocate (
//
// Un-gate SMBASE relocation for the hot-added CPU whose APIC ID is ApicId.
//
ExchangeResult = InterlockedCompareExchange64 (&Context->ApicIdGate,
MAX_UINT64, ApicId);
ExchangeResult = InterlockedCompareExchange64 (
&Context->ApicIdGate,
MAX_UINT64,
ApicId
);
if (ExchangeResult != MAX_UINT64) {
Status = EFI_PROTOCOL_ERROR;
DEBUG ((DEBUG_ERROR, "%a: ApicId=" FMT_APIC_ID " ApicIdGate=0x%Lx: %r\n",
__FUNCTION__, ApicId, ExchangeResult, Status));
DEBUG ((
DEBUG_ERROR,
"%a: ApicId=" FMT_APIC_ID " ApicIdGate=0x%Lx: %r\n",
__FUNCTION__,
ApicId,
ExchangeResult,
Status
));
return Status;
}

View File

@@ -16,19 +16,19 @@
EFI_STATUS
SmbaseAllocatePostSmmPen (
OUT UINT32 *PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
OUT UINT32 *PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
);
VOID
SmbaseReinstallPostSmmPen (
IN UINT32 PenAddress
IN UINT32 PenAddress
);
VOID
SmbaseReleasePostSmmPen (
IN UINT32 PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
IN UINT32 PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices
);
VOID
@@ -38,9 +38,9 @@ SmbaseInstallFirstSmiHandler (
EFI_STATUS
SmbaseRelocate (
IN APIC_ID ApicId,
IN UINTN Smbase,
IN UINT32 PenAddress
IN APIC_ID ApicId,
IN UINTN Smbase,
IN UINT32 PenAddress
);
#endif // SMBASE_H_