SmmBase.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /** @file
  2. This file declares SMM Base abstraction protocol.
  3. This protocol is used to install SMM handlers for support of subsequent SMI/PMI activations. This
  4. protocol is available on both IA-32 and Itanium-based systems.
  5. The EFI_SMM_BASE_PROTOCOL is a set of services that is exported by a processor device. It is
  6. a required protocol for the platform processor. This protocol can be used in both boot services and
  7. runtime mode. However, only the following member functions need to exist during runtime:
  8. - InSmm()
  9. - Communicate()
  10. This protocol is responsible for registering the handler services. The order in which the handlers are
  11. executed is prescribed only with respect to the MakeLast flag in the RegisterCallback()
  12. service. The driver exports these registration and unregistration services in boot services mode, but
  13. the registered handlers will execute through the preboot and runtime. The only way to change the
  14. behavior of a registered driver after ExitBootServices() has been invoked is to use some
  15. private communication mechanism with the driver to order it to quiesce. This model permits typical
  16. use cases, such as invoking the handler to enter ACPI mode, where the OS loader would make this
  17. call before boot services are terminated. On the other hand, handlers for services such as chipset
  18. workarounds for the century rollover in CMOS should provide commensurate services throughout
  19. preboot and OS runtime.
  20. Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
  21. SPDX-License-Identifier: BSD-2-Clause-Patent
  22. @par Revision Reference:
  23. This Protocol is defined in Framework of EFI SMM Core Interface Spec
  24. Version 0.9.
  25. **/
  26. #ifndef _SMM_BASE_H_
  27. #define _SMM_BASE_H_
  28. //
  29. // Share some common definitions with PI SMM
  30. //
  31. #include <Framework/SmmCis.h>
  32. #include <Protocol/SmmCommunication.h>
  33. ///
  34. /// Global ID for the EFI_SMM_BASE_PROTOCOL.
  35. ///
  36. #define EFI_SMM_BASE_PROTOCOL_GUID \
  37. { \
  38. 0x1390954D, 0xda95, 0x4227, {0x93, 0x28, 0x72, 0x82, 0xc2, 0x17, 0xda, 0xa8 } \
  39. }
  40. ///
  41. /// Forward declaration for EFI_SMM_BASE_PROTOCOL.
  42. ///
  43. typedef struct _EFI_SMM_BASE_PROTOCOL EFI_SMM_BASE_PROTOCOL;
  44. ///
  45. /// EFI SMM Handler return codes
  46. ///
  47. ///@{
  48. #define EFI_HANDLER_SUCCESS 0x0000
  49. #define EFI_HANDLER_CRITICAL_EXIT 0x0001
  50. #define EFI_HANDLER_SOURCE_QUIESCED 0x0002
  51. #define EFI_HANDLER_SOURCE_PENDING 0x0003
  52. ///@}
  53. /**
  54. Entry Point to Callback service
  55. @param[in] SmmImageHandle A handle allocated by the SMM infrastructure code
  56. to uniquely designate a specific DXE SMM driver.
  57. @param[in] CommunicationBuffer A pointer to a collection of data in memory
  58. that will be conveyed from a non-SMM environment
  59. into an SMM environment. The buffer must be
  60. contiguous and physically mapped, and must be
  61. a physical address.
  62. @param[in] SourceSize The size of the CommunicationBuffer.
  63. @return Status code
  64. **/
  65. typedef
  66. EFI_STATUS
  67. (EFIAPI *EFI_SMM_CALLBACK_ENTRY_POINT)(
  68. IN EFI_HANDLE SmmImageHandle,
  69. IN OUT VOID *CommunicationBuffer OPTIONAL,
  70. IN OUT UINTN *SourceSize OPTIONAL
  71. );
  72. //
  73. // SMM Base Protocol Definition
  74. //
  75. /**
  76. Register a given driver into SMRAM. This is the equivalent of performing
  77. the LoadImage/StartImage into System Management Mode.
  78. @param[in] This The protocol instance pointer.
  79. @param[in] FilePath The location of the image to be installed as the handler.
  80. @param[in] SourceBuffer An optional source buffer in case the image file
  81. is in memory.
  82. @param[in] SourceSize The size of the source image file, if in memory.
  83. @param[out] ImageHandle The handle that the base driver uses to decode
  84. the handler. Unique among SMM handlers only;
  85. not unique across DXE/EFI.
  86. @param[in] LegacyIA32Binary An optional parameter specifying that the associated
  87. file is a real-mode IA-32 binary.
  88. @retval EFI_SUCCESS The operation was successful.
  89. @retval EFI_OUT_OF_RESOURCES There were no additional SMRAM resources to load the handler
  90. @retval EFI_UNSUPPORTED This platform does not support 16-bit handlers.
  91. @retval EFI_UNSUPPORTED The platform is in runtime.
  92. @retval EFI_INVALID_PARAMETER The handlers were not the correct image type.
  93. **/
  94. typedef
  95. EFI_STATUS
  96. (EFIAPI *EFI_SMM_REGISTER_HANDLER)(
  97. IN EFI_SMM_BASE_PROTOCOL *This,
  98. IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
  99. IN VOID *SourceBuffer OPTIONAL,
  100. IN UINTN SourceSize,
  101. OUT EFI_HANDLE *ImageHandle,
  102. IN BOOLEAN LegacyIA32Binary OPTIONAL
  103. );
  104. /**
  105. Removes a handler from execution within SMRAM. This is the equivalent of performing
  106. the UnloadImage in System Management Mode.
  107. @param[in] This The protocol instance pointer.
  108. @param[in] ImageHandle The handler to be removed.
  109. @retval EFI_SUCCESS The operation was successful.
  110. @retval EFI_INVALID_PARAMETER The handler did not exist.
  111. @retval EFI_UNSUPPORTED The platform is in runtime.
  112. **/
  113. typedef
  114. EFI_STATUS
  115. (EFIAPI *EFI_SMM_UNREGISTER_HANDLER)(
  116. IN EFI_SMM_BASE_PROTOCOL *This,
  117. IN EFI_HANDLE ImageHandle
  118. );
  119. /**
  120. The SMM Inter-module Communicate Service Communicate() function
  121. provides a service to send/receive messages from a registered
  122. EFI service. The BASE protocol driver is responsible for doing
  123. any of the copies such that the data lives in boot-service-accessible RAM.
  124. @param[in] This The protocol instance pointer.
  125. @param[in] ImageHandle The handle of the registered driver.
  126. @param[in,out] CommunicationBuffer The pointer to the buffer to convey into SMRAM.
  127. @param[in,out] SourceSize The size of the data buffer being passed in.
  128. On exit, the size of data being returned.
  129. Zero if the handler does not wish to reply with any data.
  130. @retval EFI_SUCCESS The message was successfully posted.
  131. @retval EFI_INVALID_PARAMETER The buffer was NULL.
  132. **/
  133. typedef
  134. EFI_STATUS
  135. (EFIAPI *EFI_SMM_COMMUNICATE)(
  136. IN EFI_SMM_BASE_PROTOCOL *This,
  137. IN EFI_HANDLE ImageHandle,
  138. IN OUT VOID *CommunicationBuffer,
  139. IN OUT UINTN *SourceSize
  140. );
  141. /**
  142. Register a callback to execute within SMM.
  143. This allows receipt of messages created with EFI_SMM_BASE_PROTOCOL.Communicate().
  144. @param[in] This Protocol instance pointer.
  145. @param[in] SmmImageHandle Handle of the callback service.
  146. @param[in] CallbackAddress Address of the callback service.
  147. @param[in] MakeLast If present, will stipulate that the handler is posted to
  148. be executed last in the dispatch table.
  149. @param[in] FloatingPointSave An optional parameter that informs the
  150. EFI_SMM_ACCESS_PROTOCOL Driver core if it needs to save
  151. the floating point register state. If any handler
  152. require this, the state will be saved for all handlers.
  153. @retval EFI_SUCCESS The operation was successful.
  154. @retval EFI_OUT_OF_RESOURCES Not enough space in the dispatch queue.
  155. @retval EFI_UNSUPPORTED The platform is in runtime.
  156. @retval EFI_UNSUPPORTED The caller is not in SMM.
  157. **/
  158. typedef
  159. EFI_STATUS
  160. (EFIAPI *EFI_SMM_CALLBACK_SERVICE)(
  161. IN EFI_SMM_BASE_PROTOCOL *This,
  162. IN EFI_HANDLE SmmImageHandle,
  163. IN EFI_SMM_CALLBACK_ENTRY_POINT CallbackAddress,
  164. IN BOOLEAN MakeLast OPTIONAL,
  165. IN BOOLEAN FloatingPointSave OPTIONAL
  166. );
  167. /**
  168. The SmmAllocatePool() function allocates a memory region of Size bytes from memory of
  169. type PoolType and returns the address of the allocated memory in the location referenced
  170. by Buffer. This function allocates pages from EFI SMRAM Memory as needed to grow the
  171. requested pool type. All allocations are eight-byte aligned.
  172. @param[in] This Protocol instance pointer.
  173. @param[in] PoolType The type of pool to allocate.
  174. The only supported type is EfiRuntimeServicesData;
  175. the interface will internally map this runtime request to
  176. SMRAM for IA-32 and leave as this type for the Itanium
  177. processor family. Other types can be ignored.
  178. @param[in] Size The number of bytes to allocate from the pool.
  179. @param[out] Buffer A pointer to a pointer to the allocated buffer if the call
  180. succeeds; undefined otherwise.
  181. @retval EFI_SUCCESS The requested number of bytes was allocated.
  182. @retval EFI_OUT_OF_RESOURCES The pool requested could not be allocated.
  183. @retval EFI_UNSUPPORTED The platform is in runtime.
  184. **/
  185. typedef
  186. EFI_STATUS
  187. (EFIAPI *EFI_SMM_ALLOCATE_POOL)(
  188. IN EFI_SMM_BASE_PROTOCOL *This,
  189. IN EFI_MEMORY_TYPE PoolType,
  190. IN UINTN Size,
  191. OUT VOID **Buffer
  192. );
  193. /**
  194. The SmmFreePool() function returns the memory specified by Buffer to the system.
  195. On return, the memory's type is EFI SMRAM Memory. The Buffer that is freed must
  196. have been allocated by SmmAllocatePool().
  197. @param[in] This The protocol instance pointer.
  198. @param[in] Buffer The pointer to the buffer allocation.
  199. @retval EFI_SUCCESS The memory was returned to the system.
  200. @retval EFI_INVALID_PARAMETER The buffer was invalid.
  201. @retval EFI_UNSUPPORTED The platform is in runtime.
  202. **/
  203. typedef
  204. EFI_STATUS
  205. (EFIAPI *EFI_SMM_FREE_POOL)(
  206. IN EFI_SMM_BASE_PROTOCOL *This,
  207. IN VOID *Buffer
  208. );
  209. /**
  210. This routine tells caller if execution context is SMM or not.
  211. @param[in] This The protocol instance pointer.
  212. @param[out] InSmm Whether the caller is inside SMM for IA-32
  213. or servicing a PMI for the Itanium processor
  214. family.
  215. @retval EFI_SUCCESS The operation was successful.
  216. @retval EFI_INVALID_PARAMETER InSmm was NULL.
  217. **/
  218. typedef
  219. EFI_STATUS
  220. (EFIAPI *EFI_SMM_INSIDE_OUT)(
  221. IN EFI_SMM_BASE_PROTOCOL *This,
  222. OUT BOOLEAN *InSmm
  223. );
  224. /**
  225. The GetSmstLocation() function returns the location of the System Management
  226. Service Table. The use of the API is such that a driver can discover the
  227. location of the SMST in its entry point and then cache it in some driver
  228. global variable so that the SMST can be invoked in subsequent callbacks.
  229. @param[in] This The protocol instance pointer.
  230. @param[in] Smst The pointer to the SMST.
  231. @retval EFI_SUCCESS The operation was successful
  232. @retval EFI_INVALID_PARAMETER Smst was invalid.
  233. @retval EFI_UNSUPPORTED Not in SMM.
  234. **/
  235. typedef
  236. EFI_STATUS
  237. (EFIAPI *EFI_SMM_GET_SMST_LOCATION)(
  238. IN EFI_SMM_BASE_PROTOCOL *This,
  239. IN OUT EFI_SMM_SYSTEM_TABLE **Smst
  240. );
  241. ///
  242. /// This protocol is used to install SMM handlers for support of subsequent SMI/PMI
  243. /// activations. This protocol is available on both IA-32 and Itanium-based systems.
  244. ///
  245. struct _EFI_SMM_BASE_PROTOCOL {
  246. EFI_SMM_REGISTER_HANDLER Register;
  247. EFI_SMM_UNREGISTER_HANDLER UnRegister;
  248. EFI_SMM_COMMUNICATE Communicate;
  249. EFI_SMM_CALLBACK_SERVICE RegisterCallback;
  250. EFI_SMM_INSIDE_OUT InSmm;
  251. EFI_SMM_ALLOCATE_POOL SmmAllocatePool;
  252. EFI_SMM_FREE_POOL SmmFreePool;
  253. EFI_SMM_GET_SMST_LOCATION GetSmstLocation;
  254. };
  255. extern EFI_GUID gEfiSmmBaseProtocolGuid;
  256. #endif