]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
UefiCpuPkg/PiSmmCpuDxeSmm: Using global semaphores in aligned buffer
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / PiSmmCpuDxeSmm.h
index 9ea11894cdd550de81a7a1a99b419ff7118b1e84..eca42aa8d69863b93b114fcc0852afa078bfec7b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.\r
 \r
-Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -21,7 +21,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/SmmConfiguration.h>\r
 #include <Protocol/SmmCpu.h>\r
 #include <Protocol/SmmAccess2.h>\r
-#include <Protocol/SmmCpuSaveState.h>\r
 #include <Protocol/SmmReadyToLock.h>\r
 #include <Protocol/SmmCpuService.h>\r
 \r
@@ -30,7 +29,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/TimerLib.h>\r
-#include <Library/SmmLib.h>\r
 #include <Library/SynchronizationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
@@ -55,6 +53,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <CpuHotPlugData.h>\r
 \r
 #include <Register/Cpuid.h>\r
+#include <Register/Msr.h>\r
 \r
 #include "CpuService.h"\r
 #include "SmmProfile.h"\r
@@ -73,15 +72,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 ///\r
 #define IA32_PG_P                   BIT0\r
 #define IA32_PG_RW                  BIT1\r
+#define IA32_PG_U                   BIT2\r
 #define IA32_PG_WT                  BIT3\r
 #define IA32_PG_CD                  BIT4\r
 #define IA32_PG_A                   BIT5\r
+#define IA32_PG_D                   BIT6\r
 #define IA32_PG_PS                  BIT7\r
 #define IA32_PG_PAT_2M              BIT12\r
 #define IA32_PG_PAT_4K              IA32_PG_PS\r
 #define IA32_PG_PMNT                BIT62\r
 #define IA32_PG_NX                  BIT63\r
 \r
+#define PAGE_ATTRIBUTE_BITS         (IA32_PG_RW | IA32_PG_P)\r
+//\r
+// Bits 1, 2, 5, 6 are reserved in the IA32 PAE PDPTE\r
+// X64 PAE PDPTE does not have such restriction\r
+//\r
+#define IA32_PAE_PDPTE_ATTRIBUTE_BITS    (IA32_PG_P)\r
+\r
 //\r
 // Size of Task-State Segment defined in IA32 Manual\r
 //\r
@@ -306,10 +314,10 @@ typedef struct {
   // so that UC cache-ability can be set together.\r
   //\r
   SMM_CPU_DATA_BLOCK            *CpuData;\r
-  volatile UINT32               Counter;\r
+  volatile UINT32               *Counter;\r
   volatile UINT32               BspIndex;\r
-  volatile BOOLEAN              InsideSmm;\r
-  volatile BOOLEAN              AllCpusInSync;\r
+  volatile BOOLEAN              *InsideSmm;\r
+  volatile BOOLEAN              *AllCpusInSync;\r
   volatile SMM_CPU_SYNC_MODE    EffectiveSyncMode;\r
   volatile BOOLEAN              SwitchBsp;\r
   volatile BOOLEAN              *CandidateBsp;\r
@@ -346,6 +354,25 @@ typedef struct {
   UINT64                            MtrrBaseMaskPtr;        // Offset 0x58\r
 } PROCESSOR_SMM_DESCRIPTOR;\r
 \r
+\r
+///\r
+/// All global semaphores' pointer\r
+///\r
+typedef struct {\r
+  volatile UINT32      *Counter;\r
+  volatile BOOLEAN     *InsideSmm;\r
+  volatile BOOLEAN     *AllCpusInSync;\r
+  SPIN_LOCK            *PFLock;\r
+  SPIN_LOCK            *CodeAccessCheckLock;\r
+} SMM_CPU_SEMAPHORE_GLOBAL;\r
+\r
+///\r
+/// All semaphores' information\r
+///\r
+typedef struct {\r
+  SMM_CPU_SEMAPHORE_GLOBAL          SemaphoreGlobal;\r
+} SMM_CPU_SEMAPHORES;\r
+\r
 extern IA32_DESCRIPTOR                     gcSmiGdtr;\r
 extern IA32_DESCRIPTOR                     gcSmiIdtr;\r
 extern VOID                                *gcSmiIdtrPtr;\r
@@ -361,17 +388,21 @@ extern UINTN                               mSmmStackArrayEnd;
 extern UINTN                               mSmmStackSize;\r
 extern EFI_SMM_CPU_SERVICE_PROTOCOL        mSmmCpuService;\r
 extern IA32_DESCRIPTOR                     gcSmiInitGdtr;\r
+extern SPIN_LOCK                           *mPFLock;\r
+extern SPIN_LOCK                           *mConfigSmmCodeAccessCheckLock;\r
 \r
 /**\r
   Create 4G PageTable in SMRAM.\r
 \r
   @param          ExtraPages       Additional page numbers besides for 4G memory\r
+  @param          Is32BitPageTable Whether the page table is 32-bit PAE\r
   @return         PageTable Address\r
 \r
 **/\r
 UINT32\r
 Gen4GPageTable (\r
-  IN      UINTN                     ExtraPages\r
+  IN      UINTN                     ExtraPages,\r
+  IN      BOOLEAN                   Is32BitPageTable\r
   );\r
 \r
 \r
@@ -429,6 +460,21 @@ InitializeIDTSmmStackGuard (
   VOID\r
   );\r
 \r
+/**\r
+  Initialize Gdt for all processors.\r
+  \r
+  @param[in]   Cr3          CR3 value.\r
+  @param[out]  GdtStepSize  The step size for GDT table.\r
+\r
+  @return GdtBase for processor 0.\r
+          GdtBase for processor X is: GdtBase + (GdtStepSize * X)\r
+**/\r
+VOID *\r
+InitGdt (\r
+  IN  UINTN  Cr3,\r
+  OUT UINTN  *GdtStepSize\r
+  );\r
+\r
 /**\r
 \r
   Register the SMM Foundation entry point.\r
@@ -573,6 +619,15 @@ PerformRemainingTasks (
   VOID\r
   );\r
 \r
+/**\r
+  Perform the pre tasks.\r
+\r
+**/\r
+VOID\r
+PerformPreTasks (\r
+  VOID\r
+  );\r
+\r
 /**\r
   Initialize MSR spin lock by MSR index.\r
 \r
@@ -696,4 +751,25 @@ VOID
 DumpModuleInfoByIp (\r
   IN  UINTN              CallerIpAddress\r
   );\r
+\r
+/**\r
+  This API provides a way to allocate memory for page table.\r
+\r
+  This API can be called more once to allocate memory for page tables.\r
+\r
+  Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
+  allocated buffer.  The buffer returned is aligned on a 4KB boundary.  If Pages is 0, then NULL\r
+  is returned.  If there is not enough memory remaining to satisfy the request, then NULL is\r
+  returned.\r
+\r
+  @param  Pages                 The number of 4 KB pages to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+AllocatePageTableMemory (\r
+  IN UINTN           Pages\r
+  );\r
+\r
 #endif\r