]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.h
... / ...
CommitLineData
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
5 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
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
17#include <Protocol/SmmEndOfDxe.h>\r
18#include <Protocol/CpuIo2.h>\r
19#include <Protocol/SmmCommunication.h>\r
20#include <Protocol/SmmAccess2.h>\r
21#include <Protocol/FirmwareVolume2.h>\r
22#include <Protocol/LoadedImage.h>\r
23#include <Protocol/DevicePath.h>\r
24#include <Protocol/Security.h>\r
25#include <Protocol/Security2.h>\r
26#include <Protocol/SmmExitBootServices.h>\r
27#include <Protocol/SmmLegacyBoot.h>\r
28#include <Protocol/SmmReadyToBoot.h>\r
29#include <Protocol/SmmMemoryAttribute.h>\r
30#include <Protocol/SmmSxDispatch2.h>\r
31\r
32#include <Guid/Apriori.h>\r
33#include <Guid/EventGroup.h>\r
34#include <Guid/EventLegacyBios.h>\r
35#include <Guid/MemoryProfile.h>\r
36#include <Guid/LoadModuleAtFixedAddress.h>\r
37#include <Guid/SmiHandlerProfile.h>\r
38#include <Guid/EndOfS3Resume.h>\r
39#include <Guid/S3SmmInitDone.h>\r
40\r
41#include <Library/BaseLib.h>\r
42#include <Library/BaseMemoryLib.h>\r
43#include <Library/PeCoffLib.h>\r
44#include <Library/PeCoffGetEntryPointLib.h>\r
45#include <Library/CacheMaintenanceLib.h>\r
46#include <Library/DebugLib.h>\r
47#include <Library/ReportStatusCodeLib.h>\r
48#include <Library/MemoryAllocationLib.h>\r
49#include <Library/DevicePathLib.h>\r
50#include <Library/UefiLib.h>\r
51#include <Library/UefiBootServicesTableLib.h>\r
52#include <Library/PcdLib.h>\r
53#include <Library/SmmCorePlatformHookLib.h>\r
54#include <Library/PerformanceLib.h>\r
55#include <Library/HobLib.h>\r
56#include <Library/SmmMemLib.h>\r
57#include <Library/SafeIntLib.h>\r
58\r
59#include "PiSmmCorePrivateData.h"\r
60#include "HeapGuard.h"\r
61\r
62//\r
63// Used to build a table of SMI Handlers that the SMM Core registers\r
64//\r
65typedef struct {\r
66 EFI_SMM_HANDLER_ENTRY_POINT2 Handler;\r
67 EFI_GUID *HandlerType;\r
68 EFI_HANDLE DispatchHandle;\r
69 BOOLEAN UnRegister;\r
70} SMM_CORE_SMI_HANDLERS;\r
71\r
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
78typedef struct {\r
79 UINTN Signature;\r
80 LIST_ENTRY AllEntries; // All entries\r
81\r
82 EFI_GUID HandlerType; // Type of interrupt\r
83 LIST_ENTRY SmiHandlers; // All handlers\r
84} SMI_ENTRY;\r
85\r
86#define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')\r
87\r
88typedef 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
96} SMI_HANDLER;\r
97\r
98//\r
99// Structure for recording the state of an SMM Driver\r
100//\r
101#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')\r
102\r
103typedef struct {\r
104 UINTN Signature;\r
105 LIST_ENTRY Link; // mDriverList\r
106\r
107 LIST_ENTRY ScheduledLink; // mScheduledQueue\r
108\r
109 EFI_HANDLE FvHandle;\r
110 EFI_GUID FileName;\r
111 EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;\r
112 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
113\r
114 VOID *Depex;\r
115 UINTN DepexSize;\r
116\r
117 BOOLEAN Before;\r
118 BOOLEAN After;\r
119 EFI_GUID BeforeAfterGuid;\r
120\r
121 BOOLEAN Dependent;\r
122 BOOLEAN Scheduled;\r
123 BOOLEAN Initialized;\r
124 BOOLEAN DepexProtocolError;\r
125\r
126 EFI_HANDLE ImageHandle;\r
127 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
128 //\r
129 // Image EntryPoint in SMRAM\r
130 //\r
131 PHYSICAL_ADDRESS ImageEntryPoint;\r
132 //\r
133 // Image Buffer in SMRAM\r
134 //\r
135 PHYSICAL_ADDRESS ImageBuffer;\r
136 //\r
137 // Image Page Number\r
138 //\r
139 UINTN NumberOfPage;\r
140 EFI_HANDLE SmmImageHandle;\r
141 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;\r
142} EFI_SMM_DRIVER_ENTRY;\r
143\r
144#define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','d','l')\r
145\r
146///\r
147/// IHANDLE - contains a list of protocol handles\r
148///\r
149typedef struct {\r
150 UINTN Signature;\r
151 /// All handles list of IHANDLE\r
152 LIST_ENTRY AllHandles;\r
153 /// List of PROTOCOL_INTERFACE's for this handle\r
154 LIST_ENTRY Protocols;\r
155 UINTN LocateRequest;\r
156} IHANDLE;\r
157\r
158#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)\r
159\r
160#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')\r
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
167typedef struct {\r
168 UINTN Signature;\r
169 /// Link Entry inserted to mProtocolDatabase\r
170 LIST_ENTRY AllEntries;\r
171 /// ID of the protocol\r
172 EFI_GUID ProtocolID;\r
173 /// All protocol interfaces\r
174 LIST_ENTRY Protocols;\r
175 /// Registered notification handlers\r
176 LIST_ENTRY Notify;\r
177} PROTOCOL_ENTRY;\r
178\r
179#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('s','p','i','f')\r
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
185typedef struct {\r
186 UINTN Signature;\r
187 /// Link on IHANDLE.Protocols\r
188 LIST_ENTRY Link;\r
189 /// Back pointer\r
190 IHANDLE *Handle;\r
191 /// Link on PROTOCOL_ENTRY.Protocols\r
192 LIST_ENTRY ByProtocol;\r
193 /// The protocol ID\r
194 PROTOCOL_ENTRY *Protocol;\r
195 /// The interface value\r
196 VOID *Interface;\r
197} PROTOCOL_INTERFACE;\r
198\r
199#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','t','n')\r
200\r
201///\r
202/// PROTOCOL_NOTIFY - used for each register notification for a protocol\r
203///\r
204typedef struct {\r
205 UINTN Signature;\r
206 PROTOCOL_ENTRY *Protocol;\r
207 /// All notifications for this protocol\r
208 LIST_ENTRY Link;\r
209 /// Notification function\r
210 EFI_SMM_NOTIFY_FN Function;\r
211 /// Last position notified\r
212 LIST_ENTRY *Position;\r
213} PROTOCOL_NOTIFY;\r
214\r
215//\r
216// SMM Core Global Variables\r
217//\r
218extern SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;\r
219extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst;\r
220extern LIST_ENTRY gHandleList;\r
221extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase;\r
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
230VOID\r
231SmmInitializeMemoryServices (\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
253EFI_STATUS\r
254EFIAPI\r
255SmmInstallConfigurationTable (\r
256 IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r
257 IN CONST EFI_GUID *Guid,\r
258 IN VOID *Table,\r
259 IN UINTN TableSize\r
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
276EFI_STATUS\r
277EFIAPI\r
278SmmInstallProtocolInterface (\r
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
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
301EFI_STATUS\r
302EFIAPI\r
303SmmAllocatePages (\r
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
308 );\r
309\r
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
319 @param NeedGuard Flag to indicate Guard page is needed or not\r
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
327EFI_STATUS\r
328EFIAPI\r
329SmmInternalAllocatePages (\r
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
335 );\r
336\r
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
344 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r
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
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 @param IsGuarded Flag to indicate if the memory is guarded\r
361 or not\r
362\r
363 @retval EFI_NOT_FOUND Could not find the entry that covers the range\r
364 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.\r
365 @return EFI_SUCCESS Pages successfully freed.\r
366\r
367**/\r
368EFI_STATUS\r
369EFIAPI\r
370SmmInternalFreePages (\r
371 IN EFI_PHYSICAL_ADDRESS Memory,\r
372 IN UINTN NumberOfPages,\r
373 IN BOOLEAN IsGuarded\r
374 );\r
375\r
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
389EFI_STATUS\r
390EFIAPI\r
391SmmAllocatePool (\r
392 IN EFI_MEMORY_TYPE PoolType,\r
393 IN UINTN Size,\r
394 OUT VOID **Buffer\r
395 );\r
396\r
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
410EFI_STATUS\r
411EFIAPI\r
412SmmInternalAllocatePool (\r
413 IN EFI_MEMORY_TYPE PoolType,\r
414 IN UINTN Size,\r
415 OUT VOID **Buffer\r
416 );\r
417\r
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
427EFI_STATUS\r
428EFIAPI\r
429SmmFreePool (\r
430 IN VOID *Buffer\r
431 );\r
432\r
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
442EFI_STATUS\r
443EFIAPI\r
444SmmInternalFreePool (\r
445 IN VOID *Buffer\r
446 );\r
447\r
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
465EFI_STATUS\r
466SmmInstallProtocolInterfaceNotify (\r
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
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
487EFI_STATUS\r
488EFIAPI\r
489SmmUninstallProtocolInterface (\r
490 IN EFI_HANDLE UserHandle,\r
491 IN EFI_GUID *Protocol,\r
492 IN VOID *Interface\r
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
506EFI_STATUS\r
507EFIAPI\r
508SmmHandleProtocol (\r
509 IN EFI_HANDLE UserHandle,\r
510 IN EFI_GUID *Protocol,\r
511 OUT VOID **Interface\r
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
527EFI_STATUS\r
528EFIAPI\r
529SmmRegisterProtocolNotify (\r
530 IN CONST EFI_GUID *Protocol,\r
531 IN EFI_SMM_NOTIFY_FN Function,\r
532 OUT VOID **Registration\r
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
553EFI_STATUS\r
554EFIAPI\r
555SmmLocateHandle (\r
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
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
566 to the system. If Registration is NULL return the first Protocol Interface\r
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
579EFI_STATUS\r
580EFIAPI\r
581SmmLocateProtocol (\r
582 IN EFI_GUID *Protocol,\r
583 IN VOID *Registration OPTIONAL,\r
584 OUT VOID **Interface\r
585 );\r
586\r
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
606 @retval EFI_INVALID_PARAMETER One or more parameters are not valid.\r
607\r
608**/\r
609EFI_STATUS\r
610EFIAPI\r
611SmmLocateHandleBuffer (\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
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
633EFI_STATUS\r
634EFIAPI\r
635SmiManage (\r
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
640 );\r
641\r
642/**\r
643 Registers a handler to execute within SMM.\r
644\r
645 @param Handler Handler service function pointer.\r
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
653EFI_STATUS\r
654EFIAPI\r
655SmiHandlerRegister (\r
656 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r
657 IN CONST EFI_GUID *HandlerType OPTIONAL,\r
658 OUT EFI_HANDLE *DispatchHandle\r
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
670EFI_STATUS\r
671EFIAPI\r
672SmiHandlerUnRegister (\r
673 IN EFI_HANDLE DispatchHandle\r
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
689EFI_STATUS\r
690EFIAPI\r
691SmmDriverDispatchHandler (\r
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
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
711EFI_STATUS\r
712EFIAPI\r
713SmmLegacyBootHandler (\r
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
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
733EFI_STATUS\r
734EFIAPI\r
735SmmReadyToLockHandler (\r
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
740 );\r
741\r
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
755EFI_STATUS\r
756EFIAPI\r
757SmmEndOfDxeHandler (\r
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
762 );\r
763\r
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
777EFI_STATUS\r
778EFIAPI\r
779SmmExitBootServicesHandler (\r
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
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
799EFI_STATUS\r
800EFIAPI\r
801SmmReadyToBootHandler (\r
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
806 );\r
807\r
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
822EFI_STATUS\r
823EFIAPI\r
824SmmS3SmmInitDoneHandler (\r
825 IN EFI_HANDLE DispatchHandle,\r
826 IN CONST VOID *Context OPTIONAL,\r
827 IN OUT VOID *CommBuffer OPTIONAL,\r
828 IN OUT UINTN *CommBufferSize OPTIONAL\r
829 );\r
830\r
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
845EFI_STATUS\r
846EFIAPI\r
847SmmEndOfS3ResumeHandler (\r
848 IN EFI_HANDLE DispatchHandle,\r
849 IN CONST VOID *Context OPTIONAL,\r
850 IN OUT VOID *CommBuffer OPTIONAL,\r
851 IN OUT UINTN *CommBufferSize OPTIONAL\r
852 );\r
853\r
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
866EFI_STATUS\r
867EFIAPI\r
868SmmEfiNotAvailableYetArg5 (\r
869 UINTN Arg1,\r
870 UINTN Arg2,\r
871 UINTN Arg3,\r
872 UINTN Arg4,\r
873 UINTN Arg5\r
874 );\r
875\r
876//\r
877// Functions used during debug builds\r
878//\r
879\r
880/**\r
881 Traverse the discovered list for any drivers that were discovered but not loaded\r
882 because the dependency expressions evaluated to false.\r
883\r
884**/\r
885VOID\r
886SmmDisplayDiscoveredNotDispatched (\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
899VOID\r
900SmmAddMemoryRegion (\r
901 IN EFI_PHYSICAL_ADDRESS MemBase,\r
902 IN UINT64 MemLength,\r
903 IN EFI_MEMORY_TYPE Type,\r
904 IN UINT64 Attributes\r
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
916PROTOCOL_ENTRY *\r
917SmmFindProtocolEntry (\r
918 IN EFI_GUID *Protocol,\r
919 IN BOOLEAN Create\r
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
928VOID\r
929SmmNotifyProtocol (\r
930 IN PROTOCOL_INTERFACE *Prot\r
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
945PROTOCOL_INTERFACE *\r
946SmmFindProtocolInterface (\r
947 IN IHANDLE *Handle,\r
948 IN EFI_GUID *Protocol,\r
949 IN VOID *Interface\r
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
962PROTOCOL_INTERFACE *\r
963SmmRemoveInterfaceFromProtocol (\r
964 IN IHANDLE *Handle,\r
965 IN EFI_GUID *Protocol,\r
966 IN VOID *Interface\r
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
972 routine in this case. POSTFIX means all the math is done on top of the stack.\r
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
981BOOLEAN\r
982SmmIsSchedulable (\r
983 IN EFI_SMM_DRIVER_ENTRY *DriverEntry\r
984 );\r
985\r
986//\r
987// SmramProfile\r
988//\r
989\r
990/**\r
991 Initialize SMRAM profile.\r
992\r
993**/\r
994VOID\r
995SmramProfileInit (\r
996 VOID\r
997 );\r
998\r
999/**\r
1000 Install SMRAM profile protocol.\r
1001\r
1002**/\r
1003VOID\r
1004SmramProfileInstallProtocol (\r
1005 VOID\r
1006 );\r
1007\r
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
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
1018\r
1019**/\r
1020EFI_STATUS\r
1021RegisterSmramProfileImage (\r
1022 IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r
1023 IN BOOLEAN RegisterToDxe\r
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
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
1036\r
1037**/\r
1038EFI_STATUS\r
1039UnregisterSmramProfileImage (\r
1040 IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r
1041 IN BOOLEAN UnregisterToDxe\r
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
1050 EfiMaxMemoryType means the MemoryType is unknown.\r
1051 @param Size Buffer size.\r
1052 @param Buffer Buffer address.\r
1053 @param ActionString String for memory profile action.\r
1054 Only needed for user defined allocate action.\r
1055\r
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
1064\r
1065**/\r
1066EFI_STATUS\r
1067EFIAPI\r
1068SmmCoreUpdateProfile (\r
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
1075 );\r
1076\r
1077/**\r
1078 Register SMRAM profile handler.\r
1079\r
1080**/\r
1081VOID\r
1082RegisterSmramProfileHandler (\r
1083 VOID\r
1084 );\r
1085\r
1086/**\r
1087 SMRAM profile ready to lock callback function.\r
1088\r
1089**/\r
1090VOID\r
1091SmramProfileReadyToLock (\r
1092 VOID\r
1093 );\r
1094\r
1095/**\r
1096 Initialize MemoryAttributes support.\r
1097**/\r
1098VOID\r
1099EFIAPI\r
1100SmmCoreInitializeMemoryAttributesTable (\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
1134EFI_STATUS\r
1135EFIAPI\r
1136SmmCoreGetMemoryMap (\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
1144/**\r
1145 Initialize SmiHandler profile feature.\r
1146**/\r
1147VOID\r
1148SmmCoreInitializeSmiHandlerProfile (\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
1172EFI_STATUS\r
1173EFIAPI\r
1174SmiHandlerProfileRegisterHandler (\r
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
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
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
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
1200EFI_STATUS\r
1201EFIAPI\r
1202SmiHandlerProfileUnregisterHandler (\r
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
1208 );\r
1209\r
1210extern UINTN mFullSmramRangeCount;\r
1211extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;\r
1212\r
1213extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;\r
1214\r
1215extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;\r
1216\r
1217//\r
1218// Page management\r
1219//\r
1220\r
1221typedef struct {\r
1222 LIST_ENTRY Link;\r
1223 UINTN NumberOfPages;\r
1224} FREE_PAGE_LIST;\r
1225\r
1226extern 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
1249#define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')\r
1250\r
1251typedef struct {\r
1252 UINT32 Signature;\r
1253 BOOLEAN Available;\r
1254 EFI_MEMORY_TYPE Type;\r
1255 UINTN Size;\r
1256} POOL_HEADER;\r
1257\r
1258#define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')\r
1259\r
1260typedef struct {\r
1261 UINT32 Signature;\r
1262 UINT32 Reserved;\r
1263 UINTN Size;\r
1264} POOL_TAIL;\r
1265\r
1266#define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))\r
1267\r
1268#define HEAD_TO_TAIL(a) \\r
1269 ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));\r
1270\r
1271typedef struct {\r
1272 POOL_HEADER Header;\r
1273 LIST_ENTRY Link;\r
1274} FREE_POOL_HEADER;\r
1275\r
1276typedef enum {\r
1277 SmmPoolTypeCode,\r
1278 SmmPoolTypeData,\r
1279 SmmPoolTypeMax,\r
1280} SMM_POOL_TYPE;\r
1281\r
1282extern LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];\r
1283\r
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
1294UINTN\r
1295InternalAllocPagesOnOneNode (\r
1296 IN OUT FREE_PAGE_LIST *Pages,\r
1297 IN UINTN NumberOfPages,\r
1298 IN UINTN MaxAddress\r
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
1309VOID\r
1310ConvertSmmMemoryMapEntry (\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
1322VOID\r
1323CoreFreeMemoryMapStack (\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
1339EFI_STATUS\r
1340SmmInternalFreePagesEx (\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
1349VOID\r
1350SmmEntryPointMemoryManagementHook (\r
1351 VOID\r
1352 );\r
1353\r
1354#endif\r