]>
Commit | Line | Data |
---|---|---|
e42e9404 | 1 | /** @file\r |
2 | The internal header file includes the common header files, defines\r | |
3 | internal structure and functions used by SmmCore module.\r | |
4 | \r | |
afebc515 | 5 | Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e42e9404 | 7 | \r |
8 | **/\r | |
9 | \r | |
10 | #ifndef _SMM_CORE_H_\r | |
11 | #define _SMM_CORE_H_\r | |
12 | \r | |
13 | #include <PiSmm.h>\r | |
14 | \r | |
15 | #include <Protocol/DxeSmmReadyToLock.h>\r | |
16 | #include <Protocol/SmmReadyToLock.h>\r | |
46ece1ff | 17 | #include <Protocol/SmmEndOfDxe.h>\r |
e42e9404 | 18 | #include <Protocol/CpuIo2.h>\r |
19 | #include <Protocol/SmmCommunication.h>\r | |
20 | #include <Protocol/SmmAccess2.h>\r | |
d1102dba LG |
21 | #include <Protocol/FirmwareVolume2.h>\r |
22 | #include <Protocol/LoadedImage.h>\r | |
23 | #include <Protocol/DevicePath.h>\r | |
24 | #include <Protocol/Security.h>\r | |
bc2dfdbc | 25 | #include <Protocol/Security2.h>\r |
53ec4d7f SZ |
26 | #include <Protocol/SmmExitBootServices.h>\r |
27 | #include <Protocol/SmmLegacyBoot.h>\r | |
28 | #include <Protocol/SmmReadyToBoot.h>\r | |
e63da9f0 | 29 | #include <Protocol/SmmMemoryAttribute.h>\r |
7b9b55b2 | 30 | #include <Protocol/SmmSxDispatch2.h>\r |
e42e9404 | 31 | \r |
32 | #include <Guid/Apriori.h>\r | |
33 | #include <Guid/EventGroup.h>\r | |
34 | #include <Guid/EventLegacyBios.h>\r | |
84edd20b | 35 | #include <Guid/MemoryProfile.h>\r |
94a1bc12 | 36 | #include <Guid/LoadModuleAtFixedAddress.h>\r |
ca41f3f4 | 37 | #include <Guid/SmiHandlerProfile.h>\r |
a85e7127 | 38 | #include <Guid/EndOfS3Resume.h>\r |
1bae3e0e | 39 | #include <Guid/S3SmmInitDone.h>\r |
e42e9404 | 40 | \r |
41 | #include <Library/BaseLib.h>\r | |
42 | #include <Library/BaseMemoryLib.h>\r | |
43 | #include <Library/PeCoffLib.h>\r | |
e524f680 | 44 | #include <Library/PeCoffGetEntryPointLib.h>\r |
e42e9404 | 45 | #include <Library/CacheMaintenanceLib.h>\r |
46 | #include <Library/DebugLib.h>\r | |
47 | #include <Library/ReportStatusCodeLib.h>\r | |
48 | #include <Library/MemoryAllocationLib.h>\r | |
d1102dba LG |
49 | #include <Library/DevicePathLib.h>\r |
50 | #include <Library/UefiLib.h>\r | |
3c447c27 | 51 | #include <Library/UefiBootServicesTableLib.h>\r |
52 | #include <Library/PcdLib.h>\r | |
495797c5 | 53 | #include <Library/SmmCorePlatformHookLib.h>\r |
54 | #include <Library/PerformanceLib.h>\r | |
3720ee6d | 55 | #include <Library/HobLib.h>\r |
842b1242 | 56 | #include <Library/SmmMemLib.h>\r |
cab1f025 | 57 | #include <Library/SafeIntLib.h>\r |
e42e9404 | 58 | \r |
59 | #include "PiSmmCorePrivateData.h"\r | |
e63da9f0 | 60 | #include "HeapGuard.h"\r |
e42e9404 | 61 | \r |
62 | //\r | |
63 | // Used to build a table of SMI Handlers that the SMM Core registers\r | |
64 | //\r | |
65 | typedef struct {\r | |
1436aea4 MK |
66 | EFI_SMM_HANDLER_ENTRY_POINT2 Handler;\r |
67 | EFI_GUID *HandlerType;\r | |
68 | EFI_HANDLE DispatchHandle;\r | |
69 | BOOLEAN UnRegister;\r | |
e42e9404 | 70 | } SMM_CORE_SMI_HANDLERS;\r |
71 | \r | |
ca41f3f4 JY |
72 | //\r |
73 | // SMM_HANDLER - used for each SMM handler\r | |
74 | //\r | |
75 | \r | |
76 | #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')\r | |
77 | \r | |
1436aea4 MK |
78 | typedef struct {\r |
79 | UINTN Signature;\r | |
80 | LIST_ENTRY AllEntries; // All entries\r | |
ca41f3f4 | 81 | \r |
1436aea4 MK |
82 | EFI_GUID HandlerType; // Type of interrupt\r |
83 | LIST_ENTRY SmiHandlers; // All handlers\r | |
ca41f3f4 JY |
84 | } SMI_ENTRY;\r |
85 | \r | |
86 | #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')\r | |
87 | \r | |
1436aea4 MK |
88 | typedef struct {\r |
89 | UINTN Signature;\r | |
90 | LIST_ENTRY Link; // Link on SMI_ENTRY.SmiHandlers\r | |
91 | EFI_SMM_HANDLER_ENTRY_POINT2 Handler; // The smm handler's entry point\r | |
92 | UINTN CallerAddr; // The address of caller who register the SMI handler.\r | |
93 | SMI_ENTRY *SmiEntry;\r | |
94 | VOID *Context; // for profile\r | |
95 | UINTN ContextSize; // for profile\r | |
ca41f3f4 JY |
96 | } SMI_HANDLER;\r |
97 | \r | |
e42e9404 | 98 | //\r |
99 | // Structure for recording the state of an SMM Driver\r | |
100 | //\r | |
1436aea4 | 101 | #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')\r |
e42e9404 | 102 | \r |
103 | typedef struct {\r | |
1436aea4 MK |
104 | UINTN Signature;\r |
105 | LIST_ENTRY Link; // mDriverList\r | |
e42e9404 | 106 | \r |
1436aea4 | 107 | LIST_ENTRY ScheduledLink; // mScheduledQueue\r |
e42e9404 | 108 | \r |
1436aea4 MK |
109 | EFI_HANDLE FvHandle;\r |
110 | EFI_GUID FileName;\r | |
111 | EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;\r | |
112 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r | |
e42e9404 | 113 | \r |
1436aea4 MK |
114 | VOID *Depex;\r |
115 | UINTN DepexSize;\r | |
e42e9404 | 116 | \r |
1436aea4 MK |
117 | BOOLEAN Before;\r |
118 | BOOLEAN After;\r | |
119 | EFI_GUID BeforeAfterGuid;\r | |
e42e9404 | 120 | \r |
1436aea4 MK |
121 | BOOLEAN Dependent;\r |
122 | BOOLEAN Scheduled;\r | |
123 | BOOLEAN Initialized;\r | |
124 | BOOLEAN DepexProtocolError;\r | |
e42e9404 | 125 | \r |
1436aea4 MK |
126 | EFI_HANDLE ImageHandle;\r |
127 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
e42e9404 | 128 | //\r |
129 | // Image EntryPoint in SMRAM\r | |
130 | //\r | |
1436aea4 | 131 | PHYSICAL_ADDRESS ImageEntryPoint;\r |
e42e9404 | 132 | //\r |
d1102dba | 133 | // Image Buffer in SMRAM\r |
e42e9404 | 134 | //\r |
1436aea4 | 135 | PHYSICAL_ADDRESS ImageBuffer;\r |
e42e9404 | 136 | //\r |
137 | // Image Page Number\r | |
138 | //\r | |
1436aea4 MK |
139 | UINTN NumberOfPage;\r |
140 | EFI_HANDLE SmmImageHandle;\r | |
141 | EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;\r | |
e42e9404 | 142 | } EFI_SMM_DRIVER_ENTRY;\r |
143 | \r | |
1436aea4 | 144 | #define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','d','l')\r |
e42e9404 | 145 | \r |
146 | ///\r | |
147 | /// IHANDLE - contains a list of protocol handles\r | |
148 | ///\r | |
149 | typedef struct {\r | |
1436aea4 | 150 | UINTN Signature;\r |
e42e9404 | 151 | /// All handles list of IHANDLE\r |
1436aea4 | 152 | LIST_ENTRY AllHandles;\r |
e42e9404 | 153 | /// List of PROTOCOL_INTERFACE's for this handle\r |
1436aea4 MK |
154 | LIST_ENTRY Protocols;\r |
155 | UINTN LocateRequest;\r | |
e42e9404 | 156 | } IHANDLE;\r |
157 | \r | |
158 | #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)\r | |
159 | \r | |
1436aea4 | 160 | #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')\r |
e42e9404 | 161 | \r |
162 | ///\r | |
163 | /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol\r | |
164 | /// database. Each handler that supports this protocol is listed, along\r | |
165 | /// with a list of registered notifies.\r | |
166 | ///\r | |
167 | typedef struct {\r | |
1436aea4 | 168 | UINTN Signature;\r |
e42e9404 | 169 | /// Link Entry inserted to mProtocolDatabase\r |
1436aea4 | 170 | LIST_ENTRY AllEntries;\r |
e42e9404 | 171 | /// ID of the protocol\r |
1436aea4 | 172 | EFI_GUID ProtocolID;\r |
e42e9404 | 173 | /// All protocol interfaces\r |
1436aea4 | 174 | LIST_ENTRY Protocols;\r |
4be497df | 175 | /// Registered notification handlers\r |
1436aea4 | 176 | LIST_ENTRY Notify;\r |
e42e9404 | 177 | } PROTOCOL_ENTRY;\r |
178 | \r | |
afebc515 | 179 | #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('s','p','i','f')\r |
e42e9404 | 180 | \r |
181 | ///\r | |
182 | /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked\r | |
183 | /// with a protocol interface structure\r | |
184 | ///\r | |
185 | typedef struct {\r | |
1436aea4 | 186 | UINTN Signature;\r |
e42e9404 | 187 | /// Link on IHANDLE.Protocols\r |
1436aea4 | 188 | LIST_ENTRY Link;\r |
e42e9404 | 189 | /// Back pointer\r |
1436aea4 | 190 | IHANDLE *Handle;\r |
e42e9404 | 191 | /// Link on PROTOCOL_ENTRY.Protocols\r |
1436aea4 | 192 | LIST_ENTRY ByProtocol;\r |
e42e9404 | 193 | /// The protocol ID\r |
1436aea4 | 194 | PROTOCOL_ENTRY *Protocol;\r |
e42e9404 | 195 | /// The interface value\r |
1436aea4 | 196 | VOID *Interface;\r |
e42e9404 | 197 | } PROTOCOL_INTERFACE;\r |
198 | \r | |
1436aea4 | 199 | #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','t','n')\r |
e42e9404 | 200 | \r |
201 | ///\r | |
202 | /// PROTOCOL_NOTIFY - used for each register notification for a protocol\r | |
203 | ///\r | |
204 | typedef struct {\r | |
1436aea4 MK |
205 | UINTN Signature;\r |
206 | PROTOCOL_ENTRY *Protocol;\r | |
e42e9404 | 207 | /// All notifications for this protocol\r |
1436aea4 | 208 | LIST_ENTRY Link;\r |
e42e9404 | 209 | /// Notification function\r |
1436aea4 | 210 | EFI_SMM_NOTIFY_FN Function;\r |
e42e9404 | 211 | /// Last position notified\r |
1436aea4 | 212 | LIST_ENTRY *Position;\r |
e42e9404 | 213 | } PROTOCOL_NOTIFY;\r |
214 | \r | |
215 | //\r | |
216 | // SMM Core Global Variables\r | |
217 | //\r | |
218 | extern SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;\r | |
219 | extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst;\r | |
220 | extern LIST_ENTRY gHandleList;\r | |
3c447c27 | 221 | extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase;\r |
e42e9404 | 222 | \r |
223 | /**\r | |
224 | Called to initialize the memory service.\r | |
225 | \r | |
226 | @param SmramRangeCount Number of SMRAM Regions\r | |
227 | @param SmramRanges Pointer to SMRAM Descriptors\r | |
228 | \r | |
229 | **/\r | |
230 | VOID\r | |
231 | SmmInitializeMemoryServices (\r | |
232 | IN UINTN SmramRangeCount,\r | |
233 | IN EFI_SMRAM_DESCRIPTOR *SmramRanges\r | |
234 | );\r | |
235 | \r | |
236 | /**\r | |
237 | The SmmInstallConfigurationTable() function is used to maintain the list\r | |
238 | of configuration tables that are stored in the System Management System\r | |
239 | Table. The list is stored as an array of (GUID, Pointer) pairs. The list\r | |
240 | must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.\r | |
241 | \r | |
242 | @param SystemTable A pointer to the SMM System Table (SMST).\r | |
243 | @param Guid A pointer to the GUID for the entry to add, update, or remove.\r | |
244 | @param Table A pointer to the buffer of the table to add.\r | |
245 | @param TableSize The size of the table to install.\r | |
246 | \r | |
247 | @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.\r | |
248 | @retval EFI_INVALID_PARAMETER Guid is not valid.\r | |
249 | @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.\r | |
250 | @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.\r | |
251 | \r | |
252 | **/\r | |
253 | EFI_STATUS\r | |
254 | EFIAPI\r | |
255 | SmmInstallConfigurationTable (\r | |
256 | IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r | |
1436aea4 MK |
257 | IN CONST EFI_GUID *Guid,\r |
258 | IN VOID *Table,\r | |
259 | IN UINTN TableSize\r | |
e42e9404 | 260 | );\r |
261 | \r | |
262 | /**\r | |
263 | Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which\r | |
264 | Calls the private one which contains a BOOLEAN parameter for notifications\r | |
265 | \r | |
266 | @param UserHandle The handle to install the protocol handler on,\r | |
267 | or NULL if a new handle is to be allocated\r | |
268 | @param Protocol The protocol to add to the handle\r | |
269 | @param InterfaceType Indicates whether Interface is supplied in\r | |
270 | native form.\r | |
271 | @param Interface The interface for the protocol being added\r | |
272 | \r | |
273 | @return Status code\r | |
274 | \r | |
275 | **/\r | |
276 | EFI_STATUS\r | |
277 | EFIAPI\r | |
278 | SmmInstallProtocolInterface (\r | |
1436aea4 MK |
279 | IN OUT EFI_HANDLE *UserHandle,\r |
280 | IN EFI_GUID *Protocol,\r | |
281 | IN EFI_INTERFACE_TYPE InterfaceType,\r | |
282 | IN VOID *Interface\r | |
e42e9404 | 283 | );\r |
284 | \r | |
285 | /**\r | |
286 | Allocates pages from the memory map.\r | |
287 | \r | |
288 | @param Type The type of allocation to perform\r | |
289 | @param MemoryType The type of memory to turn the allocated pages\r | |
290 | into\r | |
291 | @param NumberOfPages The number of pages to allocate\r | |
292 | @param Memory A pointer to receive the base allocated memory\r | |
293 | address\r | |
294 | \r | |
295 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r | |
296 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r | |
297 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r | |
298 | @retval EFI_SUCCESS Pages successfully allocated.\r | |
299 | \r | |
300 | **/\r | |
301 | EFI_STATUS\r | |
302 | EFIAPI\r | |
303 | SmmAllocatePages (\r | |
1436aea4 MK |
304 | IN EFI_ALLOCATE_TYPE Type,\r |
305 | IN EFI_MEMORY_TYPE MemoryType,\r | |
306 | IN UINTN NumberOfPages,\r | |
307 | OUT EFI_PHYSICAL_ADDRESS *Memory\r | |
e42e9404 | 308 | );\r |
309 | \r | |
84edd20b SZ |
310 | /**\r |
311 | Allocates pages from the memory map.\r | |
312 | \r | |
313 | @param Type The type of allocation to perform\r | |
314 | @param MemoryType The type of memory to turn the allocated pages\r | |
315 | into\r | |
316 | @param NumberOfPages The number of pages to allocate\r | |
317 | @param Memory A pointer to receive the base allocated memory\r | |
318 | address\r | |
e63da9f0 | 319 | @param NeedGuard Flag to indicate Guard page is needed or not\r |
84edd20b SZ |
320 | \r |
321 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r | |
322 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r | |
323 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r | |
324 | @retval EFI_SUCCESS Pages successfully allocated.\r | |
325 | \r | |
326 | **/\r | |
327 | EFI_STATUS\r | |
328 | EFIAPI\r | |
329 | SmmInternalAllocatePages (\r | |
1436aea4 MK |
330 | IN EFI_ALLOCATE_TYPE Type,\r |
331 | IN EFI_MEMORY_TYPE MemoryType,\r | |
332 | IN UINTN NumberOfPages,\r | |
333 | OUT EFI_PHYSICAL_ADDRESS *Memory,\r | |
334 | IN BOOLEAN NeedGuard\r | |
84edd20b SZ |
335 | );\r |
336 | \r | |
e42e9404 | 337 | /**\r |
338 | Frees previous allocated pages.\r | |
339 | \r | |
340 | @param Memory Base address of memory being freed\r | |
341 | @param NumberOfPages The number of pages to free\r | |
342 | \r | |
343 | @retval EFI_NOT_FOUND Could not find the entry that covers the range\r | |
ddfae264 | 344 | @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r |
e42e9404 | 345 | @return EFI_SUCCESS Pages successfully freed.\r |
346 | \r | |
347 | **/\r | |
348 | EFI_STATUS\r | |
349 | EFIAPI\r | |
350 | SmmFreePages (\r | |
1436aea4 MK |
351 | IN EFI_PHYSICAL_ADDRESS Memory,\r |
352 | IN UINTN NumberOfPages\r | |
e42e9404 | 353 | );\r |
354 | \r | |
84edd20b SZ |
355 | /**\r |
356 | Frees previous allocated pages.\r | |
357 | \r | |
358 | @param Memory Base address of memory being freed\r | |
359 | @param NumberOfPages The number of pages to free\r | |
e63da9f0 JW |
360 | @param IsGuarded Flag to indicate if the memory is guarded\r |
361 | or not\r | |
84edd20b SZ |
362 | \r |
363 | @retval EFI_NOT_FOUND Could not find the entry that covers the range\r | |
ddfae264 | 364 | @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r |
84edd20b SZ |
365 | @return EFI_SUCCESS Pages successfully freed.\r |
366 | \r | |
367 | **/\r | |
368 | EFI_STATUS\r | |
369 | EFIAPI\r | |
370 | SmmInternalFreePages (\r | |
1436aea4 MK |
371 | IN EFI_PHYSICAL_ADDRESS Memory,\r |
372 | IN UINTN NumberOfPages,\r | |
373 | IN BOOLEAN IsGuarded\r | |
84edd20b SZ |
374 | );\r |
375 | \r | |
e42e9404 | 376 | /**\r |
377 | Allocate pool of a particular type.\r | |
378 | \r | |
379 | @param PoolType Type of pool to allocate\r | |
380 | @param Size The amount of pool to allocate\r | |
381 | @param Buffer The address to return a pointer to the allocated\r | |
382 | pool\r | |
383 | \r | |
384 | @retval EFI_INVALID_PARAMETER PoolType not valid\r | |
385 | @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r | |
386 | @retval EFI_SUCCESS Pool successfully allocated.\r | |
387 | \r | |
388 | **/\r | |
389 | EFI_STATUS\r | |
390 | EFIAPI\r | |
391 | SmmAllocatePool (\r | |
1436aea4 MK |
392 | IN EFI_MEMORY_TYPE PoolType,\r |
393 | IN UINTN Size,\r | |
394 | OUT VOID **Buffer\r | |
e42e9404 | 395 | );\r |
396 | \r | |
84edd20b SZ |
397 | /**\r |
398 | Allocate pool of a particular type.\r | |
399 | \r | |
400 | @param PoolType Type of pool to allocate\r | |
401 | @param Size The amount of pool to allocate\r | |
402 | @param Buffer The address to return a pointer to the allocated\r | |
403 | pool\r | |
404 | \r | |
405 | @retval EFI_INVALID_PARAMETER PoolType not valid\r | |
406 | @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r | |
407 | @retval EFI_SUCCESS Pool successfully allocated.\r | |
408 | \r | |
409 | **/\r | |
410 | EFI_STATUS\r | |
411 | EFIAPI\r | |
412 | SmmInternalAllocatePool (\r | |
1436aea4 MK |
413 | IN EFI_MEMORY_TYPE PoolType,\r |
414 | IN UINTN Size,\r | |
415 | OUT VOID **Buffer\r | |
84edd20b SZ |
416 | );\r |
417 | \r | |
e42e9404 | 418 | /**\r |
419 | Frees pool.\r | |
420 | \r | |
421 | @param Buffer The allocated pool entry to free\r | |
422 | \r | |
423 | @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r | |
424 | @retval EFI_SUCCESS Pool successfully freed.\r | |
425 | \r | |
426 | **/\r | |
427 | EFI_STATUS\r | |
428 | EFIAPI\r | |
429 | SmmFreePool (\r | |
1436aea4 | 430 | IN VOID *Buffer\r |
e42e9404 | 431 | );\r |
432 | \r | |
84edd20b SZ |
433 | /**\r |
434 | Frees pool.\r | |
435 | \r | |
436 | @param Buffer The allocated pool entry to free\r | |
437 | \r | |
438 | @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r | |
439 | @retval EFI_SUCCESS Pool successfully freed.\r | |
440 | \r | |
441 | **/\r | |
442 | EFI_STATUS\r | |
443 | EFIAPI\r | |
444 | SmmInternalFreePool (\r | |
1436aea4 | 445 | IN VOID *Buffer\r |
84edd20b SZ |
446 | );\r |
447 | \r | |
e42e9404 | 448 | /**\r |
449 | Installs a protocol interface into the boot services environment.\r | |
450 | \r | |
451 | @param UserHandle The handle to install the protocol handler on,\r | |
452 | or NULL if a new handle is to be allocated\r | |
453 | @param Protocol The protocol to add to the handle\r | |
454 | @param InterfaceType Indicates whether Interface is supplied in\r | |
455 | native form.\r | |
456 | @param Interface The interface for the protocol being added\r | |
457 | @param Notify indicates whether notify the notification list\r | |
458 | for this protocol\r | |
459 | \r | |
460 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
461 | @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate\r | |
462 | @retval EFI_SUCCESS Protocol interface successfully installed\r | |
463 | \r | |
464 | **/\r | |
465 | EFI_STATUS\r | |
466 | SmmInstallProtocolInterfaceNotify (\r | |
1436aea4 MK |
467 | IN OUT EFI_HANDLE *UserHandle,\r |
468 | IN EFI_GUID *Protocol,\r | |
469 | IN EFI_INTERFACE_TYPE InterfaceType,\r | |
470 | IN VOID *Interface,\r | |
471 | IN BOOLEAN Notify\r | |
e42e9404 | 472 | );\r |
473 | \r | |
474 | /**\r | |
475 | Uninstalls all instances of a protocol:interfacer from a handle.\r | |
476 | If the last protocol interface is remove from the handle, the\r | |
477 | handle is freed.\r | |
478 | \r | |
479 | @param UserHandle The handle to remove the protocol handler from\r | |
480 | @param Protocol The protocol, of protocol:interface, to remove\r | |
481 | @param Interface The interface, of protocol:interface, to remove\r | |
482 | \r | |
483 | @retval EFI_INVALID_PARAMETER Protocol is NULL.\r | |
484 | @retval EFI_SUCCESS Protocol interface successfully uninstalled.\r | |
485 | \r | |
486 | **/\r | |
487 | EFI_STATUS\r | |
488 | EFIAPI\r | |
489 | SmmUninstallProtocolInterface (\r | |
1436aea4 MK |
490 | IN EFI_HANDLE UserHandle,\r |
491 | IN EFI_GUID *Protocol,\r | |
492 | IN VOID *Interface\r | |
e42e9404 | 493 | );\r |
494 | \r | |
495 | /**\r | |
496 | Queries a handle to determine if it supports a specified protocol.\r | |
497 | \r | |
498 | @param UserHandle The handle being queried.\r | |
499 | @param Protocol The published unique identifier of the protocol.\r | |
500 | @param Interface Supplies the address where a pointer to the\r | |
501 | corresponding Protocol Interface is returned.\r | |
502 | \r | |
503 | @return The requested protocol interface for the handle\r | |
504 | \r | |
505 | **/\r | |
506 | EFI_STATUS\r | |
507 | EFIAPI\r | |
508 | SmmHandleProtocol (\r | |
1436aea4 MK |
509 | IN EFI_HANDLE UserHandle,\r |
510 | IN EFI_GUID *Protocol,\r | |
511 | OUT VOID **Interface\r | |
e42e9404 | 512 | );\r |
513 | \r | |
514 | /**\r | |
515 | Add a new protocol notification record for the request protocol.\r | |
516 | \r | |
517 | @param Protocol The requested protocol to add the notify\r | |
518 | registration\r | |
519 | @param Function Points to the notification function\r | |
520 | @param Registration Returns the registration record\r | |
521 | \r | |
522 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
523 | @retval EFI_SUCCESS Successfully returned the registration record\r | |
524 | that has been added\r | |
525 | \r | |
526 | **/\r | |
527 | EFI_STATUS\r | |
528 | EFIAPI\r | |
529 | SmmRegisterProtocolNotify (\r | |
1436aea4 MK |
530 | IN CONST EFI_GUID *Protocol,\r |
531 | IN EFI_SMM_NOTIFY_FN Function,\r | |
532 | OUT VOID **Registration\r | |
e42e9404 | 533 | );\r |
534 | \r | |
535 | /**\r | |
536 | Locates the requested handle(s) and returns them in Buffer.\r | |
537 | \r | |
538 | @param SearchType The type of search to perform to locate the\r | |
539 | handles\r | |
540 | @param Protocol The protocol to search for\r | |
541 | @param SearchKey Dependant on SearchType\r | |
542 | @param BufferSize On input the size of Buffer. On output the\r | |
543 | size of data returned.\r | |
544 | @param Buffer The buffer to return the results in\r | |
545 | \r | |
546 | @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is\r | |
547 | returned in BufferSize.\r | |
548 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
549 | @retval EFI_SUCCESS Successfully found the requested handle(s) and\r | |
550 | returns them in Buffer.\r | |
551 | \r | |
552 | **/\r | |
553 | EFI_STATUS\r | |
554 | EFIAPI\r | |
555 | SmmLocateHandle (\r | |
1436aea4 MK |
556 | IN EFI_LOCATE_SEARCH_TYPE SearchType,\r |
557 | IN EFI_GUID *Protocol OPTIONAL,\r | |
558 | IN VOID *SearchKey OPTIONAL,\r | |
559 | IN OUT UINTN *BufferSize,\r | |
560 | OUT EFI_HANDLE *Buffer\r | |
e42e9404 | 561 | );\r |
562 | \r | |
563 | /**\r | |
564 | Return the first Protocol Interface that matches the Protocol GUID. If\r | |
565 | Registration is pasased in return a Protocol Instance that was just add\r | |
4be497df | 566 | to the system. If Registration is NULL return the first Protocol Interface\r |
e42e9404 | 567 | you find.\r |
568 | \r | |
569 | @param Protocol The protocol to search for\r | |
570 | @param Registration Optional Registration Key returned from\r | |
571 | RegisterProtocolNotify()\r | |
572 | @param Interface Return the Protocol interface (instance).\r | |
573 | \r | |
574 | @retval EFI_SUCCESS If a valid Interface is returned\r | |
575 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
576 | @retval EFI_NOT_FOUND Protocol interface not found\r | |
577 | \r | |
578 | **/\r | |
579 | EFI_STATUS\r | |
580 | EFIAPI\r | |
581 | SmmLocateProtocol (\r | |
582 | IN EFI_GUID *Protocol,\r | |
583 | IN VOID *Registration OPTIONAL,\r | |
584 | OUT VOID **Interface\r | |
585 | );\r | |
586 | \r | |
285a682c JY |
587 | /**\r |
588 | Function returns an array of handles that support the requested protocol\r | |
589 | in a buffer allocated from pool. This is a version of SmmLocateHandle()\r | |
590 | that allocates a buffer for the caller.\r | |
591 | \r | |
592 | @param SearchType Specifies which handle(s) are to be returned.\r | |
593 | @param Protocol Provides the protocol to search by. This\r | |
594 | parameter is only valid for SearchType\r | |
595 | ByProtocol.\r | |
596 | @param SearchKey Supplies the search key depending on the\r | |
597 | SearchType.\r | |
598 | @param NumberHandles The number of handles returned in Buffer.\r | |
599 | @param Buffer A pointer to the buffer to return the requested\r | |
600 | array of handles that support Protocol.\r | |
601 | \r | |
602 | @retval EFI_SUCCESS The result array of handles was returned.\r | |
603 | @retval EFI_NOT_FOUND No handles match the search.\r | |
604 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the\r | |
605 | matching results.\r | |
4be497df | 606 | @retval EFI_INVALID_PARAMETER One or more parameters are not valid.\r |
285a682c JY |
607 | \r |
608 | **/\r | |
609 | EFI_STATUS\r | |
610 | EFIAPI\r | |
611 | SmmLocateHandleBuffer (\r | |
612 | IN EFI_LOCATE_SEARCH_TYPE SearchType,\r | |
613 | IN EFI_GUID *Protocol OPTIONAL,\r | |
614 | IN VOID *SearchKey OPTIONAL,\r | |
615 | IN OUT UINTN *NumberHandles,\r | |
616 | OUT EFI_HANDLE **Buffer\r | |
617 | );\r | |
618 | \r | |
e42e9404 | 619 | /**\r |
620 | Manage SMI of a particular type.\r | |
621 | \r | |
622 | @param HandlerType Points to the handler type or NULL for root SMI handlers.\r | |
623 | @param Context Points to an optional context buffer.\r | |
624 | @param CommBuffer Points to the optional communication buffer.\r | |
625 | @param CommBufferSize Points to the size of the optional communication buffer.\r | |
626 | \r | |
627 | @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.\r | |
628 | @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.\r | |
629 | @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.\r | |
630 | @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.\r | |
631 | \r | |
632 | **/\r | |
633 | EFI_STATUS\r | |
634 | EFIAPI\r | |
635 | SmiManage (\r | |
1436aea4 MK |
636 | IN CONST EFI_GUID *HandlerType,\r |
637 | IN CONST VOID *Context OPTIONAL,\r | |
638 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
639 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
e42e9404 | 640 | );\r |
641 | \r | |
642 | /**\r | |
643 | Registers a handler to execute within SMM.\r | |
644 | \r | |
4be497df | 645 | @param Handler Handler service function pointer.\r |
e42e9404 | 646 | @param HandlerType Points to the handler type or NULL for root SMI handlers.\r |
647 | @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.\r | |
648 | \r | |
649 | @retval EFI_SUCCESS Handler register success.\r | |
650 | @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.\r | |
651 | \r | |
652 | **/\r | |
653 | EFI_STATUS\r | |
654 | EFIAPI\r | |
655 | SmiHandlerRegister (\r | |
1436aea4 MK |
656 | IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r |
657 | IN CONST EFI_GUID *HandlerType OPTIONAL,\r | |
658 | OUT EFI_HANDLE *DispatchHandle\r | |
e42e9404 | 659 | );\r |
660 | \r | |
661 | /**\r | |
662 | Unregister a handler in SMM.\r | |
663 | \r | |
664 | @param DispatchHandle The handle that was specified when the handler was registered.\r | |
665 | \r | |
666 | @retval EFI_SUCCESS Handler function was successfully unregistered.\r | |
667 | @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.\r | |
668 | \r | |
669 | **/\r | |
670 | EFI_STATUS\r | |
671 | EFIAPI\r | |
672 | SmiHandlerUnRegister (\r | |
1436aea4 | 673 | IN EFI_HANDLE DispatchHandle\r |
e42e9404 | 674 | );\r |
675 | \r | |
676 | /**\r | |
677 | This function is the main entry point for an SMM handler dispatch\r | |
678 | or communicate-based callback.\r | |
679 | \r | |
680 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
681 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
682 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
683 | be conveyed from a non-SMM environment into an SMM environment.\r | |
684 | @param CommBufferSize The size of the CommBuffer.\r | |
685 | \r | |
686 | @return Status Code\r | |
687 | \r | |
688 | **/\r | |
689 | EFI_STATUS\r | |
690 | EFIAPI\r | |
691 | SmmDriverDispatchHandler (\r | |
1436aea4 MK |
692 | IN EFI_HANDLE DispatchHandle,\r |
693 | IN CONST VOID *Context OPTIONAL,\r | |
694 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
695 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
e42e9404 | 696 | );\r |
697 | \r | |
698 | /**\r | |
699 | This function is the main entry point for an SMM handler dispatch\r | |
700 | or communicate-based callback.\r | |
701 | \r | |
702 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
703 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
704 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
705 | be conveyed from a non-SMM environment into an SMM environment.\r | |
706 | @param CommBufferSize The size of the CommBuffer.\r | |
707 | \r | |
708 | @return Status Code\r | |
709 | \r | |
710 | **/\r | |
711 | EFI_STATUS\r | |
712 | EFIAPI\r | |
713 | SmmLegacyBootHandler (\r | |
1436aea4 MK |
714 | IN EFI_HANDLE DispatchHandle,\r |
715 | IN CONST VOID *Context OPTIONAL,\r | |
716 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
717 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
e42e9404 | 718 | );\r |
719 | \r | |
720 | /**\r | |
721 | This function is the main entry point for an SMM handler dispatch\r | |
722 | or communicate-based callback.\r | |
723 | \r | |
724 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
725 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
726 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
727 | be conveyed from a non-SMM environment into an SMM environment.\r | |
728 | @param CommBufferSize The size of the CommBuffer.\r | |
729 | \r | |
730 | @return Status Code\r | |
731 | \r | |
732 | **/\r | |
733 | EFI_STATUS\r | |
734 | EFIAPI\r | |
735 | SmmReadyToLockHandler (\r | |
1436aea4 MK |
736 | IN EFI_HANDLE DispatchHandle,\r |
737 | IN CONST VOID *Context OPTIONAL,\r | |
738 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
739 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
e42e9404 | 740 | );\r |
741 | \r | |
46ece1ff JY |
742 | /**\r |
743 | This function is the main entry point for an SMM handler dispatch\r | |
744 | or communicate-based callback.\r | |
745 | \r | |
746 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
747 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
748 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
749 | be conveyed from a non-SMM environment into an SMM environment.\r | |
750 | @param CommBufferSize The size of the CommBuffer.\r | |
751 | \r | |
752 | @return Status Code\r | |
753 | \r | |
754 | **/\r | |
755 | EFI_STATUS\r | |
756 | EFIAPI\r | |
757 | SmmEndOfDxeHandler (\r | |
1436aea4 MK |
758 | IN EFI_HANDLE DispatchHandle,\r |
759 | IN CONST VOID *Context OPTIONAL,\r | |
760 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
761 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
46ece1ff JY |
762 | );\r |
763 | \r | |
53ec4d7f SZ |
764 | /**\r |
765 | This function is the main entry point for an SMM handler dispatch\r | |
766 | or communicate-based callback.\r | |
767 | \r | |
768 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
769 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
770 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
771 | be conveyed from a non-SMM environment into an SMM environment.\r | |
772 | @param CommBufferSize The size of the CommBuffer.\r | |
773 | \r | |
774 | @return Status Code\r | |
775 | \r | |
776 | **/\r | |
777 | EFI_STATUS\r | |
778 | EFIAPI\r | |
779 | SmmExitBootServicesHandler (\r | |
1436aea4 MK |
780 | IN EFI_HANDLE DispatchHandle,\r |
781 | IN CONST VOID *Context OPTIONAL,\r | |
782 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
783 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
53ec4d7f SZ |
784 | );\r |
785 | \r | |
786 | /**\r | |
787 | This function is the main entry point for an SMM handler dispatch\r | |
788 | or communicate-based callback.\r | |
789 | \r | |
790 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
791 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
792 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
793 | be conveyed from a non-SMM environment into an SMM environment.\r | |
794 | @param CommBufferSize The size of the CommBuffer.\r | |
795 | \r | |
796 | @return Status Code\r | |
797 | \r | |
798 | **/\r | |
799 | EFI_STATUS\r | |
800 | EFIAPI\r | |
801 | SmmReadyToBootHandler (\r | |
1436aea4 MK |
802 | IN EFI_HANDLE DispatchHandle,\r |
803 | IN CONST VOID *Context OPTIONAL,\r | |
804 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
805 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
53ec4d7f SZ |
806 | );\r |
807 | \r | |
1bae3e0e SZ |
808 | /**\r |
809 | Software SMI handler that is called when the S3SmmInitDone signal is triggered.\r | |
810 | This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that\r | |
811 | S3 SMM initialization has been done.\r | |
812 | \r | |
813 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
814 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
815 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
816 | be conveyed from a non-SMM environment into an SMM environment.\r | |
817 | @param CommBufferSize The size of the CommBuffer.\r | |
818 | \r | |
819 | @return Status Code\r | |
820 | \r | |
821 | **/\r | |
822 | EFI_STATUS\r | |
823 | EFIAPI\r | |
824 | SmmS3SmmInitDoneHandler (\r | |
825 | IN EFI_HANDLE DispatchHandle,\r | |
e3917e22 MK |
826 | IN CONST VOID *Context OPTIONAL,\r |
827 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
1bae3e0e SZ |
828 | IN OUT UINTN *CommBufferSize OPTIONAL\r |
829 | );\r | |
830 | \r | |
d76c2da8 ED |
831 | /**\r |
832 | Software SMI handler that is called when the EndOfS3Resume event is trigged.\r | |
833 | This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that\r | |
834 | S3 resume has finished.\r | |
835 | \r | |
836 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
837 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
838 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
839 | be conveyed from a non-SMM environment into an SMM environment.\r | |
840 | @param CommBufferSize The size of the CommBuffer.\r | |
841 | \r | |
842 | @return Status Code\r | |
843 | \r | |
844 | **/\r | |
845 | EFI_STATUS\r | |
846 | EFIAPI\r | |
847 | SmmEndOfS3ResumeHandler (\r | |
848 | IN EFI_HANDLE DispatchHandle,\r | |
e3917e22 MK |
849 | IN CONST VOID *Context OPTIONAL,\r |
850 | IN OUT VOID *CommBuffer OPTIONAL,\r | |
d76c2da8 ED |
851 | IN OUT UINTN *CommBufferSize OPTIONAL\r |
852 | );\r | |
853 | \r | |
e42e9404 | 854 | /**\r |
855 | Place holder function until all the SMM System Table Service are available.\r | |
856 | \r | |
857 | @param Arg1 Undefined\r | |
858 | @param Arg2 Undefined\r | |
859 | @param Arg3 Undefined\r | |
860 | @param Arg4 Undefined\r | |
861 | @param Arg5 Undefined\r | |
862 | \r | |
863 | @return EFI_NOT_AVAILABLE_YET\r | |
864 | \r | |
865 | **/\r | |
866 | EFI_STATUS\r | |
867 | EFIAPI\r | |
868 | SmmEfiNotAvailableYetArg5 (\r | |
1436aea4 MK |
869 | UINTN Arg1,\r |
870 | UINTN Arg2,\r | |
871 | UINTN Arg3,\r | |
872 | UINTN Arg4,\r | |
873 | UINTN Arg5\r | |
e42e9404 | 874 | );\r |
875 | \r | |
876 | //\r | |
1436aea4 | 877 | // Functions used during debug builds\r |
e42e9404 | 878 | //\r |
879 | \r | |
880 | /**\r | |
881 | Traverse the discovered list for any drivers that were discovered but not loaded\r | |
4be497df | 882 | because the dependency expressions evaluated to false.\r |
e42e9404 | 883 | \r |
884 | **/\r | |
885 | VOID\r | |
886 | SmmDisplayDiscoveredNotDispatched (\r | |
887 | VOID\r | |
888 | );\r | |
889 | \r | |
890 | /**\r | |
891 | Add free SMRAM region for use by memory service.\r | |
892 | \r | |
893 | @param MemBase Base address of memory region.\r | |
894 | @param MemLength Length of the memory region.\r | |
895 | @param Type Memory type.\r | |
896 | @param Attributes Memory region state.\r | |
897 | \r | |
898 | **/\r | |
899 | VOID\r | |
900 | SmmAddMemoryRegion (\r | |
1436aea4 MK |
901 | IN EFI_PHYSICAL_ADDRESS MemBase,\r |
902 | IN UINT64 MemLength,\r | |
903 | IN EFI_MEMORY_TYPE Type,\r | |
904 | IN UINT64 Attributes\r | |
e42e9404 | 905 | );\r |
906 | \r | |
907 | /**\r | |
908 | Finds the protocol entry for the requested protocol.\r | |
909 | \r | |
910 | @param Protocol The ID of the protocol\r | |
911 | @param Create Create a new entry if not found\r | |
912 | \r | |
913 | @return Protocol entry\r | |
914 | \r | |
915 | **/\r | |
916 | PROTOCOL_ENTRY *\r | |
917 | SmmFindProtocolEntry (\r | |
1436aea4 MK |
918 | IN EFI_GUID *Protocol,\r |
919 | IN BOOLEAN Create\r | |
e42e9404 | 920 | );\r |
921 | \r | |
922 | /**\r | |
923 | Signal event for every protocol in protocol entry.\r | |
924 | \r | |
925 | @param Prot Protocol interface\r | |
926 | \r | |
927 | **/\r | |
928 | VOID\r | |
929 | SmmNotifyProtocol (\r | |
1436aea4 | 930 | IN PROTOCOL_INTERFACE *Prot\r |
e42e9404 | 931 | );\r |
932 | \r | |
933 | /**\r | |
934 | Finds the protocol instance for the requested handle and protocol.\r | |
935 | Note: This function doesn't do parameters checking, it's caller's responsibility\r | |
936 | to pass in valid parameters.\r | |
937 | \r | |
938 | @param Handle The handle to search the protocol on\r | |
939 | @param Protocol GUID of the protocol\r | |
940 | @param Interface The interface for the protocol being searched\r | |
941 | \r | |
942 | @return Protocol instance (NULL: Not found)\r | |
943 | \r | |
944 | **/\r | |
945 | PROTOCOL_INTERFACE *\r | |
946 | SmmFindProtocolInterface (\r | |
1436aea4 MK |
947 | IN IHANDLE *Handle,\r |
948 | IN EFI_GUID *Protocol,\r | |
949 | IN VOID *Interface\r | |
e42e9404 | 950 | );\r |
951 | \r | |
952 | /**\r | |
953 | Removes Protocol from the protocol list (but not the handle list).\r | |
954 | \r | |
955 | @param Handle The handle to remove protocol on.\r | |
956 | @param Protocol GUID of the protocol to be moved\r | |
957 | @param Interface The interface of the protocol\r | |
958 | \r | |
959 | @return Protocol Entry\r | |
960 | \r | |
961 | **/\r | |
962 | PROTOCOL_INTERFACE *\r | |
963 | SmmRemoveInterfaceFromProtocol (\r | |
1436aea4 MK |
964 | IN IHANDLE *Handle,\r |
965 | IN EFI_GUID *Protocol,\r | |
966 | IN VOID *Interface\r | |
e42e9404 | 967 | );\r |
968 | \r | |
969 | /**\r | |
970 | This is the POSTFIX version of the dependency evaluator. This code does\r | |
971 | not need to handle Before or After, as it is not valid to call this\r | |
fa542a1e | 972 | routine in this case. POSTFIX means all the math is done on top of the stack.\r |
e42e9404 | 973 | \r |
974 | @param DriverEntry DriverEntry element to update.\r | |
975 | \r | |
976 | @retval TRUE If driver is ready to run.\r | |
977 | @retval FALSE If driver is not ready to run or some fatal error\r | |
978 | was found.\r | |
979 | \r | |
980 | **/\r | |
981 | BOOLEAN\r | |
982 | SmmIsSchedulable (\r | |
1436aea4 | 983 | IN EFI_SMM_DRIVER_ENTRY *DriverEntry\r |
e42e9404 | 984 | );\r |
985 | \r | |
84edd20b SZ |
986 | //\r |
987 | // SmramProfile\r | |
988 | //\r | |
989 | \r | |
990 | /**\r | |
991 | Initialize SMRAM profile.\r | |
992 | \r | |
993 | **/\r | |
994 | VOID\r | |
995 | SmramProfileInit (\r | |
996 | VOID\r | |
997 | );\r | |
998 | \r | |
e524f680 SZ |
999 | /**\r |
1000 | Install SMRAM profile protocol.\r | |
1001 | \r | |
1002 | **/\r | |
1003 | VOID\r | |
1004 | SmramProfileInstallProtocol (\r | |
1005 | VOID\r | |
1006 | );\r | |
1007 | \r | |
84edd20b SZ |
1008 | /**\r |
1009 | Register SMM image to SMRAM profile.\r | |
1010 | \r | |
1011 | @param DriverEntry SMM image info.\r | |
1012 | @param RegisterToDxe Register image to DXE.\r | |
1013 | \r | |
e524f680 SZ |
1014 | @return EFI_SUCCESS Register successfully.\r |
1015 | @return EFI_UNSUPPORTED Memory profile unsupported,\r | |
1016 | or memory profile for the image is not required.\r | |
1017 | @return EFI_OUT_OF_RESOURCES No enough resource for this register.\r | |
84edd20b SZ |
1018 | \r |
1019 | **/\r | |
e524f680 | 1020 | EFI_STATUS\r |
84edd20b | 1021 | RegisterSmramProfileImage (\r |
1436aea4 MK |
1022 | IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r |
1023 | IN BOOLEAN RegisterToDxe\r | |
84edd20b SZ |
1024 | );\r |
1025 | \r | |
1026 | /**\r | |
1027 | Unregister image from SMRAM profile.\r | |
1028 | \r | |
1029 | @param DriverEntry SMM image info.\r | |
1030 | @param UnregisterToDxe Unregister image from DXE.\r | |
1031 | \r | |
e524f680 SZ |
1032 | @return EFI_SUCCESS Unregister successfully.\r |
1033 | @return EFI_UNSUPPORTED Memory profile unsupported,\r | |
1034 | or memory profile for the image is not required.\r | |
1035 | @return EFI_NOT_FOUND The image is not found.\r | |
84edd20b SZ |
1036 | \r |
1037 | **/\r | |
e524f680 | 1038 | EFI_STATUS\r |
84edd20b | 1039 | UnregisterSmramProfileImage (\r |
1436aea4 MK |
1040 | IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r |
1041 | IN BOOLEAN UnregisterToDxe\r | |
84edd20b SZ |
1042 | );\r |
1043 | \r | |
1044 | /**\r | |
1045 | Update SMRAM profile information.\r | |
1046 | \r | |
1047 | @param CallerAddress Address of caller who call Allocate or Free.\r | |
1048 | @param Action This Allocate or Free action.\r | |
1049 | @param MemoryType Memory type.\r | |
e524f680 | 1050 | EfiMaxMemoryType means the MemoryType is unknown.\r |
84edd20b SZ |
1051 | @param Size Buffer size.\r |
1052 | @param Buffer Buffer address.\r | |
e524f680 SZ |
1053 | @param ActionString String for memory profile action.\r |
1054 | Only needed for user defined allocate action.\r | |
84edd20b | 1055 | \r |
e524f680 SZ |
1056 | @return EFI_SUCCESS Memory profile is updated.\r |
1057 | @return EFI_UNSUPPORTED Memory profile is unsupported,\r | |
1058 | or memory profile for the image is not required,\r | |
1059 | or memory profile for the memory type is not required.\r | |
1060 | @return EFI_ACCESS_DENIED It is during memory profile data getting.\r | |
1061 | @return EFI_ABORTED Memory profile recording is not enabled.\r | |
1062 | @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r | |
1063 | @return EFI_NOT_FOUND No matched allocate info found for free action.\r | |
84edd20b SZ |
1064 | \r |
1065 | **/\r | |
e524f680 SZ |
1066 | EFI_STATUS\r |
1067 | EFIAPI\r | |
84edd20b | 1068 | SmmCoreUpdateProfile (\r |
e524f680 SZ |
1069 | IN PHYSICAL_ADDRESS CallerAddress,\r |
1070 | IN MEMORY_PROFILE_ACTION Action,\r | |
1071 | IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool\r | |
1072 | IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool\r | |
1073 | IN VOID *Buffer,\r | |
1074 | IN CHAR8 *ActionString OPTIONAL\r | |
84edd20b SZ |
1075 | );\r |
1076 | \r | |
1077 | /**\r | |
1078 | Register SMRAM profile handler.\r | |
1079 | \r | |
1080 | **/\r | |
1081 | VOID\r | |
1082 | RegisterSmramProfileHandler (\r | |
1083 | VOID\r | |
1084 | );\r | |
1085 | \r | |
1086 | /**\r | |
1087 | SMRAM profile ready to lock callback function.\r | |
1088 | \r | |
1089 | **/\r | |
1090 | VOID\r | |
1091 | SmramProfileReadyToLock (\r | |
1092 | VOID\r | |
1093 | );\r | |
1094 | \r | |
285a682c JY |
1095 | /**\r |
1096 | Initialize MemoryAttributes support.\r | |
1097 | **/\r | |
1098 | VOID\r | |
1099 | EFIAPI\r | |
1100 | SmmCoreInitializeMemoryAttributesTable (\r | |
1101 | VOID\r | |
1102 | );\r | |
1103 | \r | |
1104 | /**\r | |
1105 | This function returns a copy of the current memory map. The map is an array of\r | |
1106 | memory descriptors, each of which describes a contiguous block of memory.\r | |
1107 | \r | |
1108 | @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the\r | |
1109 | MemoryMap buffer. On input, this is the size of\r | |
1110 | the buffer allocated by the caller. On output,\r | |
1111 | it is the size of the buffer returned by the\r | |
1112 | firmware if the buffer was large enough, or the\r | |
1113 | size of the buffer needed to contain the map if\r | |
1114 | the buffer was too small.\r | |
1115 | @param[in, out] MemoryMap A pointer to the buffer in which firmware places\r | |
1116 | the current memory map.\r | |
1117 | @param[out] MapKey A pointer to the location in which firmware\r | |
1118 | returns the key for the current memory map.\r | |
1119 | @param[out] DescriptorSize A pointer to the location in which firmware\r | |
1120 | returns the size, in bytes, of an individual\r | |
1121 | EFI_MEMORY_DESCRIPTOR.\r | |
1122 | @param[out] DescriptorVersion A pointer to the location in which firmware\r | |
1123 | returns the version number associated with the\r | |
1124 | EFI_MEMORY_DESCRIPTOR.\r | |
1125 | \r | |
1126 | @retval EFI_SUCCESS The memory map was returned in the MemoryMap\r | |
1127 | buffer.\r | |
1128 | @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current\r | |
1129 | buffer size needed to hold the memory map is\r | |
1130 | returned in MemoryMapSize.\r | |
1131 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r | |
1132 | \r | |
1133 | **/\r | |
1134 | EFI_STATUS\r | |
1135 | EFIAPI\r | |
1136 | SmmCoreGetMemoryMap (\r | |
1137 | IN OUT UINTN *MemoryMapSize,\r | |
1138 | IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,\r | |
1139 | OUT UINTN *MapKey,\r | |
1140 | OUT UINTN *DescriptorSize,\r | |
1141 | OUT UINT32 *DescriptorVersion\r | |
1142 | );\r | |
1143 | \r | |
ca41f3f4 JY |
1144 | /**\r |
1145 | Initialize SmiHandler profile feature.\r | |
1146 | **/\r | |
1147 | VOID\r | |
1148 | SmmCoreInitializeSmiHandlerProfile (\r | |
1149 | VOID\r | |
1150 | );\r | |
1151 | \r | |
1152 | /**\r | |
1153 | This function is called by SmmChildDispatcher module to report\r | |
1154 | a new SMI handler is registered, to SmmCore.\r | |
1155 | \r | |
1156 | @param This The protocol instance\r | |
1157 | @param HandlerGuid The GUID to identify the type of the handler.\r | |
1158 | For the SmmChildDispatch protocol, the HandlerGuid\r | |
1159 | must be the GUID of SmmChildDispatch protocol.\r | |
1160 | @param Handler The SMI handler.\r | |
1161 | @param CallerAddress The address of the module who registers the SMI handler.\r | |
1162 | @param Context The context of the SMI handler.\r | |
1163 | For the SmmChildDispatch protocol, the Context\r | |
1164 | must match the one defined for SmmChildDispatch protocol.\r | |
1165 | @param ContextSize The size of the context in bytes.\r | |
1166 | For the SmmChildDispatch protocol, the Context\r | |
1167 | must match the one defined for SmmChildDispatch protocol.\r | |
1168 | \r | |
1169 | @retval EFI_SUCCESS The information is recorded.\r | |
1170 | @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.\r | |
1171 | **/\r | |
1172 | EFI_STATUS\r | |
1173 | EFIAPI\r | |
1174 | SmiHandlerProfileRegisterHandler (\r | |
1436aea4 MK |
1175 | IN SMI_HANDLER_PROFILE_PROTOCOL *This,\r |
1176 | IN EFI_GUID *HandlerGuid,\r | |
1177 | IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r | |
1178 | IN PHYSICAL_ADDRESS CallerAddress,\r | |
1179 | IN VOID *Context OPTIONAL,\r | |
1180 | IN UINTN ContextSize OPTIONAL\r | |
ca41f3f4 JY |
1181 | );\r |
1182 | \r | |
1183 | /**\r | |
1184 | This function is called by SmmChildDispatcher module to report\r | |
1185 | an existing SMI handler is unregistered, to SmmCore.\r | |
1186 | \r | |
1187 | @param This The protocol instance\r | |
1188 | @param HandlerGuid The GUID to identify the type of the handler.\r | |
1189 | For the SmmChildDispatch protocol, the HandlerGuid\r | |
1190 | must be the GUID of SmmChildDispatch protocol.\r | |
1191 | @param Handler The SMI handler.\r | |
1c3ac4b9 JY |
1192 | @param Context The context of the SMI handler.\r |
1193 | If it is NOT NULL, it will be used to check what is registered.\r | |
1194 | @param ContextSize The size of the context in bytes.\r | |
1195 | If Context is NOT NULL, it will be used to check what is registered.\r | |
ca41f3f4 JY |
1196 | \r |
1197 | @retval EFI_SUCCESS The original record is removed.\r | |
1198 | @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.\r | |
1199 | **/\r | |
1200 | EFI_STATUS\r | |
1201 | EFIAPI\r | |
1202 | SmiHandlerProfileUnregisterHandler (\r | |
1436aea4 MK |
1203 | IN SMI_HANDLER_PROFILE_PROTOCOL *This,\r |
1204 | IN EFI_GUID *HandlerGuid,\r | |
1205 | IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r | |
1206 | IN VOID *Context OPTIONAL,\r | |
1207 | IN UINTN ContextSize OPTIONAL\r | |
ca41f3f4 JY |
1208 | );\r |
1209 | \r | |
1436aea4 MK |
1210 | extern UINTN mFullSmramRangeCount;\r |
1211 | extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;\r | |
84edd20b | 1212 | \r |
1436aea4 | 1213 | extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;\r |
285a682c | 1214 | \r |
0b256fb1 JY |
1215 | extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;\r |
1216 | \r | |
63aa86b0 SZ |
1217 | //\r |
1218 | // Page management\r | |
1219 | //\r | |
1220 | \r | |
1221 | typedef struct {\r | |
1436aea4 MK |
1222 | LIST_ENTRY Link;\r |
1223 | UINTN NumberOfPages;\r | |
63aa86b0 SZ |
1224 | } FREE_PAGE_LIST;\r |
1225 | \r | |
1226 | extern LIST_ENTRY mSmmMemoryMap;\r | |
1227 | \r | |
1228 | //\r | |
1229 | // Pool management\r | |
1230 | //\r | |
1231 | \r | |
1232 | //\r | |
1233 | // MIN_POOL_SHIFT must not be less than 5\r | |
1234 | //\r | |
1235 | #define MIN_POOL_SHIFT 6\r | |
1236 | #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)\r | |
1237 | \r | |
1238 | //\r | |
1239 | // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1\r | |
1240 | //\r | |
1241 | #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)\r | |
1242 | #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)\r | |
1243 | \r | |
1244 | //\r | |
1245 | // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes\r | |
1246 | //\r | |
1247 | #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)\r | |
1248 | \r | |
1436aea4 | 1249 | #define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')\r |
861c8dff | 1250 | \r |
63aa86b0 | 1251 | typedef struct {\r |
1436aea4 MK |
1252 | UINT32 Signature;\r |
1253 | BOOLEAN Available;\r | |
1254 | EFI_MEMORY_TYPE Type;\r | |
1255 | UINTN Size;\r | |
63aa86b0 SZ |
1256 | } POOL_HEADER;\r |
1257 | \r | |
1436aea4 | 1258 | #define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')\r |
861c8dff SZ |
1259 | \r |
1260 | typedef struct {\r | |
1436aea4 MK |
1261 | UINT32 Signature;\r |
1262 | UINT32 Reserved;\r | |
1263 | UINTN Size;\r | |
861c8dff SZ |
1264 | } POOL_TAIL;\r |
1265 | \r | |
1436aea4 | 1266 | #define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))\r |
861c8dff SZ |
1267 | \r |
1268 | #define HEAD_TO_TAIL(a) \\r | |
1269 | ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));\r | |
1270 | \r | |
63aa86b0 | 1271 | typedef struct {\r |
1436aea4 MK |
1272 | POOL_HEADER Header;\r |
1273 | LIST_ENTRY Link;\r | |
63aa86b0 SZ |
1274 | } FREE_POOL_HEADER;\r |
1275 | \r | |
5f4d3e17 JY |
1276 | typedef enum {\r |
1277 | SmmPoolTypeCode,\r | |
1278 | SmmPoolTypeData,\r | |
1279 | SmmPoolTypeMax,\r | |
1280 | } SMM_POOL_TYPE;\r | |
1281 | \r | |
1282 | extern LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];\r | |
63aa86b0 | 1283 | \r |
e63da9f0 JW |
1284 | /**\r |
1285 | Internal Function. Allocate n pages from given free page node.\r | |
1286 | \r | |
1287 | @param Pages The free page node.\r | |
1288 | @param NumberOfPages Number of pages to be allocated.\r | |
1289 | @param MaxAddress Request to allocate memory below this address.\r | |
1290 | \r | |
1291 | @return Memory address of allocated pages.\r | |
1292 | \r | |
1293 | **/\r | |
1294 | UINTN\r | |
1295 | InternalAllocPagesOnOneNode (\r | |
1436aea4 MK |
1296 | IN OUT FREE_PAGE_LIST *Pages,\r |
1297 | IN UINTN NumberOfPages,\r | |
1298 | IN UINTN MaxAddress\r | |
e63da9f0 JW |
1299 | );\r |
1300 | \r | |
1301 | /**\r | |
1302 | Update SMM memory map entry.\r | |
1303 | \r | |
1304 | @param[in] Type The type of allocation to perform.\r | |
1305 | @param[in] Memory The base of memory address.\r | |
1306 | @param[in] NumberOfPages The number of pages to allocate.\r | |
1307 | @param[in] AddRegion If this memory is new added region.\r | |
1308 | **/\r | |
1309 | VOID\r | |
1310 | ConvertSmmMemoryMapEntry (\r | |
1311 | IN EFI_MEMORY_TYPE Type,\r | |
1312 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
1313 | IN UINTN NumberOfPages,\r | |
1314 | IN BOOLEAN AddRegion\r | |
1315 | );\r | |
1316 | \r | |
1317 | /**\r | |
1318 | Internal function. Moves any memory descriptors that are on the\r | |
1319 | temporary descriptor stack to heap.\r | |
1320 | \r | |
1321 | **/\r | |
1322 | VOID\r | |
1323 | CoreFreeMemoryMapStack (\r | |
1324 | VOID\r | |
1325 | );\r | |
1326 | \r | |
1327 | /**\r | |
1328 | Frees previous allocated pages.\r | |
1329 | \r | |
1330 | @param[in] Memory Base address of memory being freed.\r | |
1331 | @param[in] NumberOfPages The number of pages to free.\r | |
1332 | @param[in] AddRegion If this memory is new added region.\r | |
1333 | \r | |
1334 | @retval EFI_NOT_FOUND Could not find the entry that covers the range.\r | |
1335 | @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r | |
1336 | @return EFI_SUCCESS Pages successfully freed.\r | |
1337 | \r | |
1338 | **/\r | |
1339 | EFI_STATUS\r | |
1340 | SmmInternalFreePagesEx (\r | |
1341 | IN EFI_PHYSICAL_ADDRESS Memory,\r | |
1342 | IN UINTN NumberOfPages,\r | |
1343 | IN BOOLEAN AddRegion\r | |
1344 | );\r | |
1345 | \r | |
1346 | /**\r | |
1347 | Hook function used to set all Guard pages after entering SMM mode.\r | |
1348 | **/\r | |
1349 | VOID\r | |
1350 | SmmEntryPointMemoryManagementHook (\r | |
1351 | VOID\r | |
1352 | );\r | |
1353 | \r | |
e42e9404 | 1354 | #endif\r |