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