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