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