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