]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/SocketDxe/EntryUnload.c
1. Add Partial Keystroke Support in Nt32 WinNTGopDxe driver. See the Uefi2.3.1a chapt...
[mirror_edk2.git] / StdLib / SocketDxe / EntryUnload.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the entry and unload for the socket driver.\r
3\r
4 Copyright (c) 2011, Intel Corporation\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#include "Socket.h"\r
16\r
17\r
18CONST EFI_GUID mEslRawServiceGuid = {\r
19 0xf9f5d280, 0x8a4b, 0x48e2, { 0x96, 0x28, 0xda, 0xfa, 0xa7, 0x70, 0x54, 0x5d }\r
20};\r
21\r
22CONST EFI_GUID mEslTcp4ServiceGuid = {\r
23 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }\r
24};\r
25\r
26CONST EFI_GUID mEslUdp4ServiceGuid = {\r
27 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }\r
28};\r
29\r
30\r
31/**\r
32 Socket driver unload routine.\r
33\r
34 @param [in] ImageHandle Handle for the image.\r
35\r
36 @retval EFI_SUCCESS Image may be unloaded\r
37\r
38**/\r
39EFI_STATUS\r
40EFIAPI\r
41DriverUnload (\r
42 IN EFI_HANDLE ImageHandle\r
43 )\r
44{\r
45 UINTN BufferSize;\r
46 UINTN Index;\r
47 UINTN Max;\r
48 EFI_HANDLE * pHandle;\r
49 EFI_STATUS Status;\r
50\r
51 //\r
52 // Determine which devices are using this driver\r
53 //\r
54 BufferSize = 0;\r
55 pHandle = NULL;\r
56 Status = gBS->LocateHandle (\r
57 ByProtocol,\r
58 &gEfiCallerIdGuid,\r
59 NULL,\r
60 &BufferSize,\r
61 NULL );\r
62 if ( EFI_BUFFER_TOO_SMALL == Status ) {\r
63 for ( ; ; ) {\r
64 //\r
65 // One or more block IO devices are present\r
66 //\r
67 Status = gBS->AllocatePool (\r
68 EfiRuntimeServicesData,\r
69 BufferSize,\r
70 (VOID **) &pHandle\r
71 );\r
72 if ( EFI_ERROR ( Status )) {\r
73 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
74 "Insufficient memory, failed handle buffer allocation\r\n" ));\r
75 break;\r
76 }\r
77\r
78 //\r
79 // Locate the block IO devices\r
80 //\r
81 Status = gBS->LocateHandle (\r
82 ByProtocol,\r
83 &gEfiCallerIdGuid,\r
84 NULL,\r
85 &BufferSize,\r
86 pHandle );\r
87 if ( EFI_ERROR ( Status )) {\r
88 //\r
89 // Error getting handles\r
90 //\r
91 DEBUG (( DEBUG_ERROR | DEBUG_INIT | DEBUG_INFO,\r
92 "Failure getting Telnet handles\r\n" ));\r
93 break;\r
94 }\r
95 \r
96 //\r
97 // Remove any use of the driver\r
98 //\r
99 Max = BufferSize / sizeof ( pHandle[ 0 ]);\r
100 for ( Index = 0; Max > Index; Index++ ) {\r
101 Status = DriverStop ( &gDriverBinding,\r
102 pHandle[ Index ],\r
103 0,\r
104 NULL );\r
105 if ( EFI_ERROR ( Status )) {\r
106 DEBUG (( DEBUG_WARN | DEBUG_INIT | DEBUG_INFO,\r
107 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle[ Index ]));\r
108 break;\r
109 }\r
110 }\r
111 break;\r
112 }\r
113 }\r
114 else {\r
115 if ( EFI_NOT_FOUND == Status ) {\r
116 //\r
117 // No devices were found\r
118 //\r
119 Status = EFI_SUCCESS;\r
120 }\r
121 }\r
122\r
123 //\r
124 // Free the handle array\r
125 //\r
126 if ( NULL != pHandle ) {\r
127 gBS->FreePool ( pHandle );\r
128 }\r
129\r
130 //\r
131 // Done with the socket layer\r
132 //\r
133 if ( !EFI_ERROR ( Status )) {\r
134 Status = EslServiceUninstall ( ImageHandle );\r
135 if ( !EFI_ERROR ( Status )) {\r
136 //\r
137 // Remove the protocols installed by the EntryPoint routine.\r
138 //\r
139 Status = gBS->UninstallMultipleProtocolInterfaces (\r
140 ImageHandle,\r
141 &gEfiDriverBindingProtocolGuid,\r
142 &gDriverBinding,\r
143 &gEfiComponentNameProtocolGuid,\r
144 &gComponentName,\r
145 &gEfiComponentName2ProtocolGuid,\r
146 &gComponentName2,\r
147 NULL\r
148 );\r
149 if ( !EFI_ERROR ( Status )) {\r
150 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
151 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r
152 ImageHandle ));\r
153 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
154 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r
155 ImageHandle ));\r
156 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
157 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r
158 ImageHandle ));\r
159 }\r
160 else {\r
161 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
162 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",\r
163 ImageHandle,\r
164 Status ));\r
165 }\r
166 }\r
167 }\r
168\r
169 //\r
170 // Disconnect the network services\r
171 //\r
172 if ( !EFI_ERROR ( Status )) {\r
173 EslServiceUnload ( );\r
174 }\r
175\r
176 //\r
177 // Return the unload status\r
178 //\r
179 return Status;\r
180}\r
181\r
182\r
183/**\r
184Socket driver entry point.\r
185\r
186@param [in] ImageHandle Handle for the image.\r
187@param [in] pSystemTable Address of the system table.\r
188\r
189@retval EFI_SUCCESS Image successfully loaded.\r
190\r
191**/\r
192EFI_STATUS\r
193EFIAPI\r
194EntryPoint (\r
195 IN EFI_HANDLE ImageHandle,\r
196 IN EFI_SYSTEM_TABLE * pSystemTable\r
197 )\r
198{\r
199 EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;\r
200 EFI_STATUS Status;\r
201\r
202 DBG_ENTER ( );\r
203\r
204 //\r
205 // Display the image handle\r
206 //\r
207 DEBUG (( DEBUG_INFO,\r
208 "ImageHandle: 0x%08x\r\n",\r
209 ImageHandle ));\r
210\r
211 //\r
212 // Enable unload support\r
213 //\r
214 Status = gBS->HandleProtocol (\r
215 gImageHandle,\r
216 &gEfiLoadedImageProtocolGuid,\r
217 (VOID **)&pLoadedImage\r
218 );\r
219 if (!EFI_ERROR (Status)) {\r
220 pLoadedImage->Unload = DriverUnload;\r
221\r
222 //\r
223 // Add the driver to the list of drivers\r
224 //\r
225 Status = EfiLibInstallDriverBindingComponentName2 (\r
226 ImageHandle,\r
227 pSystemTable,\r
228 &gDriverBinding,\r
229 ImageHandle,\r
230 &gComponentName,\r
231 &gComponentName2\r
232 );\r
233 if ( !EFI_ERROR ( Status )) {\r
234 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
235 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",\r
236 ImageHandle ));\r
237 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
238 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",\r
239 ImageHandle ));\r
240 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
241 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",\r
242 ImageHandle ));\r
243\r
244 //\r
245 // Initialize the service layer\r
246 //\r
247 EslServiceLoad ( ImageHandle );\r
248\r
249 //\r
250 // Make the socket serivces available to other drivers\r
251 // and applications\r
252 //\r
253 Status = EslServiceInstall ( &ImageHandle );\r
254 if ( EFI_ERROR ( Status )) {\r
255 //\r
256 // Disconnect from the network\r
257 //\r
258 EslServiceUnload ( );\r
259\r
260 //\r
261 // Remove the driver bindings\r
262 //\r
263 gBS->UninstallMultipleProtocolInterfaces (\r
264 ImageHandle,\r
265 &gEfiDriverBindingProtocolGuid,\r
266 &gDriverBinding,\r
267 &gEfiComponentNameProtocolGuid,\r
268 &gComponentName,\r
269 &gEfiComponentName2ProtocolGuid,\r
270 &gComponentName2,\r
271 NULL\r
272 );\r
273 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
274 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r
275 ImageHandle ));\r
276 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
277 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r
278 ImageHandle ));\r
279 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
280 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r
281 ImageHandle ));\r
282 }\r
283 }\r
284 else {\r
285 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
286 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",\r
287 Status ));\r
288 }\r
289 }\r
290 DBG_EXIT_STATUS ( Status );\r
291 return Status;\r
292}\r
293\r
294\r
295PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL;\r
296PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL;\r