2 SMM Base Protocol on SMM Base2 Protocol Thunk driver.
4 This driver co-operates with SMM Base Helper SMM driver to provide SMM Base Protocol
5 based on SMM Base2 Protocol.
7 This thunk driver is expected to be loaded before PI SMM IPL driver so that
8 SMM BASE Protocol can be published immediately after SMM Base2 Protocol is installed to
9 make SMM Base Protocol.InSmm() as early as possible.
11 Copyright (c) 2009 Intel Corporation
12 All rights reserved. This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include "SmmBaseOnSmmBase2Thunk.h"
24 EFI_SMM_BASE_PROTOCOL gSmmBase
= {
28 SmmBaseRegisterCallback
,
30 SmmBaseSmmAllocatePool
,
32 SmmBaseGetSmstLocation
35 SMMBASETHUNK_COMMUNICATION_DATA gCommunicationData
= {
36 EFI_SMM_BASE_THUNK_COMMUNICATION_GUID
,
37 sizeof (SMMBASE_FUNCTION_DATA
)
40 EFI_HANDLE mImageHandle
;
41 EFI_SMM_BASE2_PROTOCOL
*mSmmBase2
= NULL
;
42 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
43 EFI_SMM_BASE_HELPER_READY_PROTOCOL
*mSmmBaseHelperReady
= NULL
;
46 Determine if in SMM mode.
48 @retval TRUE In SMM mode.
49 @retval FALSE Not in SMM mode.
59 Status
= mSmmBase2
->InSmm (mSmmBase2
, &InSmm
);
60 ASSERT_EFI_ERROR (Status
);
65 Invoke services provided by SMM Base Helper SMM driver.
68 SmmBaseHelperService (
74 gCommunicationData
.FunctionData
.Status
= EFI_UNSUPPORTED
;
78 /// If in SMM mode, directly call services in SMM Base Helper.
80 if (mSmmBaseHelperReady
== NULL
) {
85 DataSize
= (UINTN
)(sizeof (SMMBASE_FUNCTION_DATA
));
86 mSmmBaseHelperReady
->ServiceEntry (
89 &gCommunicationData
.FunctionData
,
94 /// If in non-SMM mode, call services in SMM Base Helper via SMM Communication Protocol.
96 if (mSmmCommunication
== NULL
) {
101 DataSize
= (UINTN
)(sizeof (gCommunicationData
));
102 mSmmCommunication
->Communicate (
111 Register a given driver into SMRAM. This is the equivalent of performing
112 the LoadImage/StartImage into System Management Mode.
114 @param[in] This Protocol instance pointer.
115 @param[in] FilePath Location of the image to be installed as the handler.
116 @param[in] SourceBuffer Optional source buffer in case the image file
118 @param[in] SourceSize Size of the source image file, if in memory.
119 @param[out] ImageHandle The handle that the base driver uses to decode
120 the handler. Unique among SMM handlers only,
121 not unique across DXE/EFI.
122 @param[in] LegacyIA32Binary An optional parameter specifying that the associated
123 file is a real-mode IA-32 binary.
125 @retval EFI_SUCCESS The operation was successful.
126 @retval EFI_OUT_OF_RESOURCES There were no additional SMRAM resources to load the handler
127 @retval EFI_UNSUPPORTED This platform does not support 16-bit handlers.
128 @retval EFI_UNSUPPORTED Platform is in runtime.
129 @retval EFI_INVALID_PARAMETER The handlers was not the correct image type
134 IN EFI_SMM_BASE_PROTOCOL
*This
,
135 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
136 IN VOID
*SourceBuffer
,
138 OUT EFI_HANDLE
*ImageHandle
,
139 IN BOOLEAN LegacyIA32Binary
142 if (LegacyIA32Binary
) {
143 return EFI_UNSUPPORTED
;
146 gCommunicationData
.FunctionData
.Function
= SMMBASE_REGISTER
;
147 gCommunicationData
.FunctionData
.Args
.Register
.FilePath
= FilePath
;
148 gCommunicationData
.FunctionData
.Args
.Register
.SourceBuffer
= SourceBuffer
;
149 gCommunicationData
.FunctionData
.Args
.Register
.SourceSize
= SourceSize
;
150 gCommunicationData
.FunctionData
.Args
.Register
.ImageHandle
= ImageHandle
;
151 gCommunicationData
.FunctionData
.Args
.Register
.LegacyIA32Binary
= LegacyIA32Binary
;
153 SmmBaseHelperService ();
154 return gCommunicationData
.FunctionData
.Status
;
158 Removes a handler from execution within SMRAM. This is the equivalent of performing
159 the UnloadImage in System Management Mode.
161 @param[in] This Protocol instance pointer.
162 @param[in] ImageHandle The handler to be removed.
164 @retval EFI_SUCCESS The operation was successful
165 @retval EFI_INVALID_PARAMETER The handler did not exist
166 @retval EFI_UNSUPPORTED Platform is in runtime.
171 IN EFI_SMM_BASE_PROTOCOL
*This
,
172 IN EFI_HANDLE ImageHandle
175 gCommunicationData
.FunctionData
.Function
= SMMBASE_UNREGISTER
;
176 gCommunicationData
.FunctionData
.Args
.UnRegister
.ImageHandle
= ImageHandle
;
178 SmmBaseHelperService ();
179 return gCommunicationData
.FunctionData
.Status
;
183 The SMM Inter-module Communicate Service Communicate() function
184 provides a service to send/receive messages from a registered
185 EFI service. The BASE protocol driver is responsible for doing
186 any of the copies such that the data lives in boot-service-accessible RAM.
188 @param[in] This Protocol instance pointer.
189 @param[in] ImageHandle The handle of the registered driver.
190 @param[in,out] CommunicationBuffer Pointer to the buffer to convey into SMRAM.
191 @param[in,out] BufferSize The size of the data buffer being passed in.
192 On exit, the size of data being returned.
193 Zero if the handler does not wish to reply with any data.
195 @retval EFI_SUCCESS The message was successfully posted
196 @retval EFI_INVALID_PARAMETER The buffer was NULL
201 IN EFI_SMM_BASE_PROTOCOL
*This
,
202 IN EFI_HANDLE ImageHandle
,
203 IN OUT VOID
*CommunicationBuffer
,
204 IN OUT UINTN
*BufferSize
207 if (mSmmCommunication
== NULL
) {
209 return EFI_UNSUPPORTED
;
212 return mSmmCommunication
->Communicate (
220 Register a callback to execute within SMM.
221 This allows receipt of messages created with EFI_SMM_BASE_PROTOCOL.Communicate().
223 @param[in] This Protocol instance pointer.
224 @param[in] SmmImageHandle Handle of the callback service.
225 @param[in] CallbackAddress Address of the callback service.
226 @param[in] MakeLast If present, will stipulate that the handler is posted to
227 be executed last in the dispatch table.
228 @param[in] FloatingPointSave An optional parameter that informs the
229 EFI_SMM_ACCESS_PROTOCOL Driver core if it needs to save
230 the floating point register state. If any handler
231 require this, the state will be saved for all handlers.
233 @retval EFI_SUCCESS The operation was successful
234 @retval EFI_OUT_OF_RESOURCES Not enough space in the dispatch queue
235 @retval EFI_UNSUPPORTED Platform is in runtime.
236 @retval EFI_UNSUPPORTED The caller is not in SMM.
240 SmmBaseRegisterCallback (
241 IN EFI_SMM_BASE_PROTOCOL
*This
,
242 IN EFI_HANDLE SmmImageHandle
,
243 IN EFI_SMM_CALLBACK_ENTRY_POINT CallbackAddress
,
245 IN BOOLEAN FloatingPointSave
249 return EFI_UNSUPPORTED
;
252 gCommunicationData
.FunctionData
.Function
= SMMBASE_REGISTER_CALLBACK
;
253 gCommunicationData
.FunctionData
.Args
.RegisterCallback
.SmmImageHandle
= SmmImageHandle
;
254 gCommunicationData
.FunctionData
.Args
.RegisterCallback
.CallbackAddress
= CallbackAddress
;
255 gCommunicationData
.FunctionData
.Args
.RegisterCallback
.MakeLast
= MakeLast
;
256 gCommunicationData
.FunctionData
.Args
.RegisterCallback
.FloatingPointSave
= FloatingPointSave
;
258 SmmBaseHelperService();
259 return gCommunicationData
.FunctionData
.Status
;
263 This routine tells caller if execution context is SMM or not.
265 @param[in] This Protocol instance pointer.
266 @param[out] InSmm Whether the caller is inside SMM for IA-32
267 or servicing a PMI for the Itanium processor
270 @retval EFI_SUCCESS The operation was successful
271 @retval EFI_INVALID_PARAMETER InSmm was NULL.
276 IN EFI_SMM_BASE_PROTOCOL
*This
,
280 return mSmmBase2
->InSmm (mSmmBase2
, InSmm
);
284 The SmmAllocatePool() function allocates a memory region of Size bytes from memory of
285 type PoolType and returns the address of the allocated memory in the location referenced
286 by Buffer. This function allocates pages from EFI SMRAM Memory as needed to grow the
287 requested pool type. All allocations are eight-byte aligned.
289 @param[in] This Protocol instance pointer.
290 @param[in] PoolType The type of pool to allocate.
291 The only supported type is EfiRuntimeServicesData;
292 the interface will internally map this runtime request to
293 SMRAM for IA-32 and leave as this type for the Itanium
294 processor family. Other types can be ignored.
295 @param[in] Size The number of bytes to allocate from the pool.
296 @param[out] Buffer A pointer to a pointer to the allocated buffer if the call
297 succeeds; undefined otherwise.
299 @retval EFI_SUCCESS The requested number of bytes was allocated.
300 @retval EFI_OUT_OF_RESOURCES The pool requested could not be allocated.
301 @retval EFI_UNSUPPORTED Platform is in runtime.
305 SmmBaseSmmAllocatePool (
306 IN EFI_SMM_BASE_PROTOCOL
*This
,
307 IN EFI_MEMORY_TYPE PoolType
,
312 gCommunicationData
.FunctionData
.Function
= SMMBASE_ALLOCATE_POOL
;
313 gCommunicationData
.FunctionData
.Args
.AllocatePool
.PoolType
= PoolType
;
314 gCommunicationData
.FunctionData
.Args
.AllocatePool
.Size
= Size
;
315 gCommunicationData
.FunctionData
.Args
.AllocatePool
.Buffer
= Buffer
;
317 SmmBaseHelperService ();
318 return gCommunicationData
.FunctionData
.Status
;
322 The SmmFreePool() function returns the memory specified by Buffer to the system.
323 On return, the memory's type is EFI SMRAM Memory. The Buffer that is freed must
324 have been allocated by SmmAllocatePool().
326 @param[in] This Protocol instance pointer.
327 @param[in] Buffer Pointer to the buffer allocation.
329 @retval EFI_SUCCESS The memory was returned to the system.
330 @retval EFI_INVALID_PARAMETER Buffer was invalid.
331 @retval EFI_UNSUPPORTED Platform is in runtime.
336 IN EFI_SMM_BASE_PROTOCOL
*This
,
340 gCommunicationData
.FunctionData
.Function
= SMMBASE_FREE_POOL
;
341 gCommunicationData
.FunctionData
.Args
.FreePool
.Buffer
= Buffer
;
343 SmmBaseHelperService ();
344 return gCommunicationData
.FunctionData
.Status
;
348 The GetSmstLocation() function returns the location of the System Management
349 Service Table. The use of the API is such that a driver can discover the
350 location of the SMST in its entry point and then cache it in some driver
351 global variable so that the SMST can be invoked in subsequent callbacks.
353 @param[in] This Protocol instance pointer.
354 @param[in] Smst Pointer to the SMST.
356 @retval EFI_SUCCESS The operation was successful
357 @retval EFI_INVALID_PARAMETER Smst was invalid.
358 @retval EFI_UNSUPPORTED Not in SMM.
362 SmmBaseGetSmstLocation (
363 IN EFI_SMM_BASE_PROTOCOL
*This
,
364 OUT EFI_SMM_SYSTEM_TABLE
**Smst
367 if (mSmmBaseHelperReady
== NULL
) {
369 return EFI_UNSUPPORTED
;
373 return EFI_UNSUPPORTED
;
377 return EFI_INVALID_PARAMETER
;
380 *Smst
= mSmmBaseHelperReady
->FrameworkSmst
;
385 SMM Base Protocol notification event handler.
387 @param[in] Event Event whose notification function is being invoked.
388 @param[in] Context Pointer to the notification function's context.
392 SmmBaseProtocolNotification (
400 /// Assume only one instance of SMM Base2 Protocol in the system
401 /// Locate SMM Base2 Protocol
403 Status
= gBS
->LocateProtocol (&gEfiSmmBase2ProtocolGuid
, NULL
, (VOID
**) &mSmmBase2
);
404 if (!EFI_ERROR (Status
)) {
406 /// Publish Framework SMM BASE Protocol immediately after SMM Base2 Protocol is installed to
407 /// make SMM Base Protocol.InSmm() available as early as possible.
409 Status
= gBS
->InstallProtocolInterface (
411 &gEfiSmmBaseProtocolGuid
,
412 EFI_NATIVE_INTERFACE
,
415 ASSERT_EFI_ERROR (Status
);
420 SMM Communication Protocol notification event handler.
422 @param[in] Event Event whose notification function is being invoked.
423 @param[in] Context Pointer to the notification function's context.
427 SmmCommunicationProtocolNotification (
433 /// Assume only one instance of SMM Communication Protocol in the system
434 /// Locate SMM Communication Protocol
436 gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
440 SMM Base Helper Ready Protocol notification event handler.
442 @param[in] Event Event whose notification function is being invoked.
443 @param[in] Context Pointer to the notification function's context.
447 SmmBaseHelperReadyProtocolNotification (
453 /// Assume only one instance of SMM Base Helper Ready Protocol in the system
454 /// Locate SMM Base Helper Ready Protocol
456 gBS
->LocateProtocol (&gEfiSmmBaseHelperReadyProtocolGuid
, NULL
, (VOID
**) &mSmmBaseHelperReady
);
460 Entry Point for SMM Base Protocol on SMM Base2 Protocol Thunk driver.
462 @param[in] ImageHandle Image handle of this driver.
463 @param[in] SystemTable A Pointer to the EFI System Table.
465 @retval EFI_SUCCESS The entry point is executed successfully.
470 IN EFI_HANDLE ImageHandle
,
471 IN EFI_SYSTEM_TABLE
*SystemTable
476 mImageHandle
= ImageHandle
;
479 /// Install notifications for required protocols
481 /// Note we use protocol notifications here so as that this thunk driver can be
482 /// loaded before PI SMM IPL driver. Framework SMM BASE Protocol will be published
483 /// immediately after SMM Base2 Protocol is installed to make SMM Base Protocol.InSmm()
484 /// available as early as possible because some Framework code's behavior depends on
485 /// correct detection of SMM mode via SMM Base Protocol.InSmm().
487 /// Also SMM Base Helper driver is expected to be dispatched
488 /// in the earliest round of SMM driver dispatch just after SMM IPL driver loads SMM Foundation.
489 /// So the full functionality of SMM Base Protocol is ready immediately after SMM IPL driver is
490 /// loaded. Since that point Framework SMM driver can be succesufully supported.
492 EfiCreateProtocolNotifyEvent (
493 &gEfiSmmBase2ProtocolGuid
,
495 SmmBaseProtocolNotification
,
500 EfiCreateProtocolNotifyEvent (
501 &gEfiSmmCommunicationProtocolGuid
,
503 SmmCommunicationProtocolNotification
,
508 EfiCreateProtocolNotifyEvent (
509 &gEfiSmmBaseHelperReadyProtocolGuid
,
511 SmmBaseHelperReadyProtocolNotification
,