]>
Commit | Line | Data |
---|---|---|
7f556e4d | 1 | /** @file\r |
2 | Implement the driver binding protocol for Asix AX88772 Ethernet driver.\r | |
3 | \r | |
4986bbaf | 4 | Copyright (c) 2011-2013, Intel Corporation\r |
7f556e4d | 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 "Ax88772.h"\r | |
16 | \r | |
9a1c4bec SS |
17 | ASIX_DONGLE ASIX_DONGLES[] = {\r |
18 | { 0x05AC, 0x1402, FLAG_TYPE_AX88772 }, // Apple USB Ethernet Adapter\r | |
19 | // ASIX 88772B\r | |
20 | { 0x0B95, 0x772B, FLAG_TYPE_AX88772B | FLAG_EEPROM_MAC },\r | |
21 | { 0x0000, 0x0000, FLAG_NONE } // END - Do not remove\r | |
22 | };\r | |
23 | \r | |
7f556e4d | 24 | /**\r |
25 | Verify the controller type\r | |
26 | \r | |
27 | @param [in] pThis Protocol instance pointer.\r | |
28 | @param [in] Controller Handle of device to test.\r | |
29 | @param [in] pRemainingDevicePath Not used.\r | |
30 | \r | |
31 | @retval EFI_SUCCESS This driver supports this device.\r | |
32 | @retval other This driver does not support this device.\r | |
33 | \r | |
34 | **/\r | |
35 | EFI_STATUS\r | |
36 | EFIAPI\r | |
37 | DriverSupported (\r | |
38 | IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r | |
39 | IN EFI_HANDLE Controller,\r | |
40 | IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath\r | |
41 | )\r | |
42 | {\r | |
43 | EFI_USB_DEVICE_DESCRIPTOR Device;\r | |
44 | EFI_USB_IO_PROTOCOL * pUsbIo;\r | |
45 | EFI_STATUS Status;\r | |
9a1c4bec SS |
46 | UINT32 Index;\r |
47 | \r | |
7f556e4d | 48 | //\r |
49 | // Connect to the USB stack\r | |
50 | //\r | |
51 | Status = gBS->OpenProtocol (\r | |
52 | Controller,\r | |
53 | &gEfiUsbIoProtocolGuid,\r | |
54 | (VOID **) &pUsbIo,\r | |
55 | pThis->DriverBindingHandle, \r | |
56 | Controller,\r | |
57 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
58 | );\r | |
59 | if (!EFI_ERROR ( Status )) {\r | |
60 | \r | |
61 | //\r | |
62 | // Get the interface descriptor to check the USB class and find a transport\r | |
63 | // protocol handler.\r | |
64 | //\r | |
65 | Status = pUsbIo->UsbGetDeviceDescriptor ( pUsbIo, &Device );\r | |
66 | if (EFI_ERROR ( Status )) {\r | |
67 | Status = EFI_UNSUPPORTED;\r | |
68 | }\r | |
69 | else {\r | |
70 | //\r | |
71 | // Validate the adapter\r | |
9a1c4bec SS |
72 | //\r |
73 | for (Index = 0; ASIX_DONGLES[Index].VendorId != 0; Index++) {\r | |
74 | if (ASIX_DONGLES[Index].VendorId == Device.IdVendor &&\r | |
75 | ASIX_DONGLES[Index].ProductId == Device.IdProduct) {\r | |
76 | DEBUG ((EFI_D_INFO, "Found the AX88772B\r\n"));\r | |
77 | break;\r | |
7f556e4d | 78 | }\r |
7f556e4d | 79 | }\r |
9a1c4bec SS |
80 | \r |
81 | if (ASIX_DONGLES[Index].VendorId == 0)\r | |
82 | Status = EFI_UNSUPPORTED;\r | |
7f556e4d | 83 | }\r |
84 | \r | |
85 | //\r | |
86 | // Done with the USB stack\r | |
87 | //\r | |
88 | gBS->CloseProtocol (\r | |
89 | Controller,\r | |
90 | &gEfiUsbIoProtocolGuid,\r | |
91 | pThis->DriverBindingHandle,\r | |
92 | Controller\r | |
93 | );\r | |
94 | }\r | |
95 | return Status;\r | |
96 | }\r | |
97 | \r | |
98 | \r | |
99 | /**\r | |
100 | Start this driver on Controller by opening UsbIo and DevicePath protocols.\r | |
101 | Initialize PXE structures, create a copy of the Controller Device Path with the\r | |
102 | NIC's MAC address appended to it, install the NetworkInterfaceIdentifier protocol\r | |
103 | on the newly created Device Path.\r | |
104 | \r | |
105 | @param [in] pThis Protocol instance pointer.\r | |
106 | @param [in] Controller Handle of device to work with.\r | |
107 | @param [in] pRemainingDevicePath Not used, always produce all possible children.\r | |
108 | \r | |
109 | @retval EFI_SUCCESS This driver is added to Controller.\r | |
110 | @retval other This driver does not support this device.\r | |
111 | \r | |
112 | **/\r | |
113 | EFI_STATUS\r | |
114 | EFIAPI\r | |
115 | DriverStart (\r | |
116 | IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r | |
117 | IN EFI_HANDLE Controller,\r | |
118 | IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath\r | |
119 | )\r | |
120 | {\r | |
121 | \r | |
122 | EFI_STATUS Status;\r | |
123 | NIC_DEVICE *pNicDevice;\r | |
124 | UINTN LengthInBytes;\r | |
125 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath = NULL;\r | |
126 | MAC_ADDR_DEVICE_PATH MacDeviceNode;\r | |
7361d3ff SS |
127 | EFI_USB_DEVICE_DESCRIPTOR Device;\r |
128 | UINT32 Index;\r | |
7f556e4d | 129 | \r |
130 | //\r | |
131 | // Allocate the device structure\r | |
132 | //\r | |
133 | LengthInBytes = sizeof ( *pNicDevice );\r | |
134 | Status = gBS->AllocatePool (\r | |
135 | EfiRuntimeServicesData,\r | |
136 | LengthInBytes,\r | |
137 | (VOID **) &pNicDevice\r | |
138 | );\r | |
139 | \r | |
140 | if (EFI_ERROR (Status)) {\r | |
141 | DEBUG ((EFI_D_ERROR, "gBS->AllocatePool:pNicDevice ERROR Status = %r\n", Status));\r | |
142 | goto EXIT;\r | |
143 | }\r | |
144 | \r | |
145 | //\r | |
146 | // Set the structure signature\r | |
147 | //\r | |
148 | ZeroMem ( pNicDevice, LengthInBytes );\r | |
149 | pNicDevice->Signature = DEV_SIGNATURE;\r | |
150 | \r | |
151 | Status = gBS->OpenProtocol (\r | |
152 | Controller,\r | |
153 | &gEfiUsbIoProtocolGuid,\r | |
154 | (VOID **) &pNicDevice->pUsbIo,\r | |
155 | pThis->DriverBindingHandle,\r | |
156 | Controller,\r | |
157 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
158 | );\r | |
159 | \r | |
160 | if (EFI_ERROR (Status)) {\r | |
161 | DEBUG ((EFI_D_ERROR, "gBS->OpenProtocol:EFI_USB_IO_PROTOCOL ERROR Status = %r\n", Status));\r | |
162 | gBS->FreePool ( pNicDevice );\r | |
163 | goto EXIT;\r | |
164 | }\r | |
165 | \r | |
166 | //\r | |
167 | // Initialize the simple network protocol\r | |
168 | //\r | |
169 | Status = SN_Setup ( pNicDevice );\r | |
170 | \r | |
171 | if (EFI_ERROR(Status)){\r | |
172 | DEBUG ((EFI_D_ERROR, "SN_Setup ERROR Status = %r\n", Status));\r | |
173 | gBS->CloseProtocol (\r | |
174 | Controller,\r | |
175 | &gEfiUsbIoProtocolGuid,\r | |
176 | pThis->DriverBindingHandle,\r | |
177 | Controller\r | |
178 | );\r | |
179 | gBS->FreePool ( pNicDevice );\r | |
180 | goto EXIT;\r | |
181 | }\r | |
182 | \r | |
7361d3ff SS |
183 | Status = pNicDevice->pUsbIo->UsbGetDeviceDescriptor ( pNicDevice->pUsbIo, &Device );\r |
184 | if (EFI_ERROR ( Status )) {\r | |
185 | gBS->CloseProtocol (\r | |
186 | Controller,\r | |
187 | &gEfiUsbIoProtocolGuid,\r | |
188 | pThis->DriverBindingHandle,\r | |
189 | Controller\r | |
190 | );\r | |
191 | gBS->FreePool ( pNicDevice );\r | |
192 | goto EXIT;\r | |
193 | } else {\r | |
194 | //\r | |
195 | // Validate the adapter\r | |
196 | //\r | |
197 | for (Index = 0; ASIX_DONGLES[Index].VendorId != 0; Index++) {\r | |
198 | if (ASIX_DONGLES[Index].VendorId == Device.IdVendor &&\r | |
199 | ASIX_DONGLES[Index].ProductId == Device.IdProduct) {\r | |
200 | break;\r | |
201 | }\r | |
202 | }\r | |
203 | \r | |
204 | if (ASIX_DONGLES[Index].VendorId == 0) {\r | |
205 | gBS->CloseProtocol (\r | |
206 | Controller,\r | |
207 | &gEfiUsbIoProtocolGuid,\r | |
208 | pThis->DriverBindingHandle,\r | |
209 | Controller\r | |
210 | );\r | |
211 | gBS->FreePool ( pNicDevice );\r | |
212 | goto EXIT;\r | |
213 | }\r | |
214 | \r | |
215 | pNicDevice->Flags = ASIX_DONGLES[Index].Flags;\r | |
216 | }\r | |
217 | \r | |
7f556e4d | 218 | //\r |
219 | // Set Device Path\r | |
220 | // \r | |
221 | Status = gBS->OpenProtocol (\r | |
222 | Controller,\r | |
223 | &gEfiDevicePathProtocolGuid,\r | |
224 | (VOID **) &ParentDevicePath,\r | |
225 | pThis->DriverBindingHandle,\r | |
226 | Controller,\r | |
227 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
228 | );\r | |
229 | if (EFI_ERROR(Status)) {\r | |
230 | DEBUG ((EFI_D_ERROR, "gBS->OpenProtocol:EFI_DEVICE_PATH_PROTOCOL error. Status = %r\n",\r | |
231 | Status)); \r | |
232 | gBS->CloseProtocol (\r | |
233 | Controller,\r | |
234 | &gEfiUsbIoProtocolGuid,\r | |
235 | pThis->DriverBindingHandle,\r | |
236 | Controller\r | |
237 | );\r | |
238 | gBS->FreePool ( pNicDevice );\r | |
239 | goto EXIT;\r | |
240 | }\r | |
241 | \r | |
242 | ZeroMem (&MacDeviceNode, sizeof (MAC_ADDR_DEVICE_PATH));\r | |
243 | MacDeviceNode.Header.Type = MESSAGING_DEVICE_PATH;\r | |
244 | MacDeviceNode.Header.SubType = MSG_MAC_ADDR_DP;\r | |
245 | \r | |
246 | SetDevicePathNodeLength (&MacDeviceNode.Header, sizeof (MAC_ADDR_DEVICE_PATH));\r | |
247 | \r | |
248 | CopyMem (&MacDeviceNode.MacAddress,\r | |
249 | &pNicDevice->SimpleNetworkData.CurrentAddress,\r | |
250 | PXE_HWADDR_LEN_ETHER);\r | |
251 | \r | |
252 | MacDeviceNode.IfType = pNicDevice->SimpleNetworkData.IfType;\r | |
253 | \r | |
254 | pNicDevice->MyDevPath = AppendDevicePathNode (\r | |
255 | ParentDevicePath,\r | |
256 | (EFI_DEVICE_PATH_PROTOCOL *) &MacDeviceNode\r | |
257 | );\r | |
258 | \r | |
259 | pNicDevice->Controller = NULL;\r | |
260 | \r | |
261 | //\r | |
262 | // Install both the simple network and device path protocols.\r | |
263 | //\r | |
264 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
265 | &pNicDevice->Controller,\r | |
266 | &gEfiCallerIdGuid,\r | |
267 | pNicDevice,\r | |
268 | &gEfiSimpleNetworkProtocolGuid, \r | |
269 | &pNicDevice->SimpleNetwork,\r | |
270 | &gEfiDevicePathProtocolGuid,\r | |
271 | pNicDevice->MyDevPath,\r | |
272 | NULL\r | |
273 | );\r | |
274 | \r | |
275 | if (EFI_ERROR(Status)){\r | |
276 | DEBUG ((EFI_D_ERROR, "gBS->InstallMultipleProtocolInterfaces error. Status = %r\n",\r | |
277 | Status)); \r | |
278 | gBS->CloseProtocol (\r | |
279 | Controller,\r | |
280 | &gEfiDevicePathProtocolGuid,\r | |
281 | pThis->DriverBindingHandle,\r | |
282 | Controller);\r | |
283 | gBS->CloseProtocol (\r | |
284 | Controller,\r | |
285 | &gEfiUsbIoProtocolGuid,\r | |
286 | pThis->DriverBindingHandle,\r | |
287 | Controller\r | |
288 | );\r | |
289 | gBS->FreePool ( pNicDevice );\r | |
290 | goto EXIT;\r | |
291 | }\r | |
292 | \r | |
293 | //\r | |
294 | // Open For Child Device\r | |
295 | //\r | |
296 | Status = gBS->OpenProtocol ( \r | |
297 | Controller,\r | |
298 | &gEfiUsbIoProtocolGuid,\r | |
299 | (VOID **) &pNicDevice->pUsbIo,\r | |
300 | pThis->DriverBindingHandle,\r | |
301 | pNicDevice->Controller,\r | |
302 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
303 | );\r | |
304 | \r | |
305 | if (EFI_ERROR(Status)){\r | |
306 | gBS->UninstallMultipleProtocolInterfaces (\r | |
307 | &pNicDevice->Controller,\r | |
308 | &gEfiCallerIdGuid,\r | |
309 | pNicDevice,\r | |
310 | &gEfiSimpleNetworkProtocolGuid, \r | |
311 | &pNicDevice->SimpleNetwork,\r | |
312 | &gEfiDevicePathProtocolGuid,\r | |
313 | pNicDevice->MyDevPath,\r | |
314 | NULL\r | |
315 | );\r | |
316 | gBS->CloseProtocol (\r | |
317 | Controller,\r | |
318 | &gEfiDevicePathProtocolGuid,\r | |
319 | pThis->DriverBindingHandle,\r | |
320 | Controller);\r | |
321 | gBS->CloseProtocol (\r | |
322 | Controller,\r | |
323 | &gEfiUsbIoProtocolGuid,\r | |
324 | pThis->DriverBindingHandle,\r | |
325 | Controller\r | |
326 | );\r | |
327 | gBS->FreePool ( pNicDevice );\r | |
328 | }\r | |
329 | \r | |
330 | EXIT:\r | |
331 | return Status;\r | |
332 | \r | |
333 | }\r | |
334 | \r | |
335 | /**\r | |
336 | Stop this driver on Controller by removing NetworkInterfaceIdentifier protocol and\r | |
337 | closing the DevicePath and PciIo protocols on Controller.\r | |
338 | \r | |
339 | @param [in] pThis Protocol instance pointer.\r | |
340 | @param [in] Controller Handle of device to stop driver on.\r | |
341 | @param [in] NumberOfChildren How many children need to be stopped.\r | |
342 | @param [in] pChildHandleBuffer Not used.\r | |
343 | \r | |
344 | @retval EFI_SUCCESS This driver is removed Controller.\r | |
345 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
346 | @retval other This driver was not removed from this device.\r | |
347 | \r | |
348 | **/\r | |
349 | EFI_STATUS\r | |
350 | EFIAPI\r | |
351 | DriverStop (\r | |
352 | IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r | |
353 | IN EFI_HANDLE Controller,\r | |
354 | IN UINTN NumberOfChildren,\r | |
355 | IN EFI_HANDLE * ChildHandleBuffer\r | |
356 | )\r | |
357 | {\r | |
358 | BOOLEAN AllChildrenStopped;\r | |
359 | UINTN Index;\r | |
360 | EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork;\r | |
361 | EFI_STATUS Status = EFI_SUCCESS;\r | |
362 | NIC_DEVICE *pNicDevice;\r | |
363 | \r | |
364 | //\r | |
365 | // Complete all outstanding transactions to Controller.\r | |
366 | // Don't allow any new transaction to Controller to be started.\r | |
367 | //\r | |
368 | if (NumberOfChildren == 0) {\r | |
369 | \r | |
370 | Status = gBS->OpenProtocol (\r | |
371 | Controller,\r | |
372 | &gEfiSimpleNetworkProtocolGuid,\r | |
373 | (VOID **) &SimpleNetwork,\r | |
374 | pThis->DriverBindingHandle,\r | |
375 | Controller,\r | |
376 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
377 | );\r | |
378 | \r | |
379 | if (EFI_ERROR(Status)) {\r | |
380 | //\r | |
381 | // This is a 2nd type handle(multi-lun root), it needs to close devicepath\r | |
382 | // and usbio protocol.\r | |
383 | //\r | |
384 | gBS->CloseProtocol (\r | |
385 | Controller,\r | |
386 | &gEfiDevicePathProtocolGuid,\r | |
387 | pThis->DriverBindingHandle,\r | |
388 | Controller\r | |
389 | );\r | |
390 | gBS->CloseProtocol (\r | |
391 | Controller,\r | |
392 | &gEfiUsbIoProtocolGuid,\r | |
393 | pThis->DriverBindingHandle,\r | |
394 | Controller\r | |
395 | );\r | |
396 | return EFI_SUCCESS;\r | |
397 | }\r | |
398 | \r | |
399 | pNicDevice = DEV_FROM_SIMPLE_NETWORK ( SimpleNetwork );\r | |
400 | \r | |
401 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
402 | Controller, \r | |
403 | &gEfiCallerIdGuid,\r | |
404 | pNicDevice,\r | |
405 | &gEfiSimpleNetworkProtocolGuid, \r | |
406 | &pNicDevice->SimpleNetwork,\r | |
407 | &gEfiDevicePathProtocolGuid,\r | |
408 | pNicDevice->MyDevPath,\r | |
409 | NULL\r | |
410 | );\r | |
411 | \r | |
412 | if (EFI_ERROR (Status)) {\r | |
413 | return Status;\r | |
414 | }\r | |
415 | //\r | |
416 | // Close the bus driver\r | |
417 | //\r | |
418 | Status = gBS->CloseProtocol (\r | |
419 | Controller,\r | |
420 | &gEfiDevicePathProtocolGuid,\r | |
421 | pThis->DriverBindingHandle,\r | |
422 | Controller\r | |
423 | );\r | |
424 | \r | |
425 | if (EFI_ERROR(Status)){\r | |
426 | DEBUG ((EFI_D_ERROR, "driver stop: gBS->CloseProtocol:EfiDevicePathProtocol error. Status %r\n", Status));\r | |
427 | }\r | |
428 | \r | |
429 | Status = gBS->CloseProtocol (\r | |
430 | Controller,\r | |
431 | &gEfiUsbIoProtocolGuid,\r | |
432 | pThis->DriverBindingHandle,\r | |
433 | Controller\r | |
434 | );\r | |
435 | \r | |
436 | if (EFI_ERROR(Status)){\r | |
437 | DEBUG ((EFI_D_ERROR, "driver stop: gBS->CloseProtocol:EfiUsbIoProtocol error. Status %r\n", Status));\r | |
438 | }\r | |
439 | return EFI_SUCCESS;\r | |
440 | } \r | |
441 | AllChildrenStopped = TRUE;\r | |
442 | \r | |
443 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
444 | \r | |
445 | Status = gBS->OpenProtocol (\r | |
446 | ChildHandleBuffer[Index],\r | |
447 | &gEfiSimpleNetworkProtocolGuid,\r | |
448 | (VOID **) &SimpleNetwork,\r | |
449 | pThis->DriverBindingHandle,\r | |
450 | Controller,\r | |
451 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
452 | );\r | |
453 | \r | |
454 | if (EFI_ERROR (Status)) {\r | |
455 | AllChildrenStopped = FALSE;\r | |
456 | DEBUG ((EFI_D_ERROR, "Fail to stop No.%d multi-lun child handle when opening SimpleNetwork\n", (UINT32)Index));\r | |
457 | continue;\r | |
458 | } \r | |
459 | \r | |
460 | pNicDevice = DEV_FROM_SIMPLE_NETWORK ( SimpleNetwork );\r | |
461 | \r | |
462 | gBS->CloseProtocol (\r | |
463 | Controller,\r | |
464 | &gEfiUsbIoProtocolGuid,\r | |
465 | pThis->DriverBindingHandle,\r | |
466 | ChildHandleBuffer[Index]\r | |
467 | ); \r | |
468 | \r | |
469 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
470 | ChildHandleBuffer[Index], \r | |
471 | &gEfiCallerIdGuid,\r | |
472 | pNicDevice,\r | |
473 | &gEfiSimpleNetworkProtocolGuid, \r | |
474 | &pNicDevice->SimpleNetwork,\r | |
475 | &gEfiDevicePathProtocolGuid,\r | |
476 | pNicDevice->MyDevPath,\r | |
477 | NULL\r | |
478 | );\r | |
479 | \r | |
480 | if (EFI_ERROR (Status)) {\r | |
481 | Status = gBS->OpenProtocol ( \r | |
482 | Controller,\r | |
483 | &gEfiUsbIoProtocolGuid,\r | |
484 | (VOID **) &pNicDevice->pUsbIo,\r | |
485 | pThis->DriverBindingHandle,\r | |
486 | ChildHandleBuffer[Index],\r | |
487 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
488 | );\r | |
489 | }\r | |
490 | else {\r | |
491 | int i;\r | |
492 | RX_PKT * pCurr = pNicDevice->QueueHead;\r | |
493 | RX_PKT * pFree;\r | |
494 | \r | |
495 | for ( i = 0 ; i < MAX_QUEUE_SIZE ; i++) {\r | |
496 | if ( NULL != pCurr ) {\r | |
497 | pFree = pCurr;\r | |
498 | pCurr = pCurr->pNext;\r | |
499 | gBS->FreePool (pFree);\r | |
500 | }\r | |
501 | }\r | |
502 | \r | |
503 | if ( NULL != pNicDevice->pRxTest)\r | |
504 | gBS->FreePool (pNicDevice->pRxTest);\r | |
505 | \r | |
506 | if ( NULL != pNicDevice->pTxTest)\r | |
507 | gBS->FreePool (pNicDevice->pTxTest);\r | |
508 | \r | |
509 | if ( NULL != pNicDevice->MyDevPath)\r | |
510 | gBS->FreePool (pNicDevice->MyDevPath);\r | |
511 | \r | |
512 | if ( NULL != pNicDevice)\r | |
513 | gBS->FreePool (pNicDevice);\r | |
514 | }\r | |
515 | }\r | |
516 | \r | |
517 | if (!AllChildrenStopped) {\r | |
518 | return EFI_DEVICE_ERROR;\r | |
519 | }\r | |
520 | return EFI_SUCCESS;\r | |
521 | }\r | |
522 | \r | |
523 | \r | |
524 | /**\r | |
525 | Driver binding protocol declaration\r | |
526 | **/\r | |
527 | EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {\r | |
528 | DriverSupported,\r | |
529 | DriverStart,\r | |
530 | DriverStop,\r | |
531 | 0xa,\r | |
532 | NULL,\r | |
533 | NULL\r | |
534 | };\r | |
535 | \r | |
536 | \r | |
537 | /**\r | |
538 | Ax88772 driver unload routine.\r | |
539 | \r | |
540 | @param [in] ImageHandle Handle for the image.\r | |
541 | \r | |
542 | @retval EFI_SUCCESS Image may be unloaded\r | |
543 | \r | |
544 | **/\r | |
545 | EFI_STATUS\r | |
546 | EFIAPI\r | |
547 | DriverUnload (\r | |
548 | IN EFI_HANDLE ImageHandle\r | |
549 | )\r | |
550 | {\r | |
551 | UINTN BufferSize;\r | |
552 | UINTN Index;\r | |
553 | UINTN Max;\r | |
554 | EFI_HANDLE * pHandle;\r | |
555 | EFI_STATUS Status;\r | |
556 | \r | |
557 | //\r | |
558 | // Determine which devices are using this driver\r | |
559 | //\r | |
560 | BufferSize = 0;\r | |
561 | pHandle = NULL;\r | |
562 | Status = gBS->LocateHandle (\r | |
563 | ByProtocol,\r | |
564 | &gEfiCallerIdGuid,\r | |
565 | NULL,\r | |
566 | &BufferSize,\r | |
567 | NULL );\r | |
568 | if ( EFI_BUFFER_TOO_SMALL == Status ) {\r | |
569 | for ( ; ; ) {\r | |
570 | //\r | |
571 | // One or more block IO devices are present\r | |
572 | //\r | |
573 | Status = gBS->AllocatePool (\r | |
574 | EfiRuntimeServicesData,\r | |
575 | BufferSize,\r | |
576 | (VOID **) &pHandle\r | |
577 | );\r | |
578 | if ( EFI_ERROR ( Status )) {\r | |
579 | DEBUG ((EFI_D_ERROR, "Insufficient memory, failed handle buffer allocation\r\n"));\r | |
580 | break;\r | |
581 | }\r | |
582 | \r | |
583 | //\r | |
584 | // Locate the block IO devices\r | |
585 | //\r | |
586 | Status = gBS->LocateHandle (\r | |
587 | ByProtocol,\r | |
588 | &gEfiCallerIdGuid,\r | |
589 | NULL,\r | |
590 | &BufferSize,\r | |
591 | pHandle );\r | |
592 | if ( EFI_ERROR ( Status )) {\r | |
593 | //\r | |
594 | // Error getting handles\r | |
595 | //\r | |
596 | break;\r | |
597 | }\r | |
598 | \r | |
599 | //\r | |
600 | // Remove any use of the driver\r | |
601 | //\r | |
602 | Max = BufferSize / sizeof ( pHandle[ 0 ]);\r | |
603 | for ( Index = 0; Max > Index; Index++ ) {\r | |
604 | Status = DriverStop ( &gDriverBinding,\r | |
605 | pHandle[ Index ],\r | |
606 | 0,\r | |
607 | NULL );\r | |
608 | if ( EFI_ERROR ( Status )) {\r | |
609 | DEBUG ((EFI_D_ERROR, "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle[ Index ]));\r | |
610 | break;\r | |
611 | }\r | |
612 | }\r | |
613 | break;\r | |
614 | }\r | |
615 | }\r | |
616 | else {\r | |
617 | if ( EFI_NOT_FOUND == Status ) {\r | |
618 | //\r | |
619 | // No devices were found\r | |
620 | //\r | |
621 | Status = EFI_SUCCESS;\r | |
622 | }\r | |
623 | }\r | |
624 | \r | |
625 | //\r | |
626 | // Free the handle array \r | |
627 | //\r | |
628 | if ( NULL != pHandle ) {\r | |
629 | gBS->FreePool ( pHandle );\r | |
630 | }\r | |
631 | \r | |
632 | //\r | |
633 | // Remove the protocols installed by the EntryPoint routine.\r | |
634 | //\r | |
635 | if ( !EFI_ERROR ( Status )) {\r | |
636 | gBS->UninstallMultipleProtocolInterfaces (\r | |
637 | ImageHandle,\r | |
638 | &gEfiDriverBindingProtocolGuid,\r | |
639 | &gDriverBinding, \r | |
640 | &gEfiComponentNameProtocolGuid,\r | |
641 | &gComponentName,\r | |
642 | &gEfiComponentName2ProtocolGuid,\r | |
643 | &gComponentName2,\r | |
644 | NULL\r | |
645 | );\r | |
646 | \r | |
647 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
648 | "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",\r | |
649 | ImageHandle ));\r | |
650 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
651 | "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",\r | |
652 | ImageHandle ));\r | |
653 | DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,\r | |
654 | "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",\r | |
655 | ImageHandle ));\r | |
656 | \r | |
657 | }\r | |
658 | \r | |
659 | return Status;\r | |
660 | }\r | |
661 | \r | |
662 | \r | |
663 | /**\r | |
664 | Ax88772 driver entry point.\r | |
665 | \r | |
666 | @param [in] ImageHandle Handle for the image.\r | |
667 | @param [in] pSystemTable Address of the system table.\r | |
668 | \r | |
669 | @retval EFI_SUCCESS Image successfully loaded.\r | |
670 | \r | |
671 | **/\r | |
672 | EFI_STATUS\r | |
673 | EFIAPI\r | |
674 | EntryPoint (\r | |
675 | IN EFI_HANDLE ImageHandle,\r | |
676 | IN EFI_SYSTEM_TABLE * pSystemTable\r | |
677 | )\r | |
678 | {\r | |
7f556e4d | 679 | EFI_STATUS Status;\r |
680 | \r | |
7f556e4d | 681 | //\r |
682 | // Add the driver to the list of drivers\r | |
683 | //\r | |
684 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
685 | ImageHandle,\r | |
686 | pSystemTable,\r | |
687 | &gDriverBinding,\r | |
688 | ImageHandle,\r | |
689 | &gComponentName,\r | |
690 | &gComponentName2\r | |
691 | );\r | |
692 | if ( !EFI_ERROR ( Status )) {\r | |
4986bbaf YP |
693 | DEBUG ((EFI_D_INFO, "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",\r |
694 | ImageHandle));\r | |
695 | DEBUG ((EFI_D_INFO, "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",\r | |
696 | ImageHandle));\r | |
697 | DEBUG ((EFI_D_INFO,"Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",\r | |
698 | ImageHandle ));\r | |
7f556e4d | 699 | \r |
700 | }\r | |
701 | return Status;\r | |
702 | }\r |