goto CLOSE_HC;\r
}\r
\r
+ UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
+ UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
+\r
+ //\r
+ // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
+ //\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Controller,\r
+ &mUsbBusProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &UsbBus->BusId\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to install bus protocol %r\n", Status));\r
+ goto CLOSE_HC;\r
+ }\r
+\r
//\r
// Create a fake usb device for root hub\r
//\r
\r
if (RootHub == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
- goto CLOSE_HC;\r
+ goto UNINSTALL_USBBUS;\r
}\r
\r
RootIf = AllocateZeroPool (sizeof (USB_INTERFACE));\r
if (RootIf == NULL) {\r
gBS->FreePool (RootHub);\r
Status = EFI_OUT_OF_RESOURCES;\r
- goto CLOSE_HC;\r
+ goto FREE_ROOTHUB;\r
}\r
\r
RootHub->Bus = UsbBus;\r
RootIf->Signature = USB_INTERFACE_SIGNATURE;\r
RootIf->Device = RootHub;\r
RootIf->DevicePath = UsbBus->DevicePath;\r
-\r
\r
- UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
- UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
-\r
Status = mUsbRootHubApi.Init (RootIf);\r
\r
if (EFI_ERROR (Status)) {\r
\r
UsbBus->Devices[0] = RootHub;\r
\r
- //\r
- // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
- //\r
- Status = gBS->InstallProtocolInterface (\r
- &Controller,\r
- &mUsbBusProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- &UsbBus->BusId\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to install bus protocol %r\n", Status));\r
-\r
- mUsbRootHubApi.Release (RootIf);\r
- goto FREE_ROOTHUB;\r
- }\r
-\r
-\r
DEBUG (( EFI_D_INFO, "UsbBusStart: usb bus started on %x, root hub %x\n", Controller, RootIf));\r
return EFI_SUCCESS;\r
-\r
+ \r
FREE_ROOTHUB:\r
- gBS->FreePool (RootIf);\r
- gBS->FreePool (RootHub);\r
-\r
+ if (RootIf != NULL) {\r
+ gBS->FreePool (RootIf);\r
+ }\r
+ if (RootHub != NULL) {\r
+ gBS->FreePool (RootHub);\r
+ }\r
+ \r
+UNINSTALL_USBBUS:\r
+ gBS->UninstallProtocolInterface (Controller, &mUsbBusProtocolGuid, &UsbBus->BusId);\r
+ \r
CLOSE_HC:\r
if (UsbBus->Usb2Hc != NULL) {\r
gBS->CloseProtocol (\r
Controller\r
);\r
}\r
-\r
if (UsbBus->UsbHc != NULL) {\r
gBS->CloseProtocol (\r
Controller,\r
Controller\r
);\r
}\r
-\r
gBS->CloseProtocol (\r
Controller,\r
&gEfiDevicePathProtocolGuid,\r
This->DriverBindingHandle,\r
Controller\r
);\r
-\r
gBS->FreePool (UsbBus);\r
\r
DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to start bus driver %r\n", Status));\r