From 4e920581133766a31410f9d5b091446a3bc19d8c Mon Sep 17 00:00:00 2001 From: Jeff Fan Date: Tue, 22 Mar 2016 10:19:23 +0800 Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Allocate buffer for each CPU semaphores Allocate each CPU semaphores in allocated aligned semaphores buffer. And add it into semaphores structure. Cc: Michael Kinney Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Feng Tian Reviewed-by: Michael Kinney Regression-tested-by: Laszlo Ersek --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 11 ++++++++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 22ff813b34..241cd35d32 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1208,6 +1208,7 @@ InitializeSmmCpuSemaphores ( UINTN ProcessorCount; UINTN TotalSize; UINTN GlobalSemaphoresSize; + UINTN CpuSemaphoresSize; UINTN SemaphoreSize; UINTN Pages; UINTN *SemaphoreBlock; @@ -1216,7 +1217,8 @@ InitializeSmmCpuSemaphores ( SemaphoreSize = GetSpinLockProperties (); ProcessorCount = gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus; GlobalSemaphoresSize = (sizeof (SMM_CPU_SEMAPHORE_GLOBAL) / sizeof (VOID *)) * SemaphoreSize; - TotalSize = GlobalSemaphoresSize; + CpuSemaphoresSize = (sizeof (SMM_CPU_SEMAPHORE_CPU) / sizeof (VOID *)) * ProcessorCount * SemaphoreSize; + TotalSize = GlobalSemaphoresSize + CpuSemaphoresSize; DEBUG((EFI_D_INFO, "One Semaphore Size = 0x%x\n", SemaphoreSize)); DEBUG((EFI_D_INFO, "Total Semaphores Size = 0x%x\n", TotalSize)); Pages = EFI_SIZE_TO_PAGES (TotalSize); @@ -1236,6 +1238,13 @@ InitializeSmmCpuSemaphores ( mSmmCpuSemaphores.SemaphoreGlobal.CodeAccessCheckLock = (SPIN_LOCK *)SemaphoreAddr; + SemaphoreAddr = (UINTN)SemaphoreBlock + GlobalSemaphoresSize; + mSmmCpuSemaphores.SemaphoreCpu.Busy = (SPIN_LOCK *)SemaphoreAddr; + SemaphoreAddr += ProcessorCount * SemaphoreSize; + mSmmCpuSemaphores.SemaphoreCpu.Run = (UINT32 *)SemaphoreAddr; + SemaphoreAddr += ProcessorCount * SemaphoreSize; + mSmmCpuSemaphores.SemaphoreCpu.Present = (BOOLEAN *)SemaphoreAddr; + mSmmMpSyncData->Counter = mSmmCpuSemaphores.SemaphoreGlobal.Counter; mSmmMpSyncData->InsideSmm = mSmmCpuSemaphores.SemaphoreGlobal.InsideSmm; mSmmMpSyncData->AllCpusInSync = mSmmCpuSemaphores.SemaphoreGlobal.AllCpusInSync; diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index eca42aa8d6..5a0468027d 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -366,11 +366,22 @@ typedef struct { SPIN_LOCK *CodeAccessCheckLock; } SMM_CPU_SEMAPHORE_GLOBAL; +/// +/// All semaphores for each processor +/// +typedef struct { + SPIN_LOCK *Busy; + volatile UINT32 *Run; + volatile BOOLEAN *Present; +} SMM_CPU_SEMAPHORE_CPU; + + /// /// All semaphores' information /// typedef struct { SMM_CPU_SEMAPHORE_GLOBAL SemaphoreGlobal; + SMM_CPU_SEMAPHORE_CPU SemaphoreCpu; } SMM_CPU_SEMAPHORES; extern IA32_DESCRIPTOR gcSmiGdtr;