]>
Commit | Line | Data |
---|---|---|
5866d499 AB |
1 | /** @file\r |
2 | Entry point to a Standalone MM driver.\r | |
3 | \r | |
9fd7e88c | 4 | Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>\r |
5866d499 AB |
5 | Copyright (c) 2016 - 2018, ARM Ltd. All rights reserved.<BR>\r |
6 | Copyright (c) 2018, Linaro, Limited. All rights reserved.<BR>\r | |
7 | \r | |
9344f092 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
5866d499 AB |
9 | \r |
10 | **/\r | |
11 | \r | |
12 | #include <PiMm.h>\r | |
13 | \r | |
9fd7e88c | 14 | #include <Protocol/LoadedImage.h>\r |
5866d499 AB |
15 | #include <Library/BaseLib.h>\r |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/MmServicesTableLib.h>\r | |
18 | #include <Library/StandaloneMmDriverEntryPoint.h>\r | |
19 | \r | |
9fd7e88c JW |
20 | /**\r |
21 | Unloads an image from memory.\r | |
22 | \r | |
23 | This function is a callback that a driver registers to do cleanup\r | |
24 | when the UnloadImage boot service function is called.\r | |
25 | \r | |
26 | @param ImageHandle The handle to the image to unload.\r | |
27 | \r | |
28 | @return Status returned by all unload().\r | |
29 | \r | |
30 | **/\r | |
31 | EFI_STATUS\r | |
32 | EFIAPI\r | |
33 | _DriverUnloadHandler (\r | |
2f88bd3a | 34 | EFI_HANDLE ImageHandle\r |
9fd7e88c JW |
35 | )\r |
36 | {\r | |
37 | EFI_STATUS Status;\r | |
38 | \r | |
39 | //\r | |
40 | // If an UnloadImage() handler is specified, then call it\r | |
41 | //\r | |
42 | Status = ProcessModuleUnloadList (ImageHandle);\r | |
43 | \r | |
44 | //\r | |
45 | // If the driver specific unload handler does not return an error, then call all of the\r | |
46 | // library destructors. If the unload handler returned an error, then the driver can not be\r | |
47 | // unloaded, and the library destructors should not be called\r | |
48 | //\r | |
49 | if (!EFI_ERROR (Status)) {\r | |
50 | ProcessLibraryDestructorList (ImageHandle, gMmst);\r | |
51 | }\r | |
52 | \r | |
53 | //\r | |
54 | // Return the status from the driver specific unload handler\r | |
55 | //\r | |
56 | return Status;\r | |
57 | }\r | |
58 | \r | |
5866d499 AB |
59 | /**\r |
60 | The entry point of PE/COFF Image for a Standalone MM Driver.\r | |
61 | \r | |
62 | This function is the entry point for a Standalone MM Driver.\r | |
63 | This function must call ProcessLibraryConstructorList() and\r | |
64 | ProcessModuleEntryPointList().\r | |
65 | If the return status from ProcessModuleEntryPointList()\r | |
66 | is an error status, then ProcessLibraryDestructorList() must be called.\r | |
67 | The return value from ProcessModuleEntryPointList() is returned.\r | |
68 | If _gMmRevision is not zero and SystemTable->Hdr.Revision is\r | |
69 | less than _gMmRevision, then return EFI_INCOMPATIBLE_VERSION.\r | |
70 | \r | |
6c61ec4c BD |
71 | @param ImageHandle The image handle of the Standalone MM Driver.\r |
72 | @param MmSystemTable A pointer to the MM System Table.\r | |
5866d499 AB |
73 | \r |
74 | @retval EFI_SUCCESS The Standalone MM Driver exited normally.\r | |
75 | @retval EFI_INCOMPATIBLE_VERSION _gMmRevision is greater than\r | |
76 | MmSystemTable->Hdr.Revision.\r | |
77 | @retval Other Return value from\r | |
78 | ProcessModuleEntryPointList().\r | |
79 | \r | |
80 | **/\r | |
81 | EFI_STATUS\r | |
82 | EFIAPI\r | |
83 | _ModuleEntryPoint (\r | |
2f88bd3a MK |
84 | IN EFI_HANDLE ImageHandle,\r |
85 | IN IN EFI_MM_SYSTEM_TABLE *MmSystemTable\r | |
5866d499 AB |
86 | )\r |
87 | {\r | |
88 | EFI_STATUS Status;\r | |
9fd7e88c | 89 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r |
5866d499 AB |
90 | \r |
91 | if (_gMmRevision != 0) {\r | |
92 | //\r | |
93 | // Make sure that the MM spec revision of the platform\r | |
94 | // is >= MM spec revision of the driver\r | |
95 | //\r | |
96 | if (MmSystemTable->Hdr.Revision < _gMmRevision) {\r | |
97 | return EFI_INCOMPATIBLE_VERSION;\r | |
98 | }\r | |
99 | }\r | |
100 | \r | |
101 | //\r | |
102 | // Call constructor for all libraries\r | |
103 | //\r | |
104 | ProcessLibraryConstructorList (ImageHandle, MmSystemTable);\r | |
105 | \r | |
9fd7e88c JW |
106 | //\r |
107 | // Install unload handler...\r | |
108 | //\r | |
109 | if (_gDriverUnloadImageCount != 0) {\r | |
110 | Status = gMmst->MmHandleProtocol (\r | |
111 | ImageHandle,\r | |
112 | &gEfiLoadedImageProtocolGuid,\r | |
113 | (VOID **)&LoadedImage\r | |
114 | );\r | |
115 | ASSERT_EFI_ERROR (Status);\r | |
116 | LoadedImage->Unload = _DriverUnloadHandler;\r | |
117 | }\r | |
118 | \r | |
5866d499 AB |
119 | //\r |
120 | // Call the driver entry point\r | |
121 | //\r | |
122 | Status = ProcessModuleEntryPointList (ImageHandle, MmSystemTable);\r | |
123 | \r | |
124 | //\r | |
125 | // If all of the drivers returned errors, then invoke all of the library destructors\r | |
126 | //\r | |
127 | if (EFI_ERROR (Status)) {\r | |
128 | ProcessLibraryDestructorList (ImageHandle, MmSystemTable);\r | |
129 | }\r | |
130 | \r | |
131 | //\r | |
132 | // Return the cumulative return status code from all of the driver entry points\r | |
133 | //\r | |
134 | return Status;\r | |
135 | }\r |