STATIC VOID UsbDisconnectDriver ( IN USB_INTERFACE *UsbIf ) /*++ Routine Description: Disconnect the USB interface with its driver. Arguments: UsbIf - The interface to disconnect driver from Returns: None --*/ { EFI_TPL OldTpl; // // Release the hub if it's a hub controller, otherwise // disconnect the driver if it is managed by other drivers. // if (UsbIf->IsHub) { UsbIf->HubApi->Release (UsbIf); } else if (UsbIf->IsManaged) { // // This function is called in both UsbIoControlTransfer and // the timer callback in hub enumeration. So, at least it is // called at EFI_TPL_CALLBACK. Some driver sitting on USB has // twisted TPL used. It should be no problem for us to connect // or disconnect at CALLBACK. // OldTpl = UsbGetCurrentTpl (); USB_DEBUG (("UsbDisconnectDriver: old TPL is %d\n", OldTpl)); gBS->RestoreTPL (EFI_TPL_CALLBACK); gBS->DisconnectController (UsbIf->Handle, NULL, NULL); UsbIf->IsManaged = FALSE; USB_DEBUG (("UsbDisconnectDriver: TPL after disconnect is %d\n", UsbGetCurrentTpl())); ASSERT (UsbGetCurrentTpl () == EFI_TPL_CALLBACK); gBS->RaiseTPL (OldTpl); } }
/** Connect the USB interface with its driver. EFI USB bus will create a USB interface for each separate interface descriptor. @param UsbIf The interface to connect driver to. @return EFI_SUCCESS Interface is managed by some driver. @return Others Failed to locate a driver for this interface. **/ EFI_STATUS UsbConnectDriver ( IN USB_INTERFACE *UsbIf ) { EFI_STATUS Status; EFI_TPL OldTpl; Status = EFI_SUCCESS; // // Hub is maintained by the USB bus driver. Otherwise try to // connect drivers with this interface // if (UsbIsHubInterface (UsbIf)) { // DEBUG ((EFI_D_INFO, "UsbConnectDriver: found a hub device\n")); DBG("UsbConnectDriver: found a hub device\n"); Status = mUsbHubApi.Init (UsbIf); } else { // // This function is called in both UsbIoControlTransfer and // the timer callback in hub enumeration. So, at least it is // called at TPL_CALLBACK. Some driver sitting on USB has // twisted TPL used. It should be no problem for us to connect // or disconnect at CALLBACK. // // // Only recursively wanted usb child device // if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) { OldTpl = UsbGetCurrentTpl (); // DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle)); DBG("UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle); gBS->RestoreTPL (TPL_CALLBACK); Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE); UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status); // DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", (UINT32)UsbGetCurrentTpl())); // ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); DBG("UsbConnectDriver: TPL after connect is %d\n", (UINT32)UsbGetCurrentTpl()); gBS->RaiseTPL (OldTpl); } } return Status; }
/** Disconnect the USB interface with its driver. @param UsbIf The interface to disconnect driver from. **/ EFI_STATUS UsbDisconnectDriver ( IN USB_INTERFACE *UsbIf ) { EFI_TPL OldTpl; EFI_STATUS Status; // // Release the hub if it's a hub controller, otherwise // disconnect the driver if it is managed by other drivers. // DBG("disconnect usb driver\n"); Status = EFI_SUCCESS; if (UsbIf->IsHub) { Status = UsbIf->HubApi->Release (UsbIf); } else if (UsbIf->IsManaged) { // // This function is called in both UsbIoControlTransfer and // the timer callback in hub enumeration. So, at least it is // called at TPL_CALLBACK. Some driver sitting on USB has // twisted TPL used. It should be no problem for us to connect // or disconnect at CALLBACK. // OldTpl = UsbGetCurrentTpl (); // DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle)); DBG("UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle); gBS->RestoreTPL (TPL_CALLBACK); Status = gBS->DisconnectController (UsbIf->Handle, NULL, NULL); if (!EFI_ERROR (Status)) { UsbIf->IsManaged = FALSE; } // DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status)); // ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); DBG("UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status); gBS->RaiseTPL (OldTpl); } return Status; }
STATIC EFI_STATUS UsbConnectDriver ( IN USB_INTERFACE *UsbIf ) /*++ Routine Description: Connect the USB interface with its driver. EFI USB bus will create a USB interface for each seperate interface descriptor. Arguments: UsbIf - The interface to connect driver to Returns: EFI_SUCCESS : Interface is managed by some driver Others : Failed to locate a driver for this interface --*/ { EFI_STATUS Status; EFI_TPL OldTpl; Status = EFI_SUCCESS; // // Hub is maintained by the USB bus driver. Otherwise try to // connect drivers with this interface // if (UsbIsHubInterface (UsbIf)) { USB_DEBUG (("UsbConnectDriver: found a hub device\n")); Status = mUsbHubApi.Init (UsbIf); } else { // // This function is called in both UsbIoControlTransfer and // the timer callback in hub enumeration. So, at least it is // called at EFI_TPL_CALLBACK. Some driver sitting on USB has // twisted TPL used. It should be no problem for us to connect // or disconnect at CALLBACK. // // // Only recursively wanted usb child device // if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) { OldTpl = UsbGetCurrentTpl (); USB_DEBUG (("UsbConnectDriver: TPL before connect is %d\n", OldTpl)); gBS->RestoreTPL (EFI_TPL_CALLBACK); Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE); UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status); USB_DEBUG (("UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl())); ASSERT (UsbGetCurrentTpl () == EFI_TPL_CALLBACK); gBS->RaiseTPL (OldTpl); } } return Status; }