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