]>
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 | |
16 | //\r | |
c7d265a9 | 17 | // The package level header files this module uses\r |
e386b444 | 18 | //\r |
c7d265a9 | 19 | #include <Uefi.h>\r |
20 | //\r | |
21 | // The protocols, PPI and GUID defintions for this module\r | |
22 | //\r | |
23 | #include <Protocol/LoadedImage.h>\r | |
24 | //\r | |
25 | // The Library classes this module consumes\r | |
26 | //\r | |
27 | #include <Library/UefiDriverEntryPoint.h>\r | |
28 | #include <Library/DebugLib.h>\r | |
29 | #include <Library/UefiBootServicesTableLib.h>\r | |
e386b444 | 30 | \r |
31 | \r | |
32 | /**\r | |
33 | Unload function that is registered in the LoadImage protocol. It un-installs\r | |
34 | protocols produced and deallocates pool used by the driver. Called by the core\r | |
35 | when unloading the driver.\r | |
36 | \r | |
37 | @param ImageHandle\r | |
38 | \r | |
39 | @retval EFI_SUCCESS\r | |
40 | \r | |
41 | **/\r | |
42 | STATIC\r | |
43 | EFI_STATUS\r | |
44 | EFIAPI\r | |
45 | _DriverUnloadHandler (\r | |
46 | EFI_HANDLE ImageHandle\r | |
47 | )\r | |
48 | {\r | |
49 | EFI_STATUS Status;\r | |
50 | \r | |
51 | //\r | |
52 | // If an UnloadImage() handler is specified, then call it\r | |
53 | //\r | |
54 | Status = ProcessModuleUnloadList (ImageHandle);\r | |
55 | \r | |
56 | //\r | |
57 | // If the driver specific unload handler does not return an error, then call all of the\r | |
58 | // library destructors. If the unload handler returned an error, then the driver can not be\r | |
59 | // unloaded, and the library destructors should not be called\r | |
60 | //\r | |
61 | if (!EFI_ERROR (Status)) {\r | |
e386b444 | 62 | ProcessLibraryDestructorList (ImageHandle, gST);\r |
63 | }\r | |
64 | \r | |
65 | //\r | |
66 | // Return the status from the driver specific unload handler\r | |
67 | //\r | |
68 | return Status;\r | |
69 | }\r | |
70 | \r | |
71 | \r | |
e386b444 | 72 | /**\r |
73 | Enrty point to DXE Driver.\r | |
74 | \r | |
75 | @param ImageHandle ImageHandle of the loaded driver.\r | |
76 | @param SystemTable Pointer to the EFI System Table.\r | |
77 | \r | |
78 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
79 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
80 | \r | |
81 | **/\r | |
82 | EFI_STATUS\r | |
83 | EFIAPI\r | |
84 | _ModuleEntryPoint (\r | |
85 | IN EFI_HANDLE ImageHandle,\r | |
86 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
87 | )\r | |
88 | {\r | |
89 | EFI_STATUS Status;\r | |
90 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
91 | \r | |
92 | if (_gUefiDriverRevision != 0) {\r | |
93 | //\r | |
94 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r | |
95 | //\r | |
96 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r | |
97 | return EFI_INCOMPATIBLE_VERSION;\r | |
98 | }\r | |
99 | }\r | |
100 | \r | |
c7d265a9 | 101 | //\r |
102 | // Call constructor for all libraries\r | |
103 | //\r | |
104 | ProcessLibraryConstructorList (ImageHandle, SystemTable);\r | |
105 | \r | |
e386b444 | 106 | //\r |
107 | // Install unload handler...\r | |
108 | //\r | |
109 | if (_gDriverUnloadImageCount != 0) {\r | |
110 | Status = gBS->HandleProtocol (\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 | |
e386b444 | 119 | //\r |
120 | // Call the driver entry point\r | |
121 | //\r | |
122 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\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, SystemTable);\r | |
129 | }\r | |
130 | \r | |
131 | //\r | |
132 | // Return the cummalative return status code from all of the driver entry points\r | |
133 | //\r | |
134 | return Status;\r | |
135 | }\r | |
136 | \r | |
137 | \r | |
138 | /**\r | |
139 | Enrty point wrapper of DXE Driver.\r | |
140 | \r | |
141 | @param ImageHandle ImageHandle of the loaded driver.\r | |
142 | @param SystemTable Pointer to the EFI System Table.\r | |
143 | \r | |
144 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
145 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
146 | \r | |
147 | **/\r | |
148 | EFI_STATUS\r | |
149 | EFIAPI\r | |
150 | EfiMain (\r | |
151 | IN EFI_HANDLE ImageHandle,\r | |
152 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
153 | )\r | |
154 | {\r | |
155 | return _ModuleEntryPoint (ImageHandle, SystemTable);\r | |
156 | }\r |