]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.c
MdePkg: introduce standalone MM entry point library implementation
[mirror_edk2.git] / MdePkg / Library / StandaloneMmDriverEntryPoint / StandaloneMmDriverEntryPoint.c
1 /** @file
2 Entry point to a Standalone MM driver.
3
4 Copyright (c) 2015, 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>
7
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include <PiMm.h>
19
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/MmServicesTableLib.h>
23 #include <Library/StandaloneMmDriverEntryPoint.h>
24
25 /**
26 The entry point of PE/COFF Image for a Standalone MM Driver.
27
28 This function is the entry point for a Standalone MM Driver.
29 This function must call ProcessLibraryConstructorList() and
30 ProcessModuleEntryPointList().
31 If the return status from ProcessModuleEntryPointList()
32 is an error status, then ProcessLibraryDestructorList() must be called.
33 The return value from ProcessModuleEntryPointList() is returned.
34 If _gMmRevision is not zero and SystemTable->Hdr.Revision is
35 less than _gMmRevision, then return EFI_INCOMPATIBLE_VERSION.
36
37 @param ImageHandle The image handle of the Standalone MM Driver.
38 @param SystemTable A pointer to the EFI System Table.
39
40 @retval EFI_SUCCESS The Standalone MM Driver exited normally.
41 @retval EFI_INCOMPATIBLE_VERSION _gMmRevision is greater than
42 MmSystemTable->Hdr.Revision.
43 @retval Other Return value from
44 ProcessModuleEntryPointList().
45
46 **/
47 EFI_STATUS
48 EFIAPI
49 _ModuleEntryPoint (
50 IN EFI_HANDLE ImageHandle,
51 IN IN EFI_MM_SYSTEM_TABLE *MmSystemTable
52 )
53 {
54 EFI_STATUS Status;
55
56 if (_gMmRevision != 0) {
57 //
58 // Make sure that the MM spec revision of the platform
59 // is >= MM spec revision of the driver
60 //
61 if (MmSystemTable->Hdr.Revision < _gMmRevision) {
62 return EFI_INCOMPATIBLE_VERSION;
63 }
64 }
65
66 //
67 // Call constructor for all libraries
68 //
69 ProcessLibraryConstructorList (ImageHandle, MmSystemTable);
70
71 //
72 // Call the driver entry point
73 //
74 Status = ProcessModuleEntryPointList (ImageHandle, MmSystemTable);
75
76 //
77 // If all of the drivers returned errors, then invoke all of the library destructors
78 //
79 if (EFI_ERROR (Status)) {
80 ProcessLibraryDestructorList (ImageHandle, MmSystemTable);
81 }
82
83 //
84 // Return the cumulative return status code from all of the driver entry points
85 //
86 return Status;
87 }