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