]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/SocketDxe/EntryUnload.c
OvmfPkg: Fix GCC49 build hang in PeiCore
[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
a88c3163 18/**\r
19 The following GUID values are only used by the SocketDxe driver. An\r
20 alternative set of values exists in EfiSocketLib\UseEfiSocketLib.c\r
21 which an application uses when it links against EfiSocketLib. These\r
22 two sets of values allow the SocketDxe driver to coexist with socket\r
23 applications.\r
24\r
25 Tag GUID - IPv4 in use by SocketDxe\r
26**/\r
27CONST EFI_GUID mEslIp4ServiceGuid = {\r
28 0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }\r
d7ce7006 29};\r
30\r
a88c3163 31\r
3bdf9aae 32/**\r
33 Tag GUID - IPv6 in use by SocketDxe\r
34**/\r
35CONST EFI_GUID mEslIp6ServiceGuid = {\r
36 0x2fc3b2d3, 0x6eba, 0x42b0, { 0xa4, 0xa7, 0x14, 0xc7, 0xa8, 0x4b, 0x5d, 0x22 }\r
37};\r
38\r
39\r
a88c3163 40/**\r
41 Tag GUID - TCPv4 in use by SocketDxe\r
42**/\r
d7ce7006 43CONST EFI_GUID mEslTcp4ServiceGuid = {\r
3bdf9aae 44 0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }\r
45};\r
46\r
47\r
48/**\r
49 Tag GUID - TCPv6 in use by SocketDxe\r
50**/\r
51CONST EFI_GUID mEslTcp6ServiceGuid = {\r
52 0xdd455a69, 0xec75, 0x456c, { 0x84, 0xd2, 0x95, 0xca, 0xe7, 0xd3, 0xc6, 0xd3 }\r
d7ce7006 53};\r
54\r
a88c3163 55\r
56/**\r
57 Tag GUID - UDPv4 in use by SocketDxe\r
58**/\r
d7ce7006 59CONST EFI_GUID mEslUdp4ServiceGuid = {\r
3bdf9aae 60 0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }\r
61};\r
62\r
63\r
64/**\r
65 Tag GUID - UDPv6 in use by SocketDxe\r
66**/\r
67CONST EFI_GUID mEslUdp6ServiceGuid = {\r
68 0x32ff59cd, 0xc33, 0x48d0, { 0xa2, 0x44, 0x4b, 0xb8, 0x11, 0x33, 0x64, 0x3 }\r
d7ce7006 69};\r
70\r
71\r
72/**\r
73 Socket driver unload routine.\r
74\r
75 @param [in] ImageHandle Handle for the image.\r
76\r
77 @retval EFI_SUCCESS Image may be unloaded\r
78\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82DriverUnload (\r
83 IN EFI_HANDLE ImageHandle\r
84 )\r
85{\r
86 UINTN BufferSize;\r
87 UINTN Index;\r
88 UINTN Max;\r
89 EFI_HANDLE * pHandle;\r
90 EFI_STATUS Status;\r
91\r
92 //\r
93 // Determine which devices are using this driver\r
94 //\r
95 BufferSize = 0;\r
96 pHandle = NULL;\r
97 Status = gBS->LocateHandle (\r
98 ByProtocol,\r
99 &gEfiCallerIdGuid,\r
100 NULL,\r
101 &BufferSize,\r
102 NULL );\r
103 if ( EFI_BUFFER_TOO_SMALL == Status ) {\r
104 for ( ; ; ) {\r
105 //\r
106 // One or more block IO devices are present\r
107 //\r
108 Status = gBS->AllocatePool (\r
109 EfiRuntimeServicesData,\r
110 BufferSize,\r
111 (VOID **) &pHandle\r
112 );\r
113 if ( EFI_ERROR ( Status )) {\r
114 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
115 "Insufficient memory, failed handle buffer allocation\r\n" ));\r
116 break;\r
117 }\r
118\r
119 //\r
120 // Locate the block IO devices\r
121 //\r
122 Status = gBS->LocateHandle (\r
123 ByProtocol,\r
124 &gEfiCallerIdGuid,\r
125 NULL,\r
126 &BufferSize,\r
127 pHandle );\r
128 if ( EFI_ERROR ( Status )) {\r
129 //\r
130 // Error getting handles\r
131 //\r
132 DEBUG (( DEBUG_ERROR | DEBUG_INIT | DEBUG_INFO,\r
133 "Failure getting Telnet handles\r\n" ));\r
134 break;\r
135 }\r
136 \r
137 //\r
138 // Remove any use of the driver\r
139 //\r
140 Max = BufferSize / sizeof ( pHandle[ 0 ]);\r
141 for ( Index = 0; Max > Index; Index++ ) {\r
a88c3163 142 Status = DriverStop ( &mDriverBinding,\r
d7ce7006 143 pHandle[ Index ],\r
144 0,\r
145 NULL );\r
146 if ( EFI_ERROR ( Status )) {\r
147 DEBUG (( DEBUG_WARN | DEBUG_INIT | DEBUG_INFO,\r
148 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle[ Index ]));\r
149 break;\r
150 }\r
151 }\r
152 break;\r
153 }\r
154 }\r
155 else {\r
156 if ( EFI_NOT_FOUND == Status ) {\r
157 //\r
158 // No devices were found\r
159 //\r
160 Status = EFI_SUCCESS;\r
161 }\r
162 }\r
163\r
164 //\r
165 // Free the handle array\r
166 //\r
167 if ( NULL != pHandle ) {\r
168 gBS->FreePool ( pHandle );\r
169 }\r
170\r
171 //\r
172 // Done with the socket layer\r
173 //\r
174 if ( !EFI_ERROR ( Status )) {\r
a88c3163 175 Status = EslDxeUninstall ( ImageHandle );\r
d7ce7006 176 if ( !EFI_ERROR ( Status )) {\r
177 //\r
178 // Remove the protocols installed by the EntryPoint routine.\r
179 //\r
180 Status = gBS->UninstallMultipleProtocolInterfaces (\r
181 ImageHandle,\r
182 &gEfiDriverBindingProtocolGuid,\r
a88c3163 183 &mDriverBinding,\r
d7ce7006 184 &gEfiComponentNameProtocolGuid,\r
a88c3163 185 &mComponentName,\r
d7ce7006 186 &gEfiComponentName2ProtocolGuid,\r
a88c3163 187 &mComponentName2,\r
d7ce7006 188 NULL\r
189 );\r
190 if ( !EFI_ERROR ( Status )) {\r
191 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
192 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r
193 ImageHandle ));\r
194 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
195 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r
196 ImageHandle ));\r
197 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
198 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r
199 ImageHandle ));\r
200 }\r
201 else {\r
202 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
203 "ERROR - Failed to remove gEfiDriverBindingProtocolGuid from 0x%08x, Status: %r\r\n",\r
204 ImageHandle,\r
205 Status ));\r
206 }\r
207 }\r
208 }\r
209\r
210 //\r
211 // Disconnect the network services\r
212 //\r
213 if ( !EFI_ERROR ( Status )) {\r
214 EslServiceUnload ( );\r
215 }\r
216\r
217 //\r
218 // Return the unload status\r
219 //\r
220 return Status;\r
221}\r
222\r
223\r
224/**\r
225Socket driver entry point.\r
226\r
227@param [in] ImageHandle Handle for the image.\r
228@param [in] pSystemTable Address of the system table.\r
229\r
230@retval EFI_SUCCESS Image successfully loaded.\r
231\r
232**/\r
233EFI_STATUS\r
234EFIAPI\r
235EntryPoint (\r
236 IN EFI_HANDLE ImageHandle,\r
237 IN EFI_SYSTEM_TABLE * pSystemTable\r
238 )\r
239{\r
240 EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;\r
241 EFI_STATUS Status;\r
242\r
243 DBG_ENTER ( );\r
244\r
245 //\r
246 // Display the image handle\r
247 //\r
248 DEBUG (( DEBUG_INFO,\r
249 "ImageHandle: 0x%08x\r\n",\r
250 ImageHandle ));\r
251\r
252 //\r
253 // Enable unload support\r
254 //\r
255 Status = gBS->HandleProtocol (\r
256 gImageHandle,\r
257 &gEfiLoadedImageProtocolGuid,\r
258 (VOID **)&pLoadedImage\r
259 );\r
260 if (!EFI_ERROR (Status)) {\r
261 pLoadedImage->Unload = DriverUnload;\r
262\r
263 //\r
264 // Add the driver to the list of drivers\r
265 //\r
266 Status = EfiLibInstallDriverBindingComponentName2 (\r
267 ImageHandle,\r
268 pSystemTable,\r
a88c3163 269 &mDriverBinding,\r
d7ce7006 270 ImageHandle,\r
a88c3163 271 &mComponentName,\r
272 &mComponentName2\r
d7ce7006 273 );\r
274 if ( !EFI_ERROR ( Status )) {\r
275 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
276 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",\r
277 ImageHandle ));\r
278 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
279 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",\r
280 ImageHandle ));\r
281 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
282 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",\r
283 ImageHandle ));\r
284\r
285 //\r
286 // Initialize the service layer\r
287 //\r
288 EslServiceLoad ( ImageHandle );\r
289\r
290 //\r
291 // Make the socket serivces available to other drivers\r
292 // and applications\r
293 //\r
a88c3163 294 Status = EslDxeInstall ( &ImageHandle );\r
d7ce7006 295 if ( EFI_ERROR ( Status )) {\r
296 //\r
297 // Disconnect from the network\r
298 //\r
299 EslServiceUnload ( );\r
300\r
301 //\r
302 // Remove the driver bindings\r
303 //\r
304 gBS->UninstallMultipleProtocolInterfaces (\r
305 ImageHandle,\r
306 &gEfiDriverBindingProtocolGuid,\r
a88c3163 307 &mDriverBinding,\r
d7ce7006 308 &gEfiComponentNameProtocolGuid,\r
a88c3163 309 &mComponentName,\r
d7ce7006 310 &gEfiComponentName2ProtocolGuid,\r
a88c3163 311 &mComponentName2,\r
d7ce7006 312 NULL\r
313 );\r
314 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
315 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r
316 ImageHandle ));\r
317 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
318 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r
319 ImageHandle ));\r
320 DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r
321 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r
322 ImageHandle ));\r
323 }\r
324 }\r
325 else {\r
326 DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,\r
327 "ERROR - EfiLibInstallDriverBindingComponentName2 failed, Status: %r\r\n",\r
328 Status ));\r
329 }\r
330 }\r
331 DBG_EXIT_STATUS ( Status );\r
332 return Status;\r
333}\r
334\r
335\r
a88c3163 336/**\r
337 Socket layer's service binding protocol delcaration.\r
338**/\r
339CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {\r
340 EslDxeCreateChild,\r
341 EslDxeDestroyChild\r
342};\r
343\r
344\r
345/**\r
346 The following entries disable the constructor and destructor\r
347 for the SocketDxe driver. Note that socket applications linking\r
348 against EfiSocketLib use different redirection.\r
349**/\r
350PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL; ///< No EfiSocketLib constructor needed for SocketDxe\r
351PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL; ///< No EfiSocketLib destructor needed for SocketDxe\r