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