#include <Library/DebugLib.h>\r
#include "PiSmmCoreMemoryAllocationServices.h"\r
\r
-EFI_SMRAM_DESCRIPTOR *mSmramRanges = NULL;\r
-UINTN mSmramRangeCount = 0;\r
-\r
-/**\r
- This function gets and caches SMRAM ranges that are present in the system.\r
- \r
- It will ASSERT() if SMM Access2 Protocol doesn't exist.\r
- It will ASSERT() if SMRAM ranges can't be got.\r
- It will ASSERT() if Resource can't be allocated for cache SMRAM range. \r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-GetSmramRanges (\r
- VOID\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
- UINTN Size;\r
-\r
- //\r
- // Locate SMM Access2 Protocol\r
- //\r
- Status = gBS->LocateProtocol (\r
- &gEfiSmmAccess2ProtocolGuid, \r
- NULL, \r
- (VOID **)&SmmAccess\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Get SMRAM range information\r
- //\r
- Size = 0;\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
- mSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);\r
- ASSERT (mSmramRanges != NULL);\r
-\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
-}\r
+EFI_SMRAM_DESCRIPTOR *mSmmCoreMemoryAllocLibSmramRanges = NULL;\r
+UINTN mSmmCoreMemoryAllocLibSmramRangeCount = 0;\r
\r
/**\r
Check whether the start address of buffer is within any of the SMRAM ranges.\r
{\r
UINTN Index;\r
\r
- if (mSmramRanges == NULL) {\r
- //\r
- // SMRAM ranges is not got. Try to get them all.\r
- //\r
- GetSmramRanges();\r
- }\r
-\r
- for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
- if (((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer >= mSmramRanges[Index].CpuStart) && \r
- ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer < (mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize))) {\r
+ for (Index = 0; Index < mSmmCoreMemoryAllocLibSmramRangeCount; Index ++) {\r
+ if (((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer >= mSmmCoreMemoryAllocLibSmramRanges[Index].CpuStart) && \r
+ ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer < (mSmmCoreMemoryAllocLibSmramRanges[Index].CpuStart + mSmmCoreMemoryAllocLibSmramRanges[Index].PhysicalSize))) {\r
return TRUE;\r
}\r
}\r
)\r
{\r
SMM_CORE_PRIVATE_DATA *SmmCorePrivate;\r
+ UINTN Size;\r
\r
SmmCorePrivate = (SMM_CORE_PRIVATE_DATA *)ImageHandle;\r
//\r
// Initialize memory service using free SMRAM\r
//\r
SmmInitializeMemoryServices (SmmCorePrivate->SmramRangeCount, SmmCorePrivate->SmramRanges);\r
+\r
+ mSmmCoreMemoryAllocLibSmramRangeCount = SmmCorePrivate->FullSmramRangeCount;\r
+ Size = mSmmCoreMemoryAllocLibSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR);\r
+ mSmmCoreMemoryAllocLibSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);\r
+ ASSERT (mSmmCoreMemoryAllocLibSmramRanges != NULL);\r
+ CopyMem (mSmmCoreMemoryAllocLibSmramRanges, SmmCorePrivate->FullSmramRanges, Size);\r
+\r
return EFI_SUCCESS;\r
}\r
#ifndef _PI_SMM_CORE_MEMORY_ALLOCATION_SERVICES_H_\r
#define _PI_SMM_CORE_MEMORY_ALLOCATION_SERVICES_H_\r
\r
+//\r
+// It should be aligned with the definition in PiSmmCore.\r
+//\r
typedef struct {\r
UINTN Signature;\r
+\r
///\r
/// The ImageHandle passed into the entry point of the SMM IPL. This ImageHandle\r
/// is used by the SMM Core to fill in the ParentImageHandle field of the Loaded\r
/// Image Protocol for each SMM Driver that is dispatched by the SMM Core.\r
///\r
EFI_HANDLE SmmIplImageHandle;\r
+\r
///\r
/// The number of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM\r
/// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.\r
///\r
UINTN SmramRangeCount;\r
+\r
///\r
/// A table of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM\r
/// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.\r
///\r
EFI_SMRAM_DESCRIPTOR *SmramRanges;\r
+\r
+ ///\r
+ /// The SMM Foundation Entry Point. The SMM Core fills in this field when the \r
+ /// SMM Core is initialized. The SMM IPL is responsbile for registering this entry \r
+ /// point with the SMM Configuration Protocol. The SMM Configuration Protocol may \r
+ /// not be available at the time the SMM IPL and SMM Core are started, so the SMM IPL\r
+ /// sets up a protocol notification on the SMM Configuration Protocol and registers \r
+ /// the SMM Foundation Entry Point as soon as the SMM Configuration Protocol is \r
+ /// available.\r
+ ///\r
+ EFI_SMM_ENTRY_POINT SmmEntryPoint;\r
+ \r
+ ///\r
+ /// Boolean flag set to TRUE while an SMI is being processed by the SMM Core.\r
+ /// \r
+ BOOLEAN SmmEntryPointRegistered;\r
+\r
+ ///\r
+ /// Boolean flag set to TRUE while an SMI is being processed by the SMM Core.\r
+ /// \r
+ BOOLEAN InSmm;\r
+\r
+ ///\r
+ /// This field is set by the SMM Core then the SMM Core is initialized. This field is\r
+ /// used by the SMM Base 2 Protocol and SMM Communication Protocol implementations in\r
+ /// the SMM IPL. \r
+ ///\r
+ EFI_SMM_SYSTEM_TABLE2 *Smst;\r
+\r
+ ///\r
+ /// This field is used by the SMM Communicatioon Protocol to pass a buffer into \r
+ /// a software SMI handler and for the software SMI handler to pass a buffer back to\r
+ /// the caller of the SMM Communication Protocol. \r
+ ///\r
+ VOID *CommunicationBuffer;\r
+\r
+ ///\r
+ /// This field is used by the SMM Communicatioon Protocol to pass the size of a buffer,\r
+ /// in bytes, into a software SMI handler and for the software SMI handler to pass the \r
+ /// size, in bytes, of a buffer back to the caller of the SMM Communication Protocol.\r
+ ///\r
+ UINTN BufferSize;\r
+\r
+ ///\r
+ /// This field is used by the SMM Communication Protocol to pass the return status from\r
+ /// a software SMI handler back to the caller of the SMM Communication Protocol.\r
+ ///\r
+ EFI_STATUS ReturnStatus;\r
+\r
+ EFI_PHYSICAL_ADDRESS PiSmmCoreImageBase;\r
+ UINT64 PiSmmCoreImageSize;\r
+ EFI_PHYSICAL_ADDRESS PiSmmCoreEntryPoint;\r
+\r
+ UINTN FullSmramRangeCount;\r
+ EFI_SMRAM_DESCRIPTOR *FullSmramRanges;\r
} SMM_CORE_PRIVATE_DATA;\r
\r
/**\r