]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
MdeModulePkg: Use IsZeroGuid API for zero GUID checking
[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
e524f680 5 Copyright (c) 2009 - 2016, 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
e42e9404 35\r
36#include <Guid/Apriori.h>\r
37#include <Guid/EventGroup.h>\r
38#include <Guid/EventLegacyBios.h>\r
84edd20b 39#include <Guid/MemoryProfile.h>\r
e42e9404 40\r
41#include <Library/BaseLib.h>\r
42#include <Library/BaseMemoryLib.h>\r
43#include <Library/PeCoffLib.h>\r
e524f680 44#include <Library/PeCoffGetEntryPointLib.h>\r
e42e9404 45#include <Library/CacheMaintenanceLib.h>\r
46#include <Library/DebugLib.h>\r
47#include <Library/ReportStatusCodeLib.h>\r
48#include <Library/MemoryAllocationLib.h>\r
49#include <Library/DevicePathLib.h> \r
50#include <Library/UefiLib.h> \r
3c447c27 51#include <Library/UefiBootServicesTableLib.h>\r
52#include <Library/PcdLib.h>\r
495797c5 53#include <Library/SmmCorePlatformHookLib.h>\r
54#include <Library/PerformanceLib.h>\r
c2cb08df 55#include <Library/TimerLib.h>\r
3720ee6d 56#include <Library/HobLib.h>\r
842b1242 57#include <Library/SmmMemLib.h>\r
e42e9404 58\r
59#include "PiSmmCorePrivateData.h"\r
60\r
61//\r
62// Used to build a table of SMI Handlers that the SMM Core registers\r
63//\r
64typedef struct {\r
65 EFI_SMM_HANDLER_ENTRY_POINT2 Handler;\r
66 EFI_GUID *HandlerType;\r
67 EFI_HANDLE DispatchHandle;\r
68 BOOLEAN UnRegister;\r
69} SMM_CORE_SMI_HANDLERS;\r
70\r
71//\r
72// Structure for recording the state of an SMM Driver\r
73//\r
74#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')\r
75\r
76typedef struct {\r
77 UINTN Signature;\r
78 LIST_ENTRY Link; // mDriverList\r
79\r
80 LIST_ENTRY ScheduledLink; // mScheduledQueue\r
81\r
82 EFI_HANDLE FvHandle;\r
83 EFI_GUID FileName;\r
84 EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;\r
85 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
86\r
87 VOID *Depex;\r
88 UINTN DepexSize;\r
89\r
90 BOOLEAN Before;\r
91 BOOLEAN After;\r
92 EFI_GUID BeforeAfterGuid;\r
93\r
94 BOOLEAN Dependent;\r
e42e9404 95 BOOLEAN Scheduled;\r
e42e9404 96 BOOLEAN Initialized;\r
97 BOOLEAN DepexProtocolError;\r
98\r
99 EFI_HANDLE ImageHandle;\r
100 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
101 //\r
102 // Image EntryPoint in SMRAM\r
103 //\r
104 PHYSICAL_ADDRESS ImageEntryPoint;\r
105 //\r
106 // Image Buffer in SMRAM \r
107 //\r
108 PHYSICAL_ADDRESS ImageBuffer;\r
109 //\r
110 // Image Page Number\r
111 //\r
112 UINTN NumberOfPage;\r
113} EFI_SMM_DRIVER_ENTRY;\r
114\r
115#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')\r
116\r
117///\r
118/// IHANDLE - contains a list of protocol handles\r
119///\r
120typedef struct {\r
121 UINTN Signature;\r
122 /// All handles list of IHANDLE\r
123 LIST_ENTRY AllHandles;\r
124 /// List of PROTOCOL_INTERFACE's for this handle\r
125 LIST_ENTRY Protocols;\r
126 UINTN LocateRequest;\r
127} IHANDLE;\r
128\r
129#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)\r
130\r
131#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')\r
132\r
133///\r
134/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol\r
135/// database. Each handler that supports this protocol is listed, along\r
136/// with a list of registered notifies.\r
137///\r
138typedef struct {\r
139 UINTN Signature;\r
140 /// Link Entry inserted to mProtocolDatabase\r
141 LIST_ENTRY AllEntries;\r
142 /// ID of the protocol\r
143 EFI_GUID ProtocolID;\r
144 /// All protocol interfaces\r
145 LIST_ENTRY Protocols;\r
146 /// Registerd notification handlers\r
147 LIST_ENTRY Notify;\r
148} PROTOCOL_ENTRY;\r
149\r
150#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')\r
151\r
152///\r
153/// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked\r
154/// with a protocol interface structure\r
155///\r
156typedef struct {\r
157 UINTN Signature;\r
158 /// Link on IHANDLE.Protocols\r
159 LIST_ENTRY Link;\r
160 /// Back pointer\r
161 IHANDLE *Handle;\r
162 /// Link on PROTOCOL_ENTRY.Protocols\r
163 LIST_ENTRY ByProtocol;\r
164 /// The protocol ID\r
165 PROTOCOL_ENTRY *Protocol;\r
166 /// The interface value\r
167 VOID *Interface;\r
168} PROTOCOL_INTERFACE;\r
169\r
170#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')\r
171\r
172///\r
173/// PROTOCOL_NOTIFY - used for each register notification for a protocol\r
174///\r
175typedef struct {\r
176 UINTN Signature;\r
177 PROTOCOL_ENTRY *Protocol;\r
178 /// All notifications for this protocol\r
179 LIST_ENTRY Link;\r
180 /// Notification function\r
181 EFI_SMM_NOTIFY_FN Function;\r
182 /// Last position notified\r
183 LIST_ENTRY *Position;\r
184} PROTOCOL_NOTIFY;\r
185\r
186//\r
187// SMM Core Global Variables\r
188//\r
189extern SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;\r
190extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst;\r
191extern LIST_ENTRY gHandleList;\r
3c447c27 192extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase;\r
e42e9404 193\r
194/**\r
195 Called to initialize the memory service.\r
196\r
197 @param SmramRangeCount Number of SMRAM Regions\r
198 @param SmramRanges Pointer to SMRAM Descriptors\r
199\r
200**/\r
201VOID\r
202SmmInitializeMemoryServices (\r
203 IN UINTN SmramRangeCount,\r
204 IN EFI_SMRAM_DESCRIPTOR *SmramRanges\r
205 );\r
206\r
207/**\r
208 The SmmInstallConfigurationTable() function is used to maintain the list\r
209 of configuration tables that are stored in the System Management System\r
210 Table. The list is stored as an array of (GUID, Pointer) pairs. The list\r
211 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.\r
212\r
213 @param SystemTable A pointer to the SMM System Table (SMST).\r
214 @param Guid A pointer to the GUID for the entry to add, update, or remove.\r
215 @param Table A pointer to the buffer of the table to add.\r
216 @param TableSize The size of the table to install.\r
217\r
218 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.\r
219 @retval EFI_INVALID_PARAMETER Guid is not valid.\r
220 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.\r
221 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.\r
222\r
223**/\r
224EFI_STATUS\r
225EFIAPI\r
226SmmInstallConfigurationTable (\r
227 IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,\r
228 IN CONST EFI_GUID *Guid,\r
229 IN VOID *Table,\r
230 IN UINTN TableSize\r
231 );\r
232\r
233/**\r
234 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which\r
235 Calls the private one which contains a BOOLEAN parameter for notifications\r
236\r
237 @param UserHandle The handle to install the protocol handler on,\r
238 or NULL if a new handle is to be allocated\r
239 @param Protocol The protocol to add to the handle\r
240 @param InterfaceType Indicates whether Interface is supplied in\r
241 native form.\r
242 @param Interface The interface for the protocol being added\r
243\r
244 @return Status code\r
245\r
246**/\r
247EFI_STATUS\r
248EFIAPI\r
249SmmInstallProtocolInterface (\r
250 IN OUT EFI_HANDLE *UserHandle,\r
251 IN EFI_GUID *Protocol,\r
252 IN EFI_INTERFACE_TYPE InterfaceType,\r
253 IN VOID *Interface\r
254 );\r
255\r
256/**\r
257 Allocates pages from the memory map.\r
258\r
259 @param Type The type of allocation to perform\r
260 @param MemoryType The type of memory to turn the allocated pages\r
261 into\r
262 @param NumberOfPages The number of pages to allocate\r
263 @param Memory A pointer to receive the base allocated memory\r
264 address\r
265\r
266 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
267 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
268 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r
269 @retval EFI_SUCCESS Pages successfully allocated.\r
270\r
271**/\r
272EFI_STATUS\r
273EFIAPI\r
274SmmAllocatePages (\r
275 IN EFI_ALLOCATE_TYPE Type,\r
276 IN EFI_MEMORY_TYPE MemoryType,\r
277 IN UINTN NumberOfPages,\r
278 OUT EFI_PHYSICAL_ADDRESS *Memory\r
279 );\r
280\r
84edd20b
SZ
281/**\r
282 Allocates pages from the memory map.\r
283\r
284 @param Type The type of allocation to perform\r
285 @param MemoryType The type of memory to turn the allocated pages\r
286 into\r
287 @param NumberOfPages The number of pages to allocate\r
288 @param Memory A pointer to receive the base allocated memory\r
289 address\r
290\r
291 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.\r
292 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.\r
293 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.\r
294 @retval EFI_SUCCESS Pages successfully allocated.\r
295\r
296**/\r
297EFI_STATUS\r
298EFIAPI\r
299SmmInternalAllocatePages (\r
300 IN EFI_ALLOCATE_TYPE Type,\r
301 IN EFI_MEMORY_TYPE MemoryType,\r
302 IN UINTN NumberOfPages,\r
303 OUT EFI_PHYSICAL_ADDRESS *Memory\r
304 );\r
305\r
e42e9404 306/**\r
307 Frees previous allocated pages.\r
308\r
309 @param Memory Base address of memory being freed\r
310 @param NumberOfPages The number of pages to free\r
311\r
312 @retval EFI_NOT_FOUND Could not find the entry that covers the range\r
313 @retval EFI_INVALID_PARAMETER Address not aligned\r
314 @return EFI_SUCCESS Pages successfully freed.\r
315\r
316**/\r
317EFI_STATUS\r
318EFIAPI\r
319SmmFreePages (\r
320 IN EFI_PHYSICAL_ADDRESS Memory,\r
321 IN UINTN NumberOfPages\r
322 );\r
323\r
84edd20b
SZ
324/**\r
325 Frees previous allocated pages.\r
326\r
327 @param Memory Base address of memory being freed\r
328 @param NumberOfPages The number of pages to free\r
329\r
330 @retval EFI_NOT_FOUND Could not find the entry that covers the range\r
331 @retval EFI_INVALID_PARAMETER Address not aligned\r
332 @return EFI_SUCCESS Pages successfully freed.\r
333\r
334**/\r
335EFI_STATUS\r
336EFIAPI\r
337SmmInternalFreePages (\r
338 IN EFI_PHYSICAL_ADDRESS Memory,\r
339 IN UINTN NumberOfPages\r
340 );\r
341\r
e42e9404 342/**\r
343 Allocate pool of a particular type.\r
344\r
345 @param PoolType Type of pool to allocate\r
346 @param Size The amount of pool to allocate\r
347 @param Buffer The address to return a pointer to the allocated\r
348 pool\r
349\r
350 @retval EFI_INVALID_PARAMETER PoolType not valid\r
351 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r
352 @retval EFI_SUCCESS Pool successfully allocated.\r
353\r
354**/\r
355EFI_STATUS\r
356EFIAPI\r
357SmmAllocatePool (\r
358 IN EFI_MEMORY_TYPE PoolType,\r
359 IN UINTN Size,\r
360 OUT VOID **Buffer\r
361 );\r
362\r
84edd20b
SZ
363/**\r
364 Allocate pool of a particular type.\r
365\r
366 @param PoolType Type of pool to allocate\r
367 @param Size The amount of pool to allocate\r
368 @param Buffer The address to return a pointer to the allocated\r
369 pool\r
370\r
371 @retval EFI_INVALID_PARAMETER PoolType not valid\r
372 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.\r
373 @retval EFI_SUCCESS Pool successfully allocated.\r
374\r
375**/\r
376EFI_STATUS\r
377EFIAPI\r
378SmmInternalAllocatePool (\r
379 IN EFI_MEMORY_TYPE PoolType,\r
380 IN UINTN Size,\r
381 OUT VOID **Buffer\r
382 );\r
383\r
e42e9404 384/**\r
385 Frees pool.\r
386\r
387 @param Buffer The allocated pool entry to free\r
388\r
389 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r
390 @retval EFI_SUCCESS Pool successfully freed.\r
391\r
392**/\r
393EFI_STATUS\r
394EFIAPI\r
395SmmFreePool (\r
396 IN VOID *Buffer\r
397 );\r
398\r
84edd20b
SZ
399/**\r
400 Frees pool.\r
401\r
402 @param Buffer The allocated pool entry to free\r
403\r
404 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.\r
405 @retval EFI_SUCCESS Pool successfully freed.\r
406\r
407**/\r
408EFI_STATUS\r
409EFIAPI\r
410SmmInternalFreePool (\r
411 IN VOID *Buffer\r
412 );\r
413\r
e42e9404 414/**\r
415 Installs a protocol interface into the boot services environment.\r
416\r
417 @param UserHandle The handle to install the protocol handler on,\r
418 or NULL if a new handle is to be allocated\r
419 @param Protocol The protocol to add to the handle\r
420 @param InterfaceType Indicates whether Interface is supplied in\r
421 native form.\r
422 @param Interface The interface for the protocol being added\r
423 @param Notify indicates whether notify the notification list\r
424 for this protocol\r
425\r
426 @retval EFI_INVALID_PARAMETER Invalid parameter\r
427 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate\r
428 @retval EFI_SUCCESS Protocol interface successfully installed\r
429\r
430**/\r
431EFI_STATUS\r
432SmmInstallProtocolInterfaceNotify (\r
433 IN OUT EFI_HANDLE *UserHandle,\r
434 IN EFI_GUID *Protocol,\r
435 IN EFI_INTERFACE_TYPE InterfaceType,\r
436 IN VOID *Interface,\r
437 IN BOOLEAN Notify\r
438 );\r
439\r
440/**\r
441 Uninstalls all instances of a protocol:interfacer from a handle.\r
442 If the last protocol interface is remove from the handle, the\r
443 handle is freed.\r
444\r
445 @param UserHandle The handle to remove the protocol handler from\r
446 @param Protocol The protocol, of protocol:interface, to remove\r
447 @param Interface The interface, of protocol:interface, to remove\r
448\r
449 @retval EFI_INVALID_PARAMETER Protocol is NULL.\r
450 @retval EFI_SUCCESS Protocol interface successfully uninstalled.\r
451\r
452**/\r
453EFI_STATUS\r
454EFIAPI\r
455SmmUninstallProtocolInterface (\r
456 IN EFI_HANDLE UserHandle,\r
457 IN EFI_GUID *Protocol,\r
458 IN VOID *Interface\r
459 );\r
460\r
461/**\r
462 Queries a handle to determine if it supports a specified protocol.\r
463\r
464 @param UserHandle The handle being queried.\r
465 @param Protocol The published unique identifier of the protocol.\r
466 @param Interface Supplies the address where a pointer to the\r
467 corresponding Protocol Interface is returned.\r
468\r
469 @return The requested protocol interface for the handle\r
470\r
471**/\r
472EFI_STATUS\r
473EFIAPI\r
474SmmHandleProtocol (\r
475 IN EFI_HANDLE UserHandle,\r
476 IN EFI_GUID *Protocol,\r
477 OUT VOID **Interface\r
478 );\r
479\r
480/**\r
481 Add a new protocol notification record for the request protocol.\r
482\r
483 @param Protocol The requested protocol to add the notify\r
484 registration\r
485 @param Function Points to the notification function\r
486 @param Registration Returns the registration record\r
487\r
488 @retval EFI_INVALID_PARAMETER Invalid parameter\r
489 @retval EFI_SUCCESS Successfully returned the registration record\r
490 that has been added\r
491\r
492**/\r
493EFI_STATUS\r
494EFIAPI\r
495SmmRegisterProtocolNotify (\r
496 IN CONST EFI_GUID *Protocol,\r
497 IN EFI_SMM_NOTIFY_FN Function,\r
498 OUT VOID **Registration\r
499 );\r
500\r
501/**\r
502 Locates the requested handle(s) and returns them in Buffer.\r
503\r
504 @param SearchType The type of search to perform to locate the\r
505 handles\r
506 @param Protocol The protocol to search for\r
507 @param SearchKey Dependant on SearchType\r
508 @param BufferSize On input the size of Buffer. On output the\r
509 size of data returned.\r
510 @param Buffer The buffer to return the results in\r
511\r
512 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is\r
513 returned in BufferSize.\r
514 @retval EFI_INVALID_PARAMETER Invalid parameter\r
515 @retval EFI_SUCCESS Successfully found the requested handle(s) and\r
516 returns them in Buffer.\r
517\r
518**/\r
519EFI_STATUS\r
520EFIAPI\r
521SmmLocateHandle (\r
522 IN EFI_LOCATE_SEARCH_TYPE SearchType,\r
523 IN EFI_GUID *Protocol OPTIONAL,\r
524 IN VOID *SearchKey OPTIONAL,\r
525 IN OUT UINTN *BufferSize,\r
526 OUT EFI_HANDLE *Buffer\r
527 );\r
528\r
529/**\r
530 Return the first Protocol Interface that matches the Protocol GUID. If\r
531 Registration is pasased in return a Protocol Instance that was just add\r
532 to the system. If Retistration is NULL return the first Protocol Interface\r
533 you find.\r
534\r
535 @param Protocol The protocol to search for\r
536 @param Registration Optional Registration Key returned from\r
537 RegisterProtocolNotify()\r
538 @param Interface Return the Protocol interface (instance).\r
539\r
540 @retval EFI_SUCCESS If a valid Interface is returned\r
541 @retval EFI_INVALID_PARAMETER Invalid parameter\r
542 @retval EFI_NOT_FOUND Protocol interface not found\r
543\r
544**/\r
545EFI_STATUS\r
546EFIAPI\r
547SmmLocateProtocol (\r
548 IN EFI_GUID *Protocol,\r
549 IN VOID *Registration OPTIONAL,\r
550 OUT VOID **Interface\r
551 );\r
552\r
553/**\r
554 Manage SMI of a particular type.\r
555\r
556 @param HandlerType Points to the handler type or NULL for root SMI handlers.\r
557 @param Context Points to an optional context buffer.\r
558 @param CommBuffer Points to the optional communication buffer.\r
559 @param CommBufferSize Points to the size of the optional communication buffer.\r
560\r
561 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.\r
562 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.\r
563 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.\r
564 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.\r
565\r
566**/\r
567EFI_STATUS\r
568EFIAPI\r
569SmiManage (\r
570 IN CONST EFI_GUID *HandlerType,\r
571 IN CONST VOID *Context OPTIONAL,\r
572 IN OUT VOID *CommBuffer OPTIONAL,\r
573 IN OUT UINTN *CommBufferSize OPTIONAL\r
574 );\r
575\r
576/**\r
577 Registers a handler to execute within SMM.\r
578\r
579 @param Handler Handler service funtion pointer.\r
580 @param HandlerType Points to the handler type or NULL for root SMI handlers.\r
581 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.\r
582\r
583 @retval EFI_SUCCESS Handler register success.\r
584 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.\r
585\r
586**/\r
587EFI_STATUS\r
588EFIAPI\r
589SmiHandlerRegister (\r
590 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,\r
591 IN CONST EFI_GUID *HandlerType OPTIONAL,\r
592 OUT EFI_HANDLE *DispatchHandle\r
593 );\r
594\r
595/**\r
596 Unregister a handler in SMM.\r
597\r
598 @param DispatchHandle The handle that was specified when the handler was registered.\r
599\r
600 @retval EFI_SUCCESS Handler function was successfully unregistered.\r
601 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.\r
602\r
603**/\r
604EFI_STATUS\r
605EFIAPI\r
606SmiHandlerUnRegister (\r
607 IN EFI_HANDLE DispatchHandle\r
608 );\r
609\r
610/**\r
611 This function is the main entry point for an SMM handler dispatch\r
612 or communicate-based callback.\r
613\r
614 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
615 @param Context Points to an optional handler context which was specified when the handler was registered.\r
616 @param CommBuffer A pointer to a collection of data in memory that will\r
617 be conveyed from a non-SMM environment into an SMM environment.\r
618 @param CommBufferSize The size of the CommBuffer.\r
619\r
620 @return Status Code\r
621\r
622**/\r
623EFI_STATUS\r
624EFIAPI\r
625SmmDriverDispatchHandler (\r
626 IN EFI_HANDLE DispatchHandle,\r
627 IN CONST VOID *Context, OPTIONAL\r
628 IN OUT VOID *CommBuffer, OPTIONAL\r
629 IN OUT UINTN *CommBufferSize OPTIONAL\r
630 );\r
631\r
632/**\r
633 This function is the main entry point for an SMM handler dispatch\r
634 or communicate-based callback.\r
635\r
636 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
637 @param Context Points to an optional handler context which was specified when the handler was registered.\r
638 @param CommBuffer A pointer to a collection of data in memory that will\r
639 be conveyed from a non-SMM environment into an SMM environment.\r
640 @param CommBufferSize The size of the CommBuffer.\r
641\r
642 @return Status Code\r
643\r
644**/\r
645EFI_STATUS\r
646EFIAPI\r
647SmmLegacyBootHandler (\r
648 IN EFI_HANDLE DispatchHandle,\r
649 IN CONST VOID *Context, OPTIONAL\r
650 IN OUT VOID *CommBuffer, OPTIONAL\r
651 IN OUT UINTN *CommBufferSize OPTIONAL\r
652 );\r
653\r
654/**\r
655 This function is the main entry point for an SMM handler dispatch\r
656 or communicate-based callback.\r
657\r
658 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
659 @param Context Points to an optional handler context which was specified when the handler was registered.\r
660 @param CommBuffer A pointer to a collection of data in memory that will\r
661 be conveyed from a non-SMM environment into an SMM environment.\r
662 @param CommBufferSize The size of the CommBuffer.\r
663\r
664 @return Status Code\r
665\r
666**/\r
667EFI_STATUS\r
668EFIAPI\r
669SmmReadyToLockHandler (\r
670 IN EFI_HANDLE DispatchHandle,\r
671 IN CONST VOID *Context, OPTIONAL\r
672 IN OUT VOID *CommBuffer, OPTIONAL\r
673 IN OUT UINTN *CommBufferSize OPTIONAL\r
674 );\r
675\r
46ece1ff
JY
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
691SmmEndOfDxeHandler (\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
53ec4d7f
SZ
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
713SmmExitBootServicesHandler (\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
735SmmReadyToBootHandler (\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
e42e9404 742/**\r
743 Place holder function until all the SMM System Table Service are available.\r
744\r
745 @param Arg1 Undefined\r
746 @param Arg2 Undefined\r
747 @param Arg3 Undefined\r
748 @param Arg4 Undefined\r
749 @param Arg5 Undefined\r
750\r
751 @return EFI_NOT_AVAILABLE_YET\r
752\r
753**/\r
754EFI_STATUS\r
755EFIAPI\r
756SmmEfiNotAvailableYetArg5 (\r
757 UINTN Arg1,\r
758 UINTN Arg2,\r
759 UINTN Arg3,\r
760 UINTN Arg4,\r
761 UINTN Arg5\r
762 );\r
763\r
764//\r
765//Functions used during debug buils\r
766//\r
767\r
768/**\r
769 Traverse the discovered list for any drivers that were discovered but not loaded\r
770 because the dependency experessions evaluated to false.\r
771\r
772**/\r
773VOID\r
774SmmDisplayDiscoveredNotDispatched (\r
775 VOID\r
776 );\r
777\r
778/**\r
779 Add free SMRAM region for use by memory service.\r
780\r
781 @param MemBase Base address of memory region.\r
782 @param MemLength Length of the memory region.\r
783 @param Type Memory type.\r
784 @param Attributes Memory region state.\r
785\r
786**/\r
787VOID\r
788SmmAddMemoryRegion (\r
789 IN EFI_PHYSICAL_ADDRESS MemBase,\r
790 IN UINT64 MemLength,\r
791 IN EFI_MEMORY_TYPE Type,\r
792 IN UINT64 Attributes\r
793 );\r
794\r
795/**\r
796 Finds the protocol entry for the requested protocol.\r
797\r
798 @param Protocol The ID of the protocol\r
799 @param Create Create a new entry if not found\r
800\r
801 @return Protocol entry\r
802\r
803**/\r
804PROTOCOL_ENTRY *\r
805SmmFindProtocolEntry (\r
806 IN EFI_GUID *Protocol,\r
807 IN BOOLEAN Create\r
808 );\r
809\r
810/**\r
811 Signal event for every protocol in protocol entry.\r
812\r
813 @param Prot Protocol interface\r
814\r
815**/\r
816VOID\r
817SmmNotifyProtocol (\r
818 IN PROTOCOL_INTERFACE *Prot\r
819 );\r
820\r
821/**\r
822 Finds the protocol instance for the requested handle and protocol.\r
823 Note: This function doesn't do parameters checking, it's caller's responsibility\r
824 to pass in valid parameters.\r
825\r
826 @param Handle The handle to search the protocol on\r
827 @param Protocol GUID of the protocol\r
828 @param Interface The interface for the protocol being searched\r
829\r
830 @return Protocol instance (NULL: Not found)\r
831\r
832**/\r
833PROTOCOL_INTERFACE *\r
834SmmFindProtocolInterface (\r
835 IN IHANDLE *Handle,\r
836 IN EFI_GUID *Protocol,\r
837 IN VOID *Interface\r
838 );\r
839\r
840/**\r
841 Removes Protocol from the protocol list (but not the handle list).\r
842\r
843 @param Handle The handle to remove protocol on.\r
844 @param Protocol GUID of the protocol to be moved\r
845 @param Interface The interface of the protocol\r
846\r
847 @return Protocol Entry\r
848\r
849**/\r
850PROTOCOL_INTERFACE *\r
851SmmRemoveInterfaceFromProtocol (\r
852 IN IHANDLE *Handle,\r
853 IN EFI_GUID *Protocol,\r
854 IN VOID *Interface\r
855 );\r
856\r
857/**\r
858 This is the POSTFIX version of the dependency evaluator. This code does\r
859 not need to handle Before or After, as it is not valid to call this\r
fa542a1e 860 routine in this case. POSTFIX means all the math is done on top of the stack.\r
e42e9404 861\r
862 @param DriverEntry DriverEntry element to update.\r
863\r
864 @retval TRUE If driver is ready to run.\r
865 @retval FALSE If driver is not ready to run or some fatal error\r
866 was found.\r
867\r
868**/\r
869BOOLEAN\r
870SmmIsSchedulable (\r
871 IN EFI_SMM_DRIVER_ENTRY *DriverEntry\r
872 );\r
873\r
84edd20b
SZ
874//\r
875// SmramProfile\r
876//\r
877\r
878/**\r
879 Initialize SMRAM profile.\r
880\r
881**/\r
882VOID\r
883SmramProfileInit (\r
884 VOID\r
885 );\r
886\r
e524f680
SZ
887/**\r
888 Install SMRAM profile protocol.\r
889\r
890**/\r
891VOID\r
892SmramProfileInstallProtocol (\r
893 VOID\r
894 );\r
895\r
84edd20b
SZ
896/**\r
897 Register SMM image to SMRAM profile.\r
898\r
899 @param DriverEntry SMM image info.\r
900 @param RegisterToDxe Register image to DXE.\r
901\r
e524f680
SZ
902 @return EFI_SUCCESS Register successfully.\r
903 @return EFI_UNSUPPORTED Memory profile unsupported,\r
904 or memory profile for the image is not required.\r
905 @return EFI_OUT_OF_RESOURCES No enough resource for this register.\r
84edd20b
SZ
906\r
907**/\r
e524f680 908EFI_STATUS\r
84edd20b
SZ
909RegisterSmramProfileImage (\r
910 IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r
911 IN BOOLEAN RegisterToDxe\r
912 );\r
913\r
914/**\r
915 Unregister image from SMRAM profile.\r
916\r
917 @param DriverEntry SMM image info.\r
918 @param UnregisterToDxe Unregister image from DXE.\r
919\r
e524f680
SZ
920 @return EFI_SUCCESS Unregister successfully.\r
921 @return EFI_UNSUPPORTED Memory profile unsupported,\r
922 or memory profile for the image is not required.\r
923 @return EFI_NOT_FOUND The image is not found.\r
84edd20b
SZ
924\r
925**/\r
e524f680 926EFI_STATUS\r
84edd20b
SZ
927UnregisterSmramProfileImage (\r
928 IN EFI_SMM_DRIVER_ENTRY *DriverEntry,\r
929 IN BOOLEAN UnregisterToDxe\r
930 );\r
931\r
932/**\r
933 Update SMRAM profile information.\r
934\r
935 @param CallerAddress Address of caller who call Allocate or Free.\r
936 @param Action This Allocate or Free action.\r
937 @param MemoryType Memory type.\r
e524f680 938 EfiMaxMemoryType means the MemoryType is unknown.\r
84edd20b
SZ
939 @param Size Buffer size.\r
940 @param Buffer Buffer address.\r
e524f680
SZ
941 @param ActionString String for memory profile action.\r
942 Only needed for user defined allocate action.\r
84edd20b 943\r
e524f680
SZ
944 @return EFI_SUCCESS Memory profile is updated.\r
945 @return EFI_UNSUPPORTED Memory profile is unsupported,\r
946 or memory profile for the image is not required,\r
947 or memory profile for the memory type is not required.\r
948 @return EFI_ACCESS_DENIED It is during memory profile data getting.\r
949 @return EFI_ABORTED Memory profile recording is not enabled.\r
950 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r
951 @return EFI_NOT_FOUND No matched allocate info found for free action.\r
84edd20b
SZ
952\r
953**/\r
e524f680
SZ
954EFI_STATUS\r
955EFIAPI\r
84edd20b 956SmmCoreUpdateProfile (\r
e524f680
SZ
957 IN PHYSICAL_ADDRESS CallerAddress,\r
958 IN MEMORY_PROFILE_ACTION Action,\r
959 IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool\r
960 IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool\r
961 IN VOID *Buffer,\r
962 IN CHAR8 *ActionString OPTIONAL\r
84edd20b
SZ
963 );\r
964\r
965/**\r
966 Register SMRAM profile handler.\r
967\r
968**/\r
969VOID\r
970RegisterSmramProfileHandler (\r
971 VOID\r
972 );\r
973\r
974/**\r
975 SMRAM profile ready to lock callback function.\r
976\r
977**/\r
978VOID\r
979SmramProfileReadyToLock (\r
980 VOID\r
981 );\r
982\r
84edd20b
SZ
983extern UINTN mFullSmramRangeCount;\r
984extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;\r
985\r
0b256fb1
JY
986extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;\r
987\r
63aa86b0
SZ
988//\r
989// Page management\r
990//\r
991\r
992typedef struct {\r
993 LIST_ENTRY Link;\r
994 UINTN NumberOfPages;\r
995} FREE_PAGE_LIST;\r
996\r
997extern LIST_ENTRY mSmmMemoryMap;\r
998\r
999//\r
1000// Pool management\r
1001//\r
1002\r
1003//\r
1004// MIN_POOL_SHIFT must not be less than 5\r
1005//\r
1006#define MIN_POOL_SHIFT 6\r
1007#define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)\r
1008\r
1009//\r
1010// MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1\r
1011//\r
1012#define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)\r
1013#define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)\r
1014\r
1015//\r
1016// MAX_POOL_INDEX are calculated by maximum and minimum pool sizes\r
1017//\r
1018#define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)\r
1019\r
1020typedef struct {\r
1021 UINTN Size;\r
1022 BOOLEAN Available;\r
1023} POOL_HEADER;\r
1024\r
1025typedef struct {\r
1026 POOL_HEADER Header;\r
1027 LIST_ENTRY Link;\r
1028} FREE_POOL_HEADER;\r
1029\r
1030extern LIST_ENTRY mSmmPoolLists[MAX_POOL_INDEX];\r
1031\r
e42e9404 1032#endif\r