2 Implement the driver binding protocol for Asix AX88772 Ethernet driver.
4 Copyright (c) 2011-2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 Verify the controller type
14 @param [in] pThis Protocol instance pointer.
15 @param [in] Controller Handle of device to test.
16 @param [in] pRemainingDevicePath Not used.
18 @retval EFI_SUCCESS This driver supports this device.
19 @retval other This driver does not support this device.
25 IN EFI_DRIVER_BINDING_PROTOCOL
* pThis
,
26 IN EFI_HANDLE Controller
,
27 IN EFI_DEVICE_PATH_PROTOCOL
* pRemainingDevicePath
30 EFI_USB_DEVICE_DESCRIPTOR Device
;
31 EFI_USB_IO_PROTOCOL
* pUsbIo
;
35 // Connect to the USB stack
37 Status
= gBS
->OpenProtocol (
39 &gEfiUsbIoProtocolGuid
,
41 pThis
->DriverBindingHandle
,
43 EFI_OPEN_PROTOCOL_BY_DRIVER
45 if (!EFI_ERROR ( Status
)) {
48 // Get the interface descriptor to check the USB class and find a transport
51 Status
= pUsbIo
->UsbGetDeviceDescriptor ( pUsbIo
, &Device
);
52 if (!EFI_ERROR ( Status
)) {
55 // Validate the adapter
57 if (( VENDOR_ID
!= Device
.IdVendor
)
58 || ( PRODUCT_ID
!= Device
.IdProduct
)) {
59 Status
= EFI_UNSUPPORTED
;
64 // Done with the USB stack
68 &gEfiUsbIoProtocolGuid
,
69 pThis
->DriverBindingHandle
,
75 // Return the device supported status
82 Start this driver on Controller by opening UsbIo and DevicePath protocols.
83 Initialize PXE structures, create a copy of the Controller Device Path with the
84 NIC's MAC address appended to it, install the NetworkInterfaceIdentifier protocol
85 on the newly created Device Path.
87 @param [in] pThis Protocol instance pointer.
88 @param [in] Controller Handle of device to work with.
89 @param [in] pRemainingDevicePath Not used, always produce all possible children.
91 @retval EFI_SUCCESS This driver is added to Controller.
92 @retval other This driver does not support this device.
98 IN EFI_DRIVER_BINDING_PROTOCOL
* pThis
,
99 IN EFI_HANDLE Controller
,
100 IN EFI_DEVICE_PATH_PROTOCOL
* pRemainingDevicePath
104 NIC_DEVICE
* pNicDevice
;
110 // Allocate the device structure
112 LengthInBytes
= sizeof ( *pNicDevice
);
113 Status
= gBS
->AllocatePool (
114 EfiRuntimeServicesData
,
116 (VOID
**) &pNicDevice
118 if ( !EFI_ERROR ( Status
)) {
119 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
120 "0x%08x: Allocate pNicDevice, %d bytes\r\n",
122 sizeof ( *pNicDevice
)));
125 // Set the structure signature
127 ZeroMem ( pNicDevice
, LengthInBytes
);
128 pNicDevice
->Signature
= DEV_SIGNATURE
;
131 // Connect to the USB I/O protocol
133 Status
= gBS
->OpenProtocol (
135 &gEfiUsbIoProtocolGuid
,
136 (VOID
**) &pNicDevice
->pUsbIo
,
137 pThis
->DriverBindingHandle
,
139 EFI_OPEN_PROTOCOL_BY_DRIVER
142 if ( !EFI_ERROR ( Status
)) {
144 // Allocate the necessary events
146 Status
= gBS
->CreateEvent ( EVT_TIMER
,
148 (EFI_EVENT_NOTIFY
)Ax88772Timer
,
150 (VOID
**)&pNicDevice
->Timer
);
151 if ( !EFI_ERROR ( Status
)) {
152 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
153 "0x%08x: Allocated timer\r\n",
154 pNicDevice
->Timer
));
157 // Initialize the simple network protocol
159 pNicDevice
->Controller
= Controller
;
160 SN_Setup ( pNicDevice
);
165 Status
= gBS
->SetTimer ( pNicDevice
->Timer
,
168 if ( !EFI_ERROR ( Status
)) {
170 // Install both the simple network and device path protocols.
172 Status
= gBS
->InstallMultipleProtocolInterfaces (
176 &gEfiSimpleNetworkProtocolGuid
,
177 &pNicDevice
->SimpleNetwork
,
181 if ( !EFI_ERROR ( Status
)) {
182 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
183 "Installed: gEfiCallerIdGuid on 0x%08x\r\n",
185 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
186 "Installed: gEfiSimpleNetworkProtocolGuid on 0x%08x\r\n",
188 DBG_EXIT_STATUS ( Status
);
191 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
192 "ERROR - Failed to install gEfiSimpleNetworkProtocol on 0x%08x\r\n",
196 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
197 "ERROR - Failed to start the timer, Status: %r\r\n",
202 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
203 "ERROR - Failed to create timer event, Status: %r\r\n",
208 // Done with the USB stack
212 &gEfiUsbIoProtocolGuid
,
213 pThis
->DriverBindingHandle
,
219 // Done with the device
221 gBS
->FreePool ( pNicDevice
);
225 // Display the driver start status
227 DBG_EXIT_STATUS ( Status
);
233 Stop this driver on Controller by removing NetworkInterfaceIdentifier protocol and
234 closing the DevicePath and PciIo protocols on Controller.
236 @param [in] pThis Protocol instance pointer.
237 @param [in] Controller Handle of device to stop driver on.
238 @param [in] NumberOfChildren How many children need to be stopped.
239 @param [in] pChildHandleBuffer Not used.
241 @retval EFI_SUCCESS This driver is removed Controller.
242 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
243 @retval other This driver was not removed from this device.
249 IN EFI_DRIVER_BINDING_PROTOCOL
* pThis
,
250 IN EFI_HANDLE Controller
,
251 IN UINTN NumberOfChildren
,
252 IN EFI_HANDLE
* pChildHandleBuffer
255 NIC_DEVICE
* pNicDevice
;
261 // Determine if this driver is already attached
263 Status
= gBS
->OpenProtocol (
266 (VOID
**) &pNicDevice
,
267 pThis
->DriverBindingHandle
,
269 EFI_OPEN_PROTOCOL_GET_PROTOCOL
271 if ( !EFI_ERROR ( Status
)) {
273 // AX88772 driver is no longer running on this device
275 gBS
->UninstallMultipleProtocolInterfaces (
277 &gEfiSimpleNetworkProtocolGuid
,
278 &pNicDevice
->SimpleNetwork
,
282 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
283 "Removed: gEfiSimpleNetworkProtocolGuid from 0x%08x\r\n",
285 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
286 "Removed: gEfiCallerIdGuid from 0x%08x\r\n",
292 if ( NULL
!= pNicDevice
->Timer
) {
293 gBS
->SetTimer ( pNicDevice
->Timer
, TimerCancel
, 0 );
294 gBS
->CloseEvent ( pNicDevice
->Timer
);
295 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
296 "0x%08x: Released timer\r\n",
297 pNicDevice
->Timer
));
301 // Done with the device context
303 DEBUG (( DEBUG_POOL
| DEBUG_INIT
,
304 "0x%08x: Free pNicDevice, %d bytes\r\n",
306 sizeof ( *pNicDevice
)));
307 gBS
->FreePool ( pNicDevice
);
311 // Return the shutdown status
313 DBG_EXIT_STATUS ( Status
);
319 Driver binding protocol declaration
321 EFI_DRIVER_BINDING_PROTOCOL gDriverBinding
= {
332 Ax88772 driver unload routine.
334 @param [in] ImageHandle Handle for the image.
336 @retval EFI_SUCCESS Image may be unloaded
342 IN EFI_HANDLE ImageHandle
348 EFI_HANDLE
* pHandle
;
352 // Determine which devices are using this driver
356 Status
= gBS
->LocateHandle (
362 if ( EFI_BUFFER_TOO_SMALL
== Status
) {
365 // One or more block IO devices are present
367 Status
= gBS
->AllocatePool (
368 EfiRuntimeServicesData
,
372 if ( EFI_ERROR ( Status
)) {
373 DEBUG (( DEBUG_ERROR
| DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
374 "Insufficient memory, failed handle buffer allocation\r\n" ));
379 // Locate the block IO devices
381 Status
= gBS
->LocateHandle (
387 if ( EFI_ERROR ( Status
)) {
389 // Error getting handles
391 DEBUG (( DEBUG_ERROR
| DEBUG_INIT
| DEBUG_INFO
,
392 "Failure getting Telnet handles\r\n" ));
397 // Remove any use of the driver
399 Max
= BufferSize
/ sizeof ( pHandle
[ 0 ]);
400 for ( Index
= 0; Max
> Index
; Index
++ ) {
401 Status
= DriverStop ( &gDriverBinding
,
405 if ( EFI_ERROR ( Status
)) {
406 DEBUG (( DEBUG_WARN
| DEBUG_INIT
| DEBUG_INFO
,
407 "WARNING - Failed to shutdown the driver on handle %08x\r\n", pHandle
[ Index
]));
415 if ( EFI_NOT_FOUND
== Status
) {
417 // No devices were found
419 Status
= EFI_SUCCESS
;
424 // Free the handle array
426 if ( NULL
!= pHandle
) {
427 gBS
->FreePool ( pHandle
);
431 // Remove the protocols installed by the EntryPoint routine.
433 if ( !EFI_ERROR ( Status
)) {
434 gBS
->UninstallMultipleProtocolInterfaces (
436 &gEfiDriverBindingProtocolGuid
,
438 &gEfiComponentNameProtocolGuid
,
440 &gEfiComponentName2ProtocolGuid
,
444 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
445 "Removed: gEfiComponentName2ProtocolGuid from 0x%08x\r\n",
447 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
448 "Removed: gEfiComponentNameProtocolGuid from 0x%08x\r\n",
450 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
451 "Removed: gEfiDriverBindingProtocolGuid from 0x%08x\r\n",
456 // Return the unload status
463 Ax88772 driver entry point.
465 @param [in] ImageHandle Handle for the image.
466 @param [in] pSystemTable Address of the system table.
468 @retval EFI_SUCCESS Image successfully loaded.
474 IN EFI_HANDLE ImageHandle
,
475 IN EFI_SYSTEM_TABLE
* pSystemTable
483 // Add the driver to the list of drivers
485 Status
= EfiLibInstallDriverBindingComponentName2 (
493 ASSERT_EFI_ERROR (Status
);
494 if ( !EFI_ERROR ( Status
)) {
495 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
496 "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
498 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
499 "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
501 DEBUG (( DEBUG_POOL
| DEBUG_INIT
| DEBUG_INFO
,
502 "Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
505 DBG_EXIT_STATUS ( Status
);