1 /** @file 2 Contains function prototypes for Memory Services in the SMM Core. 3 4 This header file borrows the PiSmmCore Memory Allocation services as the primitive 5 for memory allocation. 6 7 Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR> 8 This program and the accompanying materials 9 are licensed and made available under the terms and conditions of the BSD License 10 which accompanies this distribution. The full text of the license may be found at 11 http://opensource.org/licenses/bsd-license.php 12 13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 15 16 **/ 17 18 #ifndef _PI_SMM_CORE_MEMORY_ALLOCATION_SERVICES_H_ 19 #define _PI_SMM_CORE_MEMORY_ALLOCATION_SERVICES_H_ 20 21 // 22 // It should be aligned with the definition in PiSmmCore. 23 // 24 typedef struct { 25 UINTN Signature; 26 27 /// 28 /// The ImageHandle passed into the entry point of the SMM IPL. This ImageHandle 29 /// is used by the SMM Core to fill in the ParentImageHandle field of the Loaded 30 /// Image Protocol for each SMM Driver that is dispatched by the SMM Core. 31 /// 32 EFI_HANDLE SmmIplImageHandle; 33 34 /// 35 /// The number of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM 36 /// Core uses these ranges of SMRAM to initialize the SMM Core memory manager. 37 /// 38 UINTN SmramRangeCount; 39 40 /// 41 /// A table of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM 42 /// Core uses these ranges of SMRAM to initialize the SMM Core memory manager. 43 /// 44 EFI_SMRAM_DESCRIPTOR *SmramRanges; 45 46 /// 47 /// The SMM Foundation Entry Point. The SMM Core fills in this field when the 48 /// SMM Core is initialized. The SMM IPL is responsbile for registering this entry 49 /// point with the SMM Configuration Protocol. The SMM Configuration Protocol may 50 /// not be available at the time the SMM IPL and SMM Core are started, so the SMM IPL 51 /// sets up a protocol notification on the SMM Configuration Protocol and registers 52 /// the SMM Foundation Entry Point as soon as the SMM Configuration Protocol is 53 /// available. 54 /// 55 EFI_SMM_ENTRY_POINT SmmEntryPoint; 56 57 /// 58 /// Boolean flag set to TRUE while an SMI is being processed by the SMM Core. 59 /// 60 BOOLEAN SmmEntryPointRegistered; 61 62 /// 63 /// Boolean flag set to TRUE while an SMI is being processed by the SMM Core. 64 /// 65 BOOLEAN InSmm; 66 67 /// 68 /// This field is set by the SMM Core then the SMM Core is initialized. This field is 69 /// used by the SMM Base 2 Protocol and SMM Communication Protocol implementations in 70 /// the SMM IPL. 71 /// 72 EFI_SMM_SYSTEM_TABLE2 *Smst; 73 74 /// 75 /// This field is used by the SMM Communicatioon Protocol to pass a buffer into 76 /// a software SMI handler and for the software SMI handler to pass a buffer back to 77 /// the caller of the SMM Communication Protocol. 78 /// 79 VOID *CommunicationBuffer; 80 81 /// 82 /// This field is used by the SMM Communicatioon Protocol to pass the size of a buffer, 83 /// in bytes, into a software SMI handler and for the software SMI handler to pass the 84 /// size, in bytes, of a buffer back to the caller of the SMM Communication Protocol. 85 /// 86 UINTN BufferSize; 87 88 /// 89 /// This field is used by the SMM Communication Protocol to pass the return status from 90 /// a software SMI handler back to the caller of the SMM Communication Protocol. 91 /// 92 EFI_STATUS ReturnStatus; 93 94 EFI_PHYSICAL_ADDRESS PiSmmCoreImageBase; 95 UINT64 PiSmmCoreImageSize; 96 EFI_PHYSICAL_ADDRESS PiSmmCoreEntryPoint; 97 } SMM_CORE_PRIVATE_DATA; 98 99 /** 100 Called to initialize the memory service. 101 102 @param SmramRangeCount Number of SMRAM Regions 103 @param SmramRanges Pointer to SMRAM Descriptors 104 105 **/ 106 VOID 107 SmmInitializeMemoryServices ( 108 IN UINTN SmramRangeCount, 109 IN EFI_SMRAM_DESCRIPTOR *SmramRanges 110 ); 111 112 /** 113 Allocates pages from the memory map. 114 115 @param Type The type of allocation to perform 116 @param MemoryType The type of memory to turn the allocated pages 117 into 118 @param NumberOfPages The number of pages to allocate 119 @param Memory A pointer to receive the base allocated memory 120 address 121 122 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec. 123 @retval EFI_NOT_FOUND Could not allocate pages match the requirement. 124 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. 125 @retval EFI_SUCCESS Pages successfully allocated. 126 127 **/ 128 EFI_STATUS 129 EFIAPI 130 SmmAllocatePages ( 131 IN EFI_ALLOCATE_TYPE Type, 132 IN EFI_MEMORY_TYPE MemoryType, 133 IN UINTN NumberOfPages, 134 OUT EFI_PHYSICAL_ADDRESS *Memory 135 ); 136 137 /** 138 Frees previous allocated pages. 139 140 @param Memory Base address of memory being freed 141 @param NumberOfPages The number of pages to free 142 143 @retval EFI_NOT_FOUND Could not find the entry that covers the range 144 @retval EFI_INVALID_PARAMETER Address not aligned 145 @return EFI_SUCCESS Pages successfully freed. 146 147 **/ 148 EFI_STATUS 149 EFIAPI 150 SmmFreePages ( 151 IN EFI_PHYSICAL_ADDRESS Memory, 152 IN UINTN NumberOfPages 153 ); 154 155 /** 156 Allocate pool of a particular type. 157 158 @param PoolType Type of pool to allocate 159 @param Size The amount of pool to allocate 160 @param Buffer The address to return a pointer to the allocated 161 pool 162 163 @retval EFI_INVALID_PARAMETER PoolType not valid 164 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed. 165 @retval EFI_SUCCESS Pool successfully allocated. 166 167 **/ 168 EFI_STATUS 169 EFIAPI 170 SmmAllocatePool ( 171 IN EFI_MEMORY_TYPE PoolType, 172 IN UINTN Size, 173 OUT VOID **Buffer 174 ); 175 176 /** 177 Frees pool. 178 179 @param Buffer The allocated pool entry to free 180 181 @retval EFI_INVALID_PARAMETER Buffer is not a valid value. 182 @retval EFI_SUCCESS Pool successfully freed. 183 184 **/ 185 EFI_STATUS 186 EFIAPI 187 SmmFreePool ( 188 IN VOID *Buffer 189 ); 190 191 #endif 192