From 1c61953576f35507eb24032fe2804eaf9a0e976c Mon Sep 17 00:00:00 2001 From: vanjeff Date: Wed, 13 Feb 2008 09:08:24 +0000 Subject: 1. Added EFI_MEDIA_CHANGED and EFI_INVALID_PARAMETER returns in UsbMassReadBlocks(). 2. Use DEBUG () to replace some native debug function in USB stack modules. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4689 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h | 4 +- .../Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 20 ++--- .../Bus/Usb/UsbMassStorageDxe/UsbMassBot.c | 27 +++---- .../Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c | 9 +-- .../Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c | 85 ++++++++++++++-------- 5 files changed, 79 insertions(+), 66 deletions(-) (limited to 'MdeModulePkg/Bus/Usb') diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h index 3e7c700510..fe3f8b9e68 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h @@ -62,7 +62,7 @@ enum { USB_MASS_STORE_RBC = 0x01, // Reduced Block Commands USB_MASS_STORE_8020I = 0x02, // SFF-8020i, typically a CD/DVD device USB_MASS_STORE_QIC = 0x03, // Typically a tape device - USB_MASS_STORE_UFI = 0x04, // Typically a floopy disk driver device + USB_MASS_STORE_UFI = 0x04, // Typically a floppy disk driver device USB_MASS_STORE_8070I = 0x05, // SFF-8070i, typically a floppy disk driver device. USB_MASS_STORE_SCSI = 0x06, // SCSI transparent command set @@ -138,6 +138,4 @@ UsbClearEndpointStall ( IN UINT8 EndpointAddress ); -extern UINTN mUsbMscInfo; -extern UINTN mUsbMscError; #endif diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c index 1299059c07..8dd7ada7d6 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c @@ -167,7 +167,7 @@ UsbBootRequestSense ( &CmdResult ); if (EFI_ERROR (Status) || CmdResult != USB_MASS_CMD_SUCCESS) { - DEBUG ((mUsbMscError, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult)); + DEBUG ((EFI_D_ERROR, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult)); return Status; } @@ -225,7 +225,7 @@ UsbBootRequestSense ( break; } - DEBUG ((mUsbMscInfo, "UsbBootRequestSense: (%r) with sense key %x/%x/%x\n", + DEBUG ((EFI_D_INFO, "UsbBootRequestSense: (%r) with sense key %x/%x/%x\n", Status, USB_BOOT_SENSE_KEY (SenseData.SenseKey), SenseData.ASC, @@ -291,7 +291,7 @@ UsbBootExecCmd ( return EFI_SUCCESS; } - DEBUG ((mUsbMscInfo, "UsbBootExecCmd: Fail to Exec 0x%x Cmd /w %r\n", + DEBUG ((EFI_D_INFO, "UsbBootExecCmd: Fail to Exec 0x%x Cmd /w %r\n", *(UINT8 *)Cmd ,Status)); return UsbBootRequestSense (UsbMass); @@ -349,7 +349,7 @@ UsbBootExecCmdWithRetry ( DataDir, Data, DataLen, - Timeout * (Index + 1) + Timeout ); if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED) { @@ -513,7 +513,7 @@ UsbBootReadCapacity ( return EFI_NOT_READY; } - DEBUG ((mUsbMscInfo, "UsbBootReadCapacity Success LBA=%ld BlockSize=%d\n", + DEBUG ((EFI_D_INFO, "UsbBootReadCapacity Success LBA=%ld BlockSize=%d\n", Media->LastBlock, Media->BlockSize)); return EFI_SUCCESS; @@ -603,7 +603,7 @@ UsbBootGetParams ( Status = UsbBootInquiry (UsbMass); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbBootGetParams: UsbBootInquiry (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBootGetParams: UsbBootInquiry (%r)\n", Status)); return Status; } @@ -670,7 +670,7 @@ UsbBootDetectMedia ( Status = UsbBootIsUnitReady (UsbMass); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbBootDetectMedia: UsbBootIsUnitReady (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: UsbBootIsUnitReady (%r)\n", Status)); goto ON_ERROR; } @@ -687,7 +687,7 @@ UsbBootDetectMedia ( Status = UsbBootReadCapacity (UsbMass); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status)); goto ON_ERROR; } @@ -709,7 +709,7 @@ ON_ERROR: (Media->LastBlock != OldMedia.LastBlock)) { OldTpl = UsbGetCurrentTpl (); - DEBUG ((mUsbMscError, "UsbBootDetectMedia: TPL before reinstall BlockIoProtocol is %d\n", OldTpl)); + DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: TPL before reinstall BlockIoProtocol is %d\n", OldTpl)); gBS->RestoreTPL (TPL_CALLBACK); @@ -720,7 +720,7 @@ ON_ERROR: &UsbMass->BlockIo ); - DEBUG ((mUsbMscError, "UsbBootDetectMedia: TPL after reinstall is %d\n", UsbGetCurrentTpl())); + DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: TPL after reinstall is %d\n", UsbGetCurrentTpl())); ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); gBS->RaiseTPL (OldTpl); diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c index 3f4d0fc4d3..3277fa9932 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c @@ -25,9 +25,6 @@ Revision History #include "UsbMass.h" #include "UsbMassBot.h" -UINTN mUsbBotInfo = DEBUG_INFO; -UINTN mUsbBotError = DEBUG_ERROR; - STATIC EFI_STATUS UsbBotResetDevice ( @@ -83,7 +80,7 @@ UsbBotInit ( Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &UsbBot->Interface); if (EFI_ERROR (Status)) { - DEBUG ((mUsbBotError, "UsbBotInit: Get invalid BOT interface (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBotInit: Get invalid BOT interface (%r)\n", Status)); goto ON_ERROR; } @@ -120,7 +117,7 @@ UsbBotInit ( } if ((UsbBot->BulkInEndpoint == NULL) || (UsbBot->BulkOutEndpoint == NULL)) { - DEBUG ((mUsbBotError, "UsbBotInit: In/Out Endpoint invalid\n")); + DEBUG ((EFI_D_ERROR, "UsbBotInit: In/Out Endpoint invalid\n")); Status = EFI_UNSUPPORTED; goto ON_ERROR; } @@ -277,9 +274,9 @@ UsbBotDataTransfer ( &Result ); if (EFI_ERROR (Status)) { - DEBUG ((mUsbBotError, "UsbBotDataTransfer: (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBotDataTransfer: (%r)\n", Status)); if (USB_IS_ERROR (Result, EFI_USB_ERR_STALL)) { - DEBUG ((mUsbBotError, "UsbBotDataTransfer: DataIn Stall\n")); + DEBUG ((EFI_D_ERROR, "UsbBotDataTransfer: DataIn Stall\n")); UsbClearEndpointStall (UsbBot->UsbIo, Endpoint->EndpointAddress); } else if (USB_IS_ERROR (Result, EFI_USB_ERR_NAK)) { Status = EFI_NOT_READY; @@ -323,7 +320,7 @@ UsbBotGetStatus ( EFI_USB_IO_PROTOCOL *UsbIo; UINT32 Index; UINTN Timeout; - + *CmdStatus = USB_BOT_COMMAND_ERROR; Status = EFI_DEVICE_ERROR; Endpoint = UsbBot->BulkInEndpoint->EndpointAddress; @@ -346,9 +343,9 @@ UsbBotGetStatus ( &Result ); if (EFI_ERROR(Status)) { - DEBUG ((mUsbBotError, "UsbBotGetStatus (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBotGetStatus (%r)\n", Status)); if (USB_IS_ERROR (Result, EFI_USB_ERR_STALL)) { - DEBUG ((mUsbBotError, "UsbBotGetStatus: DataIn Stall\n")); + DEBUG ((EFI_D_ERROR, "UsbBotGetStatus: DataIn Stall\n")); UsbClearEndpointStall (UsbIo, Endpoint); } continue; @@ -358,13 +355,13 @@ UsbBotGetStatus ( // // Invalid Csw need perform reset recovery // - DEBUG ((mUsbBotError, "UsbBotGetStatus: Device return a invalid signature\n")); + DEBUG ((EFI_D_ERROR, "UsbBotGetStatus: Device return a invalid signature\n")); Status = UsbBotResetDevice (UsbBot, FALSE); } else if (Csw.CmdStatus == USB_BOT_COMMAND_ERROR) { // // Respond phase error need perform reset recovery // - DEBUG ((mUsbBotError, "UsbBotGetStatus: Device return a phase error\n")); + DEBUG ((EFI_D_ERROR, "UsbBotGetStatus: Device return a phase error\n")); Status = UsbBotResetDevice (UsbBot, FALSE); } else { @@ -426,7 +423,7 @@ UsbBotExecCommand ( // Status = UsbBotSendCommand (UsbBot, Cmd, CmdLen, DataDir, DataLen); if (EFI_ERROR (Status)) { - DEBUG ((mUsbBotError, "UsbBotExecCommand: UsbBotSendCommand (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotSendCommand (%r)\n", Status)); return Status; } @@ -443,7 +440,7 @@ UsbBotExecCommand ( // Status = UsbBotGetStatus (UsbBot, DataLen, &Result); if (EFI_ERROR (Status)) { - DEBUG ((mUsbBotError, "UsbBotExecCommand: UsbBotGetStatus (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotGetStatus (%r)\n", Status)); return Status; } @@ -512,7 +509,7 @@ UsbBotResetDevice ( ); if (EFI_ERROR (Status)) { - DEBUG ((mUsbBotError, "UsbBotResetDevice: (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbBotResetDevice: (%r)\n", Status)); return Status; } diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c index 016235055b..a46a9a3843 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c @@ -27,9 +27,6 @@ Revision History #include "UsbMass.h" #include "UsbMassCbi.h" -UINTN mUsbCbiInfo = DEBUG_INFO; -UINTN mUsbCbiError = DEBUG_ERROR; - STATIC EFI_STATUS UsbCbiResetDevice ( @@ -450,7 +447,7 @@ UsbCbiExecCommand ( // Status = UsbCbiSendCommand (UsbCbi, Cmd, CmdLen, Timeout); if (EFI_ERROR (Status)) { - DEBUG ((mUsbCbiError, "UsbCbiExecCommand: UsbCbiSendCommand (%r)\n",Status)); + DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiSendCommand (%r)\n",Status)); return Status; } @@ -462,7 +459,7 @@ UsbCbiExecCommand ( Status = UsbCbiDataTransfer (UsbCbi, DataDir, Data, &TransLen, Timeout); if (UsbCbi->InterruptEndpoint == NULL) { - DEBUG ((mUsbCbiError, "UsbCbiExecCommand: UsbCbiDataTransfer (%r)\n",Status)); + DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiDataTransfer (%r)\n",Status)); return Status; } @@ -471,7 +468,7 @@ UsbCbiExecCommand ( // Status = UsbCbiGetStatus (UsbCbi, Timeout, &Result); if (EFI_ERROR (Status)) { - DEBUG ((mUsbCbiError, "UsbCbiExecCommand: UsbCbiGetStatus (%r)\n",Status)); + DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiGetStatus (%r)\n",Status)); return EFI_DEVICE_ERROR; } diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c index f077e2aaad..71ccfa9d10 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c @@ -40,10 +40,6 @@ USB_MASS_TRANSPORT *mUsbMassTransport[] = { NULL }; -UINTN mUsbMscInfo = DEBUG_INFO; -UINTN mUsbMscError = DEBUG_ERROR; - - /** Retrieve the media parameters such as disk gemotric for the device's BLOCK IO protocol. @@ -84,6 +80,7 @@ UsbMassInitMedia ( Media->ReadOnly = FALSE; Media->WriteCaching = FALSE; Media->IoAlign = 0; + Media->MediaId = 1; // // Some device may spend several seconds before it is ready. @@ -102,7 +99,7 @@ UsbMassInitMedia ( Status = UsbBootIsUnitReady (UsbMass); if (EFI_ERROR (Status)) { - gBS->Stall (USB_BOOT_RETRY_UNIT_READY_STALL * (Index + 1)); + gBS->Stall (USB_BOOT_RETRY_UNIT_READY_STALL * (Index + 1)); } } @@ -122,6 +119,7 @@ UsbMassInitMedia ( **/ EFI_STATUS +EFIAPI UsbMassReset ( IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification @@ -162,6 +160,7 @@ UsbMassReset ( **/ EFI_STATUS +EFIAPI UsbMassReadBlocks ( IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, @@ -175,7 +174,7 @@ UsbMassReadBlocks ( EFI_STATUS Status; EFI_TPL OldTpl; UINTN TotalBlock; - + OldTpl = gBS->RaiseTPL (USB_MASS_TPL); UsbMass = USB_MASS_DEVICE_FROM_BLOCKIO (This); Media = &UsbMass->BlockIoMedia; @@ -187,21 +186,21 @@ UsbMassReadBlocks ( Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - + // // If it is a removable media, such as CD-Rom or Usb-Floppy, - // need to detect the media before each rw. While some of + // need to detect the media before each rw. While some of // Usb-Flash is marked as removable media. - // - // + // + // if (Media->RemovableMedia == TRUE) { Status = UsbBootDetectMedia (UsbMass); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbMassReadBlocks: UsbBootDetectMedia (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootDetectMedia (%r)\n", Status)); goto ON_EXIT; - } + } } - + // // Make sure BlockSize and LBA is consistent with BufferSize // @@ -213,13 +212,23 @@ UsbMassReadBlocks ( TotalBlock = BufferSize / Media->BlockSize; if (Lba + TotalBlock - 1 > Media->LastBlock) { - Status = EFI_BAD_BUFFER_SIZE; + Status = EFI_INVALID_PARAMETER; + goto ON_EXIT; + } + + if (!(Media->MediaPresent)) { + Status = EFI_NO_MEDIA; + goto ON_EXIT; + } + + if (MediaId != Media->MediaId) { + Status = EFI_MEDIA_CHANGED; goto ON_EXIT; } - + Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status)); UsbMassReset (This, TRUE); } @@ -249,6 +258,7 @@ ON_EXIT: **/ EFI_STATUS +EFIAPI UsbMassWriteBlocks ( IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, @@ -274,21 +284,21 @@ UsbMassWriteBlocks ( Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - + // // If it is a removable media, such as CD-Rom or Usb-Floppy, - // need to detect the media before each rw. While some of + // need to detect the media before each rw. While some of // Usb-Flash is marked as removable media. - // - // + // + // if (Media->RemovableMedia == TRUE) { Status = UsbBootDetectMedia (UsbMass); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbMassWriteBlocks: UsbBootDetectMedia (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbMassWriteBlocks: UsbBootDetectMedia (%r)\n", Status)); goto ON_EXIT; - } + } } - + // // Make sure BlockSize and LBA is consistent with BufferSize // @@ -300,20 +310,30 @@ UsbMassWriteBlocks ( TotalBlock = BufferSize / Media->BlockSize; if (Lba + TotalBlock - 1 > Media->LastBlock) { - Status = EFI_BAD_BUFFER_SIZE; + Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - + + if (!(Media->MediaPresent)) { + Status = EFI_NO_MEDIA; + goto ON_EXIT; + } + + if (MediaId != Media->MediaId) { + Status = EFI_MEDIA_CHANGED; + goto ON_EXIT; + } + // // Try to write the data even the device is marked as ReadOnly, // and clear the status should the write succeed. // Status = UsbBootWriteBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status)); UsbMassReset (This, TRUE); } - + ON_EXIT: gBS->RestoreTPL (OldTpl); return Status; @@ -330,6 +350,7 @@ ON_EXIT: **/ EFI_STATUS +EFIAPI UsbMassFlushBlocks ( IN EFI_BLOCK_IO_PROTOCOL *This ) @@ -402,7 +423,7 @@ USBMassDriverBindingSupported ( } } - DEBUG ((mUsbMscInfo, "Found a USB mass store device %r\n", Status)); + DEBUG ((EFI_D_INFO, "Found a USB mass store device %r\n", Status)); ON_EXIT: gBS->CloseProtocol ( @@ -467,7 +488,7 @@ USBMassDriverBindingStart ( // Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface); if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "USBMassDriverBindingStart: UsbIo->UsbGetInterfaceDescriptor (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbIo->UsbGetInterfaceDescriptor (%r)\n", Status)); goto ON_ERROR; } @@ -484,7 +505,7 @@ USBMassDriverBindingStart ( } if (EFI_ERROR (Status)) { - DEBUG ((mUsbMscError, "USBMassDriverBindingStart: Transport->Init (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: Transport->Init (%r)\n", Status)); goto ON_ERROR; } @@ -508,11 +529,11 @@ USBMassDriverBindingStart ( (UsbMass->Pdt != USB_PDT_CDROM) && (UsbMass->Pdt != USB_PDT_OPTICAL) && (UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) { - DEBUG ((mUsbMscError, "USBMassDriverBindingStart: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt)); + DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt)); goto ON_ERROR; } } else if (Status != EFI_NO_MEDIA){ - DEBUG ((mUsbMscError, "USBMassDriverBindingStart: UsbMassInitMedia (%r)\n", Status)); + DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMedia (%r)\n", Status)); goto ON_ERROR; } -- cgit v1.2.3