2 Entry point to a Standalone MM driver.
4 Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016 - 2018, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2018, Linaro, Limited. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Protocol/LoadedImage.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/MmServicesTableLib.h>
18 #include <Library/StandaloneMmDriverEntryPoint.h>
21 Unloads an image from memory.
23 This function is a callback that a driver registers to do cleanup
24 when the UnloadImage boot service function is called.
26 @param ImageHandle The handle to the image to unload.
28 @return Status returned by all unload().
33 _DriverUnloadHandler (
34 EFI_HANDLE ImageHandle
40 // If an UnloadImage() handler is specified, then call it
42 Status
= ProcessModuleUnloadList (ImageHandle
);
45 // If the driver specific unload handler does not return an error, then call all of the
46 // library destructors. If the unload handler returned an error, then the driver can not be
47 // unloaded, and the library destructors should not be called
49 if (!EFI_ERROR (Status
)) {
50 ProcessLibraryDestructorList (ImageHandle
, gMmst
);
54 // Return the status from the driver specific unload handler
60 The entry point of PE/COFF Image for a Standalone MM Driver.
62 This function is the entry point for a Standalone MM Driver.
63 This function must call ProcessLibraryConstructorList() and
64 ProcessModuleEntryPointList().
65 If the return status from ProcessModuleEntryPointList()
66 is an error status, then ProcessLibraryDestructorList() must be called.
67 The return value from ProcessModuleEntryPointList() is returned.
68 If _gMmRevision is not zero and SystemTable->Hdr.Revision is
69 less than _gMmRevision, then return EFI_INCOMPATIBLE_VERSION.
71 @param ImageHandle The image handle of the Standalone MM Driver.
72 @param MmSystemTable A pointer to the MM System Table.
74 @retval EFI_SUCCESS The Standalone MM Driver exited normally.
75 @retval EFI_INCOMPATIBLE_VERSION _gMmRevision is greater than
76 MmSystemTable->Hdr.Revision.
77 @retval Other Return value from
78 ProcessModuleEntryPointList().
84 IN EFI_HANDLE ImageHandle
,
85 IN IN EFI_MM_SYSTEM_TABLE
*MmSystemTable
89 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
91 if (_gMmRevision
!= 0) {
93 // Make sure that the MM spec revision of the platform
94 // is >= MM spec revision of the driver
96 if (MmSystemTable
->Hdr
.Revision
< _gMmRevision
) {
97 return EFI_INCOMPATIBLE_VERSION
;
102 // Call constructor for all libraries
104 ProcessLibraryConstructorList (ImageHandle
, MmSystemTable
);
107 // Install unload handler...
109 if (_gDriverUnloadImageCount
!= 0) {
110 Status
= gMmst
->MmHandleProtocol (
112 &gEfiLoadedImageProtocolGuid
,
113 (VOID
**)&LoadedImage
115 ASSERT_EFI_ERROR (Status
);
116 LoadedImage
->Unload
= _DriverUnloadHandler
;
120 // Call the driver entry point
122 Status
= ProcessModuleEntryPointList (ImageHandle
, MmSystemTable
);
125 // If all of the drivers returned errors, then invoke all of the library destructors
127 if (EFI_ERROR (Status
)) {
128 ProcessLibraryDestructorList (ImageHandle
, MmSystemTable
);
132 // Return the cumulative return status code from all of the driver entry points