]>
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 | |
31 | @param ImageHandle\r | |
32 | \r | |
33 | @retval EFI_SUCCESS\r | |
34 | \r | |
35 | **/\r | |
36 | STATIC\r | |
37 | EFI_STATUS\r | |
38 | EFIAPI\r | |
39 | _DriverUnloadHandler (\r | |
40 | EFI_HANDLE ImageHandle\r | |
41 | )\r | |
42 | {\r | |
43 | EFI_STATUS Status;\r | |
44 | \r | |
45 | //\r | |
46 | // If an UnloadImage() handler is specified, then call it\r | |
47 | //\r | |
48 | Status = ProcessModuleUnloadList (ImageHandle);\r | |
49 | \r | |
50 | //\r | |
51 | // If the driver specific unload handler does not return an error, then call all of the\r | |
52 | // library destructors. If the unload handler returned an error, then the driver can not be\r | |
53 | // unloaded, and the library destructors should not be called\r | |
54 | //\r | |
55 | if (!EFI_ERROR (Status)) {\r | |
e386b444 | 56 | ProcessLibraryDestructorList (ImageHandle, gST);\r |
57 | }\r | |
58 | \r | |
59 | //\r | |
60 | // Return the status from the driver specific unload handler\r | |
61 | //\r | |
62 | return Status;\r | |
63 | }\r | |
64 | \r | |
65 | \r | |
e386b444 | 66 | /**\r |
67 | Enrty point to DXE Driver.\r | |
68 | \r | |
69 | @param ImageHandle ImageHandle of the loaded driver.\r | |
70 | @param SystemTable Pointer to the EFI System Table.\r | |
71 | \r | |
72 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
73 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
74 | \r | |
75 | **/\r | |
76 | EFI_STATUS\r | |
77 | EFIAPI\r | |
78 | _ModuleEntryPoint (\r | |
79 | IN EFI_HANDLE ImageHandle,\r | |
80 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
81 | )\r | |
82 | {\r | |
83 | EFI_STATUS Status;\r | |
84 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
85 | \r | |
86 | if (_gUefiDriverRevision != 0) {\r | |
87 | //\r | |
88 | // Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI spec revision of the driver\r | |
89 | //\r | |
90 | if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {\r | |
91 | return EFI_INCOMPATIBLE_VERSION;\r | |
92 | }\r | |
93 | }\r | |
94 | \r | |
c7d265a9 | 95 | //\r |
96 | // Call constructor for all libraries\r | |
97 | //\r | |
98 | ProcessLibraryConstructorList (ImageHandle, SystemTable);\r | |
99 | \r | |
e386b444 | 100 | //\r |
101 | // Install unload handler...\r | |
102 | //\r | |
103 | if (_gDriverUnloadImageCount != 0) {\r | |
104 | Status = gBS->HandleProtocol (\r | |
105 | ImageHandle,\r | |
106 | &gEfiLoadedImageProtocolGuid,\r | |
107 | (VOID **)&LoadedImage\r | |
108 | );\r | |
109 | ASSERT_EFI_ERROR (Status);\r | |
110 | LoadedImage->Unload = _DriverUnloadHandler;\r | |
111 | }\r | |
112 | \r | |
e386b444 | 113 | //\r |
114 | // Call the driver entry point\r | |
115 | //\r | |
116 | Status = ProcessModuleEntryPointList (ImageHandle, SystemTable);\r | |
117 | \r | |
118 | //\r | |
119 | // If all of the drivers returned errors, then invoke all of the library destructors\r | |
120 | //\r | |
121 | if (EFI_ERROR (Status)) {\r | |
122 | ProcessLibraryDestructorList (ImageHandle, SystemTable);\r | |
123 | }\r | |
124 | \r | |
125 | //\r | |
126 | // Return the cummalative return status code from all of the driver entry points\r | |
127 | //\r | |
128 | return Status;\r | |
129 | }\r | |
130 | \r | |
131 | \r | |
132 | /**\r | |
133 | Enrty point wrapper of DXE Driver.\r | |
134 | \r | |
135 | @param ImageHandle ImageHandle of the loaded driver.\r | |
136 | @param SystemTable Pointer to the EFI System Table.\r | |
137 | \r | |
138 | @retval EFI_SUCCESS One or more of the drivers returned a success code.\r | |
139 | @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r | |
140 | \r | |
141 | **/\r | |
142 | EFI_STATUS\r | |
143 | EFIAPI\r | |
144 | EfiMain (\r | |
145 | IN EFI_HANDLE ImageHandle,\r | |
146 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
147 | )\r | |
148 | {\r | |
149 | return _ModuleEntryPoint (ImageHandle, SystemTable);\r | |
150 | }\r |