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