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