Home | History | Annotate | Download | only in SmmScriptLib
      1 /** @file
      2   Header file to define EFI SMM Base2 Protocol in the PI 1.2 specification.
      3 
      4   The thunk implementation for SmmScriptLib will ultilize the SmmSaveState Protocol to save SMM
      5   runtime s3 boot Script. This header file is to definied PI SMM related definition to locate
      6   SmmSaveState Protocol
      7 
      8   Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
      9 
     10   This program and the accompanying materials
     11   are licensed and made available under the terms and conditions
     12   of the BSD License which accompanies this distribution.  The
     13   full text of the license may be found at
     14   http://opensource.org/licenses/bsd-license.php
     15 
     16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     17   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     18 
     19 **/
     20 
     21 #ifndef _PI_SMM_DEFINITION_H_
     22 #define _PI_SMM_DEFINITION_H_
     23 
     24 typedef struct _EFI_SMM_CPU_IO2_PROTOCOL  EFI_SMM_CPU_IO2_PROTOCOL;
     25 
     26 ///
     27 /// Width of the SMM CPU I/O operations
     28 ///
     29 typedef enum {
     30   SMM_IO_UINT8  = 0,
     31   SMM_IO_UINT16 = 1,
     32   SMM_IO_UINT32 = 2,
     33   SMM_IO_UINT64 = 3
     34 } EFI_SMM_IO_WIDTH;
     35 
     36 /**
     37   Provides the basic memory and I/O interfaces used toabstract accesses to devices.
     38 
     39   The I/O operations are carried out exactly as requested.  The caller is responsible for any alignment
     40   and I/O width issues that the bus, device, platform, or type of I/O might require.
     41 
     42   @param[in]      This           The EFI_SMM_CPU_IO2_PROTOCOL instance.
     43   @param[in]      Width          Signifies the width of the I/O operations.
     44   @param[in]      Address        The base address of the I/O operations.
     45                                  The caller is responsible for aligning the Address if required.
     46   @param[in]      Count          The number of I/O operations to perform.
     47   @param[in,out]  Buffer         For read operations, the destination buffer to store the results.
     48                                  For write operations, the source buffer from which to write data.
     49 
     50   @retval EFI_SUCCESS            The data was read from or written to the device.
     51   @retval EFI_UNSUPPORTED        The Address is not valid for this system.
     52   @retval EFI_INVALID_PARAMETER  Width or Count, or both, were invalid.
     53   @retval EFI_OUT_OF_RESOURCES   The request could not be completed due to a lack of resources.
     54 **/
     55 typedef
     56 EFI_STATUS
     57 (EFIAPI *EFI_SMM_CPU_IO2)(
     58   IN CONST EFI_SMM_CPU_IO2_PROTOCOL  *This,
     59   IN EFI_SMM_IO_WIDTH               Width,
     60   IN UINT64                         Address,
     61   IN UINTN                          Count,
     62   IN OUT VOID                       *Buffer
     63   );
     64 
     65 typedef struct {
     66   ///
     67   /// This service provides the various modalities of memory and I/O read.
     68   ///
     69   EFI_SMM_CPU_IO2  Read;
     70   ///
     71   /// This service provides the various modalities of memory and I/O write.
     72   ///
     73   EFI_SMM_CPU_IO2  Write;
     74 } EFI_SMM_IO_ACCESS2;
     75 
     76 ///
     77 /// SMM CPU I/O 2 Protocol provides CPU I/O and memory access within SMM.
     78 ///
     79 struct _EFI_SMM_CPU_IO2_PROTOCOL {
     80   EFI_SMM_IO_ACCESS2 Mem;  ///< Allows reads and writes to memory-mapped I/O space.
     81   EFI_SMM_IO_ACCESS2 Io;   ///< Allows reads and writes to I/O space.
     82 };
     83 typedef struct _EFI_SMM_SYSTEM_TABLE2  EFI_SMM_SYSTEM_TABLE2;
     84 /**
     85   Adds, updates, or removes a configuration table entry from the System Management System Table.
     86 
     87   The SmmInstallConfigurationTable() function is used to maintain the list
     88   of configuration tables that are stored in the System Management System
     89   Table.  The list is stored as an array of (GUID, Pointer) pairs.  The list
     90   must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
     91 
     92   @param[in] SystemTable         A pointer to the SMM System Table (SMST).
     93   @param[in] Guid                A pointer to the GUID for the entry to add, update, or remove.
     94   @param[in] Table               A pointer to the buffer of the table to add.
     95   @param[in] TableSize           The size of the table to install.
     96 
     97   @retval EFI_SUCCESS            The (Guid, Table) pair was added, updated, or removed.
     98   @retval EFI_INVALID_PARAMETER  Guid is not valid.
     99   @retval EFI_NOT_FOUND          An attempt was made to delete a non-existent entry.
    100   @retval EFI_OUT_OF_RESOURCES   There is not enough memory available to complete the operation.
    101 **/
    102 typedef
    103 EFI_STATUS
    104 (EFIAPI *EFI_SMM_INSTALL_CONFIGURATION_TABLE2)(
    105   IN CONST EFI_SMM_SYSTEM_TABLE2  *SystemTable,
    106   IN CONST EFI_GUID               *Guid,
    107   IN VOID                         *Table,
    108   IN UINTN                        TableSize
    109   );
    110 /**
    111   Function prototype for invoking a function on an Application Processor.
    112 
    113   This definition is used by the UEFI MP Serices Protocol, and the
    114   PI SMM System Table.
    115 
    116   @param[in,out] Buffer  Pointer to private data buffer.
    117 **/
    118 typedef
    119 VOID
    120 (EFIAPI *EFI_AP_PROCEDURE)(
    121   IN OUT VOID  *Buffer
    122   );
    123 /**
    124   The SmmStartupThisAp() lets the caller to get one distinct application processor
    125   (AP) in the enabled processor pool to execute a caller-provided code stream
    126   while in SMM. It runs the given code on this processor and reports the status.
    127   It must be noted that the supplied code stream will be run only on an enabled
    128   processor which has also entered SMM.
    129 
    130   @param[in]     Procedure       A pointer to the code stream to be run on the designated AP of the system.
    131   @param[in]     CpuNumber       The zero-based index of the processor number of the AP on which the code stream is supposed to run.
    132   @param[in,out] ProcArguments   Allow the caller to pass a list of parameters to the code that is run by the AP.
    133 
    134   @retval EFI_SUCCESS            The call was successful and the return parameters are valid.
    135   @retval EFI_INVALID_PARAMETER  The input arguments are out of range.
    136   @retval EFI_INVALID_PARAMETER  The CPU requested is not available on this SMI invocation.
    137   @retval EFI_INVALID_PARAMETER  The CPU cannot support an additional service invocation.
    138 **/
    139 typedef
    140 EFI_STATUS
    141 (EFIAPI *EFI_SMM_STARTUP_THIS_AP)(
    142   IN EFI_AP_PROCEDURE  Procedure,
    143   IN UINTN             CpuNumber,
    144   IN OUT VOID          *ProcArguments OPTIONAL
    145   );
    146 
    147 /**
    148   Function prototype for protocol install notification.
    149 
    150   @param[in] Protocol   Points to the protocol's unique identifier.
    151   @param[in] Interface  Points to the interface instance.
    152   @param[in] Handle     The handle on which the interface was installed.
    153 
    154   @return Status Code
    155 **/
    156 typedef
    157 EFI_STATUS
    158 (EFIAPI *EFI_SMM_NOTIFY_FN)(
    159   IN CONST EFI_GUID  *Protocol,
    160   IN VOID            *Interface,
    161   IN EFI_HANDLE      Handle
    162   );
    163 
    164 /**
    165   Register a callback function be called when a particular protocol interface is installed.
    166 
    167   The SmmRegisterProtocolNotify() function creates a registration Function that is to be
    168   called whenever a protocol interface is installed for Protocol by
    169   SmmInstallProtocolInterface().
    170 
    171   @param[in]  Protocol          The unique ID of the protocol for which the event is to be registered.
    172   @param[in]  Function          Points to the notification function.
    173   @param[out] Registration      A pointer to a memory location to receive the registration value.
    174 
    175   @retval EFI_SUCCESS           Successfully returned the registration record that has been added.
    176   @retval EFI_INVALID_PARAMETER One or more of Protocol, Function and Registration is NULL.
    177   @retval EFI_OUT_OF_RESOURCES  Not enough memory resource to finish the request.
    178 **/
    179 typedef
    180 EFI_STATUS
    181 (EFIAPI *EFI_SMM_REGISTER_PROTOCOL_NOTIFY)(
    182   IN  CONST EFI_GUID     *Protocol,
    183   IN  EFI_SMM_NOTIFY_FN  Function,
    184   OUT VOID               **Registration
    185   );
    186 
    187 /**
    188   Manage SMI of a particular type.
    189 
    190   @param[in]     HandlerType     Points to the handler type or NULL for root SMI handlers.
    191   @param[in]     Context         Points to an optional context buffer.
    192   @param[in,out] CommBuffer      Points to the optional communication buffer.
    193   @param[in,out] CommBufferSize  Points to the size of the optional communication buffer.
    194 
    195   @retval EFI_WARN_INTERRUPT_SOURCE_PENDING  Interrupt source was processed successfully but not quiesced.
    196   @retval EFI_INTERRUPT_PENDING              One or more SMI sources could not be quiesced.
    197   @retval EFI_NOT_FOUND                      Interrupt source was not handled or quiesced.
    198   @retval EFI_SUCCESS                        Interrupt source was handled and quiesced.
    199 **/
    200 typedef
    201 EFI_STATUS
    202 (EFIAPI *EFI_SMM_INTERRUPT_MANAGE)(
    203   IN CONST EFI_GUID  *HandlerType,
    204   IN CONST VOID      *Context         OPTIONAL,
    205   IN OUT VOID        *CommBuffer      OPTIONAL,
    206   IN OUT UINTN       *CommBufferSize  OPTIONAL
    207   );
    208 
    209 /**
    210   Main entry point for an SMM handler dispatch or communicate-based callback.
    211 
    212   @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().
    213   @param[in]     Context         Points to an optional handler context which was specified when the
    214                                  handler was registered.
    215   @param[in,out] CommBuffer      A pointer to a collection of data in memory that will
    216                                  be conveyed from a non-SMM environment into an SMM environment.
    217   @param[in,out] CommBufferSize  The size of the CommBuffer.
    218 
    219   @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers
    220                                               should still be called.
    221   @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should
    222                                               still be called.
    223   @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still
    224                                               be called.
    225   @retval EFI_INTERRUPT_PENDING               The interrupt could not be quiesced.
    226 **/
    227 typedef
    228 EFI_STATUS
    229 (EFIAPI *EFI_SMM_HANDLER_ENTRY_POINT2)(
    230   IN EFI_HANDLE  DispatchHandle,
    231   IN CONST VOID  *Context         OPTIONAL,
    232   IN OUT VOID    *CommBuffer      OPTIONAL,
    233   IN OUT UINTN   *CommBufferSize  OPTIONAL
    234   );
    235 
    236 /**
    237   Registers a handler to execute within SMM.
    238 
    239   @param[in]  Handler            Handler service funtion pointer.
    240   @param[in]  HandlerType        Points to the handler type or NULL for root SMI handlers.
    241   @param[out] DispatchHandle     On return, contains a unique handle which can be used to later
    242                                  unregister the handler function.
    243 
    244   @retval EFI_SUCCESS            SMI handler added successfully.
    245   @retval EFI_INVALID_PARAMETER  Handler is NULL or DispatchHandle is NULL.
    246 **/
    247 typedef
    248 EFI_STATUS
    249 (EFIAPI *EFI_SMM_INTERRUPT_REGISTER)(
    250   IN  EFI_SMM_HANDLER_ENTRY_POINT2  Handler,
    251   IN  CONST EFI_GUID                *HandlerType OPTIONAL,
    252   OUT EFI_HANDLE                    *DispatchHandle
    253   );
    254 
    255 /**
    256   Unregister a handler in SMM.
    257 
    258   @param[in] DispatchHandle      The handle that was specified when the handler was registered.
    259 
    260   @retval EFI_SUCCESS            Handler function was successfully unregistered.
    261   @retval EFI_INVALID_PARAMETER  DispatchHandle does not refer to a valid handle.
    262 **/
    263 typedef
    264 EFI_STATUS
    265 (EFIAPI *EFI_SMM_INTERRUPT_UNREGISTER)(
    266   IN EFI_HANDLE  DispatchHandle
    267   );
    268 
    269 ///
    270 /// Processor information and functionality needed by SMM Foundation.
    271 ///
    272 typedef struct _EFI_SMM_ENTRY_CONTEXT {
    273   EFI_SMM_STARTUP_THIS_AP  SmmStartupThisAp;
    274   ///
    275   /// A number between zero and the NumberOfCpus field. This field designates which
    276   /// processor is executing the SMM Foundation.
    277   ///
    278   UINTN                    CurrentlyExecutingCpu;
    279   ///
    280   /// The number of current operational processors in the platform.  This is a 1 based
    281   /// counter.  This does not indicate the number of processors that entered SMM.
    282   ///
    283   UINTN                    NumberOfCpus;
    284   ///
    285   /// Points to an array, where each element describes the number of bytes in the
    286   /// corresponding save state specified by CpuSaveState. There are always
    287   /// NumberOfCpus entries in the array.
    288   ///
    289   UINTN                    *CpuSaveStateSize;
    290   ///
    291   /// Points to an array, where each element is a pointer to a CPU save state. The
    292   /// corresponding element in CpuSaveStateSize specifies the number of bytes in the
    293   /// save state area. There are always NumberOfCpus entries in the array.
    294   ///
    295   VOID                     **CpuSaveState;
    296 } EFI_SMM_ENTRY_CONTEXT;
    297 
    298 /**
    299   This function is the main entry point to the SMM Foundation.
    300 
    301   @param[in] SmmEntryContext  Processor information and functionality needed by SMM Foundation.
    302 **/
    303 typedef
    304 VOID
    305 (EFIAPI *EFI_SMM_ENTRY_POINT)(
    306   IN CONST EFI_SMM_ENTRY_CONTEXT  *SmmEntryContext
    307   );
    308 
    309 ///
    310 /// System Management System Table (SMST)
    311 ///
    312 /// The System Management System Table (SMST) is a table that contains a collection of common
    313 /// services for managing SMRAM allocation and providing basic I/O services. These services are
    314 /// intended for both preboot and runtime usage.
    315 ///
    316 struct _EFI_SMM_SYSTEM_TABLE2 {
    317   ///
    318   /// The table header for the SMST.
    319   ///
    320   EFI_TABLE_HEADER                     Hdr;
    321   ///
    322   /// A pointer to a NULL-terminated Unicode string containing the vendor name.
    323   /// It is permissible for this pointer to be NULL.
    324   ///
    325   CHAR16                               *SmmFirmwareVendor;
    326   ///
    327   /// The particular revision of the firmware.
    328   ///
    329   UINT32                               SmmFirmwareRevision;
    330 
    331   EFI_SMM_INSTALL_CONFIGURATION_TABLE2 SmmInstallConfigurationTable;
    332 
    333   ///
    334   /// I/O Service
    335   ///
    336   EFI_SMM_CPU_IO2_PROTOCOL             SmmIo;
    337 
    338   ///
    339   /// Runtime memory services
    340   ///
    341   EFI_ALLOCATE_POOL                    SmmAllocatePool;
    342   EFI_FREE_POOL                        SmmFreePool;
    343   EFI_ALLOCATE_PAGES                   SmmAllocatePages;
    344   EFI_FREE_PAGES                       SmmFreePages;
    345 
    346   ///
    347   /// MP service
    348   ///
    349   EFI_SMM_STARTUP_THIS_AP              SmmStartupThisAp;
    350 
    351   ///
    352   /// CPU information records
    353   ///
    354 
    355   ///
    356   /// A number between zero and and the NumberOfCpus field. This field designates
    357   /// which processor is executing the SMM infrastructure.
    358   ///
    359   UINTN                                CurrentlyExecutingCpu;
    360   ///
    361   /// The number of current operational processors in the platform.  This is a 1 based counter.
    362   ///
    363   UINTN                                NumberOfCpus;
    364   ///
    365   /// Points to an array, where each element describes the number of bytes in the
    366   /// corresponding save state specified by CpuSaveState. There are always
    367   /// NumberOfCpus entries in the array.
    368   ///
    369   UINTN                                *CpuSaveStateSize;
    370   ///
    371   /// Points to an array, where each element is a pointer to a CPU save state. The
    372   /// corresponding element in CpuSaveStateSize specifies the number of bytes in the
    373   /// save state area. There are always NumberOfCpus entries in the array.
    374   ///
    375   VOID                                 **CpuSaveState;
    376 
    377   ///
    378   /// Extensibility table
    379   ///
    380 
    381   ///
    382   /// The number of UEFI Configuration Tables in the buffer SmmConfigurationTable.
    383   ///
    384   UINTN                                NumberOfTableEntries;
    385   ///
    386   /// A pointer to the UEFI Configuration Tables. The number of entries in the table is
    387   /// NumberOfTableEntries.
    388   ///
    389   EFI_CONFIGURATION_TABLE              *SmmConfigurationTable;
    390 
    391   ///
    392   /// Protocol services
    393   ///
    394   EFI_INSTALL_PROTOCOL_INTERFACE       SmmInstallProtocolInterface;
    395   EFI_UNINSTALL_PROTOCOL_INTERFACE     SmmUninstallProtocolInterface;
    396   EFI_HANDLE_PROTOCOL                  SmmHandleProtocol;
    397   EFI_SMM_REGISTER_PROTOCOL_NOTIFY     SmmRegisterProtocolNotify;
    398   EFI_LOCATE_HANDLE                    SmmLocateHandle;
    399   EFI_LOCATE_PROTOCOL                  SmmLocateProtocol;
    400 
    401   ///
    402   /// SMI Management functions
    403   ///
    404   EFI_SMM_INTERRUPT_MANAGE             SmiManage;
    405   EFI_SMM_INTERRUPT_REGISTER           SmiHandlerRegister;
    406   EFI_SMM_INTERRUPT_UNREGISTER         SmiHandlerUnRegister;
    407 };
    408 
    409 #define EFI_SMM_BASE2_PROTOCOL_GUID \
    410   { \
    411     0xf4ccbfb7, 0xf6e0, 0x47fd, {0x9d, 0xd4, 0x10, 0xa8, 0xf1, 0x50, 0xc1, 0x91 }  \
    412   }
    413 
    414 typedef struct _EFI_SMM_BASE2_PROTOCOL  EFI_SMM_BASE2_PROTOCOL;
    415 
    416 /**
    417   Service to indicate whether the driver is currently executing in the SMM Initialization phase.
    418 
    419   This service is used to indicate whether the driver is currently executing in the SMM Initialization
    420   phase. For SMM drivers, this will return TRUE in InSmram while inside the driver's entry point and
    421   otherwise FALSE. For combination SMM/DXE drivers, this will return FALSE in the DXE launch. For the
    422   SMM launch, it behaves as an SMM driver.
    423 
    424   @param[in]  This               The EFI_SMM_BASE2_PROTOCOL instance.
    425   @param[out] InSmram            Pointer to a Boolean which, on return, indicates that the driver is
    426                                  currently executing inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
    427 
    428   @retval EFI_SUCCESS            The call returned successfully.
    429   @retval EFI_INVALID_PARAMETER  InSmram was NULL.
    430 **/
    431 typedef
    432 EFI_STATUS
    433 (EFIAPI *EFI_SMM_INSIDE_OUT2)(
    434   IN CONST EFI_SMM_BASE2_PROTOCOL  *This,
    435   OUT BOOLEAN                      *InSmram
    436   )
    437 ;
    438 
    439 /**
    440   Returns the location of the System Management Service Table (SMST).
    441 
    442   This function returns the location of the System Management Service Table (SMST).  The use of the
    443   API is such that a driver can discover the location of the SMST in its entry point and then cache it in
    444   some driver global variable so that the SMST can be invoked in subsequent handlers.
    445 
    446   @param[in]     This            The EFI_SMM_BASE2_PROTOCOL instance.
    447   @param[in,out] Smst            On return, points to a pointer to the System Management Service Table (SMST).
    448 
    449   @retval EFI_SUCCESS            The operation was successful.
    450   @retval EFI_INVALID_PARAMETER  Smst was invalid.
    451   @retval EFI_UNSUPPORTED        Not in SMM.
    452 **/
    453 typedef
    454 EFI_STATUS
    455 (EFIAPI *EFI_SMM_GET_SMST_LOCATION2)(
    456   IN CONST EFI_SMM_BASE2_PROTOCOL  *This,
    457   IN OUT EFI_SMM_SYSTEM_TABLE2     **Smst
    458   )
    459 ;
    460 
    461 ///
    462 /// EFI SMM Base2 Protocol is utilized by all SMM drivers to locate the SMM infrastructure
    463 /// services and determine whether the driver is being invoked inside SMRAM or outside of SMRAM.
    464 ///
    465 struct _EFI_SMM_BASE2_PROTOCOL {
    466   EFI_SMM_INSIDE_OUT2         InSmm;
    467   EFI_SMM_GET_SMST_LOCATION2  GetSmstLocation;
    468 };
    469 
    470 
    471 #endif
    472 
    473