2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2012, 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>
45 #include <Library/PcdLib.h>
46 #include <Library/SmmCorePlatformHookLib.h>
47 #include <Library/PerformanceLib.h>
48 #include <Library/TimerLib.h>
50 #include "PiSmmCorePrivateData.h"
53 // Used to build a table of SMI Handlers that the SMM Core registers
56 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
57 EFI_GUID
*HandlerType
;
58 EFI_HANDLE DispatchHandle
;
60 } SMM_CORE_SMI_HANDLERS
;
63 // Structure for recording the state of an SMM Driver
65 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
69 LIST_ENTRY Link
; // mDriverList
71 LIST_ENTRY ScheduledLink
; // mScheduledQueue
75 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
76 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
83 EFI_GUID BeforeAfterGuid
;
88 BOOLEAN DepexProtocolError
;
90 EFI_HANDLE ImageHandle
;
91 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
93 // Image EntryPoint in SMRAM
95 PHYSICAL_ADDRESS ImageEntryPoint
;
97 // Image Buffer in SMRAM
99 PHYSICAL_ADDRESS ImageBuffer
;
104 } EFI_SMM_DRIVER_ENTRY
;
106 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
109 /// IHANDLE - contains a list of protocol handles
113 /// All handles list of IHANDLE
114 LIST_ENTRY AllHandles
;
115 /// List of PROTOCOL_INTERFACE's for this handle
116 LIST_ENTRY Protocols
;
120 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
122 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
125 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
126 /// database. Each handler that supports this protocol is listed, along
127 /// with a list of registered notifies.
131 /// Link Entry inserted to mProtocolDatabase
132 LIST_ENTRY AllEntries
;
133 /// ID of the protocol
135 /// All protocol interfaces
136 LIST_ENTRY Protocols
;
137 /// Registerd notification handlers
141 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
144 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
145 /// with a protocol interface structure
149 /// Link on IHANDLE.Protocols
153 /// Link on PROTOCOL_ENTRY.Protocols
154 LIST_ENTRY ByProtocol
;
156 PROTOCOL_ENTRY
*Protocol
;
157 /// The interface value
159 } PROTOCOL_INTERFACE
;
161 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
164 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
168 PROTOCOL_ENTRY
*Protocol
;
169 /// All notifications for this protocol
171 /// Notification function
172 EFI_SMM_NOTIFY_FN Function
;
173 /// Last position notified
174 LIST_ENTRY
*Position
;
178 // SMM Core Global Variables
180 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
181 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
182 extern LIST_ENTRY gHandleList
;
183 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
186 Called to initialize the memory service.
188 @param SmramRangeCount Number of SMRAM Regions
189 @param SmramRanges Pointer to SMRAM Descriptors
193 SmmInitializeMemoryServices (
194 IN UINTN SmramRangeCount
,
195 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
199 The SmmInstallConfigurationTable() function is used to maintain the list
200 of configuration tables that are stored in the System Management System
201 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
202 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
204 @param SystemTable A pointer to the SMM System Table (SMST).
205 @param Guid A pointer to the GUID for the entry to add, update, or remove.
206 @param Table A pointer to the buffer of the table to add.
207 @param TableSize The size of the table to install.
209 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
210 @retval EFI_INVALID_PARAMETER Guid is not valid.
211 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
212 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
217 SmmInstallConfigurationTable (
218 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
219 IN CONST EFI_GUID
*Guid
,
225 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
226 Calls the private one which contains a BOOLEAN parameter for notifications
228 @param UserHandle The handle to install the protocol handler on,
229 or NULL if a new handle is to be allocated
230 @param Protocol The protocol to add to the handle
231 @param InterfaceType Indicates whether Interface is supplied in
233 @param Interface The interface for the protocol being added
240 SmmInstallProtocolInterface (
241 IN OUT EFI_HANDLE
*UserHandle
,
242 IN EFI_GUID
*Protocol
,
243 IN EFI_INTERFACE_TYPE InterfaceType
,
248 Allocates pages from the memory map.
250 @param Type The type of allocation to perform
251 @param MemoryType The type of memory to turn the allocated pages
253 @param NumberOfPages The number of pages to allocate
254 @param Memory A pointer to receive the base allocated memory
257 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
258 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
259 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
260 @retval EFI_SUCCESS Pages successfully allocated.
266 IN EFI_ALLOCATE_TYPE Type
,
267 IN EFI_MEMORY_TYPE MemoryType
,
268 IN UINTN NumberOfPages
,
269 OUT EFI_PHYSICAL_ADDRESS
*Memory
273 Frees previous allocated pages.
275 @param Memory Base address of memory being freed
276 @param NumberOfPages The number of pages to free
278 @retval EFI_NOT_FOUND Could not find the entry that covers the range
279 @retval EFI_INVALID_PARAMETER Address not aligned
280 @return EFI_SUCCESS Pages successfully freed.
286 IN EFI_PHYSICAL_ADDRESS Memory
,
287 IN UINTN NumberOfPages
291 Allocate pool of a particular type.
293 @param PoolType Type of pool to allocate
294 @param Size The amount of pool to allocate
295 @param Buffer The address to return a pointer to the allocated
298 @retval EFI_INVALID_PARAMETER PoolType not valid
299 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
300 @retval EFI_SUCCESS Pool successfully allocated.
306 IN EFI_MEMORY_TYPE PoolType
,
314 @param Buffer The allocated pool entry to free
316 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
317 @retval EFI_SUCCESS Pool successfully freed.
327 Installs a protocol interface into the boot services environment.
329 @param UserHandle The handle to install the protocol handler on,
330 or NULL if a new handle is to be allocated
331 @param Protocol The protocol to add to the handle
332 @param InterfaceType Indicates whether Interface is supplied in
334 @param Interface The interface for the protocol being added
335 @param Notify indicates whether notify the notification list
338 @retval EFI_INVALID_PARAMETER Invalid parameter
339 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
340 @retval EFI_SUCCESS Protocol interface successfully installed
344 SmmInstallProtocolInterfaceNotify (
345 IN OUT EFI_HANDLE
*UserHandle
,
346 IN EFI_GUID
*Protocol
,
347 IN EFI_INTERFACE_TYPE InterfaceType
,
353 Uninstalls all instances of a protocol:interfacer from a handle.
354 If the last protocol interface is remove from the handle, the
357 @param UserHandle The handle to remove the protocol handler from
358 @param Protocol The protocol, of protocol:interface, to remove
359 @param Interface The interface, of protocol:interface, to remove
361 @retval EFI_INVALID_PARAMETER Protocol is NULL.
362 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
367 SmmUninstallProtocolInterface (
368 IN EFI_HANDLE UserHandle
,
369 IN EFI_GUID
*Protocol
,
374 Queries a handle to determine if it supports a specified protocol.
376 @param UserHandle The handle being queried.
377 @param Protocol The published unique identifier of the protocol.
378 @param Interface Supplies the address where a pointer to the
379 corresponding Protocol Interface is returned.
381 @return The requested protocol interface for the handle
387 IN EFI_HANDLE UserHandle
,
388 IN EFI_GUID
*Protocol
,
393 Add a new protocol notification record for the request protocol.
395 @param Protocol The requested protocol to add the notify
397 @param Function Points to the notification function
398 @param Registration Returns the registration record
400 @retval EFI_INVALID_PARAMETER Invalid parameter
401 @retval EFI_SUCCESS Successfully returned the registration record
407 SmmRegisterProtocolNotify (
408 IN CONST EFI_GUID
*Protocol
,
409 IN EFI_SMM_NOTIFY_FN Function
,
410 OUT VOID
**Registration
414 Locates the requested handle(s) and returns them in Buffer.
416 @param SearchType The type of search to perform to locate the
418 @param Protocol The protocol to search for
419 @param SearchKey Dependant on SearchType
420 @param BufferSize On input the size of Buffer. On output the
421 size of data returned.
422 @param Buffer The buffer to return the results in
424 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
425 returned in BufferSize.
426 @retval EFI_INVALID_PARAMETER Invalid parameter
427 @retval EFI_SUCCESS Successfully found the requested handle(s) and
428 returns them in Buffer.
434 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
435 IN EFI_GUID
*Protocol OPTIONAL
,
436 IN VOID
*SearchKey OPTIONAL
,
437 IN OUT UINTN
*BufferSize
,
438 OUT EFI_HANDLE
*Buffer
442 Return the first Protocol Interface that matches the Protocol GUID. If
443 Registration is pasased in return a Protocol Instance that was just add
444 to the system. If Retistration is NULL return the first Protocol Interface
447 @param Protocol The protocol to search for
448 @param Registration Optional Registration Key returned from
449 RegisterProtocolNotify()
450 @param Interface Return the Protocol interface (instance).
452 @retval EFI_SUCCESS If a valid Interface is returned
453 @retval EFI_INVALID_PARAMETER Invalid parameter
454 @retval EFI_NOT_FOUND Protocol interface not found
460 IN EFI_GUID
*Protocol
,
461 IN VOID
*Registration OPTIONAL
,
466 Manage SMI of a particular type.
468 @param HandlerType Points to the handler type or NULL for root SMI handlers.
469 @param Context Points to an optional context buffer.
470 @param CommBuffer Points to the optional communication buffer.
471 @param CommBufferSize Points to the size of the optional communication buffer.
473 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
474 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
475 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
476 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
482 IN CONST EFI_GUID
*HandlerType
,
483 IN CONST VOID
*Context OPTIONAL
,
484 IN OUT VOID
*CommBuffer OPTIONAL
,
485 IN OUT UINTN
*CommBufferSize OPTIONAL
489 Registers a handler to execute within SMM.
491 @param Handler Handler service funtion pointer.
492 @param HandlerType Points to the handler type or NULL for root SMI handlers.
493 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
495 @retval EFI_SUCCESS Handler register success.
496 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
502 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
503 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
504 OUT EFI_HANDLE
*DispatchHandle
508 Unregister a handler in SMM.
510 @param DispatchHandle The handle that was specified when the handler was registered.
512 @retval EFI_SUCCESS Handler function was successfully unregistered.
513 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
518 SmiHandlerUnRegister (
519 IN EFI_HANDLE DispatchHandle
523 This function is the main entry point for an SMM handler dispatch
524 or communicate-based callback.
526 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
527 @param Context Points to an optional handler context which was specified when the handler was registered.
528 @param CommBuffer A pointer to a collection of data in memory that will
529 be conveyed from a non-SMM environment into an SMM environment.
530 @param CommBufferSize The size of the CommBuffer.
537 SmmDriverDispatchHandler (
538 IN EFI_HANDLE DispatchHandle
,
539 IN CONST VOID
*Context
, OPTIONAL
540 IN OUT VOID
*CommBuffer
, OPTIONAL
541 IN OUT UINTN
*CommBufferSize OPTIONAL
545 This function is the main entry point for an SMM handler dispatch
546 or communicate-based callback.
548 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
549 @param Context Points to an optional handler context which was specified when the handler was registered.
550 @param CommBuffer A pointer to a collection of data in memory that will
551 be conveyed from a non-SMM environment into an SMM environment.
552 @param CommBufferSize The size of the CommBuffer.
559 SmmLegacyBootHandler (
560 IN EFI_HANDLE DispatchHandle
,
561 IN CONST VOID
*Context
, OPTIONAL
562 IN OUT VOID
*CommBuffer
, OPTIONAL
563 IN OUT UINTN
*CommBufferSize OPTIONAL
567 This function is the main entry point for an SMM handler dispatch
568 or communicate-based callback.
570 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
571 @param Context Points to an optional handler context which was specified when the handler was registered.
572 @param CommBuffer A pointer to a collection of data in memory that will
573 be conveyed from a non-SMM environment into an SMM environment.
574 @param CommBufferSize The size of the CommBuffer.
581 SmmReadyToLockHandler (
582 IN EFI_HANDLE DispatchHandle
,
583 IN CONST VOID
*Context
, OPTIONAL
584 IN OUT VOID
*CommBuffer
, OPTIONAL
585 IN OUT UINTN
*CommBufferSize OPTIONAL
589 Place holder function until all the SMM System Table Service are available.
591 @param Arg1 Undefined
592 @param Arg2 Undefined
593 @param Arg3 Undefined
594 @param Arg4 Undefined
595 @param Arg5 Undefined
597 @return EFI_NOT_AVAILABLE_YET
602 SmmEfiNotAvailableYetArg5 (
611 //Functions used during debug buils
615 Traverse the discovered list for any drivers that were discovered but not loaded
616 because the dependency experessions evaluated to false.
620 SmmDisplayDiscoveredNotDispatched (
625 Add free SMRAM region for use by memory service.
627 @param MemBase Base address of memory region.
628 @param MemLength Length of the memory region.
629 @param Type Memory type.
630 @param Attributes Memory region state.
635 IN EFI_PHYSICAL_ADDRESS MemBase
,
637 IN EFI_MEMORY_TYPE Type
,
642 Finds the protocol entry for the requested protocol.
644 @param Protocol The ID of the protocol
645 @param Create Create a new entry if not found
647 @return Protocol entry
651 SmmFindProtocolEntry (
652 IN EFI_GUID
*Protocol
,
657 Signal event for every protocol in protocol entry.
659 @param Prot Protocol interface
664 IN PROTOCOL_INTERFACE
*Prot
668 Finds the protocol instance for the requested handle and protocol.
669 Note: This function doesn't do parameters checking, it's caller's responsibility
670 to pass in valid parameters.
672 @param Handle The handle to search the protocol on
673 @param Protocol GUID of the protocol
674 @param Interface The interface for the protocol being searched
676 @return Protocol instance (NULL: Not found)
680 SmmFindProtocolInterface (
682 IN EFI_GUID
*Protocol
,
687 Removes Protocol from the protocol list (but not the handle list).
689 @param Handle The handle to remove protocol on.
690 @param Protocol GUID of the protocol to be moved
691 @param Interface The interface of the protocol
693 @return Protocol Entry
697 SmmRemoveInterfaceFromProtocol (
699 IN EFI_GUID
*Protocol
,
704 This is the POSTFIX version of the dependency evaluator. This code does
705 not need to handle Before or After, as it is not valid to call this
706 routine in this case. POSTFIX means all the math is done on top of the stack.
708 @param DriverEntry DriverEntry element to update.
710 @retval TRUE If driver is ready to run.
711 @retval FALSE If driver is not ready to run or some fatal error
717 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry