summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Bus/Usb
diff options
context:
space:
mode:
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2009-12-16 00:58:46 +0000
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2009-12-16 00:58:46 +0000
commitefe9186f09a22146361c01d3121c72b1a591f50a (patch)
treee4e6d61899f435396da59b861107eec75e5ad848 /MdeModulePkg/Bus/Usb
parent7748eb28e121e7193205eb646909b80b1438f5d7 (diff)
downloadedk2-platforms-efe9186f09a22146361c01d3121c72b1a591f50a.tar.xz
add error handling on usb related modules.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9566 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Bus/Usb')
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c5
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c18
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c20
-rw-r--r--MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c14
-rw-r--r--MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c7
-rw-r--r--MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c7
6 files changed, 55 insertions, 16 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index b2f5fdbc75..a72faac201 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -849,7 +849,8 @@ UsbIoPortReset (
Address = Dev->Address;
Dev->Address = 0;
Status = UsbSetAddress (Dev, Address);
- Dev->Address = Address;
+
+ gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);
if (EFI_ERROR (Status)) {
DEBUG (( EFI_D_ERROR, "UsbIoPortReset: failed to set address for device %d - %r\n",
@@ -858,7 +859,7 @@ UsbIoPortReset (
goto ON_EXIT;
}
- gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);
+ Dev->Address = Address;
DEBUG (( EFI_D_INFO, "UsbIoPortReset: device is now ADDRESSED at %d\n", Address));
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
index c1908cf14a..191312bbb3 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
@@ -42,7 +42,12 @@ UsbFreeInterfaceDesc (
}
}
- FreePool (Setting->Endpoints);
+ //
+ // Only call FreePool() if NumEndpoints > 0.
+ //
+ if (Setting->Desc.NumEndpoints > 0) {
+ FreePool (Setting->Endpoints);
+ }
}
FreePool (Setting);
@@ -192,10 +197,13 @@ UsbCreateDesc (
return NULL;
}
- Desc = AllocateCopyPool(CtrlLen, Head);
+ Desc = AllocateZeroPool (CtrlLen);
if (Desc == NULL) {
return NULL;
}
+
+ CopyMem (Desc, Head, DescLen);
+
*Consumed = Offset + Head->Len;
return Desc;
@@ -344,7 +352,11 @@ UsbParseConfigDesc (
DescBuf += Consumed;
Len -= Consumed;
- while (Len > 0) {
+ //
+ // Make allowances for devices that return extra data at the
+ // end of their config descriptors
+ //
+ while (Len >= sizeof (EFI_USB_INTERFACE_DESCRIPTOR)) {
Setting = UsbParseInterfaceDesc (DescBuf, Len, &Consumed);
if ((Setting == NULL)) {
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
index 40f9a5633a..9636d4f2bc 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
@@ -802,7 +802,7 @@ InitUSBKeyboard (
IN OUT USB_KB_DEV *UsbKeyboardDevice
)
{
- UINT8 ConfigValue;
+ UINT16 ConfigValue;
UINT8 Protocol;
UINT8 ReportId;
UINT8 Duration;
@@ -818,12 +818,24 @@ InitUSBKeyboard (
InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));
//
- // Uses default configuration to configure the USB keyboard device.
+ // Use the config out of the descriptor
+ // Assumed the first config is the correct one and this is not always the case
+ //
+ Status = UsbGetConfiguration (
+ UsbKeyboardDevice->UsbIo,
+ &ConfigValue,
+ &TransferResult
+ );
+ if (EFI_ERROR (Status)) {
+ ConfigValue = 0x01;
+ }
+
+ //
+ // Uses default configuration to configure the USB Keyboard device.
//
- ConfigValue = 0x01;
Status = UsbSetConfiguration (
UsbKeyboardDevice->UsbIo,
- (UINT16) ConfigValue,
+ ConfigValue,
&TransferResult
);
if (EFI_ERROR (Status)) {
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
index 013b7e2cc3..cc6f2e8cee 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
@@ -235,11 +235,11 @@ UsbBootExecCmdWithRetry (
{
EFI_STATUS Status;
UINTN Retry;
+ UINT8 Terminate;
Status = EFI_SUCCESS;
- for (Retry = 0; Retry < USB_BOOT_COMMAND_RETRY; Retry++) {
-
+ for (Retry = 0, Terminate = 0; Retry < USB_BOOT_COMMAND_RETRY; Retry++) {
Status = UsbBootExecCmd (
UsbMass,
Cmd,
@@ -255,8 +255,9 @@ UsbBootExecCmdWithRetry (
//
// If the device isn't ready, just wait for it without limit on retrial times.
//
- if (Status == EFI_NOT_READY) {
+ if (Status == EFI_NOT_READY && Terminate < 3) {
Retry = 0;
+ Terminate++;
}
}
@@ -410,7 +411,10 @@ UsbBootReadCapacity (
BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.BlockLen));
if (BlockSize == 0) {
- return EFI_NOT_READY;
+ //
+ // Get sense data
+ //
+ return UsbBootRequestSense (UsbMass);
} else {
Media->BlockSize = BlockSize;
}
@@ -418,7 +422,7 @@ UsbBootReadCapacity (
DEBUG ((EFI_D_INFO, "UsbBootReadCapacity Success LBA=%ld BlockSize=%d\n",
Media->LastBlock, Media->BlockSize));
- return EFI_SUCCESS;
+ return Status;
}
/**
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
index ab669463c8..fe1aefe682 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
@@ -273,9 +273,16 @@ UsbBotDataTransfer (
);
if (EFI_ERROR (Status)) {
if (USB_IS_ERROR (Result, EFI_USB_ERR_STALL)) {
+ DEBUG ((EFI_D_INFO, "UsbBotDataTransfer: (%r)\n", Status));
+ DEBUG ((EFI_D_INFO, "UsbBotDataTransfer: DataIn Stall\n"));
UsbClearEndpointStall (UsbBot->UsbIo, Endpoint->EndpointAddress);
} else if (USB_IS_ERROR (Result, EFI_USB_ERR_NAK)) {
Status = EFI_NOT_READY;
+ } else {
+ DEBUG ((EFI_D_ERROR, "UsbBotDataTransfer: (%r)\n", Status));
+ }
+ if(Status == EFI_TIMEOUT){
+ UsbBotResetDevice(UsbBot, FALSE);
}
}
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c
index 4de18d4bb9..39176c166c 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c
@@ -457,6 +457,7 @@ UsbCbiExecCommand (
//
Status = UsbCbiSendCommand (UsbCbi, Cmd, CmdLen, Timeout);
if (EFI_ERROR (Status)) {
+ gBS->Stall(10 * USB_MASS_1_MILLISECOND);
DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiSendCommand (%r)\n",Status));
return Status;
}
@@ -486,10 +487,12 @@ UsbCbiExecCommand (
//
// For UFI device, ASC and ASCQ are returned.
//
- if (Result.Type != 0) {
+ // Do not set the USB_MASS_CMD_FAIL for a request sense command
+ // as a bad result type doesn't mean a cmd failure
+ //
+ if (Result.Type != 0 && *(UINT8*)Cmd != 0x03) {
*CmdStatus = USB_MASS_CMD_FAIL;
}
-
} else {
//
// Check page 27, CBI spec 1.1 for vaious reture status.