]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
2 | Entry point to a EFI/DXE driver.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2007, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | \r | |
c892d846 | 16 | \r |
c7d265a9 | 17 | #include <Uefi.h>\r |
c892d846 | 18 | \r |
c7d265a9 | 19 | #include <Protocol/LoadedImage.h>\r |
c892d846 | 20 | \r |
c7d265a9 | 21 | #include <Library/UefiDriverEntryPoint.h>\r |
22 | #include <Library/DebugLib.h>\r | |
23 | #include <Library/UefiBootServicesTableLib.h>\r | |
e386b444 | 24 | \r |
25 | \r | |
26 | /**\r | |
27 | Unload function that is registered in the LoadImage protocol. It un-installs\r | |
28 | protocols produced and deallocates pool used by the driver. Called by the core\r | |
29 | when unloading the driver.\r | |
30 | \r | |
373b5cf9 | 31 | @param ImageHandle ImageHandle of the loaded driver.\r |
e386b444 | 32 | \r |
373b5cf9 | 33 | @return Status returned by all unload().\r |
e386b444 | 34 | \r |
35 | **/\r | |
e386b444 | 36 | EFI_STATUS\r |
37 | EFIAPI\r | |
38 | _DriverUnloadHandler (\r | |
39 | EFI_HANDLE ImageHandle\r | |
40 | )\r | |
41 | {\r | |
42 | EFI_STATUS Status;\r | |
43 | \r | |
44 | //\r | |
45 | // If an UnloadImage() handler is specified, then call it\r | |
46 | //\r | |
47 | Status = ProcessModuleUnloadList (ImageHandle);\r | |
48 | \r | |
49 | //\r | |
50 | // If the driver specific unload handler does not return an error, then call all of the\r | |
51 | // library destructors. If the unload handler returned an error, then the driver can not be\r | |
52 | // unloaded, and the library destructors should not be called\r | |
53 | //\r | |
54 | if (!EFI_ERROR (Status)) {\r | |
e386b444 | 55 | ProcessLibraryDestructorList (ImageHandle, gST);\r |
56 | }\r | |
57 | \r | |
58 | //\r | |
59 | // Return the status from the driver specific unload handler\r | |
60 | //\r | |
61 | return Status;\r | |
62 | }\r | |
63 | \r | |
64 | \r | |
e386b444 | 65 | /**\r |
66770ccb | 66 | The entry point of PE/COFF Image for a DXE Driver, DXE Runtime Driver, DXE SMM Driver, or UEFI Driver. \r |
67 | \r | |
68 | This function is the entry point for a DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r | |
69 | or UEFI Driver. This function must call ProcessLibraryConstructorList() and\r | |
70 | ProcessModuleEntryPointList(). If the return status from ProcessModuleEntryPointList()\r | |
71 | is an error status, then ProcessLibraryDestructorList() must be called. The return value\r | |
72 | from ProcessModuleEntryPointList() is returned. If _gDriverUnloadImageCount is greater\r | |
73 | than zero, then an unload handler must be registered for this image and the unload handler\r | |
74 | must invoke ProcessModuleUnloadList().\r | |
75 | If _gUefiDriverRevision is not zero and SystemTable->Hdr.Revision is less than _gUefiDriverRevison,\r | |
76 | then return EFI_INCOMPATIBLE_VERSION.\r | |
e386b444 | 77 | \r |
e386b444 | 78 | \r |
66770ccb | 79 | @param ImageHandle ImageHandle of the loaded driver.\r |
80 | @param SystemTable Pointer to the EFI System Table.\r | |
81 | \r | |
82 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
83 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision.\r | |
84 | @retval Other Return value from ProcessModuleEntryPointList().\r | |
e386b444 | 85 | \r |
86 | **/\r | |
87 | EFI_STATUS\r | |
88 | EFIAPI\r | |
89 | _ModuleEntryPoint (\r | |
90 | IN EFI_HANDLE ImageHandle,\r | |
91 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
92 | )\r | |
93 | {\r | |
94 | EFI_STATUS Status;\r | |
95 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
96 | \r | |
97 | if (_gUefiDriverRevision != 0) {\r | |
98 | //\r | |
99 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r | |
100 | //\r | |
101 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r | |
102 | return EFI_INCOMPATIBLE_VERSION;\r | |
103 | }\r | |
104 | }\r | |
105 | \r | |
c7d265a9 | 106 | //\r |
107 | // Call constructor for all libraries\r | |
108 | //\r | |
109 | ProcessLibraryConstructorList (ImageHandle, SystemTable);\r | |
110 | \r | |
e386b444 | 111 | //\r |
112 | // Install unload handler...\r | |
113 | //\r | |
114 | if (_gDriverUnloadImageCount != 0) {\r | |
115 | Status = gBS->HandleProtocol (\r | |
116 | ImageHandle,\r | |
117 | &gEfiLoadedImageProtocolGuid,\r | |
118 | (VOID **)&LoadedImage\r | |
119 | );\r | |
120 | ASSERT_EFI_ERROR (Status);\r | |
121 | LoadedImage->Unload = _DriverUnloadHandler;\r | |
122 | }\r | |
123 | \r | |
e386b444 | 124 | //\r |
125 | // Call the driver entry point\r | |
126 | //\r | |
127 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r | |
128 | \r | |
129 | //\r | |
130 | // If all of the drivers returned errors, then invoke all of the library destructors\r | |
131 | //\r | |
132 | if (EFI_ERROR (Status)) {\r | |
133 | ProcessLibraryDestructorList (ImageHandle, SystemTable);\r | |
134 | }\r | |
135 | \r | |
136 | //\r | |
137 | // Return the cummalative return status code from all of the driver entry points\r | |
138 | //\r | |
139 | return Status;\r | |
140 | }\r | |
141 | \r | |
142 | \r | |
143 | /**\r | |
66770ccb | 144 | Required by the EBC compiler and identical in functionality to _ModuleEntryPoint(). \r |
145 | \r | |
146 | This function is required to call _ModuleEntryPoint() passing in ImageHandle, and SystemTable.\r | |
e386b444 | 147 | \r |
148 | @param ImageHandle ImageHandle of the loaded driver.\r | |
149 | @param SystemTable Pointer to the EFI System Table.\r | |
150 | \r | |
66770ccb | 151 | @retval EFI_SUCCESS The DXE Driver, DXE Runtime Driver, DXE SMM Driver,\r |
152 | or UEFI Driver exited normally.\r | |
153 | @retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than SystemTable->Hdr.Revision.\r | |
154 | @retval Other Return value from ProcessModuleEntryPointList().\r | |
e386b444 | 155 | **/\r |
156 | EFI_STATUS\r | |
157 | EFIAPI\r | |
158 | EfiMain (\r | |
159 | IN EFI_HANDLE ImageHandle,\r | |
160 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
161 | )\r | |
162 | {\r | |
163 | return _ModuleEntryPoint (ImageHandle, SystemTable);\r | |
164 | }\r |