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