2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2010, 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
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.
21 #include <Protocol/DxeSmmReadyToLock.h>
22 #include <Protocol/SmmReadyToLock.h>
23 #include <Protocol/CpuIo2.h>
24 #include <Protocol/SmmCommunication.h>
25 #include <Protocol/SmmAccess2.h>
26 #include <Protocol/FirmwareVolume2.h>
27 #include <Protocol/LoadedImage.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/Security.h>
31 #include <Guid/Apriori.h>
32 #include <Guid/EventGroup.h>
33 #include <Guid/EventLegacyBios.h>
35 #include <Library/BaseLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/PeCoffLib.h>
38 #include <Library/CacheMaintenanceLib.h>
39 #include <Library/DebugLib.h>
40 #include <Library/ReportStatusCodeLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/DevicePathLib.h>
43 #include <Library/UefiLib.h>
44 #include <Library/UefiBootServicesTableLib.h>
46 #include "PiSmmCorePrivateData.h"
49 // Used to build a table of SMI Handlers that the SMM Core registers
52 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
53 EFI_GUID
*HandlerType
;
54 EFI_HANDLE DispatchHandle
;
56 } SMM_CORE_SMI_HANDLERS
;
59 // Structure for recording the state of an SMM Driver
61 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
65 LIST_ENTRY Link
; // mDriverList
67 LIST_ENTRY ScheduledLink
; // mScheduledQueue
71 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
72 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
79 EFI_GUID BeforeAfterGuid
;
86 BOOLEAN DepexProtocolError
;
88 EFI_HANDLE ImageHandle
;
89 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
91 // Image EntryPoint in SMRAM
93 PHYSICAL_ADDRESS ImageEntryPoint
;
95 // Image Buffer in SMRAM
97 PHYSICAL_ADDRESS ImageBuffer
;
102 } EFI_SMM_DRIVER_ENTRY
;
104 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
107 /// IHANDLE - contains a list of protocol handles
111 /// All handles list of IHANDLE
112 LIST_ENTRY AllHandles
;
113 /// List of PROTOCOL_INTERFACE's for this handle
114 LIST_ENTRY Protocols
;
118 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
120 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
123 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
124 /// database. Each handler that supports this protocol is listed, along
125 /// with a list of registered notifies.
129 /// Link Entry inserted to mProtocolDatabase
130 LIST_ENTRY AllEntries
;
131 /// ID of the protocol
133 /// All protocol interfaces
134 LIST_ENTRY Protocols
;
135 /// Registerd notification handlers
139 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
142 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
143 /// with a protocol interface structure
147 /// Link on IHANDLE.Protocols
151 /// Link on PROTOCOL_ENTRY.Protocols
152 LIST_ENTRY ByProtocol
;
154 PROTOCOL_ENTRY
*Protocol
;
155 /// The interface value
157 } PROTOCOL_INTERFACE
;
159 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
162 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
166 PROTOCOL_ENTRY
*Protocol
;
167 /// All notifications for this protocol
169 /// Notification function
170 EFI_SMM_NOTIFY_FN Function
;
171 /// Last position notified
172 LIST_ENTRY
*Position
;
176 // SMM Core Global Variables
178 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
179 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
180 extern LIST_ENTRY gHandleList
;
183 Called to initialize the memory service.
185 @param SmramRangeCount Number of SMRAM Regions
186 @param SmramRanges Pointer to SMRAM Descriptors
190 SmmInitializeMemoryServices (
191 IN UINTN SmramRangeCount
,
192 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
196 The SmmInstallConfigurationTable() function is used to maintain the list
197 of configuration tables that are stored in the System Management System
198 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
199 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
201 @param SystemTable A pointer to the SMM System Table (SMST).
202 @param Guid A pointer to the GUID for the entry to add, update, or remove.
203 @param Table A pointer to the buffer of the table to add.
204 @param TableSize The size of the table to install.
206 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
207 @retval EFI_INVALID_PARAMETER Guid is not valid.
208 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
209 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
214 SmmInstallConfigurationTable (
215 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
216 IN CONST EFI_GUID
*Guid
,
222 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
223 Calls the private one which contains a BOOLEAN parameter for notifications
225 @param UserHandle The handle to install the protocol handler on,
226 or NULL if a new handle is to be allocated
227 @param Protocol The protocol to add to the handle
228 @param InterfaceType Indicates whether Interface is supplied in
230 @param Interface The interface for the protocol being added
237 SmmInstallProtocolInterface (
238 IN OUT EFI_HANDLE
*UserHandle
,
239 IN EFI_GUID
*Protocol
,
240 IN EFI_INTERFACE_TYPE InterfaceType
,
245 Allocates pages from the memory map.
247 @param Type The type of allocation to perform
248 @param MemoryType The type of memory to turn the allocated pages
250 @param NumberOfPages The number of pages to allocate
251 @param Memory A pointer to receive the base allocated memory
254 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
255 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
256 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
257 @retval EFI_SUCCESS Pages successfully allocated.
263 IN EFI_ALLOCATE_TYPE Type
,
264 IN EFI_MEMORY_TYPE MemoryType
,
265 IN UINTN NumberOfPages
,
266 OUT EFI_PHYSICAL_ADDRESS
*Memory
270 Frees previous allocated pages.
272 @param Memory Base address of memory being freed
273 @param NumberOfPages The number of pages to free
275 @retval EFI_NOT_FOUND Could not find the entry that covers the range
276 @retval EFI_INVALID_PARAMETER Address not aligned
277 @return EFI_SUCCESS Pages successfully freed.
283 IN EFI_PHYSICAL_ADDRESS Memory
,
284 IN UINTN NumberOfPages
288 Allocate pool of a particular type.
290 @param PoolType Type of pool to allocate
291 @param Size The amount of pool to allocate
292 @param Buffer The address to return a pointer to the allocated
295 @retval EFI_INVALID_PARAMETER PoolType not valid
296 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
297 @retval EFI_SUCCESS Pool successfully allocated.
303 IN EFI_MEMORY_TYPE PoolType
,
311 @param Buffer The allocated pool entry to free
313 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
314 @retval EFI_SUCCESS Pool successfully freed.
324 Installs a protocol interface into the boot services environment.
326 @param UserHandle The handle to install the protocol handler on,
327 or NULL if a new handle is to be allocated
328 @param Protocol The protocol to add to the handle
329 @param InterfaceType Indicates whether Interface is supplied in
331 @param Interface The interface for the protocol being added
332 @param Notify indicates whether notify the notification list
335 @retval EFI_INVALID_PARAMETER Invalid parameter
336 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
337 @retval EFI_SUCCESS Protocol interface successfully installed
341 SmmInstallProtocolInterfaceNotify (
342 IN OUT EFI_HANDLE
*UserHandle
,
343 IN EFI_GUID
*Protocol
,
344 IN EFI_INTERFACE_TYPE InterfaceType
,
350 Uninstalls all instances of a protocol:interfacer from a handle.
351 If the last protocol interface is remove from the handle, the
354 @param UserHandle The handle to remove the protocol handler from
355 @param Protocol The protocol, of protocol:interface, to remove
356 @param Interface The interface, of protocol:interface, to remove
358 @retval EFI_INVALID_PARAMETER Protocol is NULL.
359 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
364 SmmUninstallProtocolInterface (
365 IN EFI_HANDLE UserHandle
,
366 IN EFI_GUID
*Protocol
,
371 Queries a handle to determine if it supports a specified protocol.
373 @param UserHandle The handle being queried.
374 @param Protocol The published unique identifier of the protocol.
375 @param Interface Supplies the address where a pointer to the
376 corresponding Protocol Interface is returned.
378 @return The requested protocol interface for the handle
384 IN EFI_HANDLE UserHandle
,
385 IN EFI_GUID
*Protocol
,
390 Add a new protocol notification record for the request protocol.
392 @param Protocol The requested protocol to add the notify
394 @param Function Points to the notification function
395 @param Registration Returns the registration record
397 @retval EFI_INVALID_PARAMETER Invalid parameter
398 @retval EFI_SUCCESS Successfully returned the registration record
404 SmmRegisterProtocolNotify (
405 IN CONST EFI_GUID
*Protocol
,
406 IN EFI_SMM_NOTIFY_FN Function
,
407 OUT VOID
**Registration
411 Locates the requested handle(s) and returns them in Buffer.
413 @param SearchType The type of search to perform to locate the
415 @param Protocol The protocol to search for
416 @param SearchKey Dependant on SearchType
417 @param BufferSize On input the size of Buffer. On output the
418 size of data returned.
419 @param Buffer The buffer to return the results in
421 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
422 returned in BufferSize.
423 @retval EFI_INVALID_PARAMETER Invalid parameter
424 @retval EFI_SUCCESS Successfully found the requested handle(s) and
425 returns them in Buffer.
431 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
432 IN EFI_GUID
*Protocol OPTIONAL
,
433 IN VOID
*SearchKey OPTIONAL
,
434 IN OUT UINTN
*BufferSize
,
435 OUT EFI_HANDLE
*Buffer
439 Return the first Protocol Interface that matches the Protocol GUID. If
440 Registration is pasased in return a Protocol Instance that was just add
441 to the system. If Retistration is NULL return the first Protocol Interface
444 @param Protocol The protocol to search for
445 @param Registration Optional Registration Key returned from
446 RegisterProtocolNotify()
447 @param Interface Return the Protocol interface (instance).
449 @retval EFI_SUCCESS If a valid Interface is returned
450 @retval EFI_INVALID_PARAMETER Invalid parameter
451 @retval EFI_NOT_FOUND Protocol interface not found
457 IN EFI_GUID
*Protocol
,
458 IN VOID
*Registration OPTIONAL
,
463 Manage SMI of a particular type.
465 @param HandlerType Points to the handler type or NULL for root SMI handlers.
466 @param Context Points to an optional context buffer.
467 @param CommBuffer Points to the optional communication buffer.
468 @param CommBufferSize Points to the size of the optional communication buffer.
470 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
471 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
472 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
473 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
479 IN CONST EFI_GUID
*HandlerType
,
480 IN CONST VOID
*Context OPTIONAL
,
481 IN OUT VOID
*CommBuffer OPTIONAL
,
482 IN OUT UINTN
*CommBufferSize OPTIONAL
486 Registers a handler to execute within SMM.
488 @param Handler Handler service funtion pointer.
489 @param HandlerType Points to the handler type or NULL for root SMI handlers.
490 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
492 @retval EFI_SUCCESS Handler register success.
493 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
499 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
500 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
501 OUT EFI_HANDLE
*DispatchHandle
505 Unregister a handler in SMM.
507 @param DispatchHandle The handle that was specified when the handler was registered.
509 @retval EFI_SUCCESS Handler function was successfully unregistered.
510 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
515 SmiHandlerUnRegister (
516 IN EFI_HANDLE DispatchHandle
520 This function is the main entry point for an SMM handler dispatch
521 or communicate-based callback.
523 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
524 @param Context Points to an optional handler context which was specified when the handler was registered.
525 @param CommBuffer A pointer to a collection of data in memory that will
526 be conveyed from a non-SMM environment into an SMM environment.
527 @param CommBufferSize The size of the CommBuffer.
534 SmmDriverDispatchHandler (
535 IN EFI_HANDLE DispatchHandle
,
536 IN CONST VOID
*Context
, OPTIONAL
537 IN OUT VOID
*CommBuffer
, OPTIONAL
538 IN OUT UINTN
*CommBufferSize OPTIONAL
542 This function is the main entry point for an SMM handler dispatch
543 or communicate-based callback.
545 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
546 @param Context Points to an optional handler context which was specified when the handler was registered.
547 @param CommBuffer A pointer to a collection of data in memory that will
548 be conveyed from a non-SMM environment into an SMM environment.
549 @param CommBufferSize The size of the CommBuffer.
556 SmmLegacyBootHandler (
557 IN EFI_HANDLE DispatchHandle
,
558 IN CONST VOID
*Context
, OPTIONAL
559 IN OUT VOID
*CommBuffer
, OPTIONAL
560 IN OUT UINTN
*CommBufferSize OPTIONAL
564 This function is the main entry point for an SMM handler dispatch
565 or communicate-based callback.
567 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
568 @param Context Points to an optional handler context which was specified when the handler was registered.
569 @param CommBuffer A pointer to a collection of data in memory that will
570 be conveyed from a non-SMM environment into an SMM environment.
571 @param CommBufferSize The size of the CommBuffer.
578 SmmReadyToLockHandler (
579 IN EFI_HANDLE DispatchHandle
,
580 IN CONST VOID
*Context
, OPTIONAL
581 IN OUT VOID
*CommBuffer
, OPTIONAL
582 IN OUT UINTN
*CommBufferSize OPTIONAL
586 Place holder function until all the SMM System Table Service are available.
588 @param Arg1 Undefined
589 @param Arg2 Undefined
590 @param Arg3 Undefined
591 @param Arg4 Undefined
592 @param Arg5 Undefined
594 @return EFI_NOT_AVAILABLE_YET
599 SmmEfiNotAvailableYetArg5 (
608 //Functions used during debug buils
612 Traverse the discovered list for any drivers that were discovered but not loaded
613 because the dependency experessions evaluated to false.
617 SmmDisplayDiscoveredNotDispatched (
622 Add free SMRAM region for use by memory service.
624 @param MemBase Base address of memory region.
625 @param MemLength Length of the memory region.
626 @param Type Memory type.
627 @param Attributes Memory region state.
632 IN EFI_PHYSICAL_ADDRESS MemBase
,
634 IN EFI_MEMORY_TYPE Type
,
639 Finds the protocol entry for the requested protocol.
641 @param Protocol The ID of the protocol
642 @param Create Create a new entry if not found
644 @return Protocol entry
648 SmmFindProtocolEntry (
649 IN EFI_GUID
*Protocol
,
654 Signal event for every protocol in protocol entry.
656 @param Prot Protocol interface
661 IN PROTOCOL_INTERFACE
*Prot
665 Finds the protocol instance for the requested handle and protocol.
666 Note: This function doesn't do parameters checking, it's caller's responsibility
667 to pass in valid parameters.
669 @param Handle The handle to search the protocol on
670 @param Protocol GUID of the protocol
671 @param Interface The interface for the protocol being searched
673 @return Protocol instance (NULL: Not found)
677 SmmFindProtocolInterface (
679 IN EFI_GUID
*Protocol
,
684 Removes Protocol from the protocol list (but not the handle list).
686 @param Handle The handle to remove protocol on.
687 @param Protocol GUID of the protocol to be moved
688 @param Interface The interface of the protocol
690 @return Protocol Entry
694 SmmRemoveInterfaceFromProtocol (
696 IN EFI_GUID
*Protocol
,
701 This is the POSTFIX version of the dependency evaluator. This code does
702 not need to handle Before or After, as it is not valid to call this
703 routine in this case. The SOR is just ignored and is a nop in the grammer.
704 POSTFIX means all the math is done on top of the stack.
706 @param DriverEntry DriverEntry element to update.
708 @retval TRUE If driver is ready to run.
709 @retval FALSE If driver is not ready to run or some fatal error
715 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry